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

📄 pskpxt.~pas

📁 用delphi编写的配送管理系统
💻 ~PAS
字号:
unit pskpxt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, DBGrids, ExtCtrls, DB;

type
  TForm32 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    ComboBox1: TComboBox;
    Panel4: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    StringGrid1: TStringGrid;
    Label6: TLabel;
    Edit2: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label3: TLabel;
    Edit1: TEdit;
    procedure BitBtn1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BitBtn1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormShow(Sender: TObject);
    Procedure Clear;
    Procedure ClearString;
    Function JCxmlb: Boolean;
    function GroupSL(SPbh: String): Integer;
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2Exit(Sender: TObject);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form32: TForm32;
  Czy:  String;
implementation
   uses Data1,Sppssq;
{$R *.dfm}

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

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

procedure TForm32.Clear;
begin
  ComboBox1.Text := '';
  DataModule1.ADOQuery2.Close;
  Edit1.Clear;
  Label2.Caption := '0';
  Label4.Caption := '0';
  Label5.Caption := '0.0';
  Edit2.Clear;
end;

procedure TForm32.FormShow(Sender: TObject);
begin
  Czy := czymc;
  ComboBox1.Clear;
  with DataModule1.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 配送票号表 where (是否可用 = 1)and(完成送货 = 0)');
    Open;
  end;
  if DataModule1.ADOQuery1.RecordCount >0 then
    while Not DataModule1.ADOQuery1.Eof do
    begin
      ComboBox1.Items.Add(DataModule1.ADOQuery1.FieldByName('配送票号').Value);
      DataModule1.ADOQuery1.Next;
    end;
  Clear;
  BitBtn1.Enabled := False;
end;

procedure TForm32.SpeedButton1Click(Sender: TObject);
var
  i: Integer;
begin
  ClearString;
  i:=1;
  if Trim(ComboBox1.Text)<>''then
  begin
    with DataModule1.ADOQuery2 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from 配送申请表 where 配送票号 = (Select 配送票号 From 配送票号表 where 配送票号 = :a and 是否可用 = 1 and 完成送货 = 0)');
      Parameters.ParamByName('a').Value := Trim(ComboBox1.Text);
      Open;
    end;
    if DataModule1.ADOQuery2.RecordCount>0 then
    begin
      while Not DataModule1.ADOQuery2.Eof do
      begin
        StringGrid1.Cells[0,i]:=  DataModule1.ADOQuery2.FieldByName('商品编号').Value;
        StringGrid1.Cells[1,i]:=  DataModule1.ADOQuery2.FieldByName('商品名称').Value;
        StringGrid1.Cells[2,i]:= IntToStr(DataModule1.ADOQuery2.FieldByName('数量').Value);
        StringGrid1.Cells[3,i]:= FloatToStr(DataModule1.ADOQuery2.FieldByName('金额').Value);
        StringGrid1.Cells[4,i]:= FloatToStr(DataModule1.ADOQuery2.FieldByName('折扣').Value);
        StringGrid1.Cells[5,i]:=  DataModule1.ADOQuery2.FieldByName('客户编号').Value;
        StringGrid1.Cells[6,i]:=  DataModule1.ADOQuery2.FieldByName('客户全称').Value;
        StringGrid1.Cells[7,i]:=  DataModule1.ADOQuery2.FieldByName('配送票号').Value;
        StringGrid1.RowCount := StringGrid1.RowCount +1;
        inc(i);
        DataModule1.ADOQuery2.Next;
      end;
      StringGrid1.RowCount := StringGrid1.RowCount-1;//删除最后的空行
      with DataModule1.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from 配送票号表 where 配送票号 = :a');
        Parameters.ParamByName('a').Value := Trim(ComboBox1.Text);
        Open;
      end;
      Label2.Caption := IntToStr(DataModule1.ADOQuery1.FieldByName('品种数').Value);
      Label4.Caption := IntToStr(DataModule1.ADOQuery1.FieldByName('数量').Value);
      Label5.Caption := FloatToStr(DataModule1.ADOQuery1.FieldByName('应付金额').Value);
      BitBtn1.Enabled := True;
      Edit2.SetFocus;
    end
    else
    begin
      Application.MessageBox('该票号不存在或不可用。','提示',64);
      ComboBox1.Text := '';
    end;
  end;
end;

procedure TForm32.BitBtn1Click(Sender: TObject);
var
  jinja: Real; //商品进价,用来修改库存金额
  i: Integer;
  sum: Integer;
begin
  jinja:= 0.0;
  if Trim(Edit1.Text)=''then
  begin
    Application.MessageBox('请输入审核人。','提示',0+64);
    Edit1.SetFocus;
    Exit;
  end;
  if Trim(Edit2.Text)=''then
  begin
    Application.MessageBox('请输入实付金额。','提示',0+64);
    Edit2.SetFocus;
    Exit;
  end;
  if JCxmlb = False then
  begin
    DataModule1.ADOConnection1.BeginTrans;
    Try
      For i := 1 to StringGrid1.RowCount-1 do
      begin
        Sum := GroupSL(Trim(StringGrid1.Cells[0,i]));
        with DataModule1.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 > DataModule1.ADOQuery1.FieldByName('库存数量').Value then
        begin
          Application.MessageBox(Pchar('商品编号为'+StringGrid1.Cells[0,i]+'的商品数量大于库存数量, 不能完成该操作。'),'提示',0+64);
          Exit;
        end;
      end;
      For i := 1 to StringGrid1.RowCount-1 do
      begin
        with DataModule1.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 商品基础信息表 where 商品编号 = :a');
          Parameters.ParamByName('a').Value := Trim(DataModule1.ADOQuery2.FieldByName('商品编号').Value);
          Open;
        end;
        jinja := DataModule1.ADOQuery1.FieldByName('进价').Value;
        with DataModule1.ADOQuery1 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 := jinja * StrToInt(StringGrid1.Cells[2,i]);
          Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[0,i]);
          ExecSQL;
        end;
      end;
      with DataModule1.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('update 配送票号表 set 开票人 = :a,完成送货= 1  where 配送票号 = :b');
        Parameters.ParamByName('a').Value := Trim(Edit1.Text);
        Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[7,1]);
        ExecSQL;
      end;
      with DataModule1.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from 客户结款表 where 客户编号 = :a ');
        Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,1]);
        Open;
      end;
      if DataModule1.ADOQuery1.RecordCount >0 then
      begin
        with DataModule1.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('update 客户结款表 set 付款合计 = 付款合计 + :a ,欠款记账 = 欠款记账 + :b');
          Parameters.ParamByName('a').Value := StrToFloat(Edit2.Text);
          Parameters.ParamByName('b').Value := StrToFloat(Label5.Caption)-StrToFloat(Edit2.Text);
          ExecSQL;
        end;
      end
      else
      begin
        with DataModule1.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('insert 客户结款表 values (:a,:b,:c,:d,0.0,Default)');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,1]);
          Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[6,1]);
          Parameters.ParamByName('c').Value := StrToFloat(Label5.Caption);
          Parameters.ParamByName('d').Value := StrToFloat(Label5.Caption);
          ExecSQL;
        end;
      end;
      with DataModule1.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('insert 客户结款记录表 values(:a,:b,:c,Default,:d)');
        Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,1]);
        Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[6,1]);
        Parameters.ParamByName('c').Value := StrToFloat(Edit2.Text);
        Parameters.ParamByName('d').Value := Trim(Czy);
        ExecSQL;
      end;
      DataModule1.ADOConnection1.CommitTrans;
      Application.MessageBox('开票完成。','提示',0+64);
      Self.OnShow(Sender);
      ComboBox1.SetFocus;
    Except
      DataModule1.ADOConnection1.RollbackTrans;
      Application.MessageBox('系统出错。','提示',0+64);
      Close;
    end;
    BitBtn1.Enabled := False;
  end
  else
    Application.MessageBox('项目列表有误。','提示',64);
end;

procedure TForm32.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ReTurn then
    SpeedButton1.OnClick(Sender);
end;

procedure TForm32.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = Vk_Return)and(BitBtn1.Enabled = True) then
    BitBtn1.OnClick(Sender);
end;

procedure TForm32.FormCreate(Sender: TObject);
begin
  StringGrid1.Cells[0,0]:='      商品编号';
  StringGrid1.Cells[1,0]:='      商品名称';
  StringGrid1.Cells[2,0]:='     数量';
  StringGrid1.Cells[3,0]:='     金额';
  StringGrid1.Cells[4,0]:='   折扣';
  StringGrid1.Cells[5,0]:='       客户编号';
  StringGrid1.Cells[6,0]:='     客户全称';
  StringGrid1.Cells[7,0]:='       配送票号';
end;

procedure TForm32.ClearString;
var
  a,b: Integer;
begin
  For a := 1 to StringGrid1.RowCount-1 do
    For b := 0 to StringGrid1.ColCount-1 do
      StringGrid1.Cells[b,a]:= '';
   StringGrid1.RowCount := 2;
end;

function TForm32.GroupSL(SPbh: String): Integer;
var
  i: Integer;
begin
  ReSult := 0;
  For i := 1 to StringGrid1.RowCount -1 do
    if Trim(Spbh)= Trim(StringGrid1.Cells[0,i]) then
      Result := ReSult + StrToInt(StringGrid1.Cells[2,i]);
end;
procedure TForm32.Edit2KeyPress(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 TForm32.Edit2Exit(Sender: TObject);
begin
  if Edit2.Text = '' then
  begin
    Application.MessageBox('实付金额不能为空。','提示',0+64);
    Exit;
  end;
  if StrToFloat(Edit2.Text)<0then
  begin
    Application.MessageBox('实付金额不能小于零。','提示',0+64);
    Edit2.Clear;
    Edit2.SetFocus;
  end;
  try
    StrToFloat(Edit2.Text);
  except
    Application.MessageBox('请输入合法字符。','提示',0+64);
    Edit2.Clear;
    Edit2.SetFocus;
  end;

end;

function TForm32.JCxmlb: Boolean;
var
 a,b: Integer;
begin
  Result := False;
  For a := 1 to StringGrid1.RowCount-1 do
    For b := 0 to StringGrid1.ColCount-1 do
    if Trim(StringGrid1.Cells[b,a])= '' then
    begin
      ReSult := True;
      Break;
    end;
end;

procedure TForm32.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Trim(Edit2.Text)<>'' then
    if Key = VK_ReTurn then
      Edit1.SetFocus;
end;

end.

⌨️ 快捷键说明

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