📄 addbookinfo.~pas
字号:
unit AddBookInfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids,DB, Mask, DBCtrls;
type
TFrmAddBookInfo = class(TForm)
GrpBoxPurchaseInfo: TGroupBox;
DBGridPurInfo: TDBGrid;
LblID: TLabel;
LblName: TLabel;
BtnEdt: TButton;
BtnEdit: TButton;
BtnDelete: TButton;
BtnExit: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
EdtID: TEdit;
EdtAuthor: TEdit;
EdtName: TEdit;
EdtPress: TEdit;
EdtPrice: TEdit;
procedure BtnEdtClick(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure BtnEditClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BtnDeleteClick(Sender: TObject);
private
AddEdit:ShortInt; //判断否新增[1],编辑[2]
{ Private declarations }
public
{ Public declarations }
end;
var
FrmAddBookInfo: TFrmAddBookInfo;
implementation
uses DataModuel;
{$R *.dfm}
procedure TFrmAddBookInfo.BtnEdtClick(Sender: TObject);
begin
if DM.BookInfoTable.RecordCount=0 then
begin
MessageDlg('当前没有信息可能编辑!',mtError,[mbOK],0);
exit;
end;
EdtID.Enabled:=True;
EdtName.Enabled:=True;
EdtAuthor.Enabled:=True;
EdtPress.Enabled:=True;
EdtPrice.Enabled:=True;
EdtID.Text:=DM.BookInfoTable['BookID'];
EdtName.Text:=DM.BookInfoTable['BookName'];
EdtAuthor.Text:=DM.BookInfoTable['Author'];
EdtPress.Text:=DM.BookInfoTable['Press'];
EdtPrice.Text:=DM.BookInfoTable['Price'];
BtnEdit.Caption:='保存';
AddEdit:=2;
end;
procedure TFrmAddBookInfo.BtnExitClick(Sender: TObject);
begin
close;
end;
procedure TFrmAddBookInfo.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TFrmAddBookInfo.FormDestroy(Sender: TObject);
begin
FrmAddBookInfo:=nil;
end;
procedure TFrmAddBookInfo.BtnEditClick(Sender: TObject);
begin
if Trim(BtnEdit.Caption)='新增' then
begin
EdtID.Text:='';
EdtName.Text:='';
EdtAuthor.Text:='';
EdtPress.Text:='';
EdtPrice.Text:='';
BtnEdit.Caption:='保存';
AddEdit:=1;
EdtID.Enabled:=True;
EdtName.Enabled:=True;
EdtAuthor.Enabled:=True;
EdtPress.Enabled:=True;
EdtPrice.Enabled:=True;
exit;
end;
if Trim(BtnEdit.Caption)='保存' then
begin
if Trim(EdtID.Text)='' then
begin
MessageDlg('图书编号不能为空!',mtError,[mbOk],0);
EdtID.SetFocus;
exit;
end;
if Trim(EdtName.Text)='' then
begin
MessageDlg('书籍不能为空!',mtError,[mbOk],0);
EdtName.SetFocus;
exit;
end;
if Trim(EdtPrice.Text)='' then
begin
MessageDlg('书籍价格不能为空',mtError,[mbOK],0);
EdtPrice.SetFocus;
exit;
end;
if AddEdit=1 then
begin
if DM.BookInfoTable.Locate('BookID',Trim(EdtID.Text),[loCaseInsensitive]) then
begin
MessageDlg('图书编号已经存在!',mtError,[mbOK],0);
EdtID.SetFocus;
exit;
end;
end;
if AddEdit=1 then
DM.BookInfoTable.Append
else
DM.BookInfoTable.Edit;
DM.BookInfoTable['BookID']:=Trim(EdtID.Text);
DM.BookInfoTable['BookName']:=Trim(EdtName.Text);
DM.BookInfoTable['Author']:=Trim(EdtAuthor.Text);
DM.BookInfoTable['Press']:=Trim(EdtPress.Text);
DM.BookInfoTable['Price']:=Trim(EdtPrice.Text);
DM.BookInfoTable.Post;
EdtID.Text:='';
EdtName.Text:='';
EdtAuthor.Text:='';
EdtPress.Text:='';
EdtPrice.Text:='';
BtnEdit.Caption:='新增';
EdtID.Enabled:=False;
EdtName.Enabled:=False;
EdtAuthor.Enabled:=False;
EdtPress.Enabled:=False;
EdtPrice.Enabled:=False;
DM.BookInfoTable.Active:=False;
DM.BookInfoTable.Active:=True;
MessageDlg('信息保存成功!',mtInformation,[mbOk],0);
end;
end;
procedure TFrmAddBookInfo.FormCreate(Sender: TObject);
begin
DM.BookInfoTable.Active:=True;
EdtID.Enabled:=False;
EdtName.Enabled:=False;
EdtAuthor.Enabled:=False;
EdtPress.Enabled:=False;
EdtPrice.Enabled:=False;
end;
procedure TFrmAddBookInfo.BtnDeleteClick(Sender: TObject);
begin
if DM.BookInfoTable.RecordCount=0 then
exit;
if Application.MessageBox('要删除当前记录吗?','提示',MB_ICONQUESTION or MB_YESNO )=IDYES then
DM.BookInfoTable.Delete;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -