Unit Yindee;
procedure main;
var
fan,pageno:String;
a,b,c,i:integer;
begin
fan:=report_value(1);
//ShowMessage(fan);
zquery.close;
zquery.sql.text:='CREATE TABLE IF NOT EXISTS `yindee_ipd_profile_print` ( '+
' `med_plan_number` int(11) DEFAULT "0", '+
'`an` varchar(9) DEFAULT NULL, '+
'`doctor` varchar(7) DEFAULT NULL, '+
'`icode` varchar(7) DEFAULT NULL, '+
'`qty` int(11) DEFAULT NULL, '+
'`offdate` date DEFAULT NULL, '+
'`orderdate` date DEFAULT NULL, '+
'`orderstatus` varchar(5) DEFAULT NULL, '+
'`drugusage` varchar(7) DEFAULT NULL, '+
'`sp_use` varchar(7) DEFAULT NULL, '+
'`frequency` int(11) DEFAULT NULL, '+
'`name` varchar(250) DEFAULT NULL, '+
'`shortlist` varchar(250) DEFAULT NULL, '+
'`d1` int(11) DEFAULT NULL, '+
'`d2` int(11) DEFAULT NULL, '+
'`d3` int(11) DEFAULT NULL, '+
'`d4` int(11) DEFAULT NULL, '+
'`d5` int(11) DEFAULT NULL, '+
'`d6` int(11) DEFAULT NULL, '+
'`d7` int(11) DEFAULT NULL, '+
'`d8` int(11) DEFAULT NULL, '+
'`d9` int(11) DEFAULT NULL, '+
'`d10` int(11) DEFAULT NULL, '+
'`d11` int(11) DEFAULT NULL, '+
'`d12` int(11) DEFAULT NULL, '+
'`d13` int(11) DEFAULT NULL, '+
'`d14` int(11) DEFAULT NULL, '+
'`number` int(11) DEFAULT NULL, '+
'`icode_type` char(3) DEFAULT NULL, '+
'`return_qty` int(11) DEFAULT NULL, '+
'`vorder` int(11) DEFAULT NULL, '+
'`start_date` date DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=tis620';
zquery.execsql;
zquery.sql.text:='delete from yindee_ipd_profile_print';
zquery.execsql;
zquery.sql.text:='insert into yindee_ipd_profile_print(an,doctor,drugusage,frequency, '+
'icode,icode_type,med_plan_number,name,number,offdate,orderdate,orderstatus, '+
'qty,return_qty,shortlist,sp_use,start_date,vorder,d1,d2,d3,d4,d5,d6,d7,d8, '+
'd9,d10,d11,d12,d13,d14) '+
'select an,doctor,drugusage,frequency,icode,icode_type,med_plan_number,name,number, '+
'offdate,orderdate,orderstatus,qty,return_qty,shortlist, '+
'sp_use,start_date,vorder,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14 '+
'from ipd_profile_print where an="'+fan+'" ';
zquery.execsql;
fcds2.datarequest('select * from ipd_profile_print where an="'+fan+'" ');
fcds2.open;
//ShowMessage(inttostr(fcds2.recordcount));
fcds.datarequest('select * from yindee_ipd_profile_print');
fcds.open;
Try
b:=strtoint(getsqldata('select max(med_plan_number) as dd from ipd_profile_print where an="'+fan+'" '));
execpt b:=0; end;
//ShowMessage(inttostr(b));
a:=fcds2.recordcount mod 4;
//showmessage(inttostr(a));
pageno:='0';
inputquery('¡Ó˹´¨Ó¹Ç¹Ë¹éÒ·Õèµéͧ¡ÒþÔÁà¾ÔèÁàµÔÁ','¨Ó¹Ç¹Ë¹éÒ·Õè¾ÔÁ¾ìà¾ÔèÁ (ÃкØà»ç¹µÑÇàÅ¢à·èÒ¹Ñé¹)',pageno);
c:=strtoint(pageno);
if a>0 then
begin
for i:=1 to (4-a+(4*c)) do
begin
b:=b+1;
fcds.insert;
fcds['med_plan_number']:=b;
fcds['an']:=fcds2['an'];
fcds['start_date']:=fcds2['start_date'];
fcds['orderstatus']:='S';
fcds.post;
end;
end else
begin
for i:=1 to(4*c) do
begin
b:=b+1;
fcds.insert;
fcds['med_plan_number']:=b;
fcds['an']:=fcds2['an'];
fcds['start_date']:=fcds2['start_date'];
fcds['orderstatus']:='S';
fcds.post;
end;
end;
fcds.datarequest('select * from yindee_ipd_profile_print');
applyupdate_fcds(-1);
fcds2.close;
fcds.close;
zquery.close;
//ShowMessage('Done...');
end;
end.