Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit SearchForWindow;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Imaging.pngimage,
- Vcl.ExtCtrls, Vcl.Grids;
- type
- TSearchFor = class(TForm)
- LblGroup: TLabel;
- LblYear: TLabel;
- EdYear: TEdit;
- RadioButtonMale: TRadioButton;
- RadioButtonFemale: TRadioButton;
- ComboBoxGroup: TComboBox;
- ImageHelp: TImage;
- BtSearch: TButton;
- Table: TStringGrid;
- BtSave: TButton;
- SaveDialog: TSaveDialog;
- procedure ImageHelpClick(Sender: TObject);
- procedure ComboBoxGroupKeyPress(Sender: TObject; var Key: Char);
- procedure EdYearChange(Sender: TObject);
- procedure EdYearKeyPress(Sender: TObject; var Key: Char);
- procedure RadioButtonMaleKeyPress(Sender: TObject; var Key: Char);
- procedure ComboBoxGroupChange(Sender: TObject);
- procedure RadioButtonFemaleKeyPress(Sender: TObject; var Key: Char);
- procedure BtSearchClick(Sender: TObject);
- procedure RadioButtonMaleClick(Sender: TObject);
- procedure RadioButtonFemaleClick(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure BtSaveClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- SearchFor: TSearchFor;
- implementation
- {$R *.dfm}
- uses MainForm;
- procedure TSearchFor.BtSaveClick(Sender: TObject);
- var
- OutputFile: file of MainForm.TStudent;
- MyFile: string;
- ButtonSelected: Byte;
- i: Integer;
- Bufer: MainForm.TArr;
- begin
- if SaveDialog.Execute then
- begin
- MyFile := SaveDialog.FileName;
- if Pos('.dat', MyFile) <> Length(MyFile) - 3 then
- MyFile := MyFile + '.dat';
- ButtonSelected := 0;
- if FileExists(MyFile) then
- ButtonSelected := MessageDlg('Rewrite file?', mtConfirmation, [mbYes,mbNo], 0);
- if (not FileExists(MyFile)) or (ButtonSelected = mrYes) then
- begin
- SetLength(Bufer, Table.RowCount-1);
- for i := 0 to High(Bufer) do
- begin
- Bufer[i].Surname := Table.Cells[0, i + 1];
- Bufer[i].Name := Table.Cells[1, i + 1];
- Bufer[i].Patronymic := Table.Cells[2, i + 1];
- Bufer[i].Group := StrToInt(Table.Cells[3, i + 1]);
- Bufer[i].Number := StrToInt(Table.Cells[4, i + 1]);
- Bufer[i].DateOfBirth := Table.Cells[5, i + 1];
- Bufer[i].Sex := Table.Cells[6, i + 1];
- end;
- AssignFile(OutputFile, MyFile);
- ReWrite(OutputFile);
- for i := 0 to High(Bufer) do
- Write(OutputFile, Bufer[i]);
- BtSave.Enabled := False;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- EdYear.Text := '';
- RadioButtonMale.Checked := false;
- RadioButtonFemale.Checked := false;
- ComboBoxGroup.ItemIndex := -1;
- end;
- CloseFile(OutputFile);
- end;
- end;
- procedure TSearchFor.BtSearchClick(Sender: TObject);
- var
- i, Group: Integer;
- Year, Sex: string;
- begin
- if Length(ComboBoxGroup.Text) > 0 then
- begin
- if (ComboBoxGroup.ItemIndex = 0) then
- Group := 535;
- if (ComboBoxGroup.ItemIndex = 1) then
- Group := 510;
- if (ComboBoxGroup.ItemIndex = 2) then
- Group := 507;
- if (ComboBoxGroup.ItemIndex = 3) then
- Group := 505;
- end;
- Year := EdYear.Text;
- if RadioButtonMale.Checked then
- Sex := RadioButtonMale.Caption
- else
- Sex := RadioButtonFemale.Caption;
- for i := 0 to High(MainForm.Bufer) do
- if (((MainForm.Bufer[i].Group div 100) mod 1000) = Group) and (Copy(MainForm.Bufer[i].DateOfBirth, Length(MainForm.Bufer[i].DateOfBirth) - 3, 4) = Year) and (MainForm.Bufer[i].Sex = Sex) then
- begin
- Table.RowCount := Table.RowCount + 1;
- Table.Cells[0, Table.RowCount-1] := MainForm.Bufer[i].Surname;
- Table.Cells[1, Table.RowCount-1] := MainForm.Bufer[i].Name;
- Table.Cells[2, Table.RowCount-1] := MainForm.Bufer[i].Patronymic;
- Table.Cells[3, Table.RowCount-1] := IntToStr(MainForm.Bufer[i].Group);
- Table.Cells[4, Table.RowCount-1] := IntToStr(MainForm.Bufer[i].Number);
- Table.Cells[5, Table.RowCount-1] := MainForm.Bufer[i].DateOfBirth;
- Table.Cells[6, Table.RowCount-1] := MainForm.Bufer[i].Sex;
- end;
- if Table.RowCount = 1 then
- Application.MessageBox('Тo students found for given parameters','Result', MB_OK)
- else
- begin
- Table.Cells[0, 0] := 'Surname';
- Table.Cells[1, 0] := 'Name';
- Table.Cells[2, 0] := 'Patronymic';
- Table.Cells[3, 0] := 'Group';
- Table.Cells[4, 0] := 'Daybook number';
- Table.Cells[5, 0] := 'Date of birth';
- Table.Cells[6, 0] := 'Sex';
- Table.Visible := True;
- Table.Height := Table.RowCount * Table.DefaultRowHeight + 15;
- SearchFor.Height := SearchFor.Height + Table.Height + 25;
- BtSave.Enabled := True;
- end;
- end;
- procedure TSearchFor.ComboBoxGroupChange(Sender: TObject);
- var
- i: Integer;
- begin
- if (EdYear.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) then
- BtSearch.Enabled := True;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- end;
- procedure TSearchFor.ComboBoxGroupKeyPress(Sender: TObject; var Key: Char);
- begin
- if Key = #13 then
- begin
- Key := #0;
- EdYear.SetFocus;
- end;
- end;
- procedure TSearchFor.EdYearChange(Sender: TObject);
- var
- i: Integer;
- begin
- if Length(EdYear.Text) = 0 then
- begin
- EdYear.Color := clWhite;
- BtSearch.Enabled := False;
- end
- else
- if (Length(EdYear.Text) = 4) and (StrToInt(EdYear.Text) >= 1964) and (StrToInt(EdYear.Text) <= 2001) then
- begin
- EdYear.Color := $00CDFF9B;
- if (ComboBoxGroup.ItemIndex <> -1) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) then
- BtSearch.Enabled := True;
- end
- else
- begin
- EdYear.Color := $00BBBBFF;
- BtSearch.Enabled := False;
- end;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- end;
- procedure TSearchFor.EdYearKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, '0'..'9'];
- begin
- if Key = #13 then
- begin
- Key := #0;
- if RadioButtonFemale.Checked then
- RadioButtonMale.SetFocus
- else
- RadioButtonFemale.SetFocus
- end;
- if not(Key in IsValid) then
- Key := #0;
- end;
- procedure TSearchFor.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- var
- i: Integer;
- begin
- if (Application.MessageBox('Would you like to close the window?',
- 'Windowclosing', MB_OKCANCEL) = mrOk) then
- begin
- CanClose := true;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- EdYear.Text := '';
- RadioButtonMale.Checked := false;
- RadioButtonFemale.Checked := false;
- ComboBoxGroup.ItemIndex := -1;
- end
- else
- CanClose := false;
- end;
- procedure TSearchFor.ImageHelpClick(Sender: TObject);
- begin
- Application.MessageBox('Choose parameters and click "Find".','Help information', MB_OK);
- end;
- procedure TSearchFor.RadioButtonFemaleClick(Sender: TObject);
- var
- i: Integer;
- begin
- if (EdYear.Color = $00CDFF9B) and (ComboBoxGroup.ItemIndex <> -1) then
- BtSearch.Enabled := True;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- end;
- procedure TSearchFor.RadioButtonFemaleKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) then
- begin
- if BtSearch.Enabled then
- BtSearch.SetFocus;
- end;
- end;
- procedure TSearchFor.RadioButtonMaleClick(Sender: TObject);
- var
- i: Integer;
- begin
- if (EdYear.Color = $00CDFF9B) and (ComboBoxGroup.ItemIndex <> -1) then
- BtSearch.Enabled := True;
- Table.Visible := False;
- for i := 0 to Table.RowCount - 1 do
- Table.Rows[i].Clear;
- Table.RowCount := 1;
- SearchFor.Height := 100;
- end;
- procedure TSearchFor.RadioButtonMaleKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) then
- begin
- if BtSearch.Enabled then
- BtSearch.SetFocus;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement