⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urefund.pas

📁 DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    totalacc:=totalacc+strtofloat(stringgrid2.Cells[5,i]);
  end;
  if totalacc <> 0 then
  edit4.Text:=floattostr(totalacc);
  if edit4.Text = '' then
  begin
    showmessage('商品总进价不能为空');
    exit;
  end;
  adoquery1.Close;
  sprovide:=copy(combobox2.Text,1,5);
  adoquery2.SQL.Text:='select filid from filiale where filname = '''+combobox3.Text+'''';
  adoquery2.Open;
  sfiliale:=adoquery2.Fields[0].AsString;
  adoquery2.Close;
  for i:=1 to stringgrid2.RowCount-1 do
  begin
    adoquery3.SQL.Text:='select prid,busanum from busary where filid = '''+sfiliale+''' and prid = '''+stringgrid2.Cells[1,i]+'''';
    adoquery3.Open;
    if adoquery3.RecordCount = 0 then
    begin
      showmessage('本分店没有编号为'+stringgrid2.Cells[1,i]+'的商品');
      adoquery3.Close;
      exit;
    end
    else begin
      if adoquery3.FieldByName('busanum').AsFloat < strtofloat(stringgrid2.Cells[3,i]) then
      begin
        showmessage('本分店编号为'+stringgrid2.Cells[1,i]+'的商品库存不够');
        adoquery3.Close;
        exit;
      end;
    end;
  end;
  try
    adoquery1.Connection.BeginTrans;
    adoquery1.SQL.Text:='insert into refund values("'+edit2.Text+'","'+sprovide+'",'
    +'"'+datetostr(dtpicker3.Date)+'","'+sfiliale+'","'+edit3.Text+'","'+edit4.Text+'")';
    adoquery2.Connection.BeginTrans;
    for i:=1 to stringgrid2.RowCount-1 do
    begin
      adoquery2.SQL.Text:='insert into refund1 values("'+edit2.Text+'","'+stringgrid2.Cells[1,i]+'",'
      +'"'+stringgrid2.Cells[3,i]+'","'+stringgrid2.Cells[4,i]+'")';
      adoquery2.ExecSQL;
      adoquery3.SQL.Text:='update busary set busanum = busanum - '
      +stringgrid2.Cells[3,i]+' where filid = '''+sfiliale+''' and prid '
      +'= '''+stringgrid2.Cells[1,i]+'''';
      adoquery3.ExecSQL;
      adoquery3.Close;
    end;
    adoquery1.ExecSQL;
    adoquery2.Connection.CommitTrans;
    adoquery1.Connection.CommitTrans;
    adoquery2.Close;
    adoquery1.Close;
    showmessage('保存成功!');
    edit1.Enabled:=true;combobox1.Enabled:=true;
    dtpicker1.Enabled:=true;dtpicker2.Enabled:=true;
    edit2.Enabled:=false;
    edit3.Enabled:=false;
    combobox2.Enabled:=false;
    combobox3.Enabled:=false;
    dtpicker3.Enabled:=false;
    speedbutton1.Enabled:=true;
    speedbutton2.Enabled:=true;
    speedbutton5.Enabled:=false;
    speedbutton6.Enabled:=false;
    speedbutton7.Enabled:=true;
    speedbutton9.Enabled:=true;
  except
    adoquery2.Connection.RollbackTrans;
    adoquery1.Connection.RollbackTrans;
    adoquery2.Close;
    adoquery1.Close;
  end;
end;

procedure Tfrmrefund.SpeedButton6Click(Sender: TObject);
var
  i:integer;
begin
  edit1.Enabled:=true;
  combobox1.Enabled:=true;
  dtpicker1.Enabled:=true;
  dtpicker2.Enabled:=true;
  edit2.Enabled:=false; edit2.Text:='';
  edit3.Enabled:=false; edit3.Text:='';
  edit4.Text:='';
  combobox2.Enabled:=false; combobox2.ItemIndex:=-1;
  combobox3.Enabled:=false; combobox3.ItemIndex:=-1;
  dtpicker3.Enabled:=false;
  speedbutton1.Enabled:=true;
  speedbutton2.Enabled:=true;
  speedbutton5.Enabled:=false;
  speedbutton6.Enabled:=false;
  speedbutton7.Enabled:=true;
  speedbutton9.Enabled:=true;
  for i:=1 to stringgrid2.RowCount-1 do
  stringgrid2.Rows[i].Clear;
  stringgrid2.RowCount:=2;
  stringgrid2.Options:=stringgrid2.Options-[goediting];
end;

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

procedure Tfrmrefund.StringGrid1Click(Sender: TObject);
var
  i:integer;
begin
  if ((stringgrid1.Row > 0) and (stringgrid1.Cells[1,1] <> '')) then
  begin
    for i:=1 to stringgrid2.RowCount-1 do
      stringgrid2.Rows[i].Clear;
    stringgrid2.RowCount:=2;
    stringgrid1.Cols[0].Clear;
    stringgrid1.Cells[0,stringgrid1.Row]:='*';
    edit2.Text:=stringgrid1.Cells[1,stringgrid1.Row];
    for i:=0 to combobox2.Items.Count-1 do
      if copy(combobox2.Items.Strings[i],1,5) = stringgrid1.Cells[2,stringgrid1.Row] then
      begin
        combobox2.ItemIndex:=i;
        break;
      end;
    dtpicker3.Date:=strtodatetime(stringgrid1.Cells[3,stringgrid1.row]);
    adoquery1.SQL.Text:='select handleman,filid,accounts from refund where refid = '''+edit2.Text+'''';
    adoquery1.Open;
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
    adoquery2.Open;
    for i:=0 to combobox3.Items.Count-1 do
      if combobox3.Items.Strings[i] = adoquery2.Fields[0].AsString then
      begin
        combobox3.ItemIndex:=i;
        break;
      end;
    adoquery2.Close;
    edit3.Text:=adoquery1.FieldValues['handleman'];
    edit4.Text:=adoquery1.FieldValues['accounts'];
    adoquery1.Close;
    adoquery1.SQL.Text:='select refund1.prid,pluinfo.prname,refund1.refunum,'+
    ' refund1.refuprice from refund1 inner join pluinfo on refund1.prid = pluinfo.prid'+
    ' where refid = '''+edit2.Text+'''';
    adoquery1.Open;
    if adoquery1.RecordCount > 0 then
    begin
      stringgrid2.RowCount:=adoquery1.RecordCount+1;
      for i:=1 to stringgrid2.RowCount-1 do
      begin
        stringgrid2.Cells[1,i]:=adoquery1.FieldValues['prid'];
        stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
        stringgrid2.Cells[3,i]:=adoquery1.FieldValues['refunum'];
        stringgrid2.Cells[4,i]:=adoquery1.FieldValues['refuprice'];
        stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
        adoquery1.Next;
      end;
    end;
    adoquery1.Close;
  end;
end;

procedure Tfrmrefund.StringGrid2SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  arect:trect;
begin
  if ((acol = 3) or (acol = 4)) then
  begin
    if speedbutton5.Enabled then
    stringgrid2.Options:=stringgrid2.Options+[goediting];
  end
  else
    stringgrid2.Options:=stringgrid2.Options-[goediting];
  if speedbutton5.Enabled then
  begin
    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 Tfrmrefund.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 Tfrmrefund.StringGrid2KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  acol,arow:integer;
begin
  acol:=stringgrid2.Col; arow:=stringgrid2.row;
  if (acol = 4) then
  begin
    if (stringgrid2.Cells[4,arow] <> '') then
    begin
      if stringgrid2.Cells[3,arow] = '' then
      begin
        showmessage('请输入商品数量');
        stringgrid2.Cells[4,arow]:= '';
        stringgrid2.col:=3;
        exit;
      end
      else
      stringgrid2.Cells[5,arow]:=floattostr(strtofloat(stringgrid2.Cells[3,arow]) * strtofloat(stringgrid2.Cells[4,arow]));
    end
    else
      stringgrid2.Cells[5,arow]:='';
  end;
  if ((acol = 3) and (stringgrid2.Cells[4,arow] <> '')) then
  begin
    stringgrid2.Cells[5,arow]:=floattostr(strtofloat(stringgrid2.Cells[3,arow]) * strtofloat(stringgrid2.Cells[4,arow]));
  end;
end;

procedure Tfrmrefund.StringGrid2Exit(Sender: TObject);
var
  totalacc:real;
  i:integer;
begin
  totalacc:=0;
  for i:=1 to stringgrid2.RowCount-1 do
    if stringgrid2.Cells[5,i] <> '' then
    totalacc:=totalacc+strtofloat(stringgrid2.Cells[5,i]);
  if totalacc <> 0 then
  edit4.Text:=floattostr(totalacc);
end;

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

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

procedure Tfrmrefund.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 Tfrmrefund.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 Tfrmrefund.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if not speedbutton9.Enabled then
  begin
    canclose:=false;
    showmessage('请先保存数据然后退出');
  end;
end;

procedure Tfrmrefund.SpeedButton7Click(Sender: TObject);
begin
  if stringgrid2.cells[1,1] <> '' then
  begin
    adoquery1.SQL.Text:='select refund1.prid ,pluinfo.prname,refund1.refunum,'
    +'refund1.refuprice from refund1 inner join pluinfo on refund1.prid = '
    +'pluinfo.prid where refund1.refid = '''+edit2.Text+'''';
    adoquery2.SQL.Text:='select refund.refid,refund.refudate,refund.handleman,'
    +'filiale.filname,provinfo.provname from (refund inner join filiale on '
    +'refund.filid = filiale.filid) inner join provinfo on refund.provid = '
    +'provinfo.provid where refund.refid = '''+edit2.Text+'''';
    rvproject1.Execute;
    rvproject1.Close;
  end
  else
  showmessage('请先查询要打印的数据!');
end;

end.

⌨️ 快捷键说明

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