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

📄 cf_sell.pas

📁 delphi和SQL做的超市管理系统
💻 PAS
字号:
unit cf_sell;

interface

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

type
  Tcfra_sell = class(TFrame)
     Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    GroupBox1: TGroupBox;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Label7: TLabel;
    BitBtn6: TBitBtn;
    Edit2: TEdit;
    Edit3: TEdit;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Label8: TLabel;
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  cfra_sell: Tcfra_sell;
  TotalMoney: Real;

implementation

uses datam, publicvar;

{$R *.dfm}


procedure Tcfra_sell.BitBtn2Click(Sender: TObject);
begin
 if Edit2.Text='' then  //判断是否输入了商品编号
    begin
      Application.MessageBox(PChar('商品编号不能为空,请重新录入!')
      , PChar('提示'),MB_ICONEXCLAMATION);
      Edit2.SetFocus();
      exit;
     end;
 if Edit3.Text='' then  //判断是否输入了商品数量
    begin
      Application.MessageBox(PChar('商品数量不能为空,请重新录入!')
      , PChar('提示'),MB_ICONEXCLAMATION);
      Edit3.SetFocus();
      exit;
     end;
 dm.ADO_product.Open;
 dm.ADO_product.First;
 if  not dm.ADO_product.Locate('prod_id',edit2.Text,[])  then
    begin
    Application.MessageBox(PChar('未查到此种商品,请检查!')
      , PChar('提示'),MB_ICONEXCLAMATION);
    Edit2.Text:='';
    Edit2.SetFocus();
    exit;
   end;
 if dm.ADO_product.FieldByName('prod_stock').AsInteger<StrToInt(edit3.Text) then
   begin
    Application.MessageBox(PChar('对不起,库存数量不够!')
      , PChar('提示'),MB_ICONEXCLAMATION);
    edit3.Text:='';
    edit3.SetFocus();
    exit;
   end
 else
   begin
   //如果找到,则对临时销售表做插入的操作
   dm.ado_tmpsell.OPEN;
   dm.ado_tmpsell.Append;
   dm.ado_tmpsell.fieldbyname('sell_prod_id').asstring:=dm.ado_product.fieldbyname('prod_id').asstring;
   dm.ado_tmpsell.fieldbyname('sell_prod_name').asstring:=dm.ado_product.fieldbyname('prod_name').asstring;
   dm.ado_tmpsell.fieldbyname('sell_prod_price').asfloat:=dm.ado_product.fieldbyname('prod_price').asfloat;
   dm.ado_tmpsell.fieldbyname('sell_number').asinteger:=StrtoInt(edit3.Text);
   dm.ado_tmpsell.fieldbyname('seller_name').asstring:=username;
   dm.ado_tmpsell.fieldbyname('sell_time').asdatetime:=date();
   dm.ado_tmpsell.Post;
   TotalMoney:=TotalMoney+dm.ADO_product.fieldbyname('prod_price').AsFloat*StrtoInt(edit3.Text);
  end;
  edit2.Text:='';
  edit3.Text:='';
  Label4.Caption:=FloattoStr(TotalMoney);
end;

procedure Tcfra_sell.BitBtn1Click(Sender: TObject);
begin
TotalMoney:=0;
Label4.Caption:=FloattoStr(TotalMoney);
edit1.Text:='';
edit2.Visible:=true;
edit3.Visible:=true;
end;

procedure Tcfra_sell.BitBtn6Click(Sender: TObject);
begin
   dm.ADO_tmpsell.Open;
  if dm.ADO_tmpsell.IsEmpty then   //如果临时销售表的内容为空则不保存
   begin
    Application.MessageBox(PChar('没有销售明细,不可保存!'), PChar('提示'),
      MB_ICONEXCLAMATION);
    exit;
   end;
  if  Edit1.Text='' then
  Application.MessageBox(PChar('没有收款,不可保存!'), PChar('提示'),
      MB_ICONEXCLAMATION)
  else
  begin
    if (StrToFloat(Edit1.Text)<TotalMoney) then
    begin
      messagebox(handle,pchar('应该收金额为 '+FloatToStr(TotalMoney)+' 元,收款不足!'),'检查输入',mb_iconwarning+mb_ok);
      exit;
    end;
  //将临时表中的信息添加到销售表中
  dm.ADOQ_tmpsell.Close;
   dm.ADOQ_tmpsell.SQL.Clear;
   dm.ADOQ_tmpsell.SQL.Add('insert into t_sell select sell_prod_id,sell_prod_name,sell_prod_price,sell_number,seller_name,sell_time  from tmpsell');
   dm.adoq_tmpsell.ExecSQL;
   dm.ADOQ_tmpsell.Close;
  //更新商品的库存信息
    dm.ADO_tmpsell.Open;
    dm.ADO_tmpsell.First;
    while not dm.ADO_tmpsell.Eof do
     begin
      dm.ADO_product.Open;
      dm.ADO_product.Locate('prod_id',dm.ADO_tmpsell.fieldbyname('sell_prod_id').AsString,[]);
      dm.ADO_product.Edit;
      dm.ADO_product.FieldByName('prod_sale').AsInteger:=dm.ado_product.FieldByName('prod_sale').AsInteger+dm.ADO_tmpsell.fieldbyname('sell_number').AsInteger;
      dm.ado_product.FieldByName('prod_stock').asinteger:=dm.ado_product.FieldByName('prod_stock').AsInteger-dm.ADO_tmpsell.fieldbyname('sell_number').AsInteger;
      dm.ADO_product.Post;
      dm.ADO_tmpsell.Next;
     end;
  //删除临时表记录
   dm.ADOQ_tmpsell.SQL.Clear;
   dm.ADOQ_tmpsell.SQL.Add('delete from tmpsell');
   dm.adoq_tmpsell.ExecSQL;
   dm.ADO_tmpsell.Close;
   Messagebox(handle,pchar('找零 '+FloatToStr(StrToFloat(Edit1.Text)-TotalMoney)+' 元,谢谢惠顾!'),'销售完成',mb_iconwarning+mb_ok);
   edit2.Visible:=false;
   edit3.Visible:=false;
   edit1.Text:='';
   Label4.Caption:='0';
end;
end;

procedure Tcfra_sell.BitBtn5Click(Sender: TObject);
begin
  dm.ADOQ_tmpsell.SQL.Clear;
  dm.ADOQ_tmpsell.SQL.Add('delete from tmpsell');  //删除销售临时表信息
  dm.ADOQ_tmpsell.ExecSQL;
  dm.ADOQ_tmpsell.Close;   //关闭数据集
  dm.ADO_tmpsell.Close;
  dm.ADO_tmpsell.Open;
   edit2.Visible:=false;
   edit3.Visible:=false;
   edit1.Text:='';
   Label4.Caption:='0';
end;

procedure Tcfra_sell.BitBtn4Click(Sender: TObject);
var mes:string;
begin
mes:='是否要删除当前销售记录';
 if application.MessageBox(pchar(mes),pchar('等待确认')
    ,+MB_ICONQUESTION+mb_okcancel+MB_DEFBUTTON2)=idok then
     begin
     TotalMoney:=TotalMoney-dm.ADO_tmpsell.fieldbyname('sum').AsFloat;
     Label4.Caption:=FloattoStr(TotalMoney);
      dm.ADO_tmpsell.Delete;//删除当前销售记录
     end;
end;


end.

⌨️ 快捷键说明

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