📄 c_selledit.pas
字号:
unit c_selledit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, Mask, DBCtrls;
type
Tcfrm_selledit = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
DBComboBox1: TDBComboBox;
DBEdit1: TDBEdit;
DBComboBox2: TDBComboBox;
DBEdit2: TDBEdit;
DBComboBox3: TDBComboBox;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
DateTimePicker1: TDateTimePicker;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure DBComboBox2Change(Sender: TObject);
procedure DBComboBox3Change(Sender: TObject);
procedure DBComboBox1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
cfrm_selledit: Tcfrm_selledit;
implementation
uses c_sell, datam;
{$R *.dfm}
procedure Tcfrm_selledit.FormCreate(Sender: TObject);
begin
dm.ADO_customer.Open;
dm.ADO_customer.First;
while not dm.ADO_customer.Eof do
begin
DBCombobox1.Items.Add(dm.ADO_customer.fieldbyname('CustomerID').AsString);
dm.ADO_customer.Next;
end;
dm.ADO_depot.Open;
dm.ADO_depot.First;
while not dm.ADO_depot.Eof do
begin
DBCombobox2.Items.Add(dm.ADO_depot.fieldbyname('DepotID').AsString);
dm.ADO_depot.Next;
end;
DateTimePicker1.Date:=date();
end;
procedure Tcfrm_selledit.DBComboBox2Change(Sender: TObject);
var i:integer;
begin
DBCombobox3.Items.Clear;
dm.ADO_depot.First;
if dm.ADO_depot.Locate('DepotID',DBCombobox2.Text,[]) then
begin
dbedit2.Text:=dm.ADO_depot.fieldbyname('DepotName').AsString;
dm.ADOQ_cx.close;
dm.ADOQ_cx.sql.clear;
dm.ADOQ_cx.sql.add('select * from Storage where DepotID='+''''+DBCombobox2.text+'''');
dm.ADOQ_cx.open;
dm.ADOQ_cx.first;
if dm.ADOQ_cx.recordcount=0 then
showmessage('对不起,本仓库没有货品库存!')
else
begin
dm.ADOQ_cx.First;
while not dm.ADOQ_cx.Eof do
begin
DBcombobox3.items.Add(dm.ADOQ_cx.fieldbyname('ProductID').AsString);
dm.ADOQ_cx.Next;
end;
end;
end;
end;
procedure Tcfrm_selledit.DBComboBox3Change(Sender: TObject);
begin
dm.ADO_storage.Open;
dm.ADO_storage.First;
if dm.ADO_storage.Locate('ProductID;DepotID',VarArrayOf([DBCombobox3.Text,DBCombobox2.Text]),[]) then
begin
dbedit3.Text:=dm.ADO_storage.fieldbyname('ProductName').AsString;
dbedit4.Text:=dm.ADO_storage.fieldbyname('Spec').AsString;
dbedit5.Text:=dm.ADO_storage.fieldbyname('Unit').AsString;
end;
end;
procedure Tcfrm_selledit.DBComboBox1Change(Sender: TObject);
begin
dm.ADO_customer.First;
if dm.ADO_customer.Locate('CustomerID',DBCombobox1.Text,[]) then
dbedit1.Text:=dm.ADO_customer.fieldbyname('CompanyName').AsString;
end;
procedure Tcfrm_selledit.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
dm.ADO_customer.Close;
dm.ADO_depot.Close;
dm.ADO_storage.Close;
dm.ADO_product.Close;
release;
end;
procedure Tcfrm_selledit.BitBtn1Click(Sender: TObject);
var
paymoney,Quantity:double;
begin
if Length(dbedit6.Text)=0 then
begin
Application.MessageBox(PChar('商品数量不能为空,请重新录入!')
, PChar('提示'),MB_ICONEXCLAMATION);
dbedit6.SetFocus();
exit;
end;
if dbedit7.Text='' then
begin
Application.MessageBox(PChar('商品单价不能为空,请重新录入!')
, PChar('提示'),MB_ICONEXCLAMATION);
dbedit7.SetFocus();
exit;
end;
if dbcombobox1.Text='' then
begin
Application.MessageBox(PChar('客户编号不能为空,请重新录入!')
, PChar('提示'),MB_ICONEXCLAMATION);
dbcombobox1.SetFocus();
exit;
end;
if dbcombobox2.Text='' then
begin
Application.MessageBox(PChar('仓库编号不能为空,请重新录入!')
, PChar('提示'),MB_ICONEXCLAMATION);
dbcombobox2.SetFocus();
exit;
end;
if dbcombobox3.Text='' then
begin
Application.MessageBox(PChar('商品编号不能为空,请重新录入!')
, PChar('提示'),MB_ICONEXCLAMATION);
dbcombobox3.SetFocus();
exit;
end;
paymoney:=StrtoFloat(dbedit7.Text)*Strtofloat(dbedit6.Text);
dm.ADO_storage.Open;
dm.ADO_storage.first;
dm.ADO_storage.Locate('ProductID;DepotID',VarArrayOf([DBCombobox3.Text,DBCombobox2.Text]),[]);
Quantity:=dm.ADO_storage.fieldbyname('Quantity').asfloat-strtofloat(DBEdit6.Text);
if Quantity<0 then
begin
showmessage('对不起,本类货品在此仓库中库存不够出库数量!');
exit;
end
else if Quantity>=0 then
begin
if Bitbtn1.Tag=1 then dm.ADO_sell.Edit;
dm.ADO_sell.fieldbyname('selldate').AsDateTime:=strtodate(datetostr(DatetimePicker1.Date));
dm.ADO_sell.FieldByName('Payment').AsFloat:=paymoney;
try
dm.ADO_sell.Post;
except
Application.MessageBox(PChar('输入数据有误,请重新录入!'), PChar('提示'),
MB_ICONEXCLAMATION);
DBCombobox1.SetFocus();
exit;
end;
dm.ADO_storage.first;
if dm.ADO_storage.Locate('ProductID;DepotID',VarArrayOf([DBCombobox3.Text,DBCombobox2.Text]),[])then
begin
if Quantity=0 then dm.ADO_storage.Delete //库存数量为0则删除该库存记录
else
begin
dm.ADO_storage.Edit;
dm.ADO_storage.FieldByName('Quantity').AsFloat:= dm.ADO_storage.FieldByName('Quantity').AsFloat-Strtofloat(dbedit6.text);
dm.ADO_storage.Post;
end;
end;
end;
dm.ADO_customer.Close;
dm.ADO_depot.Close;
dm.ADO_storage.Close;
dm.ADO_product.Close;
close;
end;
procedure Tcfrm_selledit.BitBtn2Click(Sender: TObject);
begin
dm.ADO_sell.Cancel;
dm.ADO_customer.Close;
dm.ADO_depot.Close;
dm.ADO_storage.Close;
dm.ADO_product.Close;
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -