roompriceunit.~pas
来自「很好地delphi书籍源码」· ~PAS 代码 · 共 341 行
~PAS
341 行
unit RoomPriceUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ExtCtrls, DBCtrls, StdCtrls, Buttons, ComCtrls,
ToolWin, Spin, ImgList, DB, DBTables;
type
TFrmRoomPrice = class(TForm)
DBGrid1: TDBGrid;
ToolBar1: TToolBar;
AddTButton: TToolButton;
ModTButton: TToolButton;
DelTButton: TToolButton;
AddGB: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
RoomEdit: TEdit;
BedEdit: TEdit;
KindCB: TComboBox;
AddOkButton: TButton;
AddCancelButton: TButton;
Label5: TLabel;
Label6: TLabel;
RoomStateCB: TComboBox;
BedStateCB: TComboBox;
PriceSE: TSpinEdit;
ImageList1: TImageList;
ModGB: TGroupBox;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
ModRoom: TEdit;
ModBed: TEdit;
ModKind: TComboBox;
ModOkButton: TButton;
ModCancelButton: TButton;
ModRoomState: TComboBox;
ModBedState: TComboBox;
ModPrice: TSpinEdit;
Label13: TLabel;
ConEdit: TEdit;
Label14: TLabel;
Condition: TEdit;
ToolButton3: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton1: TToolButton;
Panel1: TPanel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
NameCB: TComboBox;
StateCB: TComboBox;
Table1: TTable;
SBar: TStatusBar;
ToolButton2: TToolButton;
procedure FormCreate(Sender: TObject);
procedure AddTButtonClick(Sender: TObject);
procedure AddOkButtonClick(Sender: TObject);
procedure AddCancelButtonClick(Sender: TObject);
procedure ModTButtonClick(Sender: TObject);
procedure DelTButtonClick(Sender: TObject);
procedure KindCBChange(Sender: TObject);
procedure ModCancelButtonClick(Sender: TObject);
procedure ModOkButtonClick(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ModKindChange(Sender: TObject);
procedure NameCBChange(Sender: TObject);
procedure StateCBChange(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure ToolButton1Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure ToolButton2Click(Sender: TObject);
private
Price: array of integer;
procedure SelectAll;
{ Private declarations }
public
{ Public declarations }
end;
var
FrmRoomPrice: TFrmRoomPrice;
implementation
uses DataModuleUnit, DynamicFormUnit, Dy_QReport;
const Title:array[0..6] of String=('房间号','床位号',' 房间类别 ',
'床位价格','房间状态','床位状态','客房条件描述');
{$R *.dfm}
procedure TFrmRoomPrice.FormCreate(Sender: TObject);
var
i:word;
begin
DataModule1.tRoomPrice.Close;
DataModule1.tRoomPrice.TableName:='tbHRoomState';
i:=0;
with DataModule1.tbHotelKind do
begin
Close;
Open;
SetLength(Price,RecordCount);
KindCB.Clear;
while not eof do
begin
KindCB.Items.Add(Fields[0].AsString);
Price[i]:=Fields[1].AsInteger;
Inc(i);
Next;
end;
end;
ModKind.Items:=KindCB.Items;
NameCB.Items:=KindCB.Items;
NameCB.Items.Insert(0,'所有');
SelectAll;
end;
procedure TFrmRoomPrice.SelectAll;
var
i:word;
begin
with DataModule1.tRoomPrice do
begin
Close;
Filter:='';
Filtered:=true;
Open;
end;
for i:=0 to 6 do
begin
DBGrid1.Columns[i].Title.caption:=Title[i];
DBGrid1.Columns[i].Title.Alignment:=taCenter;
DBGrid1.Columns[i].Alignment:=taCenter;
end;
end;
procedure TFrmRoomPrice.AddTButtonClick(Sender: TObject);
begin
AddGB.Visible:=true;
ModGB.Visible:=false ;
end;
procedure TFrmRoomPrice.AddOkButtonClick(Sender: TObject);
begin
if (RoomEdit.Text='') or (BedEdit.Text='')or(KindCB.Text='') then
begin
Showmessage('提供的信息不完整!');
exit;
end;
DataModule1.tRoomPrice.AppendRecord([RoomEdit.Text,BedEdit.Text,KindCB.Text,
PriceSE.Value,RoomStateCB.Text,BedStateCB.Text,ConEdit.Text]);
SelectAll;
AddGB.Visible:=false;
end;
procedure TFrmRoomPrice.AddCancelButtonClick(Sender: TObject);
begin
AddGB.Visible:=false;
end;
procedure TFrmRoomPrice.ModTButtonClick(Sender: TObject);
begin
ModGB.Visible:=true;
AddGB.Visible:=false;
with DataModule1.tRoomPrice do
begin
ModRoom.Text:=Fields[0].AsString ;
ModBed.Text:=Fields[1].AsString;
ModKind.Text:=Fields[2].AsString;
ModPrice.Value:= Fields[3].AsInteger;
ModRoomState.Text:= Fields[4].AsString;
ModBedState.Text:= Fields[5].AsString;
Condition.Text:=Fields[6].AsString;
end;
end;
procedure TFrmRoomPrice.DelTButtonClick(Sender: TObject);
begin
if Application.MessageBox('确实需要删除记录吗!',
'提示',MB_YesNo+MB_IconExclamation+MB_SystemModal)=IDYES then
DataModule1.tRoomPrice.Delete;
end;
procedure TFrmRoomPrice.KindCBChange(Sender: TObject);
begin
PriceSE.Value:=Price[KindCB.ItemIndex];
end;
procedure TFrmRoomPrice.ModCancelButtonClick(Sender: TObject);
begin
ModGB.Visible:=false;
end;
procedure TFrmRoomPrice.ModOkButtonClick(Sender: TObject);
begin
if Application.MessageBox('确实需要保存记录吗!',
'提示',MB_YesNo+MB_IconExclamation+MB_SystemModal)=IDYES then
begin
with DataModule1.tRoomPrice do
begin
Edit;
Fields[0].AsString:=ModRoom.Text;
Fields[1].AsString:=ModBed.Text;
Fields[2].AsString:=ModKind.Text;
Fields[3].AsInteger:=ModPrice.Value;
Fields[4].AsString:=ModRoomState.Text;
Fields[5].AsString:=ModBedState.Text ;
Fields[6].AsString:=Condition.Text;
Post;
SelectAll;
end;
end;
ModGB.Visible:=false;
end;
procedure TFrmRoomPrice.ToolButton7Click(Sender: TObject);
begin
DataModule1.tRoomPrice.First;
end;
procedure TFrmRoomPrice.ToolButton3Click(Sender: TObject);
begin
DataModule1.tRoomPrice.Prior;
end;
procedure TFrmRoomPrice.ToolButton5Click(Sender: TObject);
begin
DataModule1.tRoomPrice.Next;
end;
procedure TFrmRoomPrice.ToolButton6Click(Sender: TObject);
begin
DataModule1.tRoomPrice.Last;
end;
procedure TFrmRoomPrice.ModKindChange(Sender: TObject);
begin
ModPrice.Value:=Price[ModKind.ItemIndex];
end;
procedure TFrmRoomPrice.NameCBChange(Sender: TObject);
begin
with DataModule1.tRoomPrice do
begin
if NameCB.Text='所有' then SelectAll
else
Filter:='RoomKind ='+QuotedStr(NameCB.Text);
Filtered:=true;
StateCB.ItemIndex:=0;
end;
end;
procedure TFrmRoomPrice.StateCBChange(Sender: TObject);
begin
with DataModule1.tRoomPrice do
begin
if StateCB.Text='所有' then SelectAll
else
Filter:='RoomState ='+QuotedStr(StateCB.Text);
Filtered:=true;
NameCB.ItemIndex:=0;
end;
end;
procedure TFrmRoomPrice.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DataModule1.tRoomPrice do
begin
// if Column.Title.Column.Index=4 then
begin
if FieldByName('RoomState').AsString='空闲' then
DBGrid1.Canvas.Font.Color :=clBlack
else if FieldByName('RoomState').AsString='入住' then
DBGrid1.Canvas.Font.Color :=clBlue
else if FieldByName('RoomState').AsString='住满' then
DBGrid1.Canvas.Font.Color :=clRed;
end;
end;
DBGrid1.DefaultDrawDatacell(Rect,Column.field,state);
end;
procedure TFrmRoomPrice.ToolButton1Click(Sender: TObject);
begin
Close;
end;
procedure TFrmRoomPrice.DBGrid1CellClick(Column: TColumn);
var
Room,Bed :string;
begin
Room :=Column.Grid.Fields[0].AsString;
Bed :=Column.Grid.Fields[1].AsString;
with DataModule1.qGRoomFee do
begin
Close;
SQL.Clear;
SQL.Add('SELECT A.GuestID,A.GuestName,A.Sex from tbGInfo A,tbGRoomFee B');
SQL.Add('WHERE A.GuestID=B.GuestID AND B.RoomID="'+Room+'" AND B.BedID="'+Bed+'"');
Open;
if IsEmpty then SBar.SimpleText:='该床位还没有使用!'
else
SBar.SimpleText:=' 使用该床位的客户主要信息, 编号:'
+FieldByName('GuestID').AsString
+' 姓名:'+FieldByName('GuestName').AsString
+' ('+FieldByName('Sex').AsString+')';
end;
end;
procedure TFrmRoomPrice.ToolButton2Click(Sender: TObject);
var
DynamicForm:TDynamicForm;
GridPrint:TGridPrint;
begin
DynamicForm:=TDynamicForm.Create(Application);
with DynamicForm do
begin
GridPrint:=TGridPrint.Create(QuickRep,DBGrid1,TitleB,HeaderB,DetailB,
'客户使用状态及价格表');
GridPrint.DoPreview();
GridPrint.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?