Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit InputOfRecords;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.Menus,
- Vcl.Imaging.pngimage, Vcl.ExtCtrls;
- type
- TInputRec = class(TForm)
- EdSurname: TEdit;
- LblSurname: TLabel;
- EdName: TEdit;
- EdPatronymic: TEdit;
- LblName: TLabel;
- LblPatronymic: TLabel;
- LblGroup: TLabel;
- EdNumber: TEdit;
- LblNumber: TLabel;
- LblDateOfBirth: TLabel;
- LblMonth: TLabel;
- EdMonth: TEdit;
- LblDay: TLabel;
- EdDay: TEdit;
- LblYear: TLabel;
- EdYear: TEdit;
- Table: TStringGrid;
- BtCreate: TButton;
- BtReady: TButton;
- PopupMenu1: TPopupMenu;
- RadioButtonMale: TRadioButton;
- RadioButtonFemale: TRadioButton;
- ImageHelp: TImage;
- ComboBoxGroup: TComboBox;
- BtChange: TButton;
- OpenDialog: TOpenDialog;
- InputFromFile: TButton;
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure BtReadyClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure EdSurnameKeyPress(Sender: TObject; var Key: Char);
- procedure EdNameKeyPress(Sender: TObject; var Key: Char);
- procedure EdPatronymicKeyPress(Sender: TObject; var Key: Char);
- procedure EdNumberKeyPress(Sender: TObject; var Key: Char);
- procedure ImageHelpClick(Sender: TObject);
- procedure EdYearKeyPress(Sender: TObject; var Key: Char);
- procedure EdMonthKeyPress(Sender: TObject; var Key: Char);
- procedure EdDayKeyPress(Sender: TObject; var Key: Char);
- procedure EdSurnameChange(Sender: TObject);
- procedure EdNameChange(Sender: TObject);
- procedure EdPatronymicChange(Sender: TObject);
- procedure EdNumberChange(Sender: TObject);
- procedure EdYearChange(Sender: TObject);
- procedure EdMonthChange(Sender: TObject);
- procedure EdDayChange(Sender: TObject);
- procedure RadioButtonMaleClick(Sender: TObject);
- procedure RadioButtonFemaleClick(Sender: TObject);
- procedure ComboBoxGroupKeyPress(Sender: TObject; var Key: Char);
- procedure ComboBoxGroupChange(Sender: TObject);
- procedure BtCreateClick(Sender: TObject);
- procedure RadioButtonMaleKeyPress(Sender: TObject; var Key: Char);
- procedure RadioButtonFemaleKeyPress(Sender: TObject; var Key: Char);
- procedure TableMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure BtChangeClick(Sender: TObject);
- procedure InputFromFileClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- InputRec: TInputRec;
- implementation
- {$R *.dfm}
- uses MainForm, ViewRecord;
- var
- ChangeRow: Integer;
- procedure ChangeBuf(const Table: TStringGrid; var Bufer: MainForm.TArr);
- begin
- SetLength(MainForm.Bufer, Length(MainForm.Bufer) + 1);
- MainForm.Bufer[High(MainForm.Bufer)].Surname := Table.Cells[0, Table.RowCount-1];
- MainForm.Bufer[High(MainForm.Bufer)].Name := Table.Cells[1, Table.RowCount-1];
- MainForm.Bufer[High(MainForm.Bufer)].Patronymic := Table.Cells[2, Table.RowCount-1];
- MainForm.Bufer[High(MainForm.Bufer)].Group := StrToInt(Table.Cells[3, Table.RowCount-1]);
- MainForm.Bufer[High(MainForm.Bufer)].Number := StrToInt(Table.Cells[4, Table.RowCount-1]);
- MainForm.Bufer[High(MainForm.Bufer)].DateOfBirth := Table.Cells[5, Table.RowCount-1];
- MainForm.Bufer[High(MainForm.Bufer)].Sex := Table.Cells[6, Table.RowCount-1];
- end;
- procedure TInputRec.BtChangeClick(Sender: TObject);
- var
- Mon, D, Num: string;
- i: Integer;
- begin
- BtReady.Enabled := False;
- EdSurname.Text := Table.Cells[0, ChangeRow];
- EdName.Text := Table.Cells[1, ChangeRow];
- EdPatronymic.Text := Table.Cells[2, ChangeRow];
- i := 0;
- while ComboBoxGroup.Items[i] <> Table.Cells[3, ChangeRow] do
- begin
- Inc(i);
- end;
- ComboBoxGroup.ItemIndex := i;
- Table.Cells[3, ChangeRow] := '';
- Num := Table.Cells[4, ChangeRow];
- Table.Cells[4, ChangeRow] := '';
- EdNumber.Text := Num;
- EdYear.Text := Copy(Table.Cells[5, ChangeRow], Length(Table.Cells[5, ChangeRow]) - 3, 4);
- D := Table.Cells[5, ChangeRow][1];
- if Table.Cells[5, ChangeRow][2] <> '.' then
- begin
- D := D + Table.Cells[5, ChangeRow][2];
- Mon := Table.Cells[5, ChangeRow][4];
- if Table.Cells[5, ChangeRow][5] <> '.' then
- Mon := Mon + Table.Cells[5, ChangeRow][5];
- end
- else
- begin
- Mon := Table.Cells[5, ChangeRow][3];
- if Table.Cells[5, ChangeRow][4] <> '.' then
- Mon := Mon + Table.Cells[5, ChangeRow][4];
- end;
- EdMonth.Text := Mon;
- EdDay.Text := D;
- if Table.Cells[6, ChangeRow] = 'male' then
- RadioButtonMale.Checked := True
- else
- RadioButtonFemale.Checked := True;
- Table.Rows[ChangeRow].Clear;
- BtCreate.Caption := 'Apply';
- BtChange.Enabled := False;
- end;
- procedure TInputRec.BtCreateClick(Sender: TObject);
- begin
- if BtCreate.Caption = 'Create' then
- begin
- Table.RowCount := Table.RowCount + 1;
- Table.Cells[0, Table.RowCount-1] := EdSurname.Text;
- Table.Cells[1, Table.RowCount-1] := EdName.Text;
- Table.Cells[2, Table.RowCount-1] := EdPatronymic.Text;
- Table.Cells[3, Table.RowCount-1] := ComboBoxGroup.Text;
- Table.Cells[4, Table.RowCount-1] := EdNumber.Text;
- Table.Cells[5, Table.RowCount-1] := EdDay.Text + '.' + EdMonth.Text + '.' + EdYear.Text;
- if RadioButtonMale.Checked then
- Table.Cells[6, Table.RowCount-1] := RadioButtonMale.Caption
- else
- Table.Cells[6, Table.RowCount-1] := RadioButtonFemale.Caption;
- RadioButtonMale.Checked := false;
- RadioButtonFemale.Checked := false;
- EdSurname.Clear;
- EdName.Clear;
- EdPatronymic.Clear;
- EdNumber.Clear;
- EdYear.Clear;
- EdMonth.Clear;
- EdDay.Clear;
- ComboBoxGroup.ItemIndex := -1;
- ChangeBuf(Table, MainForm.Bufer);
- EdSurname.SetFocus;
- end
- else
- begin
- Table.Cells[0, ChangeRow] := EdSurname.Text;
- Table.Cells[1, ChangeRow] := EdName.Text;
- Table.Cells[2, ChangeRow] := EdPatronymic.Text;
- Table.Cells[3, ChangeRow] := ComboBoxGroup.Text;
- Table.Cells[4, ChangeRow] := EdNumber.Text;
- Table.Cells[5, ChangeRow] := EdDay.Text + '.' + EdMonth.Text + '.' + EdYear.Text;
- if RadioButtonMale.Checked then
- Table.Cells[6, ChangeRow] := RadioButtonMale.Caption
- else
- Table.Cells[6, ChangeRow] := RadioButtonFemale.Caption;
- MainForm.Bufer[ChangeRow - 1].Surname := Table.Cells[0, ChangeRow];
- MainForm.Bufer[ChangeRow - 1].Name := Table.Cells[1, ChangeRow];
- MainForm.Bufer[ChangeRow - 1].Patronymic := Table.Cells[2, ChangeRow];
- MainForm.Bufer[ChangeRow - 1].Group := StrToInt(Table.Cells[3, ChangeRow]);
- MainForm.Bufer[ChangeRow - 1].Number := StrToInt(Table.Cells[4, ChangeRow]);
- MainForm.Bufer[ChangeRow - 1].DateOfBirth := Table.Cells[5, ChangeRow];
- MainForm.Bufer[ChangeRow - 1].Sex := Table.Cells[6, ChangeRow];
- RadioButtonMale.Checked := false;
- RadioButtonFemale.Checked := false;
- EdSurname.Clear;
- EdName.Clear;
- EdPatronymic.Clear;
- EdNumber.Clear;
- EdYear.Clear;
- EdMonth.Clear;
- EdDay.Clear;
- ComboBoxGroup.ItemIndex := -1;
- ChangeBuf(Table, MainForm.Bufer);
- BtCreate.Caption := 'Create';
- BtChange.Enabled := False;
- ViewRec.BtSort.Enabled := True;
- BtReady.Enabled := True;
- end;
- end;
- procedure TInputRec.BtReadyClick(Sender: TObject);
- begin
- if Table.RowCount > 1 then
- begin
- BtReady.Enabled := false;
- Close;
- end
- else
- if (Application.MessageBox('You haven''t created the records. Would you like to close the window?',
- 'Window closing', MB_OKCANCEL) = mrOk) then
- begin
- BtReady.Enabled := false;
- Close;
- end;
- end;
- function CheckNumber(val: Integer; grp: string): Boolean;
- var
- i: Integer;
- IsCor: Boolean;
- begin
- IsCor := True;
- i := 1;
- repeat
- if grp = InputRec.Table.Cells[3,i] then
- if val = StrToInt(InputRec.Table.Cells[4,i]) then
- IsCor := False
- else
- Inc(i)
- else
- Inc(i);
- until (i >= InputRec.Table.RowCount) or not IsCor;
- CheckNumber := IsCor;
- end;
- procedure TInputRec.ComboBoxGroupChange(Sender: TObject);
- begin
- EdNumber.Enabled := True;
- if Length(EdNumber.Text) > 0 then
- if CheckNumber(StrToInt(EdNumber.Text), ComboBoxGroup.Text) then
- begin
- EdNumber.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdNumber.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end;
- end;
- procedure TInputRec.ComboBoxGroupKeyPress(Sender: TObject; var Key: Char);
- begin
- if Key = #13 then
- if EdNumber.Enabled then
- begin
- Key := #0;
- EdNumber.SetFocus;
- end
- else
- begin
- Key := #0;
- EdYear.SetFocus;
- end
- end;
- procedure TInputRec.EdDayChange(Sender: TObject);
- type
- TArr = array[1..12] of Integer;
- const
- NumOfDays: TArr = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
- var
- Year, Num: Integer;
- begin
- if Length(EdDay.Text) = 0 then
- begin
- EdDay.Color := clWhite;
- BtCreate.Enabled := False;
- end
- else
- if StrToInt(EdDay.Text) = 0 then
- begin
- EdDay.Color := clWhite;
- EdDay.Text := '';
- BtCreate.Enabled := False;
- end
- else
- if Length(EdMonth.Text) > 0 then
- begin
- Num := StrToInt(EdMonth.Text);
- if Num = 2 then
- begin
- if (Length(EdYear.Text) > 0) then
- begin
- Year := StrToInt(EdYear.Text);
- if ((Year mod 4 = 0) and not(Year mod 100 = 0)) or (Year mod 400 = 0) then
- if (StrToInt(EdDay.Text) > (NumOfdays[Num] + 1)) then
- begin
- EdDay.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end
- else
- begin
- EdDay.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- if (StrToInt(EdDay.Text) > NumOfdays[Num]) then
- begin
- EdDay.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end
- else
- begin
- EdDay.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- end
- else
- if (StrToInt(EdDay.Text) > NumOfdays[Num]) then
- begin
- EdDay.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end
- else
- begin
- EdDay.Color := $00CDFF9B;
- BtCreate.Enabled := False;
- end;
- end
- else
- begin
- if (StrToInt(EdDay.Text) > NumOfdays[Num]) then
- begin
- EdDay.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end
- else
- begin
- EdDay.Color := $00CDFF9B;
- BtCreate.Enabled := False;
- end;
- end;
- end
- else
- begin
- EdDay.Color := $00CDFF9B;
- BtCreate.Enabled := False;
- end;
- end;
- procedure TInputRec.EdDayKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, #13, '0'..'9'];
- begin
- if not (Key in IsValid) then
- Key := #0
- else
- begin
- if Key = #13 then
- begin
- Key := #0;
- if RadioButtonMale.Checked then
- RadioButtonMale.SetFocus;
- if RadioButtonFemale.Checked then
- RadioButtonFemale.SetFocus;
- if (not RadioButtonMale.Checked) and (not RadioButtonFemale.Checked) then
- RadioButtonMale.SetFocus;
- end;
- if (Length(EdDay.Text) = 1) and (Key <> #8) and (StrToInt(EdDay.Text + Key) > 31) then
- Key := #0;
- if (Length(EdDay.Text) = 0) and (Key = '0') then
- Key := #0;
- end;
- end;
- procedure TInputRec.EdMonthChange(Sender: TObject);
- var
- TempDay: string;
- begin
- if Length(EdMonth.Text) = 0 then
- begin
- EdMonth.Color := clWhite;
- BtCreate.Enabled := False;
- end
- else
- if StrToInt(EdMonth.Text) = 0 then
- begin
- EdMonth.Text := '';
- EdMonth.Color := clWhite;
- BtCreate.Enabled := False;
- end
- else
- begin
- if Length(EdDay.Text) > 0 then
- begin
- TempDay := EdDay.Text;
- EdDay.Text := '';
- EdDay.Text := TempDay;
- end;
- EdMonth.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end;
- end;
- procedure TInputRec.EdMonthKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, #13, '0'..'9'];
- begin
- if not (Key in IsValid) then
- Key := #0;
- if Key = #13 then
- begin
- Key := #0;
- EdDay.SetFocus;
- end;
- if (Length(EdMonth.Text) = 1) and (Key <> #8) and (StrToInt(EdMonth.Text + Key) > 12) then
- Key := #0;
- if (Length(EdMonth.Text) = 0) and (Key = '0') then
- Key := #0;
- end;
- procedure TInputRec.EdNameChange(Sender: TObject);
- const
- SmallLetters = ['a'..'z'];
- BigLetters = ['A'..'Z'];
- var
- Temp: string;
- Letter: Char;
- begin
- if Length(EdName.Text) > 1 then
- begin
- EdName.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdName.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end;
- if EdName.Text <> '' then
- begin
- if EdName.Text[1] in SmallLetters then
- begin
- Temp := Copy(EdName.Text, 2, Length(EdName.Text) - 1);
- Letter := EdName.Text[1];
- Dec(Letter, 32);
- EdName.Text := Letter + Temp;
- end;
- if EdName.Text[2] in BigLetters then
- begin
- Temp := Copy(EdName.Text, 2, Length(EdName.Text) - 1);
- EdName.Text := EdName.Text[1] + LowerCase(Temp);
- end;
- end
- else
- begin
- EdName.Color := clWhite;
- BtCreate.Enabled := False;
- end;
- end;
- procedure TInputRec.EdNameKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, #13, 'a'..'z', 'A'..'Z'];
- Big = ['A'..'Z'];
- begin
- if not (Key in IsValid) then
- Key := #0
- else
- begin
- if Key = #13 then
- begin
- Key := #0;
- EdPatronymic.SetFocus;
- end;
- if (Length(EdName.Text) > 0) and (Key in Big) then
- Inc(Key, 32);
- if (Length(EdName.Text) = 0) and (Key in IsValid) and not(Key in Big) and (Key <> #8) then
- Dec(Key, 32);
- if (Length(EdName.Text) = 0) and (Key = #8) then
- Key := #0;
- end;
- end;
- procedure TInputRec.EdNumberChange(Sender: TObject);
- begin
- if Length(EdNumber.Text) = 0 then
- begin
- EdNumber.Color := clWhite;
- BtCreate.Enabled := False;
- end
- else
- if StrToInt(EdNumber.Text) = 0 then
- begin
- EdNumber.Text := '';
- EdNumber.Color := clWhite;
- BtCreate.Enabled := False;
- end
- else
- begin
- if Table.RowCount > 1 then
- if CheckNumber(StrToInt(EdNumber.Text), ComboBoxGroup.Text) then
- begin
- EdNumber.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdNumber.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end
- else
- begin
- EdNumber.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end;
- end;
- end;
- procedure TInputRec.EdNumberKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, '0'..'9'];
- begin
- if Key = #13 then
- begin
- Key := #0;
- EdYear.SetFocus;
- end;
- if not (Key in IsValid) then
- Key := #0;
- if (Length(EdNumber.Text) = 1) and (Key <> #8) and (StrToInt(EdNumber.Text + Key) > 31) then
- Key := #0;
- if (Length(EdNumber.Text) = 0) and (Key = '0') then
- Key := #0;
- end;
- procedure TInputRec.EdPatronymicChange(Sender: TObject);
- const
- SmallLetters = ['a'..'z'];
- BigLetters = ['A'..'Z'];
- var
- Temp: string;
- Letter: Char;
- begin
- if Length(EdPatronymic.Text) > 1 then
- begin
- EdPatronymic.Color := $00CDFF9B;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdPatronymic.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end;
- if EdPatronymic.Text <> '' then
- begin
- if EdPatronymic.Text[1] in SmallLetters then
- begin
- Temp := Copy(EdPatronymic.Text, 2, Length(EdPatronymic.Text) - 1);
- Letter := EdPatronymic.Text[1];
- Dec(Letter, 32);
- EdPatronymic.Text := Letter + Temp;
- end;
- if EdPatronymic.Text[2] in BigLetters then
- begin
- Temp := Copy(EdPatronymic.Text, 2, Length(EdPatronymic.Text) - 1);
- EdPatronymic.Text := EdPatronymic.Text[1] + LowerCase(Temp);
- end;
- end
- else
- begin
- EdPatronymic.Color := clWhite;
- BtCreate.Enabled := False;
- end;
- end;
- procedure TInputRec.EdPatronymicKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, #13, 'a'..'z', 'A'..'Z'];
- Big = ['A'..'Z'];
- begin
- if not (Key in IsValid) then
- Key := #0
- else
- begin
- if Key = #13 then
- begin
- Key := #0;
- ComboBoxGroup.SetFocus;
- end;
- if (Length(EdPatronymic.Text) > 0) and (Key in Big) then
- Inc(Key, 32);
- if (Length(EdPatronymic.Text) = 0) and (Key in IsValid) and not(Key in Big) and (Key <> #8) then
- Dec(Key, 32);
- if (Length(EdPatronymic.Text) = 0) and (Key = #8) then
- Key := #0;
- end;
- end;
- procedure TInputRec.EdSurnameChange(Sender: TObject);
- const
- SmallLetters = ['a'..'z'];
- BigLetters = ['A'..'Z'];
- var
- Temp: string;
- Letter: Char;
- begin
- if Length(EdSurname.Text) > 1 then
- begin
- EdSurname.Color := $00CDFF9B;
- if (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdSurname.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- end;
- if EdSurname.Text <> '' then
- begin
- if EdSurname.Text[1] in SmallLetters then
- begin
- Temp := Copy(EdSurname.Text, 2, Length(EdSurname.Text) - 1);
- Letter := EdSurname.Text[1];
- Dec(Letter, 32);
- EdSurname.Text := Letter+Temp;
- end;
- if EdSurname.Text[2] in BigLetters then
- begin
- Temp := Copy(EdSurname.Text, 2, Length(EdSurname.Text) - 1);
- EdSurname.Text := EdSurname.Text[1] + LowerCase(Temp);
- end;
- end
- else
- begin
- EdSurname.Color := clWhite;
- BtCreate.Enabled := False;
- end;
- end;
- procedure TInputRec.EdSurnameKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8,#13, 'a'..'z', 'A'..'Z'];
- Big = ['A'..'Z'];
- begin
- if not (Key in IsValid) then
- Key := #0
- else
- begin
- if Key = #13 then
- begin
- Key := #0;
- EdName.SetFocus;
- end;
- if (Length(EdSurname.Text) > 0) and (Key in Big) then
- Inc(Key, 32);
- if (Length(EdSurname.Text) = 0) and (Key in IsValid) and not(Key in Big) and (Key <> #8) then
- Dec(Key, 32);
- if (Length(EdSurname.Text) = 0) and (Key = #8) then
- Key := #0;
- end;
- end;
- procedure TInputRec.EdYearChange(Sender: TObject);
- var
- TempDay: string;
- begin
- if Length(EdYear.Text) = 0 then
- begin
- EdYear.Color := clWhite;
- BtCreate.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 Length(EdDay.Text) > 0 then
- begin
- TempDay := EdDay.Text;
- EdDay.Text := '';
- EdDay.Text := TempDay;
- end;
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (RadioButtonMale.Checked or RadioButtonFemale.Checked) and (ComboBoxGroup.ItemIndex <> -1) then
- BtCreate.Enabled := True;
- end
- else
- begin
- EdYear.Text := IntToStr(StrToInt(EdYear.Text));
- EdYear.Color := $00BBBBFF;
- BtCreate.Enabled := False;
- if Length(EdDay.Text) > 0 then
- begin
- TempDay := EdDay.Text;
- EdDay.Text := '';
- EdDay.Text := TempDay;
- end;
- end;
- end;
- procedure TInputRec.EdYearKeyPress(Sender: TObject; var Key: Char);
- const
- IsValid = [#8, '0'..'9'];
- begin
- if Key = #13 then
- begin
- Key := #0;
- EdMonth.SetFocus;
- end;
- if not(Key in IsValid) then
- Key := #0;
- end;
- procedure CleanForm;
- var
- i: Integer;
- begin
- InputRec.BtReady.Enabled := true;
- InputRec.RadioButtonMale.Checked := false;
- InputRec.RadioButtonFemale.Checked := false;
- InputRec.EdSurname.Clear;
- InputRec.EdName.Clear;
- InputRec.EdPatronymic.Clear;
- InputRec.EdNumber.Clear;
- InputRec.EdYear.Clear;
- InputRec.EdMonth.Clear;
- InputRec.EdDay.Clear;
- InputRec.ComboBoxGroup.ItemIndex := -1;
- for i := 1 to InputRec.Table.RowCount - 1 do
- InputRec.Table.Rows[i].Clear;
- InputRec.Table.RowCount := 1;
- if Length(MainForm.Bufer) > 0 then
- begin
- MainProgMenu.DelRec.Enabled := True;
- MainProgMenu.View.Enabled := True;
- end;
- end;
- procedure TInputRec.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- var
- i: Integer;
- begin
- if BtReady.Enabled then
- if (Length(EdSurname.Text) > 0) or (Length(EdName.Text) > 0) or (Length(EdPatronymic.Text) > 0) or (Length(EdNumber.Text) > 0) or (Length(EdYear.Text) > 0) or (Length(EdMonth.Text) > 0) or (Length(EdDay.Text) > 0) or RadioButtonMale.Checked or RadioButtonFemale.Checked or (ComboBoxGroup.ItemIndex <> -1) then
- if (Application.MessageBox('Entry fields will be cleaned. Would you like to close the window?','Window closing', MB_OKCANCEL) = mrOk) then
- begin
- CanClose := true;
- CleanForm;
- end
- else
- CanClose := false
- else
- if (Application.MessageBox('Would you like to close the window?','Window closing', MB_OKCANCEL) = mrOk) then
- begin
- BtReady.Enabled := True;
- CanClose := true;
- CleanForm;
- end
- else
- CanClose := false
- else
- if BtCreate.Caption = 'Apply' then
- begin
- if (Application.MessageBox('You haven''t finished changing. Would you like to close the window?','Window closing', MB_OKCANCEL) = mrOk) then
- begin
- BtReady.Enabled := True;
- CanClose := true;
- BtCreate.Caption := 'Create';
- CleanForm;
- end
- end
- else
- begin
- CanClose := true;
- CleanForm;
- end;
- end;
- procedure TInputRec.FormCreate(Sender: TObject);
- 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';
- end;
- procedure TInputRec.ImageHelpClick(Sender: TObject);
- begin
- Application.MessageBox('Enter all information about the student and click "Create" to create a new record. Data is correct only if background is green.','Help information', MB_OK);
- end;
- function CheckNumberFile(val: Integer; grp: string): Boolean;
- var
- i: Integer;
- IsCor: Boolean;
- begin
- IsCor := True;
- i := 0;
- repeat
- if grp = IntToStr(MainForm.Bufer[i].Group) then
- if val = MainForm.Bufer[i].Number then
- IsCor := False
- else
- Inc(i)
- else
- Inc(i);
- until (i = Length(MainForm.Bufer)) or not IsCor;
- CheckNumberFile := IsCor;
- end;
- procedure TInputRec.InputFromFileClick(Sender: TObject);
- var
- Student: MainForm.TStudent;
- MyFile: file of MainForm.TStudent;
- const
- ValidLetters: set of Char = ['A'..'Z', 'a'..'z'];
- ValidNumbers: set of Char = ['0'..'9'];
- MaxYear = 2001;
- MinYear = 1964;
- var
- InputFile: file of TStudent;
- StartLen, i, j: Integer;
- IsCorrect, IsCorGroup: Boolean;
- begin
- IsCorrect := True;
- if OpenDialog.Execute then
- begin
- AssignFile(InputFile, OpenDialog.FileName);
- Reset(InputFile);
- if Eof(InputFile) then
- MessageDlg('File is empty. Please retry.', mtError, [mbRetry], 0)
- else
- try
- StartLen := Length(MainForm.Bufer);
- SetLength(MainForm.Bufer, StartLen + FileSize(InputFile));
- i := StartLen;
- while (i < Length(MainForm.Bufer)) and IsCorrect do
- begin
- Read(InputFile, MainForm.Bufer[i]);
- Inc(i);
- end;
- if not IsCorrect then
- begin
- SetLength(MainForm.Bufer, StartLen);
- Application.MessageBox('Read error. Please try again.','Input Error', MB_OK);
- CloseFile(InputFile);
- end;
- except
- SetLength(MainForm.Bufer, StartLen);
- Application.MessageBox('Read error. Please try again.','Input Error', MB_OK);
- CloseFile(InputFile);
- end;
- end;
- if IsCorrect then
- begin
- InputRec.Table.RowCount := Length(MainForm.Bufer) + 1;
- for i := StartLen + 1 to Length(MainForm.Bufer) do
- begin
- InputRec.Table.Cells[0,i] := MainForm.Bufer[i-1].Surname;
- InputRec.Table.Cells[1,i] := MainForm.Bufer[i-1].Name;
- InputRec.Table.Cells[2,i] := MainForm.Bufer[i-1].Patronymic;
- InputRec.Table.Cells[3,i] := IntToStr(MainForm.Bufer[i-1].Group);
- InputRec.Table.Cells[4,i] := IntToStr(MainForm.Bufer[i-1].Number);
- InputRec.Table.Cells[5,i] := MainForm.Bufer[i-1].DateOfBirth;
- InputRec.Table.Cells[6,i] := MainForm.Bufer[i-1].Sex;
- end;
- end;
- end;
- procedure TInputRec.RadioButtonFemaleClick(Sender: TObject);
- begin
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (Length(ComboBoxGroup.Text) > 0) then
- BtCreate.Enabled := True;
- end;
- procedure TInputRec.RadioButtonFemaleKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) and BtCreate.Enabled then
- BtCreate.SetFocus;
- end;
- procedure TInputRec.RadioButtonMaleClick(Sender: TObject);
- begin
- if (EdSurname.Color = $00CDFF9B) and (EdName.Color = $00CDFF9B) and (EdPatronymic.Color = $00CDFF9B) and (EdNumber.Color = $00CDFF9B) and (EdYear.Color = $00CDFF9B) and (EdMonth.Color = $00CDFF9B) and (EdDay.Color = $00CDFF9B) and (Length(ComboBoxGroup.Text) > 0) then
- BtCreate.Enabled := True;
- end;
- procedure TInputRec.RadioButtonMaleKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key = #13) and BtCreate.Enabled then
- BtCreate.SetFocus;
- end;
- procedure TInputRec.TableMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var
- ACol: Integer;
- begin
- if Button = mbLeft then
- begin
- Table.MouseToCell(x, y, ACol, ChangeRow);
- if (ChangeRow > 0) then
- begin
- BtChange.Enabled := True;
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement