//kt -- Modified with SourceScanner on 8/7/2007
unit fSurgeryView;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ORFN,
  StdCtrls, ExtCtrls, ORCtrls, ComCtrls, ORDtTm, Spin, rSurgery, DKLang;

type
  TfrmSurgeryView = class(TForm)
    pnlBase: TORAutoPanel;
    lblBeginDate: TLabel;
    calBeginDate: TORDateBox;
    lblEndDate: TLabel;
    calEndDate: TORDateBox;
    cmdOK: TButton;
    cmdCancel: TButton;
    lblMaxDocs: TLabel;
    edMaxDocs: TCaptionEdit;
    grpTreeView: TGroupBox;
    lblGroupBy: TOROffsetLabel;
    cboGroupBy: TORComboBox;
    radTreeSort: TRadioGroup;
    cmdClear: TButton;
    DKLanguageController1: TDKLanguageController;
    procedure cmdOKClick(Sender: TObject);
    procedure cmdCancelClick(Sender: TObject);
    procedure cmdClearClick(Sender: TObject);
  private
    FChanged: Boolean;
    FBeginDate: string;
    FFMBeginDate: TFMDateTime;
    FEndDate: string;
    FFMEndDate: TFMDateTime;
    FOpProc: string;
    FMaxDocs: integer;
    FGroupBy: string;
    FTreeAscending: Boolean;
    FCurrentContext: TSurgCaseContext;
  end;

function SelectSurgeryView(FontSize: Integer; ShowForm: Boolean; CurrentContext: TSurgCaseContext;
          var SurgeryContext: TSurgCaseContext): boolean ;

implementation

{$R *.DFM}

uses rCore, uCore;

//const
// TX_DATE_ERR = 'Enter valid beginning and ending dates or press Cancel.';  <-- original line.  //kt 8/7/2007
// TX_DATE_ERR_CAP = 'Error in Date Range';  <-- original line.  //kt 8/7/2007

var
  TX_DATE_ERR      : string;  //kt
  TX_DATE_ERR_CAP  : string;  //kt


procedure SetupVars;
//kt Added entire function to replace constant declarations 8/7/2007
begin
   TX_DATE_ERR := DKLangConstW('fSurgeryView_Enter_valid_beginning_and_ending_dates_or_press_Cancelx');
   TX_DATE_ERR_CAP := DKLangConstW('fSurgeryView_Error_in_Date_Range'); 
end;
 
function SelectSurgeryView(FontSize: Integer; ShowForm: Boolean; CurrentContext: TSurgCaseContext;
          var SurgeryContext: TSurgCaseContext): boolean ;
var
  frmSurgeryView: TfrmSurgeryView;
  W, H: Integer;
begin
  frmSurgeryView := TfrmSurgeryView.Create(Application);
  try
    with frmSurgeryView do
    begin
      Font.Size := FontSize;
      W := ClientWidth;
      H := ClientHeight;
      ResizeToFont(FontSize, W, H);
      ClientWidth  := W; pnlBase.Width  := W;
      ClientHeight := H; pnlBase.Height := H;
      FChanged := False;
      FCurrentContext := CurrentContext;
      calBeginDate.Text := CurrentContext.BeginDate;
      calEndDate.Text   := CurrentContext.EndDate;
      if calEndDate.Text = '' then calEndDate.Text := 'TODAY';
      if CurrentContext.MaxDocs > 0 then
        edMaxDocs.Text :=  IntToStr(CurrentContext.MaxDocs)
      else
        edMaxDocs.Text := '';
      FMaxDocs := StrToIntDef(edMaxDocs.Text, 0);
      radTreeSort.ItemIndex := 0;
      cboGroupBy.SelectByID(CurrentContext.GroupBy);
      if ShowForm then ShowModal else cmdOKClick(frmSurgeryView);

      with SurgeryContext do
       begin
        Changed := FChanged;
        OpProc := FOpProc;
        BeginDate := FBeginDate;
        FMBeginDate := FFMBeginDate;
        EndDate := FEndDate;
        FMEndDate := FFMEndDate;
        MaxDocs := FMaxDocs;
        GroupBy := FGroupBy;
        TreeAscending := FTreeAscending;
        Result := Changed ;
      end;

    end; {with frmSurgeryView}
  finally
    frmSurgeryView.Release;
  end;
end;

procedure TfrmSurgeryView.cmdOKClick(Sender: TObject);
var
  bdate, edate: TFMDateTime;
begin
  SetupVars;  //kt added 8/7/2007 to replace constants with vars.
  if calBeginDate.Text <> '' then
     bdate := StrToFMDateTime(calBeginDate.Text)
  else
     bdate := 0 ;

  if calEndDate.Text <> '' then
     edate   := StrToFMDateTime(calEndDate.Text)
  else
     edate := 0 ;

  if (bdate <= edate) then
    begin
      FBeginDate := calBeginDate.Text;
      FFMBeginDate := bdate;
      FEndDate := calEndDate.Text;
      FFMEndDate := edate;
    end
  else
    begin
      InfoBox(TX_DATE_ERR, TX_DATE_ERR_CAP, MB_OK or MB_ICONWARNING);
      Exit;
    end;

  FTreeAscending := (radTreeSort.ItemIndex = 0);
  FMaxDocs := StrToIntDef(edMaxDocs.Text, 0);
  if cboGroupBy.ItemID <> '' then
    FGroupBy := cboGroupBy.ItemID
  else
    FGroupBy := '';
  FChanged := True;
  Close;
end;

procedure TfrmSurgeryView.cmdCancelClick(Sender: TObject);
begin
  FChanged := False;
  Close;
end;

procedure TfrmSurgeryView.cmdClearClick(Sender: TObject);
begin
  cboGroupBy.ItemIndex := -1;
  radTreeSort.ItemIndex := 0;
end;

end.
