扫码入库脚本(收藏备参考)
时间:2020-10-27 访问量:1158
扫码入库
//////////////////////////////////
var
aBh:array[0..1000] of string;
aSums:array[0..1000] of integer;
count:integer;
ArrayNo:integer;
function SumToArray(sBh:string):integer;
var
bFind:Boolean;
i:integer;
begin
Result:=0;
bFind:=False;
MainFOrm.Caption:=sbh;
for i:=0 to count-1 do
begin
if aBh[i]=sBh then
begin
bFind:=True;
aSums[i]:=aSums[i]+1;
Result:=i;
break;
end;
end;
if not bFind then
begin
aBh[count]:=sBh;
aSums[count]:=aSums[count]+1;
Result:=count;
count:=count+1;
end;
MainFOrm.Caption:=inttostr(aSums[count-1]);
end;
procedure CheckAndUpdateSum(sBh:string;iSum:integer);
begin
DetailTableTADODataSet0.first;
if DetailTableTADODataSet0.Locate('条形码',sBh,loCaseInsensitive) then
begin
if DetailTableTADODataSet0.fieldByName('入库数量').value<>iSum then
begin
DetailTableTADODataSet0.edit;
DetailTableTADODataSet0.fieldByName('入库数量').value:=iSum;
DetailTableTADODataSet0.post;
end;
end
else
begin
DetailTableTADODataSet0.Append;
DetailTableTADODataSet0.fieldByName('条形码').value:=sBh;
DetailTableTADODataSet0.fieldByName('入库数量').value:=iSum;
DetailTableTADODataSet0.post;
end;
end;
///////////////
begin
DetailTableTADODataSet1.First;
while not DetailTableTADODataSet1.eof do
begin
SumToArray(DetailTableTADODataSet1.fieldByName('条形码').value);
DetailTableTADODataSet1.next;
end;
// MainFOrm.Caption:=inttostr(count);
for ArrayNo:=0 to count-1 do
begin
CheckAndUpdateSum(aBh[ArrayNo],aSums[ArrayNo]);
end;
end.
//关键点:函数定义及调用,数组定义及使用,重复判断等