unit OPDTimeCheckU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, se_controls, KsSkinForms, dxCntner, dxEditor, dxExEdtr, dxEdLib,
KsSkinPanels, StdCtrls, Buttons, JvFormPlacement, Provider, DB,
DBClient, ppComm, ppRelatv, ppDB, ppDBPipe, ppBands, ppCache, ppClass,
ppProd, ppReport, ppCtrls, ppPrnabl, JvComponent, ExtCtrls,cxButtons;
type
TOPDTimeCheckForm = class(TForm)
SeSkinPanel1: TSeSkinPanel;
SeSkinPanel2: TSeSkinPanel;
SeSkinButton1: TcxButton;
SeSkinButton2: TcxButton;
SeSkinButton3: TcxButton;
SeSkinForm1: TSeSkinForm;
Label1: TLabel;
HnEdit: TdxEdit;
SpeedButton1: TSpeedButton;
Label4: TLabel;
PtNameEdit: TdxEdit;
VNEdit: TdxEdit;
Label3: TLabel;
AdmDateEdit: TdxEdit;
Label6: TLabel;
DisChargeDateEdit: TdxEdit;
Label5: TLabel;
PtTypeEdit: TdxEdit;
dxTimeEdit1: TdxTimeEdit;
Label2: TLabel;
Label7: TLabel;
dxTimeEdit2: TdxTimeEdit;
Label8: TLabel;
dxTimeEdit3: TdxTimeEdit;
Label9: TLabel;
dxTimeEdit4: TdxTimeEdit;
Label10: TLabel;
dxTimeEdit5: TdxTimeEdit;
Label11: TLabel;
dxTimeEdit6: TdxTimeEdit;
Label12: TLabel;
dxTimeEdit7: TdxTimeEdit;
Label13: TLabel;
dxTimeEdit8: TdxTimeEdit;
Label14: TLabel;
dxTimeEdit9: TdxTimeEdit;
Label15: TLabel;
dxTimeEdit10: TdxTimeEdit;
JvFormStorage1: TJvFormStorage;
SeSkinButton4: TcxButton;
DataSource1: TDataSource;
cds: TClientDataSet;
DataSetProvider1: TDataSetProvider;
ppReport1: TppReport;
ppHeaderBand1: TppHeaderBand;
ppDetailBand1: TppDetailBand;
ppFooterBand1: TppFooterBand;
ppLabel1: TppLabel;
ppLabel2: TppLabel;
ppTitleBand1: TppTitleBand;
ppSummaryBand1: TppSummaryBand;
ppLabel3: TppLabel;
ppLabel4: TppLabel;
ppLabel5: TppLabel;
ppLabel6: TppLabel;
ppLabel7: TppLabel;
ppLabel8: TppLabel;
ppLabel9: TppLabel;
ppLabel10: TppLabel;
ppLabel11: TppLabel;
ppLabel12: TppLabel;
ppLabel13: TppLabel;
ppLabel14: TppLabel;
ppLabel15: TppLabel;
ppLabel16: TppLabel;
ppDBCalc1: TppDBCalc;
ppDBText1: TppDBText;
ppDBPipeline2: TppDBPipeline;
ppDBText2: TppDBText;
ppDBText3: TppDBText;
ppDBText4: TppDBText;
ppDBText5: TppDBText;
ppDBText6: TppDBText;
ppDBText7: TppDBText;
ppDBText8: TppDBText;
ppDBText9: TppDBText;
ppDBText10: TppDBText;
ppDBText11: TppDBText;
ppDBText12: TppDBText;
ppDBText13: TppDBText;
ppLabel17: TppLabel;
ppLabel18: TppLabel;
ppLabel19: TppLabel;
ppLabel20: TppLabel;
ppLabel21: TppLabel;
ppLabel22: TppLabel;
ppLabel23: TppLabel;
ppLabel24: TppLabel;
ppLabel25: TppLabel;
ppLabel26: TppLabel;
Bevel1: TBevel;
Bevel2: TBevel;
Label16: TLabel;
dxTimeEdit11: TdxTimeEdit;
Label17: TLabel;
dxTimeEdit12: TdxTimeEdit;
Label18: TLabel;
Label19: TLabel;
dxTimeEdit13: TdxTimeEdit;
dxTimeEdit14: TdxTimeEdit;
Label20: TLabel;
dxTimeEdit15: TdxTimeEdit;
Label21: TLabel;
dxTimeEdit16: TdxTimeEdit;
Label22: TLabel;
dxTimeEdit17: TdxTimeEdit;
Label23: TLabel;
dxTimeEdit18: TdxTimeEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SpeedButton1Click(Sender: TObject);
procedure HnEditChange(Sender: TObject);
procedure SeSkinButton3Click(Sender: TObject);
procedure SeSkinButton1Click(Sender: TObject);
procedure dxTimeEdit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit3KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit4KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit5KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit6KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit7KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit8KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit9KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure dxTimeEdit10KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SeSkinButton2Click(Sender: TObject);
procedure SeSkinButton4Click(Sender: TObject);
function DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
OPDTimeCheckForm: TOPDTimeCheckForm;
implementation
uses mainu,kskdmu,miscutil, VNSelectU, GetDateRangeInputU,
JvJCLUtils,thaidate;
{$R *.dfm}
procedure TOPDTimeCheckForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TOPDTimeCheckForm.SpeedButton1Click(Sender: TObject);
begin
showpatientfinddialog(hnedit);
end;
procedure TOPDTimeCheckForm.HnEditChange(Sender: TObject);
begin
ptnameedit.clear;
pttypeedit.clear;
admdateedit.clear;
dischargedateedit.clear;
vnedit.clear;
dxtimeedit1.text:='';
dxtimeedit2.text:='';
dxtimeedit3.text:='';
dxtimeedit4.text:='';
dxtimeedit5.text:='';
dxtimeedit6.text:='';
dxtimeedit7.text:='';
dxtimeedit8.text:='';
dxtimeedit9.text:='';
dxtimeedit10.text:='';
dxtimeedit11.text:='';
dxtimeedit12.text:='';
dxtimeedit13.text:='';
dxtimeedit14.text:='';
dxtimeedit15.text:='';
dxtimeedit16.text:='';
dxtimeedit17.text:='';
dxtimeedit18.text:='';
if not validhncode(hnedit.text) then
exit;
application.createform(TVNSelectForm, vnselectform);
try
vnselectform.fhn_ := hnedit.text;
vnselectform.showmodal;
vnedit.text := vnselectform.fvn_;
finally
freeandnil(vnselectform);
end;
if vnedit.text = '' then
exit;
ptnameedit.text :=
vartostr(getsqldata('select concat(pname,fname," ",lname) as ptname from patient where hn="' +
hnedit.text + '"'));
pttypeedit.text := vartostr(getsqldata('select pttype from ovst where vn="' +
vnedit.text + '"'));
pttypeedit.text :=
vartostr(getsqldata('select name from pttype where pttype="' +
pttypeedit.text + '"')) + ' ' +
vartostr(getsqldata('select pttypeno from ovst where vn="' + vnedit.text +
'"'));
admdateedit.text :=
formatdatetime('d mmm ee',
getsqldata('select vstdate from ovst where vn="' +
vnedit.text + '"'));
dischargedateedit.text :=
formatdatetime('hh:nn:ss',
getsqldata('select vsttime from ovst where vn="' +
vnedit.text + '"'));
with kskdm.fcds2 do
begin
close;
datarequest('select * from service_time where vn="'+vnedit.text+'"');
open;
if recordcount>0 then
begin
dxtimeedit1.time:=fieldbyname('service1').asdatetime;
dxtimeedit1.refresh;
dxtimeedit2.time:=fieldbyname('service2').asdatetime;
dxtimeedit2.refresh;
dxtimeedit3.time:=fieldbyname('service3').asdatetime;
dxtimeedit3.refresh;
dxtimeedit4.time:=fieldbyname('service4').asdatetime;
dxtimeedit4.refresh;
dxtimeedit5.time:=fieldbyname('service5').asdatetime;
dxtimeedit5.refresh;
dxtimeedit6.time:=fieldbyname('service6').asdatetime;
dxtimeedit6.refresh;
dxtimeedit7.time:=fieldbyname('service7').asdatetime;
dxtimeedit7.refresh;
dxtimeedit8.time:=fieldbyname('service8').asdatetime;
dxtimeedit8.refresh;
dxtimeedit9.time:=fieldbyname('service9').asdatetime;
dxtimeedit9.refresh;
dxtimeedit10.time:=fieldbyname('service10').asdatetime;
dxtimeedit10.refresh;
dxtimeedit11.time:=fieldbyname('service11').asdatetime;
dxtimeedit11.refresh;
dxtimeedit12.time:=fieldbyname('service12').asdatetime;
dxtimeedit12.refresh;
dxtimeedit13.time:=fieldbyname('service13').asdatetime;
dxtimeedit13.refresh;
dxtimeedit14.time:=fieldbyname('service14').asdatetime;
dxtimeedit14.refresh;
dxtimeedit15.time:=fieldbyname('service15').asdatetime;
dxtimeedit15.refresh;
dxtimeedit16.time:=fieldbyname('service16').asdatetime;
dxtimeedit16.refresh;
dxtimeedit17.time:=fieldbyname('service17').asdatetime;
dxtimeedit17.refresh;
dxtimeedit18.time:=fieldbyname('service18').asdatetime;
dxtimeedit18.refresh;
end;
close;
end;
activecontrol:=dxtimeedit1;
end;
procedure TOPDTimeCheckForm.SeSkinButton3Click(Sender: TObject);
begin
close;
end;
procedure TOPDTimeCheckForm.SeSkinButton1Click(Sender: TObject);
begin
if messagedlg('Please confirm save ?',mtconfirmation,[mbyes,mbno],0)<>mryes then exit;
with kskdm.bcds1 do
begin
close;
datarequest('select * from service_time where vn="'+vnedit.text+'"');
open;
if recordcount>0 then edit else insert;
fieldbyname('vn').asstring:=vnedit.text;
fieldbyname('hn').asstring:=hnedit.text;
fieldbyname('vstdate').asdatetime:=getsqldata('select vstdate from ovst where vn="'+vnedit.text+'"');
fieldbyname('vsttime').asdatetime:=getsqldata('select vsttime from ovst where vn="'+vnedit.text+'"');
fieldbyname('staff').asstring:=flgn;
try fieldbyname('service1').asdatetime:=dxtimeedit1.time; except end;
try fieldbyname('service2').asdatetime:=dxtimeedit2.time; except end;
try fieldbyname('service3').asdatetime:=dxtimeedit3.time; except end;
try fieldbyname('service4').asdatetime:=dxtimeedit4.time; except end;
try fieldbyname('service5').asdatetime:=dxtimeedit5.time; except end;
try fieldbyname('service6').asdatetime:=dxtimeedit6.time; except end;
try fieldbyname('service7').asdatetime:=dxtimeedit7.time; except end;
try fieldbyname('service8').asdatetime:=dxtimeedit8.time; except end;
try fieldbyname('service9').asdatetime:=dxtimeedit9.time; except end;
try fieldbyname('service10').asdatetime:=dxtimeedit10.time; except end;
try fieldbyname('service11').asdatetime:=dxtimeedit11.time; except end;
try fieldbyname('service12').asdatetime:=dxtimeedit12.time; except end;
try fieldbyname('service13').asdatetime:=dxtimeedit13.time; except end;
try fieldbyname('service14').asdatetime:=dxtimeedit14.time; except end;
try fieldbyname('service15').asdatetime:=dxtimeedit15.time; except end;
try fieldbyname('service16').asdatetime:=dxtimeedit16.time; except end;
try fieldbyname('service17').asdatetime:=dxtimeedit17.time; except end;
try fieldbyname('service18').asdatetime:=dxtimeedit18.time; except end;
post;
datarequest('select * from service_time where vn="'+vnedit.text+'"');
applyupdates(-1);
close;
end;
hnedit.clear;
activecontrol:=hnedit;
end;
procedure TOPDTimeCheckForm.dxTimeEdit1KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit2;
end;
procedure TOPDTimeCheckForm.dxTimeEdit2KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit3;
end;
procedure TOPDTimeCheckForm.dxTimeEdit3KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit4;
end;
procedure TOPDTimeCheckForm.dxTimeEdit4KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit5;
end;
procedure TOPDTimeCheckForm.dxTimeEdit5KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit6;
end;
procedure TOPDTimeCheckForm.dxTimeEdit6KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit7;
end;
procedure TOPDTimeCheckForm.dxTimeEdit7KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit8;
end;
procedure TOPDTimeCheckForm.dxTimeEdit8KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit9;
end;
procedure TOPDTimeCheckForm.dxTimeEdit9KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=dxtimeedit10;
end;
procedure TOPDTimeCheckForm.dxTimeEdit10KeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if key=vk_return then activecontrol:=seskinbutton1;
end;
procedure TOPDTimeCheckForm.SeSkinButton2Click(Sender: TObject);
begin
if not validhncode(hnedit.text) then exit;
if messagedlg('Please confirm delete ?',mtconfirmation,[mbyes,mbno],0)<>mryes then exit;
kskdm.fcds.datarequest('EXEC delete from service_time where vn="'+vnedit.text+'"');
hnedit.clear;
activecontrol:=hnedit;
end;
procedure TOPDTimeCheckForm.SeSkinButton4Click(Sender: TObject);
var
s, icd1, icd2: string;
d1, d2: Tdatetime;
i, rec: integer;
function GetDiffServiceTime(i1,i2:integer):real;
begin
try
result:=getsqldata('select avg(service'+inttostr(i2)+'-service'+inttostr(i1)+') as cc '+
' from service_time where vstdate between "'+
formatdatetime('yyyy-mm-dd',d1)+'" and "'+
formatdatetime('yyyy-mm-dd',d2)+'" and service'+inttostr(i2)+'>=service'+inttostr(i1)+' '+
' and service'+inttostr(i2)+' is not null and service'+inttostr(i1)+' is not null '+
' and service'+inttostr(i2)+'<>"00:00:00" and service'+inttostr(i1)+'<>"00:00:00"') / 100;
except
result:=0;
end;
end;
begin
// s := formatthaidate('mm/yy', date);
application.createform(TGetDateRangeInputForm, GetDateRangeinputForm);
with getdaterangeinputform do
begin
dxdateedit1.date := incday(date, -30);
dxdateedit2.date := date;
showmodal;
end;
if getdaterangeinputform.modalresult <> mrok then
begin
freeandnil(getdaterangeinputform);
exit;
end
else
begin
d1 := getdaterangeinputform.dxdateedit1.date;
d2 := getdaterangeinputform.dxdateedit2.date;
freeandnil(getdaterangeinputform);
end;
if d2 < d1 then
raise exception.create('Invalid Date Range')
else
begin
screen.cursor:=crhourglass;
cds.close;
cds.datarequest('select * from service_time where vstdate between "'+
formatdatetime('yyyy-mm-dd',d1)+'" and "'+
formatdatetime('yyyy-mm-dd',d2)+'" order by vn ');
cds.open;
pplabel18.caption:=floattostrf(GetDiffServiceTime(1,2),ffcurrency,10,2);
pplabel19.caption:=floattostrf(GetDiffServiceTime(2,3),ffcurrency,10,2);
pplabel20.caption:=floattostrf(GetDiffServiceTime(3,4),ffcurrency,10,2);
pplabel21.caption:=floattostrf(GetDiffServiceTime(4,5),ffcurrency,10,2);
pplabel22.caption:=floattostrf(GetDiffServiceTime(5,6),ffcurrency,10,2);
pplabel23.caption:=floattostrf(GetDiffServiceTime(6,7),ffcurrency,10,2);
pplabel24.caption:=floattostrf(GetDiffServiceTime(7,8),ffcurrency,10,2);
pplabel25.caption:=floattostrf(GetDiffServiceTime(8,9),ffcurrency,10,2);
pplabel26.caption:=floattostrf(GetDiffServiceTime(9,10),ffcurrency,10,2);
screen.cursor:=crdefault;
pplabel2.caption:=formatdatetime('d mmmm eeee',d1)+' - '+
formatdatetime('d mmmm eeee',d2);
ppreport1.print;
end;
end;
function TOPDTimeCheckForm.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
result:=datasetprovider_datarequest(sender,input);
end;
procedure TOPDTimeCheckForm.FormCreate(Sender: TObject);
begin
attachprovider(tform(sender));
end;
end.