📄 decgroomunit.~pas
字号:
unit DecGRoomUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, Buttons, StdCtrls, DB, DBTables, ComCtrls,
ExtCtrls, Mask, jpeg, ImgList;
type
TFrmDecGRoom = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
GuestIDCB: TComboBox;
LookUpIDSB: TSpeedButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
StopDBGrid: TDBGrid;
GroupBox3: TGroupBox;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
EndME: TMaskEdit;
Edit1: TEdit;
PriceLabel1: TLabel;
EndRoomCB: TEdit;
EndBedCB: TEdit;
Image1: TImage;
ImageList1: TImageList;
StopOKSB: TSpeedButton;
CloseSB: TSpeedButton;
StatusBar1: TStatusBar;
ChooseDTSB: TSpeedButton;
procedure LookUpIDSBClick(Sender: TObject);
procedure GuestIDCBChange(Sender: TObject);
procedure StopOKSBClick(Sender: TObject);
procedure StopDBGridCellClick(Column: TColumn);
procedure FormCreate(Sender: TObject);
procedure CloseSBClick(Sender: TObject);
procedure ChooseDTSBClick(Sender: TObject);
private
StrValue:array[0..8]of string; //存放tbGRoomFee表中有9个字段对应的值
procedure SelectAll;
{ Private declarations }
public
{ Public declarations }
end;
var
FrmDecGRoom: TFrmDecGRoom;
function GetMyDateTime : TDateTime; stdcall; external 'MyDll.dll';
implementation
uses DataModuleUnit, GetYourInputUnit;
{$R *.dfm}
procedure TFrmDecGRoom.LookUpIDSBClick(Sender: TObject);
var
GName:string;
begin
GName:=GetYourString;
with DataModule1.qGInfo do
begin
Close;
sql.Clear;
SQL.Add('SELECT GuestID From tbGInfo where GuestName="'+GName+'"');
Open;
GuestIDCB.Clear;
First;
while not eof do
begin
GuestIDCB.Items.Add(Fields[0].Value);
Next;
end;
GuestIDCB.ItemIndex:=0;
if RecordCount=1 then GuestIDCB.OnChange(self)
else Showmessage('存在同名客户,请利用客户编号确定是哪一位!');
end;
StopDBGrid.Enabled:=true;
end;
procedure TFrmDecGRoom.GuestIDCBChange(Sender: TObject);
var
i:word;
begin
if GuestIDCB.Text='' then exit;
if Not IsInteger(GuestIDCB.Text) then
begin
Showmessage('客户编号是一个整数,您再检查一下,好吗?');
exit;
end;
with DataModule1.qGRoomFee do
begin
Close;
SQL.Clear;
SQL.Add('select * From tbGRoomFee where GuestID='+GuestIDCB.Text);
Open;
if Not IsEmpty then
begin
StopDBGrid.Enabled:=true;
TabSheet1.ImageIndex:=0;
for i:=0 to FieldCount-1 do
StrValue[i]:=Fields[i].Value;
EndRoomCB.Text:=FieldByName('RoomID').Value;
EndBedCB.Text:=FieldByName('BedID').Value;
TabSheet1.Caption:=' 客户 '+StrValue[1]+' 床位使用信息如下:';
end;
end;
SelectAll;
end;
procedure TFrmDecGRoom.StopOKSBClick(Sender: TObject);
var
SQLStr,Price:string;
StartDT,EndDT:TDateTime;
Days,Hours:Single;
Exact24_Hour :boolean;
begin
Exact24_Hour:=false;
if (EndRoomCB.Text='')or(EndBedCB.Text='')or(EndME.Text='') then
begin
Application.MessageBox('请重新核实信息是否齐全!','提示',
MB_Ok+MB_IconAsterisk+MB_ApplModal);
exit;
end;
with DataModule1.qGRoomFee do //取出床位使用时间
begin
Close;
SQL.Clear;
SQL.Add('select * from tbGRoomFee');
SQL.Add('where RoomID="'+EndRoomCB.Text+'" and '+'BedID="'+EndBedCB.Text+'"');
Open;
StartDT:=FieldByName('BedStartDateTime').AsDateTime;
end;
EndDT:=StrToDateTime(EndME.Text);
if EndDT<StartDT then
begin
ShowMessage('床位停用时间不能在使用时间之前');
Exit;
end;
//如果不是精确24小时制,则只计床位启用日期
if not Exact24_Hour then StartDT:=Int(StartDT);
Days:=Int(EndDT-StartDT); //计算日期差值
if not Exact24_Hour then Hours:=Frac(EndDT)*24 //时间
else Hours:=Frac(EndDT-StartDT)*24;
if (Hours>12)and(Hours<18) then Days:=Days+0.5;
if Hours>18 then Days:=Days+1;
//更新停用时间、床位使用天数
{
CREATE PROCEDURE Update_tbGRoomFee
(@ID int, @Room char (8), @Bed char (8), @EndDT datetime)
AS UPDATE tbGRoomFee
SET BedEndDateTime = @EndDT
WHERE GuestID=@ID and RoomId=@Room and BedID=@Bed
}
Edit1.Text:=FloatToStr(Days);
with Tquery.Create(Application) do
begin
DatabaseName:=DataModule1.qGRoomFee.DatabaseName;
Close;
SQL.Clear;
SQL.Add('Select BedPrice from tbHRoomState where RoomID="'+EndRoomCB.Text
+'" AND BedID="'+EndBedCB.Text+'"');
Open;
Price:=FieldByName('BedPrice').AsString;
free;
end;
SQLStr:='BEGIN TRAN MyTran '
+'EXEC Update_tbGRoomFee '
+ GuestIDCB.Text+',"'
+ EndRoomCB.Text+'","'
+ EndBedCB.Text+'",'
+ Edit1.text+','
+ Price+',"'
+ EndME.Text+'"'
+' UPDATE tbHRoomState SET BedState="空闲" '
+' Where RoomID="'+EndRoomCB.Text+'" and BedID="'+EndBedCB.Text+'"'
+' UPDATE tbHRoomState SET RoomState="空闲"'
+' Where RoomID="'+EndRoomCB.Text+'"'
+' if (Select Count(*) from tbHRoomState '
+' where RoomID="'+EndRoomCB.Text+'" AND BedState="入住")>0'
+' BEGIN'
+' UPDATE tbHRoomState SET RoomState="入住"'
+' Where RoomID="'+EndRoomCB.Text+'"'
+' END'
+' COMMIT TRAN';
with DataModule1.qGRoomFee do
begin
Close;
SQL.Clear;
SQL.Add(SQLStr);
ExecSQL;
end;
SelectAll;
EndRoomCB.Text:='';
EndBedCB.Text:='';
end;
procedure TFrmDecGRoom.SelectAll;
begin
if GuestIDCB.Text='' then exit;
with DataModule1.qGRoomFee do
begin
Close;
SQL.Clear;
SQL.Add('select GuestID as 客户编号,GuestName as 客户姓名,');
SQL.Add('CardID as 证件号码, RoomID as 房间号, BedID as 床位号,');
SQL.Add('BedStartDateTime as 床位启用时间,BedEndDateTime as 床位停用时间');
SQL.Add('From tbGRoomFee where GuestID='+GuestIDCB.Text);
SQL.Add('AND BedStartDateTime>BedEndDateTime');
Open;
end;
end;
procedure TFrmDecGRoom.StopDBGridCellClick(Column: TColumn);
begin
EndRoomCB.Text:=Column.Grid.Fields[3].AsString;
EndBedCB.Text:=Column.Grid.Fields[4].AsString;
ChooseDTSB.Enabled:=true;
end;
procedure TFrmDecGRoom.FormCreate(Sender: TObject);
begin
GuestIDCB.Items:=FindGuestID;
end;
procedure TFrmDecGRoom.CloseSBClick(Sender: TObject);
begin
Close;
end;
procedure TFrmDecGRoom.ChooseDTSBClick(Sender: TObject);
begin
EndME.Text:=DateTimeToStr(GetMyDateTime);
StopOKSB.Enabled:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -