📄 room.pas
字号:
unit room;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Mask, Grids, DBGrids, Db, DBTables, ComCtrls;
type
Troomform = class(TForm)
Label1: TLabel;
rmtype: TComboBox;
Label2: TLabel;
Label3: TLabel;
sl: TMaskEdit;
Bevel1: TBevel;
Label4: TLabel;
rmno: TMaskEdit;
jg: TMaskEdit;
Label6: TLabel;
s0: TRadioButton;
s1: TRadioButton;
Bevel3: TBevel;
Bevel4: TBevel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
DBGrid1: TDBGrid;
s2: TRadioButton;
DataSource1: TDataSource;
Q1: TQuery;
Q2: TQuery;
s3: TRadioButton;
StatusBar1: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure rmtypeClick(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
roomform: Troomform;
implementation
uses dataproc;
{$R *.DFM}
var
but,oldroomno:string;
procedure formini;
begin
with roomform do
begin
rmno.text:='';
s0.Checked :=true;
button1.Enabled :=true;
button2.Enabled :=true;
button3.Enabled :=true;
button4.Enabled :=false;
button5.Enabled :=false;
if rmno.Enabled =false then
rmno.enabled:=true;
end
end;
procedure formunini;
begin
with roomform do
begin
button1.Enabled :=false;
button2.Enabled :=false;
button3.Enabled :=false;
button4.Enabled :=true;
button5.Enabled :=true;
end
end;
procedure datatoctr;
var
aa:array [0..2] of string;
begin
with roomform do
begin
if rmtype.itemindex>-1 then
begin
getvalue(aa,'select price,bednum from roomtype where roomtype="'+copy(rmtype.items[rmtype.itemindex],1,2)+'"');
jg.text:=aa[0];
sl.text:=aa[1];
q1.Active :=false;
q1.sql.clear;
q1.sql.add('select roomno,status from room where roomtype=:proomtype');
q1.ParamByName ('proomtype').asstring:=copy(rmtype.items[rmtype.itemindex],1,2);
q1.Prepare;
q1.open;
chinesegrid(dbgrid1);
q1.Active :=true;
end
end
end;
procedure Troomform.FormCreate(Sender: TObject);
begin
formini;
comadd(rmtype,2,'select roomtype,name from roomtype');
datatoctr;
end;
procedure Troomform.rmtypeClick(Sender: TObject);
begin
datatoctr;
end;
procedure Troomform.Button6Click(Sender: TObject);
begin
roomform.close;
end;
procedure Troomform.Button1Click(Sender: TObject);
begin
but:='1';
formunini;
rmno.SetFocus ;
end;
procedure Troomform.Button5Click(Sender: TObject);
begin
formini;
end;
procedure Troomform.Button4Click(Sender: TObject);
begin
if length(trim(rmno.text))=0 then
begin
showmessage('房间编号不能为空');
rmno.SetFocus ;
exit;
end;
if but='1' then
try
q2.Active :=false;
q2.sql.Add('insert into room values(:proomno,:proomtype,:pstatus)');
q2.ParamByName ('proomno').asstring:=trim(rmno.text);
q2.ParamByName ('proomtype').asstring:=copy(rmtype.Items[rmtype.itemindex],1,2);
if s0.Checked =true then
q2.ParamByName ('pstatus').asstring:='0';
if s1.checked =true then
q2.ParamByName ('pstatus').asstring:='1';
if s2.checked =true then
q2.ParamByName ('pstatus').asstring:='2';
if s3.checked =true then
q2.ParamByName ('pstatus').asstring:='3';
q2.Prepare;
q2.ExecSQL;
q1.active:=false;
q1.Active :=true;
chinesegrid(dbgrid1);
formini;
except
showmessage('编号已存在');
rmno.SetFocus ;
end;
if but='2' then
try
q2.Active :=false;
q2.sql.clear;
q2.sql.add('update room set roomno=:proomno,roomtype=:proomtype,status=:pstatus where roomno=:poldroomno');
q2.ParamByName ('proomno').asstring:=trim(rmno.text);
q2.ParamByName ('proomtype').asstring:=copy(rmtype.Items[rmtype.itemindex],1,2);
if s0.Checked =true then
q2.ParamByName ('pstatus').asstring:='0';
if s1.checked =true then
q2.ParamByName ('pstatus').asstring:='1';
if s2.checked =true then
q2.ParamByName ('pstatus').asstring:='2';
if s3.checked =true then
q2.ParamByName ('pstatus').asstring:='3';
q2.ParamByName ('poldroomno').asstring:=oldroomno;
q2.Prepare;
q2.ExecSQL;
q1.Active :=false;
q1.Active :=true;
chinesegrid(dbgrid1);
formini;
except
showmessage('编号已存在');
rmno.SetFocus ;
end;
if but='3' then
try
if messagedlg('确实删除吗?',mtWarning,[mbyes,mbno],1)=mryes then
begin
q2.Active :=false;
q2.sql.add('delete room where roomno=:proomno');
q2.ParamByName ('proomno').asstring:=oldroomno;
q2.Prepare;
q2.ExecSQL;
q1.Active :=false;
q1.Active :=true;
chinesegrid(dbgrid1);
end;
finally
formini;
end;
end;
procedure Troomform.Button2Click(Sender: TObject);
begin
but:='2';
if q1.RecordCount =0 then
showmessage('无记录,不能修改')
else
begin
rmno.Text :=q1.fieldbyname('roomno').asstring;
oldroomno:=trim(rmno.text);
if trim(q1.FieldByName ('status').asstring)='0' then
s0.Checked :=true;
if trim(q1.FieldByName ('status').asstring)='1' then
s1.Checked :=true;
if trim(q1.FieldByName ('status').asstring)='2' then
s2.Checked :=true;
if trim(q1.FieldByName ('status').asstring)='3' then
s3.Checked :=true;
formunini;
end
end;
procedure Troomform.Button3Click(Sender: TObject);
begin
but:='3';
if q1.RecordCount =0 then
showmessage('无记录,不能删除')
else
begin
rmno.Text :=q1.fieldbyname('roomno').asstring;
oldroomno:=trim(rmno.text);
if trim(q1.FieldByName ('status').asstring)='0' then
s0.Checked :=true;
if trim(q1.FieldByName ('status').asstring)='1' then
begin
showmessage('此房间正在使用!');
s1.Checked :=true;
exit;
end;
if trim(q1.FieldByName ('status').asstring)='2' then
s2.Checked :=true;
if trim(q1.FieldByName ('status').asstring)='3' then
s3.Checked :=true;
formunini;
rmno.Enabled :=false;
end
end;
procedure Troomform.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
selectnext(activecontrol,true,true);
end;
procedure Troomform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
q1.free;
q2.free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -