uredeploy.~pas

来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 605 行 · 第 1/2 页

~PAS
605
字号
    edit2.Text:=maxid+'0001'
  else
    edit2.Text:=inttostr(strtoint64(adoquery1.FieldValues['maxid'])+1);
  adoquery1.Close;
  for i:=1 to stringgrid2.RowCount-1 do
    stringgrid2.Rows[i].Clear;
  stringgrid2.RowCount:=2;
  stringgrid1.Cols[0].Clear; 
end;

procedure Tfrmredeploy.SpeedButton5Click(Sender: TObject);
var
  i:integer;
  sfilout,sfilin:string;
  totalacc:real;
begin
  if edit2.Text = '' then
  begin
    showmessage('单据编号不能为空');
    exit;
  end;
  if combobox2.Text = '' then
  begin
    showmessage('出库分店不能为空!');
    exit;
  end;
  if combobox3.Text = '' then
  begin
    showmessage('入库分店不能为空');
    exit;
  end;
  if combobox3.Text = combobox2.Text then
  begin
    showmessage('入库分店与出库分店不能相同');
    exit;
  end;
  if edit3.Text = '' then
  begin
    showmessage('经手人不能为空');
    exit;
  end;
  totalacc:=0;
  for i:=1 to stringgrid2.RowCount-1 do
  begin
    if stringgrid2.Cells[1,i] = '' then
    begin
      showmessage('第'+inttostr(i)+'行商品编号不能为空');
      exit;
    end;
    if stringgrid2.Cells[3,i] = '' then
    begin
      showmessage('第'+inttostr(i)+'行商品数量不能为空');
      exit;
    end;
  end;
  adoquery1.SQL.Text:='select filid from filiale where filname = '''+combobox2.Text+'''';
  adoquery1.Open;
  sfilout:=adoquery1.Fields[0].AsString;
  adoquery1.Close;
  adoquery1.SQL.Text:='select filid from filiale where filname = '''+combobox3.Text+'''';
  adoquery1.Open;
  sfilin:=adoquery1.Fields[0].AsString;
  adoquery1.Close;
   for i:=1 to stringgrid2.RowCount-1 do
  begin
    adoquery3.SQL.Text:='select prid,busanum from busary where filid = '''
    +sfilout+''' and prid = '''+stringgrid2.Cells[1,i]+'''';
    adoquery3.Open;
    if adoquery3.RecordCount = 0 then
    begin
      showmessage('分店'''+combobox2.Text+'''没有编号为'+stringgrid2.Cells[1,i]+'的商品');
      adoquery3.Close;
      exit;
    end
    else begin
      if adoquery3.FieldByName('busanum').AsFloat < strtofloat(stringgrid2.Cells[3,i]) then
      begin
        showmessage('分店'''+combobox2.Text+'''编号为'+stringgrid2.Cells[1,i]+'的商品库存不够');
        adoquery3.Close;
        exit;
      end;
    end;
  end;
  adoquery3.Close;
  try
    adoquery1.Connection.BeginTrans;
    adoquery1.SQL.Text:='insert into redeploy values("'+edit2.Text+'","'+sfilout
    +'","'+sfilin+'","'+edit3.Text+'","'+datetostr(dtpicker1.date)+'")';
    adoquery2.Connection.BeginTrans;
    for i:=1 to stringgrid2.RowCount-1 do
    begin
      adoquery2.SQL.Text:='insert into redeploy1 values("'+edit2.Text+'","'
      +stringgrid2.Cells[1,i]+'",'+stringgrid2.Cells[3,i]+')';
      adoquery2.ExecSQL;
      adoquery3.SQL.Text:='update busary set busanum = busanum - '
      +stringgrid2.Cells[3,i]+' where filid = '''+sfilout+''' and prid '
      +'= '''+stringgrid2.Cells[1,i]+'''';
      adoquery3.ExecSQL;
      adoquery3.Close;
      adoquery3.SQL.Text:='select prid,busanum from busary where filid'
      +' = '''+sfilin+''' and prid = '''+stringgrid2.Cells[1,i]+'''';
      adoquery3.Open;
      adoquery3.Edit;
      if adoquery3.RecordCount > 0 then
        adoquery3.Fieldvalues['busanum']:=adoquery3.Fieldvalues['busanum']+strtocurr(stringgrid2.Cells[3,i])
      else begin
        adoquery3.FieldValues['prid']:=stringgrid2.Cells[1,i];
        adoquery3.FieldValues['busanum']:=stringgrid2.Cells[3,i];
        adoquery3.FieldValues['filid']:=sfilin;
      end;
      adoquery3.Post;
    end;
    adoquery3.Close;
    adoquery1.ExecSQL;
    adoquery2.Connection.CommitTrans;
    adoquery1.Connection.CommitTrans;
    adoquery2.Close;
    adoquery1.Close;
    showmessage('保存成功!');
    dtpicker3.Enabled:=false;
    combobox2.ItemIndex:=-1; combobox2.Enabled:=false;
    combobox3.ItemIndex:=-1; combobox3.Enabled:=false;
    edit3.Text:=''; edit3.Enabled:=false;
    edit2.Text:='';
    edit1.Enabled:=true;
    dtpicker1.Enabled:=true;
    dtpicker2.Enabled:=true;
    speedbutton1.Enabled:=true;
    speedbutton2.Enabled:=true;
    speedbutton7.Enabled:=true;
    speedbutton9.Enabled:=true;
    speedbutton5.Enabled:=false;
    speedbutton6.Enabled:=false;
  except
    adoquery2.Connection.RollbackTrans;
    adoquery1.Connection.RollbackTrans;
    adoquery2.Close;
    adoquery1.Close;
    showmessage('数据保存出错,请再试一次!');
  end;
end;

procedure Tfrmredeploy.SpeedButton6Click(Sender: TObject);
begin
   dtpicker3.Enabled:=false;
   combobox2.ItemIndex:=-1; combobox2.Enabled:=false;
   combobox3.ItemIndex:=-1; combobox3.Enabled:=false;
   edit3.Text:=''; edit3.Enabled:=false;
   edit2.Text:='';
   edit1.Enabled:=true;
   dtpicker1.Enabled:=true;
   dtpicker2.Enabled:=true;
   speedbutton1.Enabled:=true;
   speedbutton2.Enabled:=true;
   speedbutton7.Enabled:=true;
   speedbutton9.Enabled:=true;
   speedbutton5.Enabled:=false;
   speedbutton6.Enabled:=false;
   stringgrid2.Options:=stringgrid2.Options-[goediting];
   stringgrid2.Col:=0;
end;

procedure Tfrmredeploy.SpeedButton9Click(Sender: TObject);
begin
  self.Close;
end;

procedure Tfrmredeploy.StringGrid2KeyPress(Sender: TObject; var Key: Char);
var
  i,pnum,acol:integer;
  str:string;
begin
  acol:=stringgrid2.Col;
  if ((not (key in ['0'..'9'])) and (key <> '.') and (key <>#8 ) and (key <>#3)) then
  begin
    showmessage('请输入数字或小数点');
    key:=chr(0);
  end
  else begin
    str:=stringgrid2.Cells[acol,stringgrid2.Row];
    pnum:=0;
    for i:=1 to length(str) do
      if str[i] = '.' then inc(pnum);
    if ((pnum >0) and (key = '.')) then
      key:=chr(0);
  end;
end;

procedure Tfrmredeploy.StringGrid2SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  arect:trect;
begin
  if speedbutton5.Enabled then
  begin
    if (acol = 3) then
      stringgrid2.Options:=stringgrid2.Options+[goediting]
    else
      stringgrid2.Options:=stringgrid2.Options-[goediting];
    if ((acol = 1) or (acol = 2)) then
    begin
      arect:=stringgrid2.CellRect(acol,arow);
      arect.Left:=arect.Left+stringgrid2.Left;
      arect.Top:=arect.Top+stringgrid2.Top;
      dxbuttonedit1.Left:=arect.Left+1;
      dxbuttonedit1.Top:=arect.Top+1;
      dxbuttonedit1.Height:=stringgrid2.RowHeights[arow];
      dxbuttonedit1.Width:=stringgrid2.ColWidths[acol]+1;
      dxbuttonedit1.Visible:=true;
      dxbuttonedit1.Text:=stringgrid2.Cells[acol,arow];
      dxbuttonedit1.SetFocus;
    end;
    if arow <> stringgrid2.RowCount-1 then
    if stringgrid2.Cells[1,stringgrid2.RowCount-1] = '' then
    begin
      stringgrid2.Rows[stringgrid2.RowCount-1].Clear;
      if stringgrid2.RowCount > 2 then
        stringgrid2.RowCount:=stringgrid2.RowCount-1;
    end;
  end;
end;

procedure Tfrmredeploy.dxButtonEdit1Exit(Sender: TObject);
begin
  dxbuttonedit1.Text:='';
  dxbuttonedit1.Visible:=false;
end;

procedure Tfrmredeploy.dxButtonEdit1ButtonClick(Sender: TObject;
  AbsoluteIndex: Integer);
begin
  application.CreateForm(tfrmfilprod,frmfilprod);
  frmfilprod.whosel:='redeploy';
  frmfilprod.ShowModal;
  frmfilprod.Release;
end;

procedure Tfrmredeploy.N1Click(Sender: TObject);
var
  arow:integer;
begin
  if  speedbutton5.Enabled then
  begin
    arow:=stringgrid2.RowCount-1;
    if stringgrid2.Cells[1,arow] <> '' then
      stringgrid2.RowCount:=stringgrid2.RowCount+1;
  end
  else
    showmessage('请先点击添加按钮');
end;

procedure Tfrmredeploy.N2Click(Sender: TObject);
var
  i:integer;
begin
  if speedbutton5.Enabled then
  begin
    if stringgrid2.RowCount > 2 then
    begin
      for i:=stringgrid2.Row to stringgrid2.RowCount-2 do
        stringgrid2.Rows[i]:=stringgrid2.Rows[i+1];
      stringgrid2.rows[stringgrid2.RowCount-1].Clear;
      stringgrid2.RowCount:=stringgrid2.RowCount-1;
    end
    else
      stringgrid2.Rows[1].Clear;
  end
  else
    showmessage('请先点击添加按钮');
end;

procedure Tfrmredeploy.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if not speedbutton9.Enabled then
  begin
    canclose:=false;
    showmessage('请先保存数据然后退出');
  end;
end;

procedure Tfrmredeploy.SpeedButton7Click(Sender: TObject);
begin
  if stringgrid2.Cells[1,1] <> '' then
  begin
    adoquery1.SQL.Text:='select redeploy1.prid,pluinfo.prname,pluinfo.plu,redeploy1.salenum'
    +' from redeploy1 inner join pluinfo on redeploy1.prid = pluinfo.prid where'
    +' redeploy1.redepid = '''+edit2.Text+'''';
    adoquery2.SQL.Text:='select * from redeploy where redepid = '''+edit2.Text+'''';
    adoquery1.Open;
    adoquery2.Open;
    rvproject1.Execute;
    rvproject1.Close;
    adoquery1.Close;
    adoquery2.Close;
  end
  else
    showmessage('请先查找要打印的数据');  
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?