⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getyourinputunit.~pas

📁 很好地delphi书籍源码
💻 ~PAS
字号:
unit GetYourInputUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DBCtrls, ExtCtrls;

type
  AllChar=set of Char ;
  TFrmGetYourInput = class(TForm)
    GroupBox1: TGroupBox;
    Label2: TLabel;
    FirstNameCB: TComboBox;
    Label1: TLabel;
    NameCB: TComboBox;
    BitBtn2: TBitBtn;
    BitBtn1: TBitBtn;
    Shape1: TShape;
    procedure FormCreate(Sender: TObject);
    procedure FirstNameCBChange(Sender: TObject);
  private
    procedure SelectAll;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmGetYourInput: TFrmGetYourInput;

function GetYourString:string;
function IsInteger(Str:string):boolean;
function IsFloat(Str:string):boolean;
function FindGuestID:TStrings ;
function CreateNewID(Date:TDateTime):string;
function FindRoomKind:TStrings ;
function RoomKindCBChange(KindCB:String;var Price:string):TStrings ;
function RoomIDChange(RoomCB:String):TStrings;

implementation

uses DataModuleUnit;
{$R *.dfm}

function GetYourString:string;
begin
  try
    FrmGetYourInput:= TFrmGetYourInput.Create(Application);
    try
      if FrmGetYourInput.ShowModal=mrOK then
        Result:=FrmGetYourInput.NameCB.Text
      else
        Result:=''
    finally
      FrmGetYourInput.Free;
    end;
  except on E: Exception do
      MessageDlg ('创建窗体时出现错误:'+E.Message, mtError,[mbOK],0);
  end;
end;

function FindGuestID:TStrings;
var
   S:TStrings;
begin
  S:=TStringList.Create;
  with DataModule1.qGInfo  do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select GuestID From tbGInfo where GuestID>=0');
    Open;
    First;
    S.Clear;
    while not eof do
    begin
      S.Add(Fields[0].Value);
      Next;
    end;
  end;
  result:=S;
end;

function RoomIDChange(RoomCB:String):TStrings;
var
  S:TStrings;
  Bed:string;
begin
   S:=TStringList.Create;
   with DataModule1.qHRoomState do
   begin
     Close;
     SQL.Clear;
     SQL.Add('select BedID from tbHRoomState');
     SQL.Add('where RoomID="'+RoomCB+'" and BedState="空闲"');
     Open;
     First;
     while not eof do
     begin
       Bed:=FieldByName('BedID').AsString;
       if  S.IndexOf(Bed)<0 then  S.Add(Bed);
       Next;
     end;
  end;
  result:=S;
end;

function RoomKindCBChange(KindCB:String;var Price:string):TStrings ;
var
   S:TStrings;
   Room:string;
begin
  S:=TStringList.Create;
  with DataModule1.qHRoomState do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select RoomID,BedPrice from tbHRoomState');
    SQL.Add('where RoomKind="'+KindCB+'" and RoomState<>"住满"');
    Open;
    First;
    Price:=FieldByName('BedPrice').AsString;
    while not eof do
    begin
      Room:=FieldByName('RoomID').AsString;
      if  S.IndexOf(Room)<0 then S.Add(Room);
      Next;
    end;
  end;
  result:=S;
end;

function FindRoomKind:TStrings ;
var
   S:TStrings;
begin
  S:=TStringList.Create;
  with DataModule1.tbHotelKind do
  begin
    Close;
    Open;
    while not eof do
    begin
      S.Add(Fields[0].AsString);
      Next;
    end;
  end;
  result:=S;
end;

procedure TFrmGetYourInput.FormCreate(Sender: TObject);
begin
  SelectAll;
end;



function IsInteger(Str:string):boolean;
var
  SetStr:AllChar;
  i:Word;
  Ch:char;
begin
  SetStr:=['0','1','2','3','4','5','6','7','8','9'];
  Result:=true;
  if Str='' then
  begin
    Result:=false;
    exit;
  end;
  for i:=1 to Length(Str) do
  begin
    Ch:=Str[i];
    if (Ch in SetStr) then  continue
    else
    begin
       Result:=false;
       break;
    end;
  end;
end;

function IsFloat(Str:string):boolean;
var
  SetStr:AllChar;
  i:Word;
  Ch:char;
begin
  SetStr:=['.','0','1','2','3','4','5','6','7','8','9'];
  Result:=true;
  if Str='' then
  begin
    Result:=false;
    exit;
  end;
  for i:=0 to Length(Str)-1 do
  begin
    Ch:=Str[i];
    if (Ch in SetStr) then  continue
    else
    begin
       Result:=false;
       break;
    end;
  end;
end;

function CreateNewID(Date:TDateTime):string;
var
  S:string;
begin
  S:=trim(format('%10.0f',[50000*Date]));
  Result:=S;
end;

procedure TFrmGetYourInput.SelectAll;
begin
   with DataModule1.qGInfo  do
  begin
    Close;
    sql.Clear;
    SQL.Add('SELECT DISTINCT GuestName From tbGInfo where GuestID>=0' );
    SQL.Add('and GuestName like "'+FirstNameCB.Text+'%"');
    Open;
    First;
    NameCB.Clear;
    while not eof do
    begin
     NameCB.Items.Add(FieldByName('GuestName').Value);
     Next;
    end;
  end;
end;

procedure TFrmGetYourInput.FirstNameCBChange(Sender: TObject);
begin
  SelectAll;
  NameCB.ItemIndex:=0;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -