| [459] | 1 | unit fConsultBD;
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | interface
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | uses
 | 
|---|
 | 6 |   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ORFN,
 | 
|---|
 | 7 |   StdCtrls, ExtCtrls, ORCtrls, ORDtTm, uConsults;
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | type
 | 
|---|
 | 10 |   TfrmConsultsByDate = class(TForm)
 | 
|---|
 | 11 |     pnlBase: TORAutoPanel;
 | 
|---|
 | 12 |     lblBeginDate: TLabel;
 | 
|---|
 | 13 |     calBeginDate: TORDateBox;
 | 
|---|
 | 14 |     lblEndDate: TLabel;
 | 
|---|
 | 15 |     calEndDate: TORDateBox;
 | 
|---|
 | 16 |     radSort: TRadioGroup;
 | 
|---|
 | 17 |     cmdOK: TButton;
 | 
|---|
 | 18 |     cmdCancel: TButton;
 | 
|---|
 | 19 |     procedure cmdOKClick(Sender: TObject);
 | 
|---|
 | 20 |     procedure cmdCancelClick(Sender: TObject);
 | 
|---|
 | 21 |     procedure calBeginDateKeyPress(Sender: TObject; var Key: Char);
 | 
|---|
 | 22 |     procedure calEndDateKeyPress(Sender: TObject; var Key: Char);
 | 
|---|
 | 23 |   private
 | 
|---|
 | 24 |     FChanged: Boolean;
 | 
|---|
 | 25 |     FBeginDate: string;
 | 
|---|
 | 26 |     FEndDate: string;
 | 
|---|
 | 27 |     FAscending: Boolean;
 | 
|---|
 | 28 |   end;
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 |   TConsultDateRange = record
 | 
|---|
 | 31 |     Changed: Boolean;
 | 
|---|
 | 32 |     BeginDate: string;
 | 
|---|
 | 33 |     EndDate: string;
 | 
|---|
 | 34 |     Ascending: Boolean;
 | 
|---|
 | 35 |   end;
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | function SelectConsultDateRange(FontSize: Integer; CurrentContext: TSelectContext; var ConsultDateRange: TConsultDateRange): boolean;
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | implementation
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | {$R *.DFM}
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | uses rCore, rConsults;
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | const
 | 
|---|
 | 46 |    TX_DATE_ERR = 'Enter valid beginning and ending dates or press Cancel.';
 | 
|---|
 | 47 |    TX_DATE_ERR_CAP = 'Error in Date Range';
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | function SelectConsultDateRange(FontSize: Integer; CurrentContext: TSelectContext; var ConsultDateRange: TConsultDateRange): boolean;
 | 
|---|
 | 50 | { displays date range select form for progress Consults and returns a record of the selection }
 | 
|---|
 | 51 | var
 | 
|---|
 | 52 |   frmConsultsByDate: TfrmConsultsByDate;
 | 
|---|
 | 53 |   W, H: Integer;
 | 
|---|
 | 54 |   CurrentBegin, CurrentEnd: string;
 | 
|---|
 | 55 | begin
 | 
|---|
 | 56 |   frmConsultsByDate := TfrmConsultsByDate.Create(Application);
 | 
|---|
 | 57 |   try
 | 
|---|
 | 58 |     with frmConsultsByDate do
 | 
|---|
 | 59 |     begin
 | 
|---|
 | 60 |       Font.Size := FontSize;
 | 
|---|
 | 61 |       W := ClientWidth;
 | 
|---|
 | 62 |       H := ClientHeight;
 | 
|---|
 | 63 |       ResizeToFont(FontSize, W, H);
 | 
|---|
 | 64 |       ClientWidth  := W; pnlBase.Width  := W;
 | 
|---|
 | 65 |       ClientHeight := H; pnlBase.Height := H;
 | 
|---|
 | 66 |       FChanged := False;
 | 
|---|
 | 67 |       with radSort do {if SortConsultsAscending then ItemIndex := 0 else} ItemIndex := 1;
 | 
|---|
 | 68 |       CurrentBegin := CurrentContext.BeginDate;
 | 
|---|
 | 69 |       CurrentEnd := CurrentContext.EndDate;
 | 
|---|
 | 70 |       if CurrentBegin <> '' then
 | 
|---|
 | 71 |         calBeginDate.Text := CurrentBegin;
 | 
|---|
 | 72 |       if CurrentEnd <> '' then
 | 
|---|
 | 73 |         calEndDate.Text := CurrentEnd;
 | 
|---|
 | 74 |       if calEndDate.Text = '' then calEndDate.Text := 'TODAY';
 | 
|---|
 | 75 |       ShowModal;
 | 
|---|
 | 76 |       with ConsultDateRange do
 | 
|---|
 | 77 |       begin
 | 
|---|
 | 78 |         Changed := FChanged;
 | 
|---|
 | 79 |         BeginDate := FBeginDate;
 | 
|---|
 | 80 |         EndDate := FEndDate;
 | 
|---|
 | 81 |         Ascending := FAscending;
 | 
|---|
 | 82 |         Result := Changed ;
 | 
|---|
 | 83 |       end; {with ConsultDateRange}
 | 
|---|
 | 84 |     end; {with frmConsultsByDate}
 | 
|---|
 | 85 |   finally
 | 
|---|
 | 86 |     frmConsultsByDate.Release;
 | 
|---|
 | 87 |   end;
 | 
|---|
 | 88 | end;
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | procedure TfrmConsultsByDate.cmdOKClick(Sender: TObject);
 | 
|---|
 | 91 | var
 | 
|---|
 | 92 |   bdate, edate: TFMDateTime;
 | 
|---|
 | 93 | begin
 | 
|---|
 | 94 |   bdate := StrToFMDateTime(calBeginDate.Text);
 | 
|---|
 | 95 |   edate   := StrToFMDateTime(calEndDate.Text);
 | 
|---|
 | 96 |   if ((bdate > 0) and (edate > 0)) and (bdate <= edate) then
 | 
|---|
 | 97 |   begin
 | 
|---|
 | 98 |     FChanged := True;
 | 
|---|
 | 99 |     FBeginDate := calBeginDate.Text;
 | 
|---|
 | 100 |     FEndDate := calEndDate.Text;
 | 
|---|
 | 101 |     FAscending := radSort.ItemIndex = 0;
 | 
|---|
 | 102 |     Close;
 | 
|---|
 | 103 |   end else
 | 
|---|
 | 104 |   begin
 | 
|---|
 | 105 |     InfoBox(TX_DATE_ERR, TX_DATE_ERR_CAP, MB_OK or MB_ICONWARNING);
 | 
|---|
 | 106 |     Exit;
 | 
|---|
 | 107 |   end;
 | 
|---|
 | 108 | end;
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | procedure TfrmConsultsByDate.cmdCancelClick(Sender: TObject);
 | 
|---|
 | 111 | begin
 | 
|---|
 | 112 |   Close;
 | 
|---|
 | 113 | end;
 | 
|---|
 | 114 | 
 | 
|---|
 | 115 | procedure TfrmConsultsByDate.calBeginDateKeyPress(Sender: TObject;
 | 
|---|
 | 116 |   var Key: Char);
 | 
|---|
 | 117 | begin
 | 
|---|
 | 118 |   if (Key = #13) then cmdOKClick(Self);
 | 
|---|
 | 119 | end;
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | procedure TfrmConsultsByDate.calEndDateKeyPress(Sender: TObject;
 | 
|---|
 | 122 |   var Key: Char);
 | 
|---|
 | 123 | begin
 | 
|---|
 | 124 |   if (Key = #13) then cmdOKClick(Self);
 | 
|---|
 | 125 | end;
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | end.
 | 
|---|