代码内容是:
计算商品存量,当进货时判断’商品存量库’是否有商品名,如有,在商品数量上添加,如无,添加整条资料
我各种计算商品存量的想法好吗?如各位有不同的想法,请提出,大家讨论一下
  procedure upd(ColNum:integer);
  var
   upe,Ce0,Ce1,Ce2,Ce3:string;
   j,kcl:integer;
   pd:boolean;
   begin
    Ce0:=sg1.Cells[0,ColNum];
    Ce1:=sg1.Cells[1,ColNum];
    Ce2:=sg1.Cells[2,ColNum];
    Ce3:=sg1.Cells[3,ColNum];
   with DataModule1.shpcl do
    begin
     CreateData(DataModule1.shpcl,’select * From 商品存量’,1); //打开数据库
     for j:=1 to RecordCount-1 do
      begin
       if FieldValues[‘编号’]=Ce0 then  //好像不能判断是否相等,应怎么改??
        begin
         kcl:=strtoint(FieldValues['存量'])+strtoint(Ce2);
         pd:=true;
        end
       else
        begin
         kcl:=strtoint(Ce2);
         pd:=false;
        end;
       Next;
      end;
   if pd then
    upe:='update 商品存量='+inttostr(kcl)+' where 编号='+Ce0  //这句出错??
   else
    upe:=format('insert into 商品存量(编号,商品名,存量,统计日期) Values(%s,%s,%s,%s)',
                [Quotedstr(Ce0),Quotedstr(Ce1),inttostr(kcl),Quotedstr(Datetostr(DTP1.Date))]);
       SQL.Clear;
       SQL.Add(upe);
       Prepared;
       ExecSQL;
    end;
   end;try          //这段是’运行’
 for i:=1 to sg1.RowCount-1 do
  upd(i);
Except
 Msgbox('入库失败,再试');
 Exit;