📄 usale.~pas
字号:
unit USale;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,IdGlobal;
type
TForm6 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
SpeedButton1: TSpeedButton;
procedure Button1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form6: TForm6;
AmountLeft:Integer;
implementation
uses USelect, Udm;
{$R *.dfm}
procedure TForm6.Button1Click(Sender: TObject);
var
strSql:String;
nDiscount,nAmount:Integer;
begin
//是否已经选择了某一书本
if Edit1.Text = '' then
begin
Application.MessageBox('请先选择书籍!','系统提示');
Exit;
end;
nDiscount :=StrToIntDef(Trim(Edit2.Text),-1);
if (nDiscount>100) or (nDiscount<0) then
begin
Application.MessageBox('输入的折扣有错!','系统提示');
Exit;
end;
nAmount :=StrToIntDef(Edit3.Text,-1);
if (nAmount<1) then
begin
Application.MessageBox('输入数量出错!','系统提示');
Exit;
end;
if nAmount>AmountLeft then
begin
Application.MessageBox('库存不够!','系统提示');
Exit;
end;
//保存数据
Dm.ConnBookstore.BeginTrans;
try
strSql :='Insert SalesList (Discount,Amount,ISBN) Values('
+Trim(Edit2.Text)+','+Trim(Edit3.Text)+','''
+Trim(Edit1.Text)+''')';
Dm.ConnBookstore.Execute(strSql);
strSql :='Update book Set AmountLeft='+IntToStr(AmountLeft-nAmount)
+'Where ISBN='''+Trim(Edit1.Text)+'''';
Dm.ConnBookstore.Execute(strSql);
Dm.ConnBookstore.CommitTrans;
Application.MessageBox('操作成功!','系统提示');
Edit1.Text :='';
Edit2.Text :='';
Edit3.Text :='';
except
Dm.ConnBookstore.RollbackTrans;
end;
end;
procedure TForm6.SpeedButton1Click(Sender: TObject);
begin
if Form7.ShowModal=mrOK then
begin
Edit1.Text :=Dm.TblBook.FieldByName('ISBN').AsString;
AmountLeft :=Dm.TblBook.FieldByName('AmountLeft').AsInteger;
end;
end;
procedure TForm6.Button2Click(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -