📄 frm_houseu.~pas
字号:
unit frm_houseU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, frm_infoU, DB, StdCtrls, Grids, DBGrids, ComCtrls,Control_houseU,
ClassesU;
type
Tfrm_house = class(Tfrm_info)
edt_houseNo: TEdit;
Label1: TLabel;
Label2: TLabel;
edt_floorNum: TEdit;
Label3: TLabel;
edt_roomNum: TEdit;
Label4: TLabel;
DTP_begin: TDateTimePicker;
Label5: TLabel;
Memo_remark: TMemo;
procedure FormShow(Sender: TObject);
procedure btn_delClick(Sender: TObject);
procedure edt_floorNumKeyPress(Sender: TObject; var Key: Char);
procedure edt_roomNumKeyPress(Sender: TObject; var Key: Char);
procedure btn_addClick(Sender: TObject);
procedure btn_editClick(Sender: TObject);
procedure DBGrid_infoCellClick(Column: TColumn);
private
{ Private declarations }
public
//填充数据
procedure FillData;
end;
var
frm_house: Tfrm_house;
implementation
{$R *.dfm}
procedure Tfrm_house.FillData;
begin
DataSource_info.DataSet:=Control_houseU.GetHouseArray;
self.DBGrid_info.Columns[0].Visible :=false;
end;
procedure Tfrm_house.FormShow(Sender: TObject);
begin
inherited;
FillData;
end;
procedure Tfrm_house.btn_delClick(Sender: TObject);
var
House:THouse;
begin
if(self.btn_del.Caption='删除') then
begin
if MessageBox(Handle, '您确定要删除该公寓信息', '信息',
MB_ICONQUESTION or MB_OKCANCEL) = IDOK then
begin
Control_houseU.DelHouse(self.edt_houseNo.Tag);
FillData;
if self.DBGrid_info.Fields[0].IsNull then
exit;
self.edt_houseNo.Tag:=self.DBGrid_info.Fields[0].Value;//保存id
self.edt_houseNo.Text :=self.DBGrid_info.Fields[1].Value;
self.edt_floorNum.Text:=inttostr(self.DBGrid_info.Fields[2].Value);
self.edt_roomNum.Text:=inttostr(self.DBGrid_info.Fields[3].Value);
self.DTP_begin.Date:=self.DBGrid_info.Fields[4].Value;
self.Memo_remark.Text:=self.DBGrid_info.Fields[5].Value;
end;
end;
if(self.btn_del.Caption='保存') then
begin
if((edt_houseNo.Text='') or (edt_floorNum.Text='')
or (edt_roomNum.Text='')) then
begin
MessageBox(Handle, '内容填写不正确!', '信息', MB_ICONEXCLAMATION);
exit;
end;
//查找是否存在重复
House:=THouse.Create;
House:=GetHouseByHouseNo(trim(edt_houseNo.Text));
if(House<>nil) then
begin
if(House.id<>edt_houseNo.Tag) then
begin
MessageBox(Handle, '公寓号已经存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
exit;
end;
end;
House:=THouse.Create;
House.id:=edt_houseNo.Tag;
House.HouseID:=trim(edt_houseNo.Text);
House.floorNum:=strtoint(trim(edt_floorNum.Text));
House.roomNum:=strtoint(trim(edt_roomNum.Text));
House.beginDate:=DateToStr(self.DTP_begin.Date);
House.remark:=self.Memo_remark.Text;
if(Control_houseU.EditHouse(House)) then
begin
MessageBox(Handle, '修改成功!', '信息', MB_ICONASTERISK);
//刷新内容
FillData;
end
else
begin
MessageBox(Handle, '修改失败!', '信息', MB_ICONEXCLAMATION);
exit;
end;
end;
if(self.btn_del.Caption='确定') then
begin
if((edt_houseNo.Text='') or (edt_floorNum.Text='')
or (edt_roomNum.Text='')) then
begin
MessageBox(Handle, '内容填写不正确!', '信息', MB_ICONEXCLAMATION);
exit;
end;
//查找是否存在重复
if (GetHouseByHouseNo(trim(edt_houseNo.Text)))<>nil then
begin
MessageBox(Handle, '公寓号已经存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
exit;
end;
House:=THouse.Create;
House.HouseID:=trim(edt_houseNo.Text);
House.floorNum:=strtoint(trim(edt_floorNum.Text));
House.roomNum:=strtoint(trim(edt_roomNum.Text));
House.beginDate:=DateToStr(self.DTP_begin.Date);
House.remark:=self.Memo_remark.Text;
if(Control_houseU.AddHouse(House)) then
begin
MessageBox(Handle, '添加成功!', '信息', MB_ICONASTERISK);
self.edt_houseNo.Text :='';
self.edt_floorNum.Text :='';
self.edt_roomNum.Text :='';
self.Memo_remark.Text :='';
//刷新内容
FillData;
end
else
begin
MessageBox(Handle, '添加失败!', '信息', MB_ICONEXCLAMATION);
exit;
end;
end;
inherited;
end;
procedure Tfrm_house.edt_floorNumKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not((key in ['0'..'9',#8,#13])) then
key:=#0;
end;
procedure Tfrm_house.edt_roomNumKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not((key in ['0'..'9',#8,#13])) then
key:=#0;
end;
procedure Tfrm_house.btn_addClick(Sender: TObject);
begin
inherited;
self.edt_houseNo.Tag:=0;
self.edt_houseNo.Text :='';
self.edt_floorNum.Text :='';
self.DTP_begin.Date:=strtodate('1980-1-1');
self.edt_roomNum.Text :='';
self.Memo_remark.Text :='';
self.edt_houseNo.SetFocus;
end;
procedure Tfrm_house.btn_editClick(Sender: TObject);
begin
if self.btn_edit.Caption='修改' then
begin
if edt_houseNo.Text ='' then
begin
MessageBox(Handle, '没有可以修改的数据!', '信息', MB_ICONEXCLAMATION);
exit;
end
else
begin
self.edt_houseNo.SetFocus;
end;
end;
inherited;
end;
procedure Tfrm_house.DBGrid_infoCellClick(Column: TColumn);
begin
if self.DBGrid_info.Fields[0].IsNull then
exit;
self.edt_houseNo.Tag:=self.DBGrid_info.Fields[0].Value;//保存id
self.edt_houseNo.Text :=self.DBGrid_info.Fields[1].Value;
self.edt_floorNum.Text:=inttostr(self.DBGrid_info.Fields[2].Value);
self.edt_roomNum.Text:=inttostr(self.DBGrid_info.Fields[3].Value);
self.DTP_begin.Date:=self.DBGrid_info.Fields[4].Value;
self.Memo_remark.Text:=self.DBGrid_info.Fields[5].Value;
inherited;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -