Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainForm;
- 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;
- type
- THeadForm = class(TForm)
- StringGrid1: TStringGrid;
- Button1: TButton;
- Button2: TButton;
- Label1: TLabel;
- MainMenu1: TMainMenu;
- PopupMenu1: TPopupMenu;
- SaveDialog1: TSaveDialog;
- OpenDialog1: TOpenDialog;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure StringGrid1DblClick(Sender: TObject);
- procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- procedure N5Click(Sender: TObject);
- procedure N4Click(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure N3Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- type
- TStudent = packed record
- Name : String[18];
- Group : Integer;
- Number : Byte;
- Day : Integer;
- Month : Integer;
- Year : Integer;
- Sex : Boolean;
- Speciality : String[16]; // спецуха
- end;
- var
- HeadForm: THeadForm;
- I, N, Row, RowForDelete: Integer;
- Path : String;
- IsFileOpen : Boolean;
- implementation
- {$R *.dfm}
- uses Add, List, Edit;
- procedure THeadForm.Button1Click(Sender: TObject);
- begin
- Form1.ShowModal;
- end;
- procedure THeadForm.Button2Click(Sender: TObject);
- begin
- Form2.ShowModal;
- end;
- procedure THeadForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := MessageBox(Form1.Handle, 'Вы уверены, что хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION)=ID_YES;
- end;
- procedure THeadForm.FormCreate(Sender: TObject);
- begin
- StringGrid1.Cells[0,0] := 'Код группы';
- StringGrid1.Cells[1,0] := 'Отделение';
- StringGrid1.ColWidths[1] := 150;
- StringGrid1.Cells[2,0] := 'ФИО';
- StringGrid1.Cells[3,0] := 'Номер';
- StringGrid1.Cells[4,0] := 'Дата рождения';
- StringGrid1.Cells[5,0] := 'Пол';
- I := 1;
- end;
- Function Open (): String;
- Begin
- With HeadForm Do
- Begin
- If OpenDialog1.Execute Then
- Begin
- Path := OpenDialog1.Filename;
- IsFileOpen := True;
- End
- Else
- IsFileOpen := False;
- End;
- Open := Path;
- End;
- procedure THeadForm.N3Click(Sender: TObject); // save
- Var
- FileWithStudents : File of TStudent;
- Str, Birthday : String;
- I, Depth : Integer;
- StudentsForFile : TStudent;
- begin
- If (SaveDialog1.Execute) then
- Begin
- Try
- Path := SaveDialog1.FileName;
- Str := ExtractFileExt(Path);
- If(Str = '') Then
- Path := Path + '.nik';
- Rewrite(FileWithStudents, Path);
- Seek(FileWithStudents, 0);
- Truncate(FileWithStudents);
- Depth := HeadForm.StringGrid1.RowCount;
- If Depth > 1 then
- For I := 0 To Depth - 2 Do
- Begin
- StudentsForFile.Group := StrToInt(HeadForm.StringGrid1.Cells[0, I + 1]);
- StudentsForFile.Speciality := HeadForm.StringGrid1.Cells[1, I + 1];
- StudentsForFile.Name := HeadForm.StringGrid1.Cells[2, I + 1];
- StudentsForFile.Number := StrToInt(HeadForm.StringGrid1.Cells[3, I + 1]);
- Birthday := HeadForm.StringGrid1.Cells[4, I + 1];
- StudentsForFile.Day := StrToInt (Birthday[1] + Birthday[2]);
- StudentsForFile.Month := StrToInt (Birthday[4] + Birthday[5]);
- StudentsForFile.Year := StrToInt (Birthday[7] + Birthday[8] + Birthday[9]+ Birthday[10]);
- If (HeadForm.StringGrid1.Cells[5, I + 1] = 'Мужской') then
- StudentsForFile.Sex := True
- else
- StudentsForFile.Sex := False;
- Write(FileWithStudents, StudentsForFile);
- End;
- CloseFile(FileWithStudents);
- Except
- Application.MessageBox('Что-то пошло не так :\', 'Ошибка', MB_ICONSTOP);
- End;
- End;
- end;
- procedure THeadForm.N2Click(Sender: TObject); // open
- Var
- FileWithStudents : File of TStudent;
- Day, Year, Month, Birthday, Sex : String;
- I, MsgResult, K, Counter, N: Integer;
- StudentsForFile : TStudent;
- IsFirstTime, CanClose : Boolean;
- begin
- I := 1;
- IsFirstTime := True;
- AssignFile(FileWithStudents, Path);
- If(OpenDialog1.Execute) Then
- Begin
- Try
- Path := OpenDialog1.FileName;
- Reset(FileWithStudents, Path);
- While(Not(Eof(FileWithStudents))) Do
- Begin
- If (I = 1) Then
- Finalize(FileWithStudents);
- Read(FileWithStudents, StudentsForFile);
- If IsFirstTime then
- Begin
- MsgResult := MessageDlg ('Дополнить существующие записи?', mtConfirmation, [mbYes, mbNo], 0);
- If MsgResult = mrYes then
- begin
- I := HeadForm.StringGrid1.RowCount;
- end
- else
- begin
- HeadForm.StringGrid1.RowCount := 1;
- end;
- IsFirstTime := False;
- End;
- N := HeadForm.StringGrid1.RowCount;
- K := 1;
- While K <> N Do
- begin
- Counter := 0;
- If HeadForm.StringGrid1.Cells[0,K] = IntToStr(StudentsForFile.Group) then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[1,K] = StudentsForFile.Speciality then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[2,K] = StudentsForFile.Name then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[3,K] = IntToStr(StudentsForFile.Number) then
- Inc(Counter);
- Day := IntToStr(StudentsForFile.Day);
- If (Length(Day) = 1) then
- Day := '0' + Day;
- Month := IntToStr(StudentsForFile.Month);
- If (Length(Month) = 1) then
- Month := '0' + Month;
- Year := IntToStr(StudentsForFile.Year);
- Birthday := Day + '.' + Month + '.' + Year;
- If HeadForm.StringGrid1.Cells[4,K] = Birthday then
- Inc(Counter);
- If StudentsForFile.Sex then
- Sex := 'Мужской'
- else
- Sex := 'Женский';
- If HeadForm.StringGrid1.Cells[5,K] = Sex then
- Inc(Counter);
- Inc(K);
- If Counter = 6 then
- begin
- MessageBox(Form1.Handle, Pchar('Информация о студенте из файла уже есть в базе данных.'), 'Ошибка', MB_ICONSTOP);
- Counter := 0;
- Exit
- end;
- end;
- HeadForm.StringGrid1.RowCount := HeadForm.StringGrid1.RowCount + 1;
- HeadForm.StringGrid1.Cells[0, I] := IntToStr(StudentsForFile.Group);
- HeadForm.StringGrid1.Cells[1, I] := StudentsForFile.Speciality;
- HeadForm.StringGrid1.Cells[2, I] := StudentsForFile.Name;
- HeadForm.StringGrid1.Cells[3, I] := IntToStr(StudentsForFile.Number);
- Day := IntToStr(StudentsForFile.Day);
- If Length(Day) = 1 then
- Day := '0' + Day;
- Month := IntToStr(StudentsForFile.Month);
- If Length(Month) = 1 then
- Month := '0' + Month;
- Year := IntToStr(StudentsForFile.Year);
- HeadForm.StringGrid1.Cells[4, I] := Day + '.' + Month + '.' + Year;
- If StudentsForFile.Sex = True then
- HeadForm.StringGrid1.Cells[5, I] := 'Мужской'
- else
- HeadForm.StringGrid1.Cells[5, I] := 'Женский';
- N3.Enabled := True;
- Inc(I);
- End;
- CloseFile(FileWithStudents);
- Except
- Application.MessageBox('Что-то пошло не так :\', 'Ошибка', MB_ICONSTOP);
- End;
- End;
- end;
- procedure THeadForm.N4Click(Sender: TObject);
- Const
- STR1 = '1)Добавьте студентов в "базу данных" через окно "Добавить студента".';
- STR2 = '2)Ранее добавленные студенты будут отображены в главном окне.';
- STR3 = '3)Отсортированный список студентов можно узнать, нажав кнопку "Отсортированный список". Там же отображены фильтры сортировки.';
- STR4 = '4)Чтобы редактировать строку с данными о студенте, дважды кликните на нее. В окне редактирования также будет возможность удалить строку.';
- begin
- Application.MessageBox(STR1 + #13#10 + STR2 + #13#10 + STR3 + #13#10 + STR4, 'Инструкция', 0);
- end;
- procedure THeadForm.N5Click(Sender: TObject);
- begin
- Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 0);
- end;
- procedure THeadForm.StringGrid1DblClick(Sender: TObject);
- Var
- Birthday, Str : String;
- Speciality : Integer;
- begin
- If Row <> 0 then
- Begin
- Form3.Surname.Text := HeadForm.StringGrid1.Cells[2, Row];
- Form3.Group.Text := HeadForm.StringGrid1.Cells[0, Row];
- Form3.Number.Text := HeadForm.StringGrid1.Cells[3, Row];
- Birthday := HeadForm.StringGrid1.Cells[4, Row];
- Form3.Edit1.Text := Birthday[1] + Birthday[2];
- Form3.Edit2.Text := Birthday[4] + Birthday[5];
- Form3.Edit3.Text := Birthday[7] + Birthday[8] + Birthday[9] + Birthday[10];
- Form3.RadioButton5.Checked := False;
- Form3.RadioButton6.Checked := False;
- If HeadForm.StringGrid1.Cells[5, Row] = 'Мужской' then
- Form3.RadioButton5.Checked := True
- else
- Form3.RadioButton6.Checked := True;
- Str := HeadForm.StringGrid1.Cells[1, Row];
- //Я понимаю, что 4 if'a - это некрасиво, тут case of - идеальный вариант.
- //Но delphi ругается на case of почему-то
- Speciality := -1;
- If Str = 'Ассенизация' then
- Speciality := 0;
- If Str = 'Тракторостроение' then
- Speciality := 1;
- If Str = 'Программирование' then
- Speciality := 2;
- If Str = 'Швейное дело' then
- Speciality := 3;
- Form3.RadioGroup1.ItemIndex := Speciality;
- RowForDelete := Row;
- Form3.ShowModal;
- Row := 0;
- End;
- end;
- procedure THeadForm.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- begin
- Row := Arow;
- end;
- end.
- -----------------------------------------------------------------------------------------------------------------------------------
- unit Add;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Menus;
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- Group: TEdit;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Surname: TEdit;
- Number: TEdit;
- RadioButton5: TRadioButton;
- RadioButton6: TRadioButton;
- RadioGroup1: TRadioGroup;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- Edit1: TEdit;
- Edit2: TEdit;
- Edit3: TEdit;
- Button1: TButton;
- procedure N1Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure SurnameKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- uses MainForm;
- {$R *.dfm}
- type
- TStudent = record
- Name : String[18];
- Group : Integer;
- Number : Byte;
- Day : Integer;
- Month : Integer;
- Year : Integer;
- Sex : Boolean;
- end;
- Var
- Student : TStudent;
- IsChosen, CanClose : Boolean;
- procedure TForm1.Button1Click(Sender: TObject);
- Var
- N, I, Counter, K: Integer;
- Str, Birthday, Sex : String[20];
- Day, Month : String[2];
- Year : String[4];
- begin
- IsChosen := True;
- CanClose := False;
- If (Length(Surname.Text) = 0) or (Length(Group.Text) = 0) or (Length(Number.Text) = 0) or (Length(Edit1.Text) = 0) or (Length(Edit2.Text) = 0) or (Length(Edit3.Text) = 0) then
- Begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Не оставляйте поля пустыми.'), 'Ошибка', MB_ICONSTOP);
- End;
- If IsChosen then
- If (RadioGroup1.ItemIndex = -1) or ((RadioButton5.Checked = False) and (RadioButton6.Checked = False)) then
- begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Не оставляйте пункты неотмеченными.'), 'Ошибка', MB_ICONSTOP);
- end;
- If IsChosen then
- Begin
- Str := Surname.Text;
- For I := 1 To Length(Str) Do
- If (Ord(Str[I]) < 192) or ((Ord(Str[I])) > 255) then // это от А до я
- If Not(Str[I] in ['.', #08, #09, #32, #16]) then
- begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Фамилия и инициалы должны состоять из кириллицы. Также допустимы точки и пробелы.'), 'Ошибка', MB_ICONSTOP);
- Surname.Text := '';
- Break
- end;
- End;
- If IsChosen then
- begin
- If (StrToInt(Edit1.Text) < 1) or (StrToInt(Edit1.Text) > 31) then
- begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Число должно быть в диапазоне от 1 до 31.'), 'Ошибка', MB_ICONSTOP);
- Edit1.Text := '';
- end;
- end;
- If IsChosen then
- begin
- If (StrToInt(Edit2.Text) < 1) or (StrToInt(Edit2.Text) > 12) then
- begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Месяц должен быть в диапазоне от 1 до 12.'), 'Ошибка', MB_ICONSTOP);
- Edit2.Text := '';
- end;
- end;
- If IsChosen then
- begin
- If (StrToInt(Edit3.Text) < 1900) or (StrToInt(Edit3.Text) > 2023) then
- begin
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Год должен быть в диапазоне от 1900 до 2023.'), 'Ошибка', MB_ICONSTOP);
- Edit3.Text := '';
- end;
- end;
- If IsChosen then
- Begin
- try
- Student.Name := Surname.Text;
- Student.Group := StrToInt(Group.Text);
- Student.Number := StrToInt(Number.Text);
- Student.Day := StrToInt(Edit1.Text);
- Student.Month := StrToInt(Edit2.Text);
- Student.Year := StrToInt(Edit3.Text);
- If RadioButton6.Checked then
- Student.Sex := False; // если female ))
- If RadioButton5.Checked then
- Student.Sex := True; // если male
- CanClose := True;
- HeadForm.N3.Enabled := True;
- except
- IsChosen := False;
- MessageBox(Form1.Handle, Pchar('Проверьте исходные данные.'), 'Ошибка', MB_ICONSTOP);
- Student.Name := '';
- Student.Group := -1;
- Student.Number := 255;
- Student.Day := -1;
- Student.Month := -1;
- Student.Year := -1;
- end;
- End;
- If CanClose then
- begin
- N := HeadForm.StringGrid1.RowCount - 1;
- Counter := 0;
- For I := 1 To N Do
- begin
- If HeadForm.StringGrid1.Cells[0,I] = IntToStr(Student.Group) then
- Inc(Counter);
- K := RadioGroup1.ItemIndex;
- Case K of
- 0: Str := 'Ассенизация';
- 1: Str := 'Тракторостроение';
- 2: Str := 'Программирование';
- 3: Str := 'Швейное дело';
- End;
- If HeadForm.StringGrid1.Cells[1,I] = Str then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[2,I] = Student.Name then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[3,I] = IntToStr(Student.Number) then
- Inc(Counter);
- Day := IntToStr(Student.Day);
- If (Length(Day) = 1) then
- Day := '0' + Day;
- Month := IntToStr(Student.Month);
- If (Length(Month) = 1) then
- Month := '0' + Month;
- Year := IntToStr(Student.Year);
- Birthday := Day + '.' + Month + '.' + Year;
- If HeadForm.StringGrid1.Cells[4,I] = Birthday then
- Inc(Counter);
- If Student.Sex then
- Sex := 'Мужской'
- else
- Sex := 'Женский';
- If HeadForm.StringGrid1.Cells[5,I] = Sex then
- Inc(Counter);
- If Counter = 6 then
- begin
- CanClose := False;
- MessageBox(Form1.Handle, Pchar('Такой студент уже есть в базе данных.'), 'Ошибка', MB_ICONSTOP);
- Counter := 0;
- Break
- end;
- end;
- If CanClose then
- Form1.Close;
- end;
- end;
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- Var
- N, I, Counter, K: Integer;
- Str, Birthday, Sex : String[20];
- Day, Month : String[2];
- Year : String[4];
- begin
- If CanClose then
- Begin
- I := HeadForm.StringGrid1.RowCount;
- HeadForm.StringGrid1.RowCount := HeadForm.StringGrid1.RowCount + 1;
- HeadForm.StringGrid1.Cells[0, I] := IntToStr(Student.Group);
- If RadioGroup1.ItemIndex <> -1 then
- Begin
- N := RadioGroup1.ItemIndex;
- Case N of
- 0: Str := 'Ассенизация';
- 1: Str := 'Тракторостроение';
- 2: Str := 'Программирование';
- 3: Str := 'Швейное дело';
- End;
- HeadForm.StringGrid1.Cells[1, I] := Str;
- End;
- HeadForm.StringGrid1.Cells[2, I] := Student.Name;
- HeadForm.StringGrid1.Cells[3, I] := IntToStr(Student.Number);
- If Length(Edit1.Text) = 1 then
- Edit1.Text := '0' + Edit1.Text;
- If Length(Edit2.Text) = 1 then
- Edit2.Text := '0' + Edit2.Text;
- HeadForm.StringGrid1.Cells[4, I] := Edit1.Text + '.' + Edit2.Text + '.' + Edit3.Text;
- If Student.Sex then
- HeadForm.StringGrid1.Cells[5, I] := 'Мужской'
- else
- HeadForm.StringGrid1.Cells[5, I] := 'Женский';
- Surname.Text := '';
- Group.Text := '';
- Number.Text := '';
- Edit1.Text := '';
- Edit2.Text := '';
- Edit3.Text := '';
- RadioButton5.Checked := False;
- RadioButton6.Checked := False;
- RadioGroup1.ItemIndex := -1;
- CanClose := False;
- Inc(I);
- End;
- end;
- procedure TForm1.N1Click(Sender: TObject);
- Const
- STR1 = 'Пример даты рождения: 14.05.2005';
- STR2 = 'Пример фамилии и инициалов: Арефин В.А.';
- STR3 = 'Фамилия и инициалы должны состоять из кириллицы.';
- begin
- Application.MessageBox(STR1 + #10#13 + STR2 + #10#13 + STR3, 'Примеры заполнения полей и правила', 0);
- end;
- procedure TForm1.SurnameKeyPress(Sender: TObject; var Key: Char);
- begin
- If (Ord(Key) < 1040) or ((Ord(Key) > 1103)) then // это от А до я
- If Not(Key in ['.', #08, #09, #32, #16]) then // тут точка, пробел, шифт, таб, бэкспэйс
- Key := #0;
- end;
- end.
- -----------------------------------------------------------------------------------------------------------------------------------
- unit Edit;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtCtrls;
- type
- TForm3 = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Group: TEdit;
- Surname: TEdit;
- Number: TEdit;
- RadioButton5: TRadioButton;
- RadioButton6: TRadioButton;
- RadioGroup1: TRadioGroup;
- Edit1: TEdit;
- Edit2: TEdit;
- Edit3: TEdit;
- Button1: TButton;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure N1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form3: TForm3;
- implementation
- {$R *.dfm}
- uses MainForm;
- {$R *.dfm}
- type
- TStudent = record
- Name : String[18];
- Group : Integer;
- Number : Byte;
- Day : Integer;
- Month : Integer;
- Year : Integer;
- Sex : Boolean;
- end;
- Var
- Student : TStudent;
- IsChosen, CanClose : Boolean;
- procedure TForm3.Button1Click(Sender: TObject);
- Var
- N, I, Counter, K: Integer;
- Str, Birthday, Sex : String[20];
- Day, Month : String[2];
- Year : String[4];
- begin
- IsChosen := True;
- CanClose := False;
- If (Length(Surname.Text) = 0) or (Length(Group.Text) = 0) or (Length(Number.Text) = 0) or (Length(Edit1.Text) = 0) or (Length(Edit2.Text) = 0) or (Length(Edit3.Text) = 0) then
- Begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Не оставляйте поля пустыми.'), 'Ошибка', MB_ICONSTOP);
- End;
- If IsChosen then
- If (RadioGroup1.ItemIndex = -1) or ((RadioButton5.Checked = False) and (RadioButton6.Checked = False)) then
- begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Не оставляйте пункты неотмеченными.'), 'Ошибка', MB_ICONSTOP);
- end;
- If IsChosen then
- Begin
- Str := Surname.Text;
- For I := 1 To Length(Str) Do
- If (Ord(Str[I]) < 192) or ((Ord(Str[I])) > 255) then // это от А до я
- If Not(Str[I] in ['.', #08, #09, #32, #16]) then
- begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Фамилия и инициалы должны состоять из кириллицы. Также допустимы точки и пробелы.'), 'Ошибка', MB_ICONSTOP);
- Surname.Text := '';
- Break
- end;
- End;
- If IsChosen then
- begin
- If (StrToInt(Edit1.Text) < 1) or (StrToInt(Edit1.Text) > 31) then
- begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Число должно быть в диапазоне от 1 до 31.'), 'Ошибка', MB_ICONSTOP);
- Edit1.Text := '';
- end;
- end;
- If IsChosen then
- begin
- If (StrToInt(Edit2.Text) < 1) or (StrToInt(Edit2.Text) > 12) then
- begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Месяц должен быть в диапазоне от 1 до 12.'), 'Ошибка', MB_ICONSTOP);
- Edit2.Text := '';
- end;
- end;
- If IsChosen then
- begin
- If (StrToInt(Edit3.Text) < 1900) or (StrToInt(Edit3.Text) > 2023) then
- begin
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Год должен быть в диапазоне от 1900 до 2023.'), 'Ошибка', MB_ICONSTOP);
- Edit3.Text := '';
- end;
- end;
- If IsChosen then
- Begin
- try
- Student.Name := Surname.Text;
- Student.Group := StrToInt(Group.Text);
- Student.Number := StrToInt(Number.Text);
- Student.Day := StrToInt(Edit1.Text);
- Student.Month := StrToInt(Edit2.Text);
- Student.Year := StrToInt(Edit3.Text);
- If RadioButton6.Checked then
- Student.Sex := False; // если female ))
- If RadioButton5.Checked then
- Student.Sex := True; // если male
- CanClose := True;
- except
- IsChosen := False;
- MessageBox(Form3.Handle, Pchar('Проверьте исходные данные.'), 'Ошибка', MB_ICONSTOP);
- Student.Name := '';
- Student.Group := -1;
- Student.Number := 255;
- Student.Day := -1;
- Student.Month := -1;
- Student.Year := -1;
- end;
- End;
- If IsChosen then
- begin
- N := HeadForm.StringGrid1.RowCount - 1;
- For I := 1 To N Do
- begin
- Counter := 0;
- If HeadForm.StringGrid1.Cells[0,I] = IntToStr(Student.Group) then
- Inc(Counter);
- K := RadioGroup1.ItemIndex;
- Case K of
- 0: Str := 'Ассенизация';
- 1: Str := 'Тракторостроение';
- 2: Str := 'Программирование';
- 3: Str := 'Швейное дело';
- End;
- If HeadForm.StringGrid1.Cells[1,I] = Str then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[2,I] = Student.Name then
- Inc(Counter);
- If HeadForm.StringGrid1.Cells[3,I] = IntToStr(Student.Number) then
- Inc(Counter);
- Day := IntToStr(Student.Day);
- If (Length(Day) = 1) then
- Day := '0' + Day;
- Month := IntToStr(Student.Month);
- If (Length(Month) = 1) then
- Month := '0' + Month;
- Year := IntToStr(Student.Year);
- Birthday := Day + '.' + Month + '.' + Year;
- If HeadForm.StringGrid1.Cells[4,I] = Birthday then
- Inc(Counter);
- If Student.Sex then
- Sex := 'Мужской'
- else
- Sex := 'Женский';
- If HeadForm.StringGrid1.Cells[5,I] = Sex then
- Inc(Counter);
- If Counter = 6 then
- begin
- CanClose := False;
- MessageBox(Form3.Handle, Pchar('Такой студент уже есть в базе данных.'), 'Ошибка', MB_ICONSTOP);
- Counter := 0;
- Break
- end;
- end;
- If CanClose then
- Form3.Close;
- end;
- end;
- procedure TForm3.Button2Click(Sender: TObject);
- Var
- IsSure : Boolean;
- I, N: Integer;
- begin
- IsSure := False;
- If (RowForDelete <> 0) then
- IsSure := MessageBox(Form3.Handle, 'Вы уверены, что хотите удалить информацию об данном студенте?', 'Удаление', MB_YESNO + MB_ICONQUESTION)=ID_YES;
- If IsSure then
- begin
- N := HeadForm.StringGrid1.RowCount - 1;
- For I := RowForDelete To N Do
- begin
- HeadForm.StringGrid1.Rows[I] := HeadForm.StringGrid1.Rows[I + 1];
- end;
- HeadForm.StringGrid1.RowCount := HeadForm.StringGrid1.RowCount - 1;
- RowForDelete := 0;
- Form3.Close;
- end;
- end;
- procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
- Var
- N, I, Counter, K: Integer;
- Str, Birthday, Sex : String[20];
- Day, Month : String[2];
- Year : String[4];
- begin
- If CanClose then
- Begin
- I := Row;
- HeadForm.StringGrid1.Cells[0, I] := IntToStr(Student.Group);
- If RadioGroup1.ItemIndex <> -1 then
- Begin
- N := RadioGroup1.ItemIndex;
- Case N of
- 0: Str := 'Ассенизация';
- 1: Str := 'Тракторостроение';
- 2: Str := 'Программирование';
- 3: Str := 'Швейное дело';
- End;
- HeadForm.StringGrid1.Cells[1, I] := Str;
- End;
- HeadForm.StringGrid1.Cells[2, I] := Student.Name;
- HeadForm.StringGrid1.Cells[3, I] := IntToStr(Student.Number);
- If Length(Edit1.Text) = 1 then
- Edit1.Text := '0' + Edit1.Text;
- If Length(Edit2.Text) = 1 then
- Edit2.Text := '0' + Edit2.Text;
- HeadForm.StringGrid1.Cells[4, I] := Edit1.Text + '.' + Edit2.Text + '.' + Edit3.Text;
- If Student.Sex then
- HeadForm.StringGrid1.Cells[5, I] := 'Мужской'
- else
- HeadForm.StringGrid1.Cells[5, I] := 'Женский';
- Surname.Text := '';
- Group.Text := '';
- Number.Text := '';
- Edit1.Text := '';
- Edit2.Text := '';
- Edit3.Text := '';
- RadioButton5.Checked := False;
- RadioButton6.Checked := False;
- RadioGroup1.ItemIndex := -1;
- CanClose := False;
- Inc(I);
- End;
- end;
- procedure TForm3.FormCreate(Sender: TObject);
- begin
- //Surname.Text := HeadForm.StringGrid1.Cells[N, 0];
- //HeadForm.StringGrid1.Se
- end;
- procedure TForm3.N1Click(Sender: TObject);
- Const
- STR1 = 'Пример даты рождения: 14.05.2005';
- STR2 = 'Пример фамилии и инициалов: Арефин В.А.';
- STR3 = 'Фамилия и инициалы должны состоять из кириллицы.';
- begin
- Application.MessageBox(STR1 + #10#13 + STR2 + #10#13 + STR3, 'Примеры заполнения полей и правила', 0);
- end;
- end.
- -----------------------------------------------------------------------------------------------------------------------------------
- unit List;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;
- type
- TForm2 = class(TForm)
- StringGrid1: TStringGrid;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form2: TForm2;
- implementation
- {$R *.dfm}
- uses MainForm;
- type
- TStudent = packed record
- Name : String[18];
- Group : Integer;
- Number : Byte;
- Day : Integer;
- Month : Integer;
- Year : Integer;
- Sex : Boolean;
- Speciality : String[16]; // спецуха
- end;
- Var
- Students : Array of TStudent;
- function IsAdult (I : Integer) : Boolean;
- Var
- Adult : Boolean;
- CurrentData : String[10];
- Year, Month, Day : Integer;
- Begin
- Adult := False;
- CurrentData := DateToStr(Date);
- Day := StrToInt(CurrentData[1] + CurrentData[2]);
- Month := StrToInt(CurrentData[4] + CurrentData[5]);
- Year := StrToInt(CurrentData[7] + CurrentData[8] + CurrentData[9] + CurrentData[10]);
- If Students[I].Year < (Year - 18) then
- Adult := True; // точно совершеннолетний
- If (Students[I].Year = (Year - 18)) and (Students[I].Month < Month) then
- Adult := True; // точно совершеннолетний
- If (Students[I].Year = (Year - 18)) and (Students[I].Month = Month) and (Students[I].Day <= Day) then
- Adult := True; // точно совершеннолетний
- IsAdult := Adult;
- End;
- procedure TForm2.FormActivate(Sender: TObject);
- Var
- Depth, I, J, Counter: Integer;
- Birthday : String[10];
- Min : TStudent;
- begin
- StringGrid1.Cells[0,0] := 'Код группы';
- StringGrid1.Cells[1,0] := 'Отделение';
- StringGrid1.ColWidths[1] := 150;
- StringGrid1.Cells[2,0] := 'ФИО';
- StringGrid1.Cells[3,0] := 'Номер';
- StringGrid1.Cells[4,0] := 'Дата рождения';
- StringGrid1.Cells[5,0] := 'Пол';
- StringGrid1.RowCount := 1;
- Depth := HeadForm.StringGrid1.RowCount;
- SetLength(Students, Depth - 1);
- If Depth > 1 then
- For I := 0 To Depth - 2 Do
- Begin
- Students[I].Group := StrToInt(HeadForm.StringGrid1.Cells[0, I + 1]);
- Students[I].Speciality := HeadForm.StringGrid1.Cells[1, I + 1];
- Students[I].Name := HeadForm.StringGrid1.Cells[2, I + 1];
- Students[I].Number := StrToInt(HeadForm.StringGrid1.Cells[3, I + 1]);
- Birthday := HeadForm.StringGrid1.Cells[4, I + 1];
- Students[I].Day := StrToInt (Birthday[1] + Birthday[2]);
- Students[I].Month := StrToInt (Birthday[4] + Birthday[5]);
- Students[I].Year := StrToInt (Birthday[7] + Birthday[8] + Birthday[9]+ Birthday[10]);
- If (HeadForm.StringGrid1.Cells[5, I + 1] = 'Мужской') then
- Students[I].Sex := True
- else
- Students[I].Sex := False;
- End;
- If Depth > 2 then // для сортировки нужно хотя бы 2 элемента массива (глубина = инфа + заголовок, поэтому - 1)
- Begin
- For I := 0 To (Depth - 1) Do //сортиро4ка по номерам группы (по возрастанию)
- begin
- If (Students[I].Speciality = 'Программирование') and Not(IsAdult(I)) then
- Begin
- For J := I + 1 To (Depth - 2) do
- If (Students[J].Group < Students[I].Group) then
- Begin
- Min := Students[J];
- Students[J] := Students[I];
- Students[I] := Min;
- End;
- End;
- end;
- For I := 0 To (Depth - 1) Do //сортиро4ка по номерам в журнале (по возрастанию)
- begin
- If (Students[I].Speciality = 'Программирование') and Not(IsAdult(I)) then
- Begin
- For J := I + 1 To (Depth - 2) do
- If (Students[J].Number < Students[I].Number) and (Students[J].Group = Students[I].Group) then
- Begin
- Min := Students[J];
- Students[J] := Students[I];
- Students[I] := Min;
- End;
- End;
- end;
- End;
- If (Depth > 1) then
- Begin
- Counter := 0;
- For I := 0 To (Depth - 2) Do // вывод инфы
- If (Students[I].Speciality = 'Программирование') and Not(IsAdult(I)) then
- begin
- Form2.StringGrid1.RowCount := Form2.StringGrid1.RowCount + 1 ;
- Form2.StringGrid1.Cells[0, I + 1] := IntToStr(Students[I].Group);
- Form2.StringGrid1.Cells[1, I + 1] := Students[I].Speciality;
- Form2.StringGrid1.Cells[2, I + 1] := Students[I].Name;
- Form2.StringGrid1.Cells[3, I + 1] := IntToStr(Students[I].Number);
- Form2.StringGrid1.Cells[4, I + 1] := IntToStr(Students[I].Day) + '.' + IntToStr(Students[I].Month) + '.' + IntToStr(Students[I].Year);
- If Students[I].Sex then
- Form2.StringGrid1.Cells[5, I + 1] := 'Мужской'
- else
- Form2.StringGrid1.Cells[5, I + 1] := 'Женский';
- Inc(Counter);
- End;
- If Counter = 0 then
- begin
- Form2.StringGrid1.Visible := False;
- end;
- End;
- If Depth = 1 then
- Form2.StringGrid1.Visible := False;
- For I := 0 To Form2.StringGrid1.RowCount - 1 Do
- If Form2.StringGrid1.Cells[0, I] = '' then
- Form2.StringGrid1.RowCount := Form2.StringGrid1.RowCount - 1;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement