Advertisement
Vanya_Shestakov

Untitled

Dec 10th, 2020 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 6.29 KB | None | 0 0
  1. unit ShowRecords;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Vcl.Menus,
  8.   Vcl.Buttons, MainMenu,  System.RegularExpressions;
  9.  
  10. type
  11.   TShowRecordsForm = class(TForm)
  12.     GridOfRecords: TStringGrid;
  13.     MainMenu: TMainMenu;
  14.     N1: TMenuItem;
  15.     Label1: TLabel;
  16.     EditOfAge: TEdit;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     EditOfDiagnosis: TEdit;
  20.     Label4: TLabel;
  21.     AmountOfNonresidentLabel: TLabel;
  22.     FindPatientsButton: TBitBtn;
  23.     ShowAllButton: TBitBtn;
  24.     Label5: TLabel;
  25.     AmountOfPatientsLabel: TLabel;
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure N1Click(Sender: TObject);
  28.     procedure LoadData();
  29.     procedure FindPatientsButtonClick(Sender: TObject);
  30.     procedure ShowResultOfSearch(Age: Integer; Diagnosis: String);
  31.     procedure ShowAllButtonClick(Sender: TObject);
  32.     procedure FindPatientsButtonKeyPress(Sender: TObject; var Key: Char);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. var
  40.   ShowRecordsForm: TShowRecordsForm;
  41.  
  42. implementation
  43.  
  44. {$R *.dfm}
  45.  
  46. const
  47.     COL_OF_SURNAME = 0;
  48.     COL_OF_SEX = 1;
  49.     COL_OF_AGE = 2;
  50.     COL_OF_CITY = 3;
  51.     COL_OF_DIAGNOSIS = 4;
  52.  
  53. procedure TShowRecordsForm.FindPatientsButtonClick(Sender: TObject);
  54. var
  55.     RegEx: TRegEx;
  56. begin
  57.     if (Length(EditOfAge.Text) <> 0) and (Length(EditOfDiagnosis.Text) <> 0) then
  58.     begin
  59.         if RegEx.IsMatch(EditOfDiagnosis.Text, '^[A-Za-zА-Яа-я]+\s?-?[A-Za-zА-Яа-я]+$') and
  60.            RegEx.IsMatch(EditOfAge.Text, '^\d{1,3}+$') then
  61.         begin
  62.             ShowResultOfSearch(StrToInt(EditOfAge.Text),  EditOfDiagnosis.Text);
  63.         end
  64.         else
  65.             MessageDlg('Введите корректные данные! (см. Справка)', mtError, [mbOK], 0);
  66.     end
  67.     else
  68.         MessageDlg('Заполните все поля!', mtError, [mbOK], 0);
  69. end;
  70.  
  71. procedure TShowRecordsForm.ShowAllButtonClick(Sender: TObject);
  72. begin
  73.     LoadData();
  74. end;
  75.  
  76. procedure TShowRecordsForm.ShowResultOfSearch(Age: Integer; Diagnosis: String);
  77. var
  78.     I, J, NonresidentPatients: Integer;
  79. begin
  80.     J := 1;
  81.     for I := 0 to High(ArrOfPatients) do
  82.     begin
  83.         if (StrToInt(ArrOfPatients[I].Age) > Age) and (AnsiCompareText(ArrOfPatients[I].Diagnosis, Diagnosis) = 0) then
  84.         begin
  85.             if AnsiCompareText(ArrOfPatients[I].City, 'Минск') <> 0 then
  86.             begin
  87.                 Inc(NonresidentPatients);
  88.             end;
  89.             GridOfRecords.Cells[COL_OF_SURNAME, J] := ArrOfPatients[I].Surname;
  90.             GridOfRecords.Cells[COL_OF_SEX, J] := ArrOfPatients[I].Sex;
  91.             GridOfRecords.Cells[COL_OF_AGE, J] := ArrOfPatients[I].Age;
  92.             GridOfRecords.Cells[COL_OF_CITY, J] := ArrOfPatients[I].City;
  93.             GridOfRecords.Cells[COL_OF_DIAGNOSIS, J] := ArrOfPatients[I].Diagnosis;
  94.             Inc(J);
  95.         end;
  96.     end;
  97.     if J <> 1 then
  98.     begin
  99.         MessageDlg('По вашему запросу было найдено пациентов: ' + IntToStr(J - 1), mtInformation, [mbOK], 0);
  100.         GridOfRecords.RowCount := J;
  101.         AmountOfNonresidentLabel.Caption := IntToStr(NonresidentPatients);
  102.         AmountOfPatientsLabel.Caption := IntToStr(GridOfRecords.RowCount - 1);
  103.     end
  104.     else
  105.     begin
  106.         MessageDlg('По вашему запросу ничего не найдено', mtInformation, [mbOK], 0);
  107.     end;
  108. end;
  109.  
  110. procedure TShowRecordsForm.FindPatientsButtonKeyPress(Sender: TObject; var Key: Char);
  111. begin
  112.     if key = #13 then FindPatientsButton.Click;
  113. end;
  114.  
  115. procedure TShowRecordsForm.FormCreate(Sender: TObject);
  116. begin
  117.     GridOfRecords.FixedCols := 0;
  118.     GridOfRecords.FixedRows := 1;
  119.     GridOfRecords.ColCount := 5;
  120.     GridOfRecords.RowCount := 2;
  121.     GridOfRecords.Cells[COL_OF_SURNAME, 0] := 'ФАМИЛИЯ';
  122.     GridOfRecords.Cells[COL_OF_SEX, 0] := 'ПОЛ';
  123.     GridOfRecords.Cells[COL_OF_AGE, 0] := 'ВОЗРАСТ';
  124.     GridOfRecords.Cells[COL_OF_CITY, 0] := 'ГОРОД';
  125.     GridOfRecords.Cells[COL_OF_DIAGNOSIS, 0] := 'ДИАГНОЗ';
  126. end;
  127.  
  128. procedure TShowRecordsForm.N1Click(Sender: TObject);
  129. const
  130.     Title = 'Сведения о пациентах';
  131.     Separator = #13#10;
  132.     Information = 'Предоставляется информация о всех пациентах клиники и даётся информация о количестве' +
  133.     ' иногородних пациентов. Можно выполнить поиск пациентов старше определённого возраста с определённым диагнозом';
  134.  
  135.     InformationAboutInput = 'Ввод данных' + Separator + Separator + 'Возраст: должен быть указан целым числом в диапазоне от 0 до 99 лет.' +
  136.     Separator + 'Диагноз: может быть указан с помощью символов русского алфавита, допускается символ пробела или тире' +
  137.     ' при условии, что они связывают два слова, максимальное количество слов: 2';
  138. begin
  139.     MessageDlg(Title + Separator + Separator +
  140.     Information + Separator + Separator + InformationAboutInput, mtInformation, [mbOK], 0);
  141. end;
  142.  
  143. procedure TShowRecordsForm.LoadData();
  144. var
  145.     I, NonresidentPatients: Integer;
  146. begin
  147.     GridOfRecords.RowCount := Length(ArrOfPatients) + 1;
  148.     for I := 0 to Length(ArrOfPatients) - 1 do
  149.     begin
  150.         if AnsiCompareText(ArrOfPatients[I].City, 'Минск') <> 0 then
  151.         begin
  152.             Inc(NonresidentPatients);
  153.         end;
  154.         GridOfRecords.Cells[COL_OF_SURNAME, I + 1] := ArrOfPatients[I].Surname;
  155.         GridOfRecords.Cells[COL_OF_SEX, I + 1] := ArrOfPatients[I].Sex;
  156.         GridOfRecords.Cells[COL_OF_AGE, I + 1] := ArrOfPatients[I].Age;
  157.         GridOfRecords.Cells[COL_OF_CITY, I + 1] := ArrOfPatients[I].City;
  158.         GridOfRecords.Cells[COL_OF_DIAGNOSIS, I + 1] := ArrOfPatients[I].Diagnosis;
  159.     end;
  160.     AmountOfNonresidentLabel.Caption := IntToStr(NonresidentPatients);
  161.     AmountOfPatientsLabel.Caption := IntToStr(GridOfRecords.RowCount - 1);
  162.  
  163. end;
  164.  
  165. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement