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

📄 xsthxt.pas

📁 用delphi编写的销售管理系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit xsthxt;

interface

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

type
  TForm27 = class(TForm)
    Panel2: TPanel;
    Panel1: TPanel;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    Image2: TImage;
    Label5: TLabel;
    Label7: TLabel;
    Label2: TLabel;
    Label1: TLabel;
    Shape3: TShape;
    Shape1: TShape;
    Label4: TLabel;
    Edit4: TEdit;
    Label14: TLabel;
    Edit1: TEdit;
    StringGrid1: TStringGrid;
    DBGrid1: TDBGrid;
    ListBox1: TListBox;
    Label3: TLabel;
    Label9: TLabel;
    Label21: TLabel;
    Panel3: TPanel;
    Label8: TLabel;
    Label6: TLabel;
    Label17: TLabel;
    Label12: TLabel;
    Label18: TLabel;
    Label10: TLabel;
    Label19: TLabel;
    Label11: TLabel;
    Label16: TLabel;
    Edit8: TEdit;
    ComboBox2: TComboBox;
    Edit2: TEdit;
    DataSource1: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    Function  JCxmlb : Boolean;//检查项目列表是否有误
    procedure Clear; //窗体初始化
    Function IsNull:BooLean;
    Function AfterIsNull: Boolean;
    Function CurrentIsCF:Boolean;
    Function GroupSL(SPbh: String): Integer;
    Function SumPrice :Real;
    Function SumSL: Integer;
    Function Kinds: Integer;
    Procedure ClearString;
    Procedure ClearStringEnd;
    Procedure SelectSPxx;
    Function FirstIsNull:Boolean;
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit8Exit(Sender: TObject);
    procedure Edit8KeyPress(Sender: TObject; var Key: Char);
    procedure BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Edit8KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit4KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ListBox1DblClick(Sender: TObject);
    procedure ListBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit2Exit(Sender: TObject);
    procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form27: TForm27;
  x,y: Integer;
  Ss:Boolean = False ;//判断当焦点在StringGrid1上时是否按回车键
  s1: Boolean = False;//在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止连续出现对话框
  s2: Boolean = False; //在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止删除行时,统计的数量金额错误
  
implementation
  uses datamodal, spxsgl,xsxx;
{$R *.dfm}

procedure TForm27.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]:='       退货票号';
  StringGrid1.Cells[8,0]:='    退货日期';
  Label9.Caption := FormatDateTime('yyyy-mm-dd',Now());
end;

procedure TForm27.FormShow(Sender: TObject);
begin
  Label21.Caption:= czy;
  ListBox1.Items.Clear;
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select distinct 客户全称 from 销售表');
    Open;
  end;
  while not Data.ADOQuery1.Eof do
  begin
    ListBox1.Items.Add(Data.ADOQuery1.FieldByName('客户全称').AsString);
    Data.ADOQuery1.Next;
  end;
  ComboBox2.ItemIndex := 0;
  BitBtn3.SetFocus;
end;

procedure TForm27.BitBtn3Click(Sender: TObject);
var
  s,m: String;
  i: integer;
begin
  Label9.Caption := FormatDateTime('yyyy-mm-dd',Now());
  s:= 'XP'+ FormatDateTime('yyyymmdd',Now());
  With Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select max(销售退单票号) as ss From 销售退单票号表 ');
    Open;
  end;
  If Data.ADOQuery1.FieldByName('ss').Value = null then
    s := s + '001'
  else
  begin
    m:= Trim(Data.ADOQuery1.FieldByName('ss').Value) ;
    i:= StrToInt(Trim(Copy(m,11,5))) ;
    if i<9 then
      s:= s + '00'+ InttoStr(i +1)
    else if i<99 then
      s:= s + '0'+ InttoStr(i +1)
    else
      s:= s +InttoStr(i +1);
  end;
  Label3.Caption := s;
  Edit4.SetFocus;

end;

procedure TForm27.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
  mm: Boolean;
begin
  if y = 2 then
  begin
    mm := (Key <#8)or(Key >#8)and(Key<#48)or(Key>#57);
    if mm then
      Key := #0;
  end;
end;


procedure TForm27.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  y := ACol;
  x := ARow;
  begin
    if (ACol = 1)and( Trim(StringGrid1.Cells[0,x])='')or(ACol = 2)and(Trim(StringGrid1.Cells[0,x])<>'') then
      StringGrid1.Options := StringGrid1.Options +[goEditing]
    else
      StringGrid1.Options := StringGrid1.Options -[goEditing];
  end ;
end;

function TForm27.JCxmlb: Boolean;
var
  a,b: integer;
begin
  for a := 1 to StringGrid1.RowCount-1 do
    For b := 0 to StringGrid1.ColCount-1 do
    begin
      if StringGrid1.Cells[b,a]='' then
      begin
         Jcxmlb := False;
         break;
      end
      else
        Jcxmlb := True;
    end;
end;

procedure TForm27.Clear;
var
  r,c: integer;
begin
  ComboBox2.ItemIndex := 0;
  Label3.Caption := '';
  Label9.Caption := '';
  Edit8.Text := '1.0';
  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;
end;

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

procedure TForm27.BitBtn4Click(Sender: TObject);
var
  row: Integer;
  SPjg: Real;//记录商品进价,用来修改库存金额
begin
  if (Trim(Edit4.Text)='')or (Jcxmlb = False)or(Trim(ComboBox2.Text)='')then
  begin
    Application.MessageBox('项目列表有误。','提示',0+64);
    Exit;
  end;
  Data.ADOConnection1.BeginTrans;
  try
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Insert 销售退单票号表 values (:a,:b,:c,:d,:e,:f,Default,:g,:h)');
    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 := ComboBox2.Text;
    Parameters.ParamByName('f').Value := StrToFloat(Edit2.Text);
    Parameters.ParamByName('g').Value := Trim(Edit4.Text);
    Parameters.ParamByName('h').Value := Trim(Label21.Caption);
    ExecSQL;
  end;
  For Row := 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,Row]);
      Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,Row]);
      Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[5,Row]);
      Parameters.ParamByName('d').Value := Trim(StringGrid1.Cells[6,Row]);
      Parameters.ParamByName('e').Value := StrToInt(StringGrid1.Cells[2,Row]);
      Parameters.ParamByName('f').Value := StrToFloat(StringGrid1.Cells[3,Row]);
      Parameters.ParamByName('g').Value := StrToFloat(StringGrid1.Cells[4,Row]);
      Parameters.ParamByName('h').Value := Trim(StringGrid1.Cells[7,1]);
      ExecSQL;
    end;
    with Data.ADOQuery4 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('Select * from 商品基础信息表 where 商品编号 = :a');
      Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,Row]);
      Open;
    end;
    Spjg := Data.ADOQuery4.FieldByName('进价').Value;
    with Data.ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update 库存表 set 库存数量 = 库存数量 + :a ,库存金额 = 库存金额 + :b where 商品编号 = :c');
      Parameters.ParamByName('a').Value := StrToInt(StringGrid1.Cells[2,Row]);
      Parameters.ParamByName('b').Value := StrToInt(StringGrid1.Cells[2,Row])*Spjg;
      Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[0,Row]);
      ExecSQL;
    end;
  end;
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add(' update 客户结款表 set 欠款记账 = 欠款记账 - :b ,付款合计 = 付款合计 + :c ,结款时间 = Default where 客户编号 = :d');
    Parameters.ParamByName('b').Value :=  StrToFloat(Label19.Caption)-StrToFloat(Edit2.Text);
    Parameters.ParamByName('c').Value :=  StrToFloat(Label19.Caption)-StrToFloat(Edit2.Text);
    Parameters.ParamByName('d').Value := Trim(StringGrid1.Cells[5,1]);
    ExecSQL;
  end;
  with Data.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(Label21.Caption);
    ExecSQL;
  end;
  Data.ADOConnection1.CommitTrans;
  Application.MessageBox('保存成功。','提示',0+64);
  Clear;
  Except
    Data.ADOConnection1.RollbackTrans;
    Application.MessageBox('系统出错。','提示',64);
    Close;
  end;
end;

procedure TForm27.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  R,L: Integer;
  cp: String;// 记录当前行的价格
  cl: String;//记录当前行的数量
begin
    S1 := False;
    s2 := False;
    ss := False;
    cp := '';
    cl:= '';
    if key = VK_Delete then
    begin
      if StringGrid1.RowCount>2 then
      begin
        If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
        begin
         if IsNull = False then
         begin
           cl := StringGrid1.Cells[2,x];
           cp := StringGrid1.Cells[3,x];
           if CurrentIsCf = False then
             Label17.Caption := IntToStr(StrToInt(Label17.Caption)-1);
         end;
          ClearString;
          if x <> StringGrid1.RowCount-1 then
          begin
            For r := x+1 to StringGrid1.RowCount-1 do
              For l := 0 to StringGrid1.ColCount-1 do
                StringGrid1.Cells[l,r-1]:= StringGrid1.Cells[l,r];
          end;
          ClearStringEnd;
          StringGrid1.RowCount := StringGrid1.RowCount-1;
          s2 := True;
          if Trim(cl)<>'' then
            Label18.Caption := IntToStr(StrToInt(Label18.Caption)- StrToInt(cl));
          if Trim(cp)<>'' then
            Label19.Caption := FloatToStr(StrToFloat(Label19.Caption)-StrToFloat(cp));
          StringGrid1.SetFocus;
          StringGrid1.Col := 2;
          StringGrid1.Col := 1;
          Exit;
        end;
      end
      else if  StringGrid1.RowCount = 2 then
      begin
        If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
        begin
          ClearString;
          Label17.Caption := '0';
          Label18.Caption :='0';
          Label19.Caption := '0.0';
          StringGrid1.SetFocus;
          StringGrid1.Col := 2;
          StringGrid1.Col := 1;
        end;
      end;
    end;
    if (key = Vk_Next)and(DBGrid1.Visible = True)then
    begin
      DBGrid1.SetFocus;
      Exit;
    end;
    if (Key = VK_Down)and(IsNull = False)and(x = StringGrid1.RowCount-1) then
    begin
      StringGrid1.RowCount := StringGrid1.RowCount+1;
      StringGrid1.Cells[5,StringGrid1.RowCount-1]:= StringGrid1.Cells[5,StringGrid1.RowCount-2];
      StringGrid1.Cells[6,StringGrid1.RowCount-1]:= StringGrid1.Cells[6,StringGrid1.RowCount-2];
      StringGrid1.Cells[4,StringGrid1.RowCount-1]:= '1.0';
      StringGrid1.Cells[7,StringGrid1.RowCount-1]:= StringGrid1.Cells[7,StringGrid1.RowCount-2];
      StringGrid1.Cells[8,StringGrid1.RowCount-1]:= StringGrid1.Cells[8,StringGrid1.RowCount-2];
      StringGrid1.Col := 1;
      Exit;
    end;
    if key = vk_ReTurn then
      if Trim(StringGrid1.Cells[0,x])='' then
      begin
        Ss := True;
        DataSource1.DataSet := nil;
        DBGrid1.Visible := False;
        SelectSPXX;
        if Data.ADOQuery1.RecordCount>1 then
        begin
          DataSource1.DataSet := Data.ADOQuery1;
          DBGrid1.Visible := True;
          DBGrid1.SetFocus;
        end
        else if Data.ADOQuery1.RecordCount = 1  then
        begin
          StringGrid1.Cells[0,x]:= Data.ADOQuery1.FieldByName('商品编号').Value;
          StringGrid1.Cells[1,x]:= Data.ADOQuery1.FieldByName('商品名称').Value;
          StringGrid1.SetFocus;
          StringGrid1.Col := 2;
        end
        else
        begin
          Application.MessageBox('该商品不存在。','提示',64);
          ClearString;
          if StringGrid1.RowCount>2 then
            StringGrid1.RowCount := StringGrid1.RowCount-1;
        end;
      end;
      if (Key = VK_Shift)and(JCxmlb = True) then
        Edit2.SetFocus;
end;

⌨️ 快捷键说明

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