BMS-HOSxP Community
HOSxP => Delphi / Pascal => ข้อความที่เริ่มโดย: dusit ที่ ตุลาคม 06, 2009, 11:38:29 AM
-
ผมใช้ dbf CDS และ mysQlCDS เพื่อย้ายข้อมูลจาก dbfCDS ไปลง CDSMySQl
DBGrid แสดงถูกต้องครับ Append ได้ หน้าปก
แต่ ไม่พบข้อมูลใน Mysql ครับ
รบกวนถามว่าผมทำผิดตรงไหนครับ
procedure TFormDcpan2SQL.Button1Click(Sender: TObject);
begin
sqlCDS.Delete; // ลบของเดิมทิ้งหมดเลย
dbfCDS.First; // เริ่มต้น Reccord
while not DBFCDS.Eof do // loop DBF
begin
sqlCDS.Append; // สร้าง Record และถ่ายโอน
sqlCDS.FieldByName('hhc').AsString:=DBFCDS.FieldByName('hhc').AsString;
sqlCDS.FieldByName('hhcrefer').AsString:=DBFCDS.FieldByName('hhcrefer').AsString;
sqlCDS.FieldByName('hn').AsString:=DBFCDS.FieldByName('hn').AsString;
sqlCDS.FieldByName('an').AsString:=DBFCDS.FieldByName('an').AsString;
sqlCDS.FieldByName('ward').AsString:=DBFCDS.FieldByName('ward').AsString;
sqlCDS.FieldByName('dx').AsString:=DBFCDS.FieldByName('dx').AsString;
sqlCDS.FieldByName('disc').AsString:=DBFCDS.FieldByName('disc').AsString;
sqlCDS.FieldByName('contact_phone').AsString:=DBFCDS.FieldByName('cont_phone').AsString;
sqlCDS.FieldByName('prob_continue').AsString:=DBFCDS.FieldByName('prob_cont').AsString;
DBFCDS.Next; // เลื่อน Rec
end;
if sqlCDS.State in [dsInsert, dsEdit] then
sqlCDS.Post; //
if sqlCDS.ChangeCount > 0 then
sqlCDS.ApplyUpdates(-1); // ตรงนี้ น่าจะ update ลง mysql จริงแล้ว แต่ทำไมไม่เข้าครับ
sqlCDS.SaveToFile('d:\dcplan.cds'); // เลยใส่ไว้ในไฟล์แทนชั่วคราวแก้ขัดไปก่อน แต่อยากให้อัพเดทไปเลย
end;
end.
ขอบคุณครับ
ปล. นอกเรื่อง
========
ไม่พบ ------------ source code hosxp ----- ใน RapidSVN ครับ
OperationDetailEntryU, OperationCostSummaryU, OperationAppointmentU,
-
Unit Script;
function addzero(s:string;i:integer):string;
begin
//result:=s;
while length(s)<i do
begin
s:='0'+s;
end;
result:=s;
end;
function CheckPID(pid: string): boolean;
var
i: integer;
nMod, nValue, cv: integer;
snmod: string;
begin
pid := replacestr(pid, '-', '');
result := false;
if length(replacestr(pid, ' ', '')) <> 13 then
exit;
try
cv := strtoint(copy(pid, 1, 1));
nValue := cv * 13;
for i := 2 to 12 do
begin
cv := strtoint(copy(pid, i, 1));
nValue := nValue + (cv * (14 - i));
end;
nMod := 11 - (nValue mod 11);
snmod := inttostr(nmod);
snmod := copy(snmod, length(snmod), 1);
result := copy(pid, 13, 1) = snmod;
except
result := false;
end;
end;
function MakeFullCID(cid: string): string;
begin
result := cid;
if length(cid) = 17 then
exit;
result := '';
if length(cid) <> 13 then
exit;
result := copy(cid, 1, 1) + '-' +
copy(cid, 2, 4) + '-' +
copy(cid, 6, 5) + '-' +
copy(cid, 11, 2) + '-' +
copy(cid, 13, 1);
end;
Procedure Main;
var
i:integer;
dbf:TDBF;
tc:tclientdataset;
tcid:tclientdataset;
begin
dbf:=tdbf.create(nil);
dbf.tablename:='O:\CSCDMEM.DBF';
dbf.open;
dbf.first;
tc:=tclientdataset.create(nil);
tcid:=tclientdataset.create(nil);
while not dbf.eof do
begin
tc.data:=HoSxP_GetDataset('select * from patient where hn = "'+dbf.fieldbyname('hn').asstring+'"');
if tc.recordcount>0 then
begin
showdebugtext('Update patient : '+tc.fieldbyname('hn').asstring);
tc.edit;
tc.fieldbyname('gov_chronic_id').asstring:=dbf.fieldbyname('memberno').asstring;
tc.fieldbyname('pttype').asstring:= '22';
if checkpid(dbf.fieldbyname('cspid').asstring) then
begin
tc.fieldbyname('cid').asstring:=dbf.fieldbyname('cspid').asstring;
tcid.data:=HOSxP_GetDataset('select * from ptcardno where hn="'+dbf.fieldbyname('hn').asstring+'" and cardtype="01"');
if tcid.recordcount>0 then
begin
tcid.edit;
end else
begin
tcid.insert;
end;
tcid.fieldbyname('hn').asstring:=dbf.fieldbyname('hn').asstring;
tcid.fieldbyname('cardno').asstring:=makefullcid(dbf.fieldbyname('cspid').asstring);
tcid.fieldbyname('cardtype').asstring:='01';
tcid.post;
if tcid.changecount>0 then
HOSxP_UpdateDelta(tcid.delta, 'select * from ptcardno where hn="'+dbf.fieldbyname('hn').asstring+'" and cardtype="01"');
end;
tc.post;
if tc.changecount>0 then
HOSxP_UpdateDelta(tc.delta,'select * from patient where hn = "'+dbf.fieldbyname('hn').asstring+'"');
end;
dbf.next;
end;
dbf.free;
tc.free;
showmessage('done.');
end;
end.