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

📄 xsglxt.pas

📁 用delphi编写的销售管理系统
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  begin
    if JCxmlb = True then
    begin
      For i := 1 to StringGrid1.RowCount-1 do
      begin
        Sum := GroupSL(StringGrid1.Cells[0,i]);
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 库存表 where 商品编号 = :a');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,i]);
          Open;
        end;
        if Sum >Data.ADOQuery1.FieldByName('库存数量').Value then
        begin
          if Isdy = True then
          begin
            Application.MessageBox(Pchar('商品编号为'+ Trim(StringGrid1.Cells[0,i])+'的商品数量大于库存数量,不能完成订单销售。'),'提示',64);
            Exit;
          end
          else
          begin
            Application.MessageBox(Pchar('商品编号为'+ Trim(StringGrid1.Cells[0,i])+'的商品数量大于库存数量,不能完成销售操作。'),'提示',64) ;
            Exit;
          end;
        end;
      end;
      Data.ADOConnection1.BeginTrans;
      Try
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('Insert 销售票号表 Values(:a,:b,:c,:d,:e,:f,Default,:h,:i)');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[7,1]);
          Parameters.ParamByName('b').Value := StrToInt(Label17.Caption);
          Parameters.ParamByName('c').Value := StrToInt(Label18.Caption);
          Parameters.ParamByName('d').Value := StrToFloat(Label19.Caption);
          Parameters.ParamByName('e').Value := Trim(ComboBox2.Text);
          Parameters.ParamByName('f').Value := StrToFloat(Edit2.Text);
          Parameters.ParamByName('h').Value := Trim(Edit4.Text);
          Parameters.ParamByName('i').Value := Trim(Label21.Caption);
          ExecSQL;
        end;
        For i := 1 to StringGrid1.RowCount-1 do
        begin
          with Data.ADOQuery1 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('Insert 销售表 values(:a,:b,:c,:d,:e,:f,:g,:h)');
            Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,1]);
            Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,1]);
            Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[5,1]);
            Parameters.ParamByName('d').Value := Trim(StringGrid1.Cells[6,1]);
            Parameters.ParamByName('e').Value := StrToInt(StringGrid1.Cells[2,i]);
            Parameters.ParamByName('f').Value := StrToFloat(StringGrid1.Cells[3,i]);
            Parameters.ParamByName('g').Value := StrToFloat(StringGrid1.Cells[4,i]);
            Parameters.ParamByName('h').Value := Trim(StringGrid1.Cells[7,1]);
            ExecSQL;
          end;
        end;
        For i := 1 to StringGrid1.RowCount-1 do
        begin
          with Data.ADOQuery2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from 商品基础信息表 where 商品编号 = :a');
            Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,i]);
            Open;
          end;
          jj := Data.ADOQuery2.FieldByName('进价').Value;
          with Data.ADOQuery2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('update 库存表 set 库存数量 = 库存数量 - :a,库存金额 =库存金额 -:b where 商品编号 = :c ');
            Parameters.ParamByName('a').Value := StrToInt(StringGrid1.Cells[2,i]);
            Parameters.ParamByName('b').Value := jj*StrToInt(StringGrid1.Cells[2,i]);
            Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[0,i]);
            ExecSQL;
          end;
        end;
        with Data.ADOQuery2 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 客户结款表 where 客户编号 = :a');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,1]);
          Open;
        end;
        if Data.ADOQuery2.RecordCount <1 then
        begin
          with Data.ADOQuery1 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('Insert 客户结款表 Values (:a ,:b ,:c ,:d,:e,default)');
            Parameters.ParamByName('a').Value :=  Trim(StringGrid1.Cells[5,1]);
            Parameters.ParamByName('b').Value :=  Trim(StringGrid1.Cells[6,1]);
            Parameters.ParamByName('c').Value :=  StrToFloat(Label19.Caption);
            Parameters.ParamByName('d').Value := StrToFloat(Label19.Caption)-StrToFloat(Edit2.Text);
            Parameters.ParamByName('e').Value :=  StrToFloat(Edit2.Text);
            ExecSQL;
          end;
        end
        else
        begin
          with Data.ADOQuery1 do
          begin
            Close;
            SQL.Clear;
            SQL.Add(' update 客户结款表 set 金额小计 = 金额小计 + :a ,欠款记账 = 欠款记账 + :b ,付款合计 = 付款合计 + :c ,结款时间 = Default where 客户编号 = :d');
            Parameters.ParamByName('a').Value :=  StrToFloat(Label19.Caption);
            Parameters.ParamByName('b').Value :=  StrToFloat(Label19.Caption)-StrToFloat(Edit2.Text);
            Parameters.ParamByName('c').Value :=  StrToFloat(Edit2.Text);
            Parameters.ParamByName('d').Value := Trim(StringGrid1.Cells[5,1]);
            ExecSQL;
          end;
        end;
        if isDy = True then
        begin
          With Data.ADOQuery2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('update 订货票号表 set 是否可用 = 1 where 订单号 = :a');
            Parameters.ParamByName('a').Value := ddh;
            ExecSQL;
          end;
          ComboBox3.Clear;
        end;
       Data.ADOConnection1.CommitTrans;
       Application.MessageBox('保存成功。','提示',0+64);
       ComboBox3.Clear;
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 订货票号表 where 是否可用 = 0');
          Open;
        end;
        if Data.ADOQuery1.RecordCount>0 then
        while not Data.ADOQuery1.Eof do
        begin
          ComboBox3.Items.Add(Data.ADOQuery1.FieldByName('订单号').AsString);
          Data.ADOQuery1.Next;
        end;
       Clear;
      Except
        Data.ADOConnection1.RollbackTrans;
        Application.MessageBox('系统出错。','提示',0+64);
        Close;
      end;
   end
   else
   begin
     Application.MessageBox('项目列表有误。','提示',64);
     Exit;
   end;
  end
  else
  begin
    Application.MessageBox('经手人不能为空。','提示',64);
    Edit4.SetFocus;
  end;
end;

procedure TForm24.Edit8Exit(Sender: TObject);
begin
  if Edit8.Text = '' then
  begin
    Application.MessageBox('折扣不能为空。','提示',0+64);
    Edit8.SetFocus;
  end;
  if (StrToFloat(Edit8.Text)>1)or(StrToFloat(Edit8.Text)<0)then
  begin
    Application.MessageBox('折扣不能大于1或小于0。','提示',0+64);
    Edit8.Clear;
    Edit8.SetFocus;
  end;
  try
    StrToFloat(Edit8.Text);
  except
    Application.MessageBox('请输入合法字符。','提示',0+64);
    Edit8.Clear;
    Edit8.SetFocus;
  end;
end;

procedure TForm24.Clear;
var
  r,c: integer;
begin
  ComboBox2.ItemIndex := 0;
  Label3.Caption := '';
  Label16.Caption := '';
  Edit8.Text := '1.0';
  Edit1.ReadOnly := False;
  Edit8.ReadOnly := False;
  Label17.Caption := '0';
  Label18.Caption := '0';
  Label19.Caption := '0.0';
  Edit4.Clear;
  Edit1.Clear;
  Edit2.Clear;
  BitBtn3.SetFocus;
  For r := 1 to StringGrid1.RowCount-1 do
    For c := 0 to StringGrid1.ColCount-1 do
      StringGrid1.Cells[c,r]:='';
  StringGrid1.RowCount  :=2;
  isdy := False;
  ComboBox3.Text := '';
end;

procedure TForm24.BitBtn7Click(Sender: TObject);
begin
  Clear;
  BitBtn3.SetFocus;
end;

procedure TForm24.BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  TBitBtn(Sender).Font.Color := clRed;
end;

procedure TForm24.BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  TBitBtn(Sender).Font.Color := clBlue;
end;

procedure TForm24.Edit8KeyPress(Sender: TObject; var Key: Char);
var
  a: Boolean;
begin
  a := (Key <#8)or(Key >#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
  if a then
    Key := #0;
end;

procedure TForm24.ComboBox3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  a,b: integer;
begin
  if Key = Vk_return then
  begin
    if (Trim(Label16.Caption)='')or(Trim(Label3.Caption)='')then
    begin
      Application.MessageBox('请添加销售票号和销售时间。','提示',0+64);
      Exit;
    end;
    if Trim(ComboBox3.Text)<>''then
      if Application.MessageBox('确实要按订单销售商品吗?','提示',MB_YESNO )= ID_Yes then
      begin
        Edit8.ReadOnly := True;
        Isdy := True;
        ClearForDd;
        ComboBox3.SetFocus;
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 订货票号表 where 订单号 = :a');
          Parameters.ParamByName('a').Value := Trim(ComboBox3.Text);
          Open;
        end;
        ddh := Trim(ComboBox3.Text);
        If Data.ADOQuery1.RecordCount >0 then
        begin
          Label17.Caption := IntToStr(Data.ADOQuery1.FieldByName('品种数').Value);
          Label18.Caption := IntToStr(Data.ADOQuery1.FieldByName('数量').Value);
          Label19.Caption := FloatToStr(Data.ADOQuery1.FieldByName('应付金额').Value)
        end;
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 客户订货表 where 订货票号 = :a');
          Parameters.ParamByName('a').Value := Trim(ComboBox3.Text);
          Open;
        end;
        a:= 1;
        StringGrid1.RowCount := Data.ADOQuery1.RecordCount+1;
        while Not Data.ADOQuery1.Eof do
        begin
          StringGrid1.Cells[0,a]:= Data.ADOQuery1.FieldByName('商品编号').Value;
          StringGrid1.Cells[1,a]:= Data.ADOQuery1.FieldByName('商品名称').Value;
          StringGrid1.Cells[2,a]:= IntToStr(Data.ADOQuery1.FieldByName('数量').Value);
          StringGrid1.Cells[3,a]:= FloatToStr(Data.ADOQuery1.FieldByName('金额').Value);
          StringGrid1.Cells[4,a]:= FloatToStr(Data.ADOQuery1.FieldByName('折扣').Value);
          StringGrid1.Cells[5,a]:= Data.ADOQuery1.FieldByName('客户编号').Value;
          StringGrid1.Cells[6,a]:= Data.ADOQuery1.FieldByName('客户名称').Value;
          StringGrid1.Cells[7,a]:= Label3.Caption;
          StringGrid1.Cells[8,a]:= Label16.Caption;
          Data.ADOQuery1.Next;
          Inc(a);
        end;
        StringGrid1.SetFocus;
      end
      else
        ComboBox3.Text := '';
  end;
end;

procedure TForm24.Edit8KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = VK_return then
  begin
    if Edit8.Text = '' then
  begin
    Application.MessageBox('折扣不能为空。','提示',0+64);
    Edit8.SetFocus;
    Edit8.Clear;
    Exit;
  end;
  if (StrToFloat(Edit8.Text)>1)or(StrToFloat(Edit8.Text)<0)then
  begin
    Application.MessageBox('折扣不能大于1或小于0。','提示',0+64);
    Edit8.Clear;
    Edit8.SetFocus;
    Exit;
  end;
  try
    StrToFloat(Edit8.Text);
  except
    Application.MessageBox('请输入合法字符。','提示',0+64);
    Edit8.Clear;
    Edit8.SetFocus;
    Exit;
  end;
    if (Trim(Edit8.Text)<>'')and(Trim(StringGrid1.Cells[2,StringGrid1.Rowcount-1])='')then
      StringGrid1.Cells[4,StringGrid1.RowCount-1]:= Edit8.Text;
    StringGrid1.SetFocus;
  end;
end;

procedure TForm24.Edit4KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Trim(Edit4.Text)<>'') and(Key = VK_ReTurn)then
    Edit1.SetFocus;
end;

procedure TForm24.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if FirstIsNull = False then
    Exit;
  if Key = VK_Next then
  begin
    ListBox1.Visible:= True;
    ListBox1.SetFocus;
    ListBox1.ItemIndex := 0;
  end;
  if Key = Vk_ReTurn then
  begin
    ListBox1.Visible := False;
    if (Trim(Label3.Caption)='')or(Trim(Label16.Caption)='') then
    begin
      Application.MessageBox('请添加销售票号和销售时间。','提示',64);

⌨️ 快捷键说明

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