📄 salsrecord.pas
字号:
unit salsrecord;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TF_salsrecord = class(TForm)
Panel1: TPanel;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
btn_Search: TBitBtn;
btn_Update: TBitBtn;
btn_Add: TBitBtn;
btn_Delete: TBitBtn;
btn_Clear: TBitBtn;
btn_Out: TBitBtn;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
procedure btn_SearchClick(Sender: TObject);
procedure btn_UpdateClick(Sender: TObject);
procedure btn_AddClick(Sender: TObject);
procedure btn_DeleteClick(Sender: TObject);
procedure btn_ClearClick(Sender: TObject);
procedure btn_OutClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_salsrecord: TF_salsrecord;
strSQL:String;
implementation
uses datamodule;
{$R *.dfm}
procedure TF_salsrecord.btn_SearchClick(Sender: TObject);
begin
with DM_datamodule do
begin
if crmDB.Connected then
begin
with qry_SalsRecord do
begin
create(nil);
sql.Add('select * from SalsRecord where 产品编号=:f1');
Parambyname('f1').AsString:=combobox2.Text;
prepare;
open;
if Recordcount<>0 then
begin
combobox1.Text:=fieldbyname('客户编号').AsString;
edit3.Text:=fieldbyname('销售日期').AsString;
edit4.Text:=fieldbyname('销售数量').AsString;
Close;
end
else
begin
messagedlg('不存在该销售记录!查找失败!',mtinformation,[mbok],0);
close;
end;
end;
end
else
messagedlg('请先登陆!',mtinformation,[mbok],0);
end;
end;
procedure TF_salsrecord.btn_UpdateClick(Sender: TObject);
begin
strSQL:='update SalsRecord set 客户编号=:f2,销售日期=:f3,销售数量=:f4 where 产品编号=:f1';
with DM_datamodule do
begin
if crmDB.Connected then
begin
with qry_SalsRecord do
begin
create(nil);
sql.Add('select * from SalsRecord where 产品编号=:f1');
Parambyname('f1').AsString:=combobox2.Text;
open;
if Recordcount<>0 then
begin
sql.Add(strSQL);
Parambyname('f2').AsString:=combobox1.Text;
Parambyname('f3').AsDateTime:=strtodatetime(edit3.Text);
Parambyname('f4').AsFloat:=strtofloat(edit4.Text);
ExecSQL;
Close;
messagedlg('修改成功!',mtinformation,[mbok],0);
end
else
begin
messagedlg('不存在该销售记录!修改失败!',mtinformation,[mbok],0);
close;
end;
end;
end
else
messagedlg('请先登陆!',mtinformation,[mbok],0);
end;
end;
procedure TF_salsrecord.btn_AddClick(Sender: TObject);
begin
strSQL:='insert into SalsRecord values(:f1,:f2,:f3,:f4)';
with DM_datamodule do
begin
if crmDB.Connected then
begin
with qry_SalsRecord do
begin
create(nil);
sql.Add('select * from SalsRecord where 产品编号=:f1');
Parambyname('f1').AsString:=combobox2.Text;
open;
if Recordcount=0 then
begin
sql.Add(strSQL);
Parambyname('f2').AsString:=combobox1.Text;
Parambyname('f3').AsDateTime:=strtodatetime(edit3.Text);
Parambyname('f4').AsFloat:=strtofloat(edit4.Text);
ExecSQL;
Close;
messagedlg('新增成功!',mtinformation,[mbok],0);
end
else
begin
messagedlg('已经存在该销售记录!新增失败!',mtinformation,[mbok],0);
close;
end;
end;
end
else
messagedlg('请先登陆!',mtinformation,[mbok],0);
end;
end;
procedure TF_salsrecord.btn_DeleteClick(Sender: TObject);
begin
strSQL:='delete from SalsRecord where 产品编号=:f1';
with DM_datamodule do
begin
if crmDB.Connected then
begin
if messagedlg('确定要删除吗?',mtinformation,[mbyes,mbno],0)=mrYes then
begin
if messagedlg('确定要删除吗?',mtinformation,[mbyes,mbno],0)=mrYes then
begin
with qry_SalsRecord do
begin
create(nil);
sql.Add('select * from SalsRecord where 产品编号=:f1');
Parambyname('f1').AsString:=combobox2.Text;
open;
if Recordcount<>0 then
begin
sql.Add(strSQL);
ExecSQL;
Close;
messagedlg('删除成功!',mtinformation,[mbok],0);
edit3.Text:=datetostr(now);
edit4.Text:='0';
end
else
begin
messagedlg('不存在该销售记录!删除失败!',mtinformation,[mbok],0);
close;
end;
end;
end;
end;
end
else
messagedlg('请先登陆!',mtinformation,[mbok],0);
end;
end;
procedure TF_salsrecord.btn_ClearClick(Sender: TObject);
begin
edit3.Text:=datetostr(now);
edit4.Text:='0';
end;
procedure TF_salsrecord.btn_OutClick(Sender: TObject);
begin
combobox1.Clear;
combobox2.Clear;
edit3.Text:=datetostr(now);
edit4.Text:='0';
Close;
end;
procedure TF_salsrecord.FormShow(Sender: TObject);
begin
with DM_datamodule.qry_CustomersInfo do
begin
close;
sql.Clear;
sql.Add('select 客户编号 from CustomersInfo');
try
prepare;
execsql;
open;
first;
while not eof do
begin
combobox1.Items.Add(fieldbyname('客户编号').AsString);
next;
end;
finally
close;
end;
end;
combobox1.Text:=combobox1.Items.Text;
combobox1.ItemIndex:=0;
with DM_datamodule.qry_ProductorInfo do
begin
close;
sql.Clear;
sql.Add('select 产品编号 from ProductorInfo');
try
prepare;
execsql;
open;
first;
while not eof do
begin
combobox2.Items.Add(fieldbyname('产品编号').AsString);
next;
end;
finally
close;
end;
end;
combobox2.Text:=combobox2.Items.Text;
combobox2.ItemIndex:=0;
edit3.Text:=datetostr(now);
edit4.Text:='0';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -