Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ComCtrls, StdCtrls, ExtCtrls, Grids;
- type
- TClient = record
- Name: string;
- Surname: string;
- RoomNumber: Integer;
- ArrivalDate: TDateTime; // Дата заезда
- DepartureDate: TDateTime; // Дата выезда
- end;
- TForm1 = class(TForm)
- StringGrid1: TStringGrid;
- Panel1: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Edit1: TEdit;
- Edit2: TEdit;
- Edit3: TEdit;
- Edit4: TEdit;
- Edit5: TEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- ComboBox1: TComboBox;
- Label6: TLabel;
- Edit6: TEdit;
- Button4: TButton;
- DateTimePicker1: TDateTimePicker;
- Label7: TLabel;
- DateTimePicker2: TDateTimePicker;
- Label8: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- private
- Clients: array of TClient;
- ClientCount: Integer;
- FilteredClients: array of TClient;
- FilteredCount: Integer;
- procedure AddClient(const Name, Surname: string; RoomNumber: Integer; ArrivalDate, DepartureDate: TDateTime);
- procedure DeleteClient(Index: Integer);
- procedure UpdateClient(Index: Integer; const Name, Surname: string; RoomNumber: Integer; ArrivalDate, DepartureDate: TDateTime);
- procedure ApplyFilter;
- procedure DisplayClients(Clients: array of TClient; Count: Integer);
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- // Инициализация StringGrid
- StringGrid1.ColCount := 7;
- StringGrid1.RowCount := 2;
- StringGrid1.Cells[0, 0] := 'ID';
- StringGrid1.Cells[1, 0] := 'Имя';
- StringGrid1.Cells[2, 0] := 'Фамилия';
- StringGrid1.Cells[3, 0] := 'Номер комнаты';
- StringGrid1.Cells[4, 0] := 'Дата заезда';
- StringGrid1.Cells[5, 0] := 'Дата выезда';
- StringGrid1.Cells[6, 0] := 'Дней'; // Добавляем столбец для количества дней
- // Инициализация ComboBox для фильтрации
- ComboBox1.Items.Add('Все');
- ComboBox1.Items.Add('Имя');
- ComboBox1.Items.Add('Фамилия');
- ComboBox1.Items.Add('Номер комнаты'); // Добавляем номер комнаты в фильтр
- ComboBox1.ItemIndex := 0;
- ClientCount := 0;
- FilteredCount := 0;
- end;
- // ?????????? ???????
- procedure TForm1.AddClient(const Name, Surname: string; RoomNumber: Integer; ArrivalDate, DepartureDate: TDateTime);
- var
- NewClient: TClient;
- begin
- NewClient.Name := Name;
- NewClient.Surname := Surname;
- NewClient.RoomNumber := RoomNumber;
- NewClient.ArrivalDate := ArrivalDate;
- NewClient.DepartureDate := DepartureDate;
- SetLength(Clients, ClientCount + 1);
- Clients[ClientCount] := NewClient;
- Inc(ClientCount);
- end;
- // ???????? ???????
- procedure TForm1.DeleteClient(Index: Integer);
- var
- i: Integer;
- begin
- if (Index >= 0) and (Index <= ClientCount - 1) then
- begin
- for i := Index to ClientCount - 2 do
- Clients[i] := Clients[i + 1];
- SetLength(Clients, ClientCount - 1);
- Dec(ClientCount);
- end;
- end;
- // ????????? ?????? ???????
- procedure TForm1.UpdateClient(Index: Integer; const Name, Surname: string; RoomNumber: Integer; ArrivalDate, DepartureDate: TDateTime);
- begin
- if (Index >= 0) and (Index <= ClientCount - 1) then
- begin
- Clients[Index].Name := Name;
- Clients[Index].Surname := Surname;
- Clients[Index].RoomNumber := RoomNumber;
- Clients[Index].ArrivalDate := ArrivalDate;
- Clients[Index].DepartureDate := DepartureDate;
- end;
- end;
- // ?????????? ???????
- procedure TForm1.ApplyFilter;
- var
- i: Integer;
- Days: Integer; // ?????????? ????
- begin
- FilteredCount := 0;
- SetLength(FilteredClients, 0);
- case ComboBox1.ItemIndex of
- 1: // ???
- begin
- for i := 0 to ClientCount - 1 do
- if Clients[i].Name = Edit6.Text then
- begin
- SetLength(FilteredClients, FilteredCount + 1);
- FilteredClients[FilteredCount] := Clients[i];
- Inc(FilteredCount);
- end;
- end;
- 2: // ???????
- begin
- for i := 0 to ClientCount - 1 do
- if Clients[i].Surname = Edit6.Text then
- begin
- SetLength(FilteredClients, FilteredCount + 1);
- FilteredClients[FilteredCount] := Clients[i];
- Inc(FilteredCount);
- end;
- end;
- 3: // ????? ???????
- begin
- for i := 0 to ClientCount - 1 do
- if Clients[i].RoomNumber = StrToInt(Edit6.Text) then
- begin
- SetLength(FilteredClients, FilteredCount + 1);
- FilteredClients[FilteredCount] := Clients[i];
- Inc(FilteredCount);
- end;
- end;
- else
- begin
- // ???? ?????? ?? ??????, ?? ???????????? ??? ???????
- SetLength(FilteredClients, ClientCount);
- for i := 0 to ClientCount - 1 do // ???????? ???????? ???????
- FilteredClients[i] := Clients[i];
- FilteredCount := ClientCount;
- end;
- end;
- end;
- // ??????????? ???????? ? StringGrid
- procedure TForm1.DisplayClients(Clients: array of TClient; Count: Integer);
- var
- i: Integer;
- Days: Integer; // ?????????? ????
- begin
- StringGrid1.RowCount := Count + 1;
- for i := 0 to Count - 1 do
- begin
- StringGrid1.Cells[0, i + 1] := IntToStr(i + 1);
- StringGrid1.Cells[1, i + 1] := Clients[i].Name;
- StringGrid1.Cells[2, i + 1] := Clients[i].Surname;
- StringGrid1.Cells[3, i + 1] := IntToStr(Clients[i].RoomNumber);
- StringGrid1.Cells[4, i + 1] := DateToStr(Clients[i].ArrivalDate); // ?????????? ???? ??????
- StringGrid1.Cells[5, i + 1] := DateToStr(Clients[i].DepartureDate); // ?????????? ???? ??????
- // ????????? ?????????? ????
- Days := Trunc(Clients[i].DepartureDate - Clients[i].ArrivalDate);
- StringGrid1.Cells[6, i + 1] := IntToStr(Days);
- end;
- end;
- // ??????????? ???????
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- AddClient(Edit1.Text, Edit2.Text, StrToInt(Edit3.Text), DateTimePicker1.Date, DateTimePicker2.Date);
- ApplyFilter;
- DisplayClients(FilteredClients, FilteredCount);
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- if StringGrid1.Row > 1 then
- begin
- DeleteClient(StringGrid1.Row - 2);
- ApplyFilter;
- DisplayClients(FilteredClients, FilteredCount);
- end;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- if StringGrid1.Row > 1 then
- begin
- UpdateClient(StringGrid1.Row - 2, Edit1.Text, Edit2.Text, StrToInt(Edit3.Text), DateTimePicker1.Date, DateTimePicker2.Date);
- ApplyFilter;
- DisplayClients(FilteredClients, FilteredCount);
- end;
- end;
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- ApplyFilter;
- DisplayClients(FilteredClients, FilteredCount);
- end;
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- ComboBox1.ItemIndex := 0;
- Edit6.Text := '';
- ApplyFilter;
- DisplayClients(FilteredClients, FilteredCount);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement