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

📄 spjcxxgl.~pas

📁 用delphi编写的销售管理系统
💻 ~PAS
字号:
unit spjcxxgl;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons;

type
  TForm7 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    Panel3: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label8: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    Label13: TLabel;
    Edit10: TEdit;
    Edit9: TEdit;
    Label11: TLabel;
    Edit8: TEdit;
    Label10: TLabel;
    Edit7: TEdit;
    Edit6: TEdit;
    Edit11: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Edit4: TEdit;
    Edit2: TEdit;
    Label2: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit1: TEdit;
    procedure BitBtn1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Panel2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure BitBtn3Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure EditClear;
    Procedure DisableEdit;
    procedure Edit7KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);//数据初始化
    procedure EditValue;
    procedure FindNext;//使下一个编辑框获得焦点
    Procedure FindPrior;//使上一个编辑框获得焦点
    Function IsNullEdit: Boolean;
    procedure Edit11KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);//为编辑框赋值
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;
  aa: Boolean = False ;//设置保存按钮是否可用
implementation
  uses datamodal;
{$R *.dfm}

procedure TForm7.BitBtn1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Screen.Cursor := -21;
  TBitBtn(Sender).Font.Color := clRed;
end;

procedure TForm7.Panel2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Screen.Cursor := -2;
  BitBtn1.Font.Color := clBlue;
  BitBtn2.Font.Color := clBlue;
  BitBtn3.Font.Color := clBlue;
  BitBtn4.Font.Color := clBlue;
  BitBtn5.Font.Color := clBlue;
  BitBtn6.Font.Color := clBlue;
  BitBtn7.Font.Color := clBlue;
  BitBtn8.Font.Color := clBlue;
end;

procedure TForm7.BitBtn3Click(Sender: TObject);
var
  s,m: String;
  i: integer;
begin
  EditClear;
  Edit7.Enabled := True;
  Edit8.Enabled := True;
  Edit9.Enabled := True;
  aa := True;
  BitBtn5.Enabled := False;
  BitBtn6.Enabled := False;
  s:= 'S'+ 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,10,5))) ;
    if i<9 then
      s:= s + '00'+ InttoStr(i +1)
    else if i<99then
      s:= s + '0'+ InttoStr(i +1)
    else
      s:= s +InttoStr(i +1);
  end;
  Edit1.Text := Trim(s);
  Edit2.SetFocus;
end;

procedure TForm7.Edit1Change(Sender: TObject);
begin
  if (Trim(Edit1.Text)<>'')and (Trim(Edit2.Text)<>'')and(Trim(Edit3.Text)<>'')and
    (Trim(Edit4.Text)<>'') and(Trim(Edit5.Text)<>'')and(Trim(Edit6.Text)<>'')and
    (Trim(Edit7.Text)<>'')and(Trim(Edit8.Text)<>'')and(Trim(Edit9.Text)<>'')and
    (Trim(Edit10.Text)<>'')and(aa = True)then
     BitBtn4.Enabled := True
  else
    BitBtn4.Enabled := False;
end;

procedure TForm7.BitBtn1Click(Sender: TObject);
begin
 if Not Data.ADOQuery2.Bof  then
  begin
    Data.ADOQuery2.Prior;
    EditValue;
  end
  else
    BitBtn1.Enabled := False;
    BitBtn2.Enabled := True;
    BitBtn5.Enabled := True;
    DisableEdit;
    BitBtn6.Enabled := True;
    BitBtn4.Enabled := False;
end;

procedure TForm7.BitBtn2Click(Sender: TObject);
begin
  if Not Data.ADOQuery2.Eof then
  begin
    Data.ADOQuery2.Next;
    EditValue;
  end
  else
    BitBtn2.Enabled := False;
    BitBtn1.Enabled := True;
    BitBtn5.Enabled := True;
    DisableEdit;
    BitBtn6.Enabled := True;
    BitBtn4.Enabled := False;
end;

procedure TForm7.BitBtn5Click(Sender: TObject);
begin
  Try
  if Application.MessageBox('确实要修改该条记录吗?','提示',MB_YESNO )= ID_Yes then
  begin
    if IsNullEdit = False then
    begin
      with Data.ADOQuery2 do
      begin
        DisableEdit;
        Edit;
        BitBtn4.Enabled := False;
        FieldByName('商品编号').Value := Edit1.Text;
        FieldByName('商品名称').Value := Edit2.Text ;
        FieldByName('简称').Value := Edit3.Text;
        FieldByName('规格').Value := Edit4.Text ;
        FieldByName('产地').Value := Edit5.Text ;
        FieldByName('单位').Value := Edit6.Text ;
        FieldByName('保质期').Value := StrToInt(Trim(Edit11.Text)) ;
        FieldByName('进价').Value :=  StrToFloat(Edit7.Text);
        FieldByName('批发价').Value := StrToFloat(Edit8.Text) ;
        FieldByName('零售价').Value := StrToFloat(Edit9.Text) ;
        FieldByName('备注').Value := Edit10.Text ;
        Post;
        Application.MessageBox('修改成功。','提示',0+64);
      end;
    end
    else
    begin
      Application.MessageBox('数据项不能为空.','提示',64);
      Exit;
    end
  end
  else
  EditValue;
  Except
  Application.MessageBox('系统出错。','提示',0+64);
  Close;
  end;
end;

procedure TForm7.BitBtn6Click(Sender: TObject);
begin
  BitBtn4.Enabled := False;
  Try
  if Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
  begin
    with Data.ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('delete 商品基础信息表 where 商品编号 = :a');
      Parameters.ParamByName('a').Value := Trim(Edit1.Text);
      ExecSQL;
    end;
    Application.MessageBox('该条记录已经删除。','提示',0+64);
    OnShow(Sender);
  end;
  Except
    Application.MessageBox('系统出错。','提示',0+64);
    Close;
  end;
end;

procedure TForm7.BitBtn7Click(Sender: TObject);
begin
  Self.OnShow(Sender);
  BitBtn4.Enabled := False;
  BitBtn6.Enabled := True;
  BitBtn5.Enabled := True;
  BitBtn2.Enabled := True;
  DisableEdit;
end;

procedure TForm7.BitBtn4Click(Sender: TObject);
begin
  With Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 商品基础信息表 where 商品编号 = :a');
    Parameters.ParamByName('a').Value := Trim(Edit1.Text);
    Open;
  end;
  if Data.ADOQuery1.RecordCount > 0 then
  begin
    Application.MessageBox('该商品已经存在。','提示',0+64);
    Exit;
  end;
  if StrToFloat(Trim(Edit8.Text))>StrToFloat(Trim(Edit9.Text))then
    if Application.MessageBox('批发价确实要大于零售价吗?','提示',MB_YESNO)<> ID_Yes then
      Exit;
  Try
  With Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Insert 商品基础信息表 values ( :a,:b,:c,:d,:e,:f,:h,:i,:j,:k,:m )');
    Parameters.ParamByName('a').Value := Trim(Edit1.Text);
    Parameters.ParamByName('b').Value := Trim(Edit2.Text);
    Parameters.ParamByName('c').Value := Trim(Edit3.Text);
    Parameters.ParamByName('d').Value := Trim(Edit4.Text);
    Parameters.ParamByName('e').Value := Trim(Edit5.Text);
    Parameters.ParamByName('f').Value := Trim(Edit6.Text);
    Parameters.ParamByName('h').Value := StrToInt(Trim(Edit11.Text));
    Parameters.ParamByName('i').Value := StrToFloat(Trim(Edit7.Text));
    Parameters.ParamByName('j').Value := StrToFloat(Trim(Edit8.Text));
    Parameters.ParamByName('k').Value := StrToFloat(Trim(Edit9.Text));
    Parameters.ParamByName('m').Value := Trim(Edit10.Text);
    ExecSQL;
  end;
    Application.MessageBox('保存成功。','提示',0+64);
    BitBtn1.Enabled := True;
    BitBtn2.Enabled := True;
    self.OnShow(Sender);
    Except
    Application.MessageBox('系统出错。','提示',0+64);
    Close;
    end;

end;

procedure TForm7.EditClear;
begin
  Edit1.Clear;
  Edit2.Clear;
  Edit3.Clear;
  Edit4.Clear;
  Edit5.Clear;
  Edit6.Clear;
  Edit7.Clear;
  Edit8.Clear;
  Edit9.Clear;
  Edit10.Clear;
  Edit11.Clear;
end;

procedure TForm7.Edit7KeyPress(Sender: TObject; var Key: Char);
var
  m: Boolean;
begin
  m := (key <#8)or(Key>#8)and(key < #46)or(key>#46)and(key <#48)or(key > #57);
  if m then
    key := #0;
end;

procedure TForm7.FormShow(Sender: TObject);
begin
  with Data.ADOQuery2 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 商品基础信息表');
    Open;
  end;
  If Data.ADOQuery2.FieldByName('商品编号').Value = null then
  begin
    Application.MessageBox('该表数据为空,请向该表中插入数据。','提示',0+64);
    BitBtn1.Enabled := False;
    BitBtn2.Enabled := False;
    BitBtn5.Enabled := False;
    BitBtn6.Enabled := False;
    BitBtn7.Enabled := False;
  end
  else
    EditValue;
  DisableEdit;
end;

procedure TForm7.EditValue;
begin
  if Data.ADOQuery2.FieldByName('商品编号').Value <> null then
  begin
    Edit1.Text :=  Data.ADOQuery2.FieldByName('商品编号').Value;
    Edit2.Text :=  Data.ADOQuery2.FieldByName('商品名称').Value;
    Edit3.Text :=  Data.ADOQuery2.FieldByName('简称').Value;
    Edit4.Text :=  Data.ADOQuery2.FieldByName('规格').Value;
    Edit5.Text :=  Data.ADOQuery2.FieldByName('产地').Value;
    Edit6.Text :=  Data.ADOQuery2.FieldByName('单位').Value;
    Edit11.Text:=  IntToStr(Data.ADOQuery2.FieldByName('保质期').Value);
    Edit7.Text :=  FloatToStr(Data.ADOQuery2.FieldByName('进价').Value);
    Edit8.Text :=  FloatToStr(Data.ADOQuery2.FieldByName('批发价').Value);
    Edit9.Text :=  FloatToStr(Data.ADOQuery2.FieldByName('零售价').Value);
    Edit10.Text :=  Data.ADOQuery2.FieldByName('备注').Value;
  end
  else
  begin
    Edit1.Clear;
    Edit2.Clear;
    Edit3.Clear;
    Edit4.Clear;
    Edit5.Clear;
    Edit7.Clear;
    Edit8.Clear;
    Edit9.Clear;
    Edit10.Clear;
    Edit11.Clear;
  end;
end;

procedure TForm7.Edit11KeyPress(Sender: TObject; var Key: Char);
var
  m: Boolean;
begin
  m := (key <#8)or(Key>#8)and(key <#48)or(key>#57);
  if m then
    key := #0;
end;
procedure TForm7.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_return then
    FindNext
  else if key = vk_Up then
    FindPrior;
end;

procedure TForm7.DisableEdit;
begin
  Edit7.Enabled := False;
  Edit8.Enabled := False;
  Edit9.Enabled := False;
end;

procedure TForm7.FindNext;
begin
  if FindNextControl(ActiveControl,True,False,False)is TEdit then
    if TEdit(FindNextControl(ActiveControl,True,False,False)).Enabled = True then
      TEdit(FindNextControl(ActiveControl,True,False,False)).SetFocus
    else
    begin
      ActiveControl := FindNextControl(ActiveControl,True,False,False);
      FindNext;
    end;
end;

procedure TForm7.FindPrior;
begin
  if FindNextControl(ActiveControl,False,False,False)is TEdit then
    if TEdit(FindNextControl(ActiveControl,False,False,False)).Enabled = True then
      TEdit(FindNextControl(ActiveControl,False,False,False)).SetFocus
    else
    begin
      ActiveControl := FindNextControl(ActiveControl,False,False,False);
      FindPrior;
    end;
end;

function TForm7.IsNullEdit: Boolean;
var
  Count: Integer;
begin
  IsNullEdit := False;
  For Count := 0 to Panel3.ControlCount-1 do
    if Panel3.Controls[Count]is TEdit then
      if Trim(TEdit(Panel3.Controls[Count]).Text)='' then
      begin
        IsNullEdit := True;
        Break;
      end;
end;

end.

⌨️ 快捷键说明

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