ไม่ครบเนื่องจากว่าคนหนึ่งคนสามารถอยู่หลายคลินิคได้ครับ
เอาอันนี้ไปแทนครับ
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; a:Integer ; d: Word; m: Word; y: Word;
begin
cds.data := hosxp_getdataset('select * from clinicmember where hn is not null and hn <>""');
tc := tclientdataset.create(nil);
pt := tclientdataset.create(nil);
cds.first;
while not cds.eof do
begin
tc.data := HOSxP_GetDataset('select sex,birthday,last_update from patient where hn = "' + cds.fieldbyname('hn').asstring + '"');
s := '';
while not tc.eof do
begin
if s = '' then s := tc.fieldbyname('sex').asstring else
s := tc.fieldbyname('sex').asstring;
// a := datediff(tc.fieldbyname('birthday').asdatetime, tc.fieldbyname('last_update').asdatetime, d, m, y);
a := (now()-tc.fieldbyname('birthday').asdatetime)/365;
tc.next;
end;
if trim(s) <> '' then
begin
pt.data := HOSxP_Getdataset('select * from clinicmember where hn = "' + cds.fieldbyname('hn').asstring + '"');
if pt.recordcount > 0 then
begin
while not pt.eof do
begin
pt.edit;
pt.fieldbyname('sex').asstring := s;
pt.fieldbyname('age_y').asstring := a;
pt.post;
pt.next
end;
if pt.changecount > 0 then
begin
showdebugtext('Update Clinicmember AGE_Y SEX : '+cds.fieldbyname('hn').asstring+' -- > '+s);
hosxp_updatedelta(pt.delta, 'select * from clinicmember 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.