Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit ShowRecords;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Vcl.Menus,
- Vcl.Buttons, MainMenu, System.RegularExpressions;
- type
- TShowRecordsForm = class(TForm)
- GridOfRecords: TStringGrid;
- MainMenu: TMainMenu;
- N1: TMenuItem;
- Label1: TLabel;
- EditOfAge: TEdit;
- Label2: TLabel;
- Label3: TLabel;
- EditOfDiagnosis: TEdit;
- Label4: TLabel;
- AmountOfNonresidentLabel: TLabel;
- FindPatientsButton: TBitBtn;
- ShowAllButton: TBitBtn;
- Label5: TLabel;
- AmountOfPatientsLabel: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure N1Click(Sender: TObject);
- procedure LoadData();
- procedure FindPatientsButtonClick(Sender: TObject);
- procedure ShowResultOfSearch(Age: Integer; Diagnosis: String);
- procedure ShowAllButtonClick(Sender: TObject);
- procedure FindPatientsButtonKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- ShowRecordsForm: TShowRecordsForm;
- implementation
- {$R *.dfm}
- const
- COL_OF_SURNAME = 0;
- COL_OF_SEX = 1;
- COL_OF_AGE = 2;
- COL_OF_CITY = 3;
- COL_OF_DIAGNOSIS = 4;
- procedure TShowRecordsForm.FindPatientsButtonClick(Sender: TObject);
- var
- RegEx: TRegEx;
- begin
- if (Length(EditOfAge.Text) <> 0) and (Length(EditOfDiagnosis.Text) <> 0) then
- begin
- if RegEx.IsMatch(EditOfDiagnosis.Text, '^[A-Za-zА-Яа-я]+\s?-?[A-Za-zА-Яа-я]+$') and
- RegEx.IsMatch(EditOfAge.Text, '^\d{1,3}+$') then
- begin
- ShowResultOfSearch(StrToInt(EditOfAge.Text), EditOfDiagnosis.Text);
- end
- else
- MessageDlg('Введите корректные данные! (см. Справка)', mtError, [mbOK], 0);
- end
- else
- MessageDlg('Заполните все поля!', mtError, [mbOK], 0);
- end;
- procedure TShowRecordsForm.ShowAllButtonClick(Sender: TObject);
- begin
- LoadData();
- end;
- procedure TShowRecordsForm.ShowResultOfSearch(Age: Integer; Diagnosis: String);
- var
- I, J, NonresidentPatients: Integer;
- begin
- J := 1;
- for I := 0 to High(ArrOfPatients) do
- begin
- if (StrToInt(ArrOfPatients[I].Age) > Age) and (AnsiCompareText(ArrOfPatients[I].Diagnosis, Diagnosis) = 0) then
- begin
- if AnsiCompareText(ArrOfPatients[I].City, 'Минск') <> 0 then
- begin
- Inc(NonresidentPatients);
- end;
- GridOfRecords.Cells[COL_OF_SURNAME, J] := ArrOfPatients[I].Surname;
- GridOfRecords.Cells[COL_OF_SEX, J] := ArrOfPatients[I].Sex;
- GridOfRecords.Cells[COL_OF_AGE, J] := ArrOfPatients[I].Age;
- GridOfRecords.Cells[COL_OF_CITY, J] := ArrOfPatients[I].City;
- GridOfRecords.Cells[COL_OF_DIAGNOSIS, J] := ArrOfPatients[I].Diagnosis;
- Inc(J);
- end;
- end;
- if J <> 1 then
- begin
- MessageDlg('По вашему запросу было найдено пациентов: ' + IntToStr(J - 1), mtInformation, [mbOK], 0);
- GridOfRecords.RowCount := J;
- AmountOfNonresidentLabel.Caption := IntToStr(NonresidentPatients);
- AmountOfPatientsLabel.Caption := IntToStr(GridOfRecords.RowCount - 1);
- end
- else
- begin
- MessageDlg('По вашему запросу ничего не найдено', mtInformation, [mbOK], 0);
- end;
- end;
- procedure TShowRecordsForm.FindPatientsButtonKeyPress(Sender: TObject; var Key: Char);
- begin
- if key = #13 then FindPatientsButton.Click;
- end;
- procedure TShowRecordsForm.FormCreate(Sender: TObject);
- begin
- GridOfRecords.FixedCols := 0;
- GridOfRecords.FixedRows := 1;
- GridOfRecords.ColCount := 5;
- GridOfRecords.RowCount := 2;
- GridOfRecords.Cells[COL_OF_SURNAME, 0] := 'ФАМИЛИЯ';
- GridOfRecords.Cells[COL_OF_SEX, 0] := 'ПОЛ';
- GridOfRecords.Cells[COL_OF_AGE, 0] := 'ВОЗРАСТ';
- GridOfRecords.Cells[COL_OF_CITY, 0] := 'ГОРОД';
- GridOfRecords.Cells[COL_OF_DIAGNOSIS, 0] := 'ДИАГНОЗ';
- end;
- procedure TShowRecordsForm.N1Click(Sender: TObject);
- const
- Title = 'Сведения о пациентах';
- Separator = #13#10;
- Information = 'Предоставляется информация о всех пациентах клиники и даётся информация о количестве' +
- ' иногородних пациентов. Можно выполнить поиск пациентов старше определённого возраста с определённым диагнозом';
- InformationAboutInput = 'Ввод данных' + Separator + Separator + 'Возраст: должен быть указан целым числом в диапазоне от 0 до 99 лет.' +
- Separator + 'Диагноз: может быть указан с помощью символов русского алфавита, допускается символ пробела или тире' +
- ' при условии, что они связывают два слова, максимальное количество слов: 2';
- begin
- MessageDlg(Title + Separator + Separator +
- Information + Separator + Separator + InformationAboutInput, mtInformation, [mbOK], 0);
- end;
- procedure TShowRecordsForm.LoadData();
- var
- I, NonresidentPatients: Integer;
- begin
- GridOfRecords.RowCount := Length(ArrOfPatients) + 1;
- for I := 0 to Length(ArrOfPatients) - 1 do
- begin
- if AnsiCompareText(ArrOfPatients[I].City, 'Минск') <> 0 then
- begin
- Inc(NonresidentPatients);
- end;
- GridOfRecords.Cells[COL_OF_SURNAME, I + 1] := ArrOfPatients[I].Surname;
- GridOfRecords.Cells[COL_OF_SEX, I + 1] := ArrOfPatients[I].Sex;
- GridOfRecords.Cells[COL_OF_AGE, I + 1] := ArrOfPatients[I].Age;
- GridOfRecords.Cells[COL_OF_CITY, I + 1] := ArrOfPatients[I].City;
- GridOfRecords.Cells[COL_OF_DIAGNOSIS, I + 1] := ArrOfPatients[I].Diagnosis;
- end;
- AmountOfNonresidentLabel.Caption := IntToStr(NonresidentPatients);
- AmountOfPatientsLabel.Caption := IntToStr(GridOfRecords.RowCount - 1);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement