unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBClient, Grids, DBGrids, ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
DBGrid1: TDBGrid;
cds: TClientDataSet;
ds: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
cxDateEdit1: TcxDateEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var tc, pt: tclientdataset; s: string;
begin
cds.data := hosxp_getdataset('select hn,count(*) as cardno_count from ptcardno where cardtype="01" and cardno not like"" group by hn');
tc := tclientdataset.create(nil);
pt := tclientdataset.create(nil);
cds.first;
while not cds.eof do
begin
tc.data := HOSxP_GetDataset('select cardno from ptcardno where hn = "' + cds.fieldbyname('hn').asstring + '" and cardtype="01" and cardno not like"" ');
s := '';
while not tc.eof do
begin
if s = '' then s := tc.fieldbyname('cardno').asstring else
s := s + ':' + tc.fieldbyname('cardno').asstring;
tc.next;
end;
if trim(s) <> '' then
begin
pt.data := HOSxP_Getdataset('select * from patient where hn = "' + cds.fieldbyname('hn').asstring + '"');
if pt.recordcount > 0 then
begin
pt.edit;
pt.fieldbyname('cid').asstring := replacestr(s,'-','');
pt.post;
if pt.changecount > 0 then
begin
showdebugtext('Update CID hn : '+cds.fieldbyname('hn').asstring+' -- > Old CID = '+pt.fieldbyname('cid').asstring+'-----> NEW CID = '+replacestr(s,'-',''));
hosxp_updatedelta(pt.delta, 'select * from patient where hn = "' + cds.fieldbyname('hn').asstring + '"');
end;
end;
end;
cds.next;
end;
tc.free;
pt.free;
showmessage('Update Done.');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
fcds.data := cds.data;
ExportDatasetToExcel('test.xls');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
fcds.data := cds.data;
CreateDatasetReport('HOSxP Report');
end;
end.