//数组初始化
procedure tloginfrm.init_inv(chandler:string;dvouchdate:String);
var strsql,cinvcode:string;
inum:real;
i:integer;
tmp:inv_unit;
begin
// 把计划信息存入动态数组中
strsql:='select cinvcode,iQuantity as inum from plan where cpercode='''+chandler+'''';
with dm do
begin
if ADOQ_cinit_inv_num.active then ADOQ_cinit_inv_num.active:=false;
ADOQ_cinit_inv_num.sql.Clear;
ADOQ_cinit_inv_num.sql.add(strsql);
ADOQ_cinit_inv_num.open;
while not ADOQ_cinit_inv_num.eof do
begin
cinvcode:=trim(ADOQ_cinit_inv_num.FieldByName('cinvcode').Asstring);
inum:=ADOQ_cinit_inv_num.FieldByName('inum').asfloat;
add_sel_inv(cinvcode,inum,0); //增加过程
ADOQ_cinit_inv_num.next;
end;
ADOQ_cinit_inv_num.Close;
//把预订信息存入数组中
strsql:='select cinvcode,sum(iQuantity) as inum from Tmp_Rdrecord as rds join Tmp_Rdrecords as rd on rd.irdid=rds.irdid ';
strsql:=strsql+' where date(dvouchdate)='''+yw_date+''' and ';
strsql:=strsql+' chandler='''+chandler+''' and (cInvalider IS NULL) group by cinvcode ';
if adoq_cinv.active then adoq_cinv.Close;
Adoq_cinv.sql.Clear;
Adoq_cinv.sql.add(strsql);
Adoq_cinv.Active:=TRUE;
while not adoq_cinv.eof do
begin
cinvcode:=trim(ADOQ_cinv.FieldByName('cinvcode').Asstring);
inum:=ADOQ_cinv.FieldByName('inum').asfloat;
i:=f_sel_id(cinvcode);
if i=-1 then
begin //add inv_unit
{tmp.cinvcode:=cinvcode;
tmp.inv_plan:=-1;
tmp.inv_sum:=inum;
setlength(SEL_INV,Length(SEL_INV)+1);
SEL_INV[Length(SEL_INV)-1]:=tmp; }
add_sel_inv(cinvcode,-1,inum);
end
else
SEL_INV[I].inv_sum:=inum; // end of if i=-1
adoq_cinv.next;
end; //end of while
adoq_cinv.Close;
end; // end of with dm do
//查找函数
function Tloginfrm.F_sel_id(cinvcode:string):integer ;
var
i:integer;
begin
for i:=0 to length(SEL_INV)-1 DO
begin
if cinvcode=sel_inv[i].cinvcode then
begin
f_sel_id:=i;
exit;
end;
end;
f_sel_id:=-1; //没有找到
end ;
///增加
procedure Tloginfrm.add_sel_inv(cincode:string;inv_plan:real;inv_sum:real);
var
i:integer;
tmp:inv_unit;
begin
tmp.cinvcode:=cincode;
tmp.inv_plan:=inv_plan;
tmp.inv_sum:=inv_sum;
setlength(SEL_INV,Length(SEL_INV)+1);
SEL_INV[Length(SEL_INV)-1]:=tmp;
END;