procedure TForm1.Button8Click(Sender: TObject);
var tc,hos:tclientdataset;
address : string;
shn:string;
addrcode:string;
reli : Integer;
begin
dbf1.close;
dbf1.tablename:=ConnectStringEdit.text+'\person.dbf'; //+'\opd\opd.dbf'
dbf1.open;
zquery.sql.text:='delete from person_for18pcu ';
zquery.execsql;
pg.position:=0;
pg.max:=dbf1.RecordCount;
fabort:=false;
tc:=tclientdataset.create(nil);
hos:=tclientdataset.create(nil);
while (not dbf1.eof) and (not fabort) do
begin
pg.position := pg.position + 1;
//shn := TransformHN(dbf1.fieldbyname('HN').asstring);
shn := dbf1.fieldbyname('CID').asstring;
statuslabel.caption := shn ;
application.processmessages;
tc.data:=hosxp_getdataset('select p2.cid as p2cid,p3.cid as p3cid,p4.cid as p4cid,p.* from person p '+
'left outer join person p2 on p2.person_id=p.father_person_id '+
'left outer join person p3 on p3.person_id=p.mother_person_id '+
'left outer join person p4 on p4.person_id=p.couple_person_id '+
'where p.person_id='''+ dbf1.fieldbyname('PID').asstring+'''');
hos.data:=hosxp_getdataset( 'select * from person_for18pcu where CID = ''' + shn + '''');
//if hos.recordcount = 0 then
// hos.insert else hos.edit;
hos.insert;
statuslabel.caption := shn;
//if trim(vartostr(hos['hos_guid'])) = '' then
// hos['hos_guid'] := get_new_guid;
hos['PCUCODE'] := shn;
hos['CID'] := dbf1['CID'];
hos['PID'] := dbf1['PID'];
hos['HID'] := dbf1['HID'];
try
hos['PRENAME'] := dbf1['PRENAME'];
hos['NAME'] := dbf1['NAME'];
hos['LNAME'] := dbf1['LNAME'];
hos['HN'] := dbf1['HN'];
hos['SEX'] := dbf1['SEX'];
hos['BIRTH'] := dbf1['BIRTH'];
hos['HOUSE'] := dbf1['HOUSE'];
hos['VILLAGE'] := dbf1['VILLAGE'];
hos['TAMBON'] := dbf1['TAMBON'];
hos['AMPUR'] := dbf1['AMPUR'];
hos['CHANGWAT']:= dbf1['CHANGWAT'];
hos['MSTATUS'] := dbf1['MSTATUS'];
hos['OCCUPA'] := dbf1['OCCUPA'];
hos['RACE'] := '0'+dbf1['RACE'];
hos['NATION'] := '0'+dbf1['RACE'];// no NATION
hos['RELIGION']:= IntTostr(tc['religion']);
hos['EDUCATE'] := dbf1['EDUCATE'];
hos['FSTATUS'] := dbf1['FSTATUS'];
hos['FATHER'] := tc['p2cid'];
hos['MOTHER'] := tc['p3cid'];
hos['COUPLE'] := tc['p4cid'];
hos['MOVEIN'] := dbf1['MOVEIN'];
hos['DISCHAR'] := dbf1['DISCHAR'];
hos['DDISCH'] := dbf1['DDISCH'];
hos['BGROUP'] := dbf1['BGROUP'];
hos['LABOR'] := dbf1['LABOR'];
hos['VHID'] := dbf1['VHID'];
hos['TYPEAREA']:= dbf1['TYPEAREA'];
hos['D_UPDATE']:= dbf1['D_UPDATE'];
except
end;
try
//tc.post;
hos.post;
except
on e: exception do
begin
memo1.lines.add(
formatdatetime('hh:nn:ss', now) + ' ' +
e.message);
hos.cancel;
end;
end;
if hos.changecount>0 then hosxp_updatedelta(hos.delta,
'select * from person_for18pcu where CID = ''' + shn + '''');
tc.close;
hos.close;
application.processmessages;
dbf1.next;
end;
showmessage('Import table home_for18pcu àÊÃç¨áÅéÇ !');
tc.free;
hos.free;
dbf1.close;
// fcds.data := cds.data;
// CreateDatasetReport('HOSxP Report');
//fcds.data := cds.data;
//ExportDatasetToExcel('test.xls');
// showmessage('done.');
end;