UnitSell.pas
资源名称:东之源.rar [点击查看]
上传用户:zexin0769
上传日期:2010-01-19
资源大小:443k
文件大小:8k
源码类别:
百货/超市行业
开发平台:
Delphi
- unit UnitSell;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, DB, ADODB, Grids, DBGrids, StdCtrls, Mask, DBCtrls;
- type
- TFrameSell = class(TFrame)
- Image1: TImage;
- Image2: TImage;
- DBGrid1: TDBGrid;
- ADOQuery1: TADOQuery;
- DataSource1: TDataSource;
- Panel1: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Image3: TImage;
- DBEdit1: TDBEdit;
- DBEdit2: TDBEdit;
- GroupBox1: TGroupBox;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Edit1: TEdit;
- Image4: TImage;
- Image5: TImage;
- Image6: TImage;
- DBEdit3: TDBEdit;
- DBEdit4: TDBEdit;
- Image7: TImage;
- Label7: TLabel;
- procedure Image2Click(Sender: TObject);
- procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
- procedure Image3Click(Sender: TObject);
- procedure Image5Click(Sender: TObject);
- procedure DBEdit2KeyPress(Sender: TObject; var Key: Char);
- procedure Image6Click(Sender: TObject);
- procedure DBGrid1CellClick(Column: TColumn);
- procedure Image7Click(Sender: TObject);
- procedure Image4Click(Sender: TObject);
- function IsAllNum(s:string):bool;
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure Label7Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- implementation
- uses UnitLogin;
- var
- ADOQuery2: TADOQuery;
- MoneyTotal: Real;
- {$R *.dfm}
- procedure TFrameSell.Image2Click(Sender: TObject);
- begin
- DBEdit1.Color := clWhite;
- DBEdit2.Color := clWhite;
- DBEdit1.Enabled := True;
- DBEdit2.Enabled := True;
- ADOQuery1.Active := True;
- ADOQuery1.Append;
- DBEdit1.SetFocus;
- image2.Enabled := False;
- image3.Visible := True;
- image5.Visible := True;
- image6.Visible := True;
- end;
- procedure TFrameSell.DBEdit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if Key=#13 then DBEdit2.SetFocus;
- end;
- procedure TFrameSell.Image3Click(Sender: TObject);
- var
- i: Integer;
- begin
- {提交数据}
- if (DBEdit1.Text<>'') and (DBEdit2.Text<>'') then
- begin
- ADOQuery2:= TADOQuery.Create(self);
- ADOQuery2.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataFile+';Persist Security Info=False;';
- ADOQuery2.SQL.Clear;
- ADOQuery2.SQL.Add('select * from t_prod where prod_id=' + DBEdit1.Text);
- ADOQuery2.Open;
- if ADOQuery2.Eof then
- begin
- messagebox(handle,'数据库中没有该商品编号!','重新输入',mb_iconwarning+mb_ok);
- DBEdit1.SelectAll;
- DBEdit1.SetFocus;
- exit;
- end;
- if ADOQuery2.FieldByName('prod_stock').AsInteger < strtoint(DBEdit2.Text) then
- begin
- messagebox(handle,pchar('应该商品当前库存为 '+ADOQuery2.FieldByName('prod_stock').AsString+' ,不足所输销售数量!'),'重新输入',mb_iconwarning+mb_ok);
- DBEdit2.SelectAll;
- DBEdit2.SetFocus;
- exit;
- end;
- DBEdit3.Text := ADOQuery2.FieldByName('prod_name').AsString;
- DBEdit4.Text := ADOQuery2.FieldByName('prod_price').AsString;
- ADOQuery2.Free;
- ADOQuery1.Post;
- MoneyTotal := 0;
- for i:=1 to ADOQuery1.RecordCount do
- begin
- MoneyTotal := MoneyTotal + ADOQuery1.FieldByName('sell_prod_Price').AsVariant * ADOQuery1.FieldByName('sell_number').asinteger;
- ADOQuery1.Prior;
- end;
- Label4.Caption := FloatToStr(MoneyTotal);
- ADOQuery1.Append;
- DBEdit1.SetFocus;
- Edit1.Color := clWhite;
- Edit1.Enabled := True;
- Image4.Enabled := True;
- Label7.Enabled := True;
- end
- else
- messagebox(handle,'您的输入不正确(空值)!','检查输入',mb_iconwarning+mb_ok)
- end;
- procedure TFrameSell.Image7Click(Sender: TObject);
- var
- i: integer;
- begin
- ADOQuery1.Edit;
- ADOQuery1.Post;
- Image7.Visible := False;
- MoneyTotal := 0;
- for i:=1 to ADOQuery1.RecordCount do
- begin
- MoneyTotal := MoneyTotal + ADOQuery1.FieldByName('sell_prod_Price').AsVariant * ADOQuery1.FieldByName('sell_number').asinteger;
- ADOQuery1.Prior;
- end;
- Label4.Caption := FloatToStr(MoneyTotal);
- ADOQuery1.Append;
- end;
- procedure TFrameSell.Image5Click(Sender: TObject);
- var
- i: integer;
- begin
- ADOQuery1.Cancel;
- for i:=1 to ADOQuery1.RecordCount do
- ADOQuery1.delete;
- DBEdit1.Color := $00FFF0DC;
- DBEdit2.Color := $00FFF0DC;
- DBEdit1.Enabled := False;
- DBEdit2.Enabled := False;
- ADOQuery1.Active := False;
- image2.Enabled := True;
- image3.Visible := False;
- image5.Visible := False;
- image6.Visible := False;
- Image7.Visible := False;
- Edit1.Text := '';
- Label4.Caption := '0';
- Edit1.Color := $00FFF0DC;
- Image4.Enabled := False;
- Label7.Enabled := False;
- Edit1.Enabled := False;
- end;
- procedure TFrameSell.DBEdit2KeyPress(Sender: TObject; var Key: Char);
- begin
- if Key=#13 then Image3Click(self);
- end;
- procedure TFrameSell.Image6Click(Sender: TObject);
- var
- i: integer;
- begin
- ADOQuery1.Cancel;
- if ADOQuery1.RecordCount>0 then ADOQuery1.Delete;
- if ADOQuery1.RecordCount<=0 then
- begin
- Edit1.Text := '';
- Label4.Caption := '0';
- Edit1.Color := $00FFF0DC;
- Image4.Enabled := False;
- Label7.Enabled := False;
- Edit1.Enabled := False;
- end;
- MoneyTotal := 0;
- for i:=1 to ADOQuery1.RecordCount do
- begin
- MoneyTotal := MoneyTotal + ADOQuery1.FieldByName('sell_prod_Price').AsVariant * ADOQuery1.FieldByName('sell_number').asinteger;
- ADOQuery1.Prior;
- end;
- Label4.Caption := FloatToStr(MoneyTotal);
- ADOQuery1.Append;
- Image7.Visible := False;
- end;
- procedure TFrameSell.DBGrid1CellClick(Column: TColumn);
- begin
- Image7.Visible := True;
- end;
- procedure TFrameSell.Image4Click(Sender: TObject);
- var
- i: integer;
- begin
- if (Edit1.Text<>'') and IsAllNum(Edit1.Text) then
- begin
- if (StrToFloat(Edit1.Text)<MoneyTotal) then
- begin
- messagebox(handle,pchar('应该收金额为 '+FloatToStr(MoneyTotal)+' 元,收款不足!'),'检查输入',mb_iconwarning+mb_ok);
- exit;
- end;
- ADOQuery1.Cancel;
- {!!!!!! = 库存量相应减少代码 = !!!!!}
- for i:=1 to ADOQuery1.RecordCount do
- begin
- ADOQuery2:= TADOQuery.Create(self);
- ADOQuery2.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataFile+';Persist Security Info=False;';
- ADOQuery2.SQL.Clear;
- ADOQuery2.SQL.Add('update t_prod set prod_stock=prod_stock-'+ADOQuery1.FieldByName('sell_number').AsString+',prod_sale=prod_sale+'+ADOQuery1.FieldByName('sell_number').AsString+' where prod_id='+ADOQuery1.FieldByName('sell_prod_id').AsString);
- ADOQuery2.ExecSQL;
- end;
- ADOQuery1.SQL.Clear;
- ADOQuery1.SQL.Add('update t_sell set sell_pay = 1');
- ADOQuery1.ExecSQL;
- ADOQuery1.SQL.Clear;
- ADOQuery1.SQL.Add('select * from t_sell where not sell_pay');
- Messagebox(handle,pchar('找零 '+FloatToStr(StrToFloat(Edit1.Text)-MoneyTotal)+' 元,谢谢惠顾!'),'销售完成',mb_iconwarning+mb_ok);
- DBEdit1.Color := $00FFF0DC;
- DBEdit2.Color := $00FFF0DC;
- DBEdit1.Enabled := False;
- DBEdit2.Enabled := False;
- ADOQuery1.Active := False;
- image2.Enabled := True;
- image3.Visible := False;
- image5.Visible := False;
- image6.Visible := False;
- Image7.Visible := False;
- Edit1.Text := '';
- Label4.Caption := '0';
- Edit1.Color := $00FFF0DC;
- Image4.Enabled := False;
- Label7.Enabled := False;
- Edit1.Enabled := False;
- end
- else
- begin
- messagebox(handle,'您的输入不正确(空值或非数值)!','检查输入',mb_iconwarning+mb_ok);
- Edit1.SetFocus;
- end;
- end;
- function TFrameSell.IsAllNum(s:string):bool;
- var
- i:integer;
- begin
- for i := 1 To Length(s) do
- if (s[i] < '0') or (s[i] > '9') then
- begin
- IsAllNum := False;
- Exit;
- end;
- IsAllNum := True;
- end;
- procedure TFrameSell.Edit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if Key=#13 then Image4Click(self);
- end;
- procedure TFrameSell.Label7Click(Sender: TObject);
- begin
- Image4Click(self);
- end;
- end.