Advertisement
SmnVadik

Lab 4.1 (Delphi form)

Mar 27th, 2023 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 24.88 KB | None | 0 0
  1. unit Unit1;
  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.StdCtrls, Vcl.Grids, Vcl.Menus;
  8.  
  9. type
  10.  
  11.     TStudent = record
  12.         Surname: String[20];
  13.         Number: Integer;
  14.         Discipline: String[20];
  15.         Grade: Real;
  16.     end;
  17.  
  18.     TArrRecord = array of TStudent;
  19.  
  20.   TMainForm = class(TForm)
  21.     StringGridList: TStringGrid;
  22.     ButtonAdd: TButton;
  23.     ButtonInfo: TButton;
  24.     Label1: TLabel;
  25.     ComboBox1: TComboBox;
  26.     MainMenu1: TMainMenu;
  27.     F: TMenuItem;
  28.     Task: TMenuItem;
  29.     Instruction: TMenuItem;
  30.     Developer: TMenuItem;
  31.     OpenF: TMenuItem;
  32.     SaveF: TMenuItem;
  33.     N7: TMenuItem;
  34.     Exit: TMenuItem;
  35.     OpenDialog1: TOpenDialog;
  36.     SaveDialog1: TSaveDialog;
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure ButtonAddClick(Sender: TObject);
  39.     procedure StringGridListDblClick(Sender: TObject);
  40.     procedure StringGridListKeyDown(Sender: TObject; var Key: Word;
  41.       Shift: TShiftState);
  42.     procedure ButtonInfoClick(Sender: TObject);
  43.     procedure ComboBox1Change(Sender: TObject);
  44.     procedure StringGridListKeyPress(Sender: TObject; var Key: Char);
  45.     procedure OpenFClick(Sender: TObject);
  46.     procedure SaveFClick(Sender: TObject);
  47.     procedure TaskClick(Sender: TObject);
  48.     procedure InstructionClick(Sender: TObject);
  49.     procedure DeveloperClick(Sender: TObject);
  50.     procedure ExitClick(Sender: TObject);
  51.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  52.   private
  53.     { Private declarations }
  54.   public
  55.     { Public declarations }
  56.   end;
  57.  
  58. const
  59.     SIZE = 8;
  60.  
  61. var
  62.   MainForm: TMainForm;
  63.   ArrRecord: TArrRecord;
  64.   Path: String;
  65.   IsFileOpen: Boolean;
  66.  
  67. implementation
  68.  
  69. {$R *.dfm}
  70.  
  71. uses Unit2, Unit3, Unit4;
  72.  
  73.  
  74. procedure TMainForm.ButtonAddClick(Sender: TObject);
  75. var
  76.     Add: Word;
  77.     Student: TStudent;
  78.     I, J: Byte;
  79.     IsCorrect: Boolean;
  80. begin
  81.     Add := AddForm.ShowModal;
  82.     If Add = mrOk Then
  83.     Begin
  84.         J := StringGridList.RowCount;
  85.         StringGridList.RowCount := StringGridList.RowCount + 1;
  86.  
  87.         SetLength(ArrRecord, J);
  88.         ArrRecord[J - 1].Surname := AddForm.EditName.Text;
  89.         ArrRecord[J - 1].Number := StrToInt(AddForm.ComboBoxGroup.Text);
  90.         ArrRecord[J - 1].Discipline := AddForm.ComboBoxDisc.Text;
  91.         ArrRecord[J - 1].Grade := StrToFloat(AddForm.EditGrade.Text);
  92.  
  93.         IsCorrect := True;
  94.         For I := 1 to StringGridList.RowCount do
  95.         Begin
  96.             If StringGridList.Cells[0, I] = ArrRecord[J - 1].Surname Then
  97.             Begin
  98.                 If StringGridList.Cells[1, I] = IntToStr(ArrRecord[J - 1].Number) Then
  99.                 Begin
  100.                     if StringGridList.Cells[2, I] = ArrRecord[J - 1].Discipline then
  101.                     Begin
  102.                         If StringGridList.Cells[3, I] = FloatToStr(ArrRecord[J - 1].Grade) Then
  103.                         Begin
  104.                             IsCorrect := False;
  105.                             break;
  106.                         End;
  107.                     End;
  108.                 End;
  109.             End;
  110.         End;
  111.  
  112.  
  113.         If IsCorrect Then
  114.         Begin
  115.             StringGridList.Cells[0, J] := ArrRecord[J - 1].Surname;
  116.             StringGridList.Cells[1, J] := IntToStr(ArrRecord[J - 1].Number);
  117.             StringGridList.Cells[2, J] := ArrRecord[J - 1].Discipline;
  118.             StringGridList.Cells[3, J] := FloatToStr(ArrRecord[J - 1].Grade);
  119.         End
  120.         Else
  121.         Begin
  122.             For I := J to StringGridList.RowCount - 2 do
  123.                 Begin
  124.                     StringGridList.Cells[0, I] := StringGridList.Cells[0, I + 1];
  125.                     StringGridList.Cells[1, I] := StringGridList.Cells[1, I + 1];
  126.                     StringGridList.Cells[2, I] := StringGridList.Cells[2, I + 1];
  127.                     StringGridList.Cells[3, I] := StringGridList.Cells[3, I + 1];
  128.                 End;
  129.                 StringGridList.RowCount := StringGridList.RowCount - 1;
  130.                 SetLength(ArrRecord, StringGridList.RowCount - 1);
  131.  
  132.                 For I := 0 to StringGridList.RowCount - 2 do
  133.                 Begin
  134.                     ArrRecord[I].Surname := StringGridList.Cells[0, I + 1];
  135.                     ArrRecord[I].Number := StrToInt(StringGridList.Cells[1, I + 1]);
  136.                     ArrRecord[I].Discipline := StringGridList.Cells[2, I + 1];
  137.                     ArrRecord[I].Grade := StrToFloat(StringGridList.Cells[3, I + 1]);
  138.                 End;
  139.         End;
  140.  
  141.         AddForm.EditName.Clear;
  142.         AddForm.ComboBoxGroup.ClearSelection;
  143.         AddForm.ComboBoxDisc.ClearSelection;
  144.         AddForm.EditGrade.Clear;
  145.  
  146.         SaveF.Enabled := True;
  147.     End;
  148. end;
  149.  
  150.  
  151. procedure TMainForm.ButtonInfoClick(Sender: TObject);
  152. var
  153.     I, J, Count: Integer;
  154.     Form4: TInfoForm;
  155. begin
  156.     Form4 := TInfoForm.Create(nil);
  157.     try
  158.         Form4.Show;
  159.     finally
  160.  
  161.     end;
  162. end;
  163.  
  164.  
  165. procedure TMainForm.ComboBox1Change(Sender: TObject);
  166. var
  167.     I, J, Count: Integer;
  168.     Str: String[20];
  169. begin
  170.     Count := 0;
  171.     For J := 0 to StringGridList.RowCount - 2 do
  172.     Begin
  173.         If ArrRecord[J].Discipline = ComboBox1.Text Then
  174.             Inc(Count)
  175.         Else
  176.             ButtonInfo.Enabled := False;
  177.     End;
  178.     If Count <> 0 Then
  179.         ButtonInfo.Enabled := True
  180.     Else
  181.         ButtonInfo.Enabled := False;
  182. End;
  183.  
  184.  
  185. procedure TMainForm.DeveloperClick(Sender: TObject);
  186. begin
  187.     Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0)
  188. end;
  189.  
  190. procedure TMainForm.ExitClick(Sender: TObject);
  191. begin
  192.     MainForm.Close;
  193. end;
  194.  
  195. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  196. begin
  197.     CanClose := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION) = ID_YES;
  198. end;
  199.  
  200. procedure TMainForm.FormCreate(Sender: TObject);
  201. var I, J: Integer;
  202. begin
  203.     J := 0;
  204.     StringGridList.Cells[0, J] := 'фамилия';
  205.     StringGridList.Cells[1, J] := 'номер группы';
  206.     StringGridList.Cells[2, J] := 'дисциплина';
  207.     StringGridList.Cells[3, J] := 'средний балл';
  208. end;
  209.  
  210.  
  211. procedure TMainForm.InstructionClick(Sender: TObject);
  212. const
  213.     Str1 = '1. Нажмите "добавить студента" чтобы добавить новую запись.';
  214.     Str2 = #13#10'2. Кликните 2 раза по строке, чтобы редактировать её.';
  215.     Str3 = #13#10'3. Чтобы удалить строку выберите её и нажмите Delete.';
  216.     Str4 = #13#10'4. Вы можете соханить данные в файл или открыть файл.';
  217.     Str5 = #13#10'5. Выберите дисциплину, которая будет читаться, чтобы отобразить'#13#10'информацию о студентах.';
  218.     Str6 = #13#10'6. Если количество студентов превышает 8 человек, тогда будут отобраны'#13#10'студенты с большим средним баллом.';
  219. begin
  220.     Application.MessageBox(Str1 + Str2 + Str3 + Str4 + Str5 + Str6, 'Инструкция', 0);
  221. end;
  222.  
  223. procedure TMainForm.OpenFClick(Sender: TObject);
  224. var
  225.     F: File of TStudent;
  226.     I, Count: Integer;
  227. begin
  228.     Count := 0;
  229.     I := 0;
  230.     AssignFile(F, Path);
  231.     If(OpenDialog1.Execute) Then
  232.     Begin
  233.         Try
  234.             StringGridList.RowCount := 1;
  235.             Path := OpenDialog1.FileName;
  236.             Reset(F, Path);
  237.             If FileSize(F) <> 0 Then
  238.             Begin
  239.                 Finalize(ArrRecord);
  240.                 SetLength(ArrRecord, FileSize(F));
  241.                 For I := 0 to FileSize(F) - 1 do
  242.                 Begin
  243.                     Read(F, ArrRecord[I]);
  244.                     Inc(Count);
  245.                 End;
  246.                 StringGridList.RowCount := Count + 1;
  247.  
  248.                 For I := 0 to Count - 1 do
  249.                 Begin
  250.                     StringGridList.Cells[0, I + 1] := ArrRecord[I].Surname;
  251.                     StringGridList.Cells[1, I + 1] := IntToStr(ArrRecord[I].Number);
  252.                     StringGridList.Cells[2, I + 1] := ArrRecord[I].Discipline;
  253.                     StringGridList.Cells[3, I + 1] := FloatToStr(ArrRecord[I].Grade);
  254.                 End;
  255.  
  256.                 SaveF.Enabled := True;
  257.             End;
  258.             CloseFile(F);
  259.         Except
  260.             Application.MessageBox('Некорректный файл!', 'Ошибка', MB_ICONSTOP);
  261.         End;
  262.     End;
  263.  
  264. end;
  265.  
  266. procedure TMainForm.SaveFClick(Sender: TObject);
  267. var
  268.     F: File of TStudent;
  269.     I: Integer;
  270.     Str: String;
  271. begin
  272.     If (SaveDialog1.Execute) Then
  273.     Begin
  274.         Try
  275.             Path := SaveDialog1.FileName;
  276.             Str := ExtractFileExt(Path);
  277.             If(Str = '') Then
  278.                 Path := Path + '.dat';
  279.             AssignFile(F, path);
  280.             Rewrite(F, Path);
  281.             Seek(F, 0);
  282.             Truncate(F);
  283.             For I := 0 To Length(ArrRecord) - 1 Do
  284.             Begin
  285.                 Write(F, ArrRecord[I]);
  286.             End;
  287.             CloseFile(F);
  288.         Except
  289.             Application.MessageBox('Некорректный файл!', 'Ошибка', MB_ICONSTOP);
  290.         End;
  291.     End;
  292. end;
  293.  
  294.  
  295. procedure TMainForm.StringGridListDblClick(Sender: TObject);
  296. var
  297.     Student: TStudent;
  298.     EditForm: TEditForm;
  299.     Edit: Word;
  300.     I, J, SelectedRow: Integer;begin
  301.     J := 0;
  302.     SelectedRow := StringGridList.Row;
  303.     if SelectedRow > 0 Then
  304.     Begin
  305.         EditForm := TEditForm.Create(nil);
  306.         try
  307.             EditForm.EditName.Text := ArrRecord[SelectedRow - 1].Surname;
  308.             EditForm.ComboBoxGroup.Text := IntToStr(ArrRecord[SelectedRow - 1].Number);
  309.             EditForm.ComboBoxDisc.Text := ArrRecord[SelectedRow - 1].Discipline;
  310.             EditForm.EditGrade.Text := FloatToStr(ArrRecord[SelectedRow - 1].Grade);
  311.  
  312.             if EditForm.ShowModal = mrOK then
  313.             Begin
  314.                 ArrRecord[SelectedRow - 1].Surname := EditForm.EditName.Text;
  315.                 ArrRecord[SelectedRow - 1].Number := StrToInt(EditForm.ComboBoxGroup.Text);
  316.                 ArrRecord[SelectedRow - 1].Discipline := EditForm.ComboBoxDisc.Text;
  317.                 ArrRecord[SelectedRow - 1].Grade := StrToFloat(EditForm.EditGrade.Text);
  318.  
  319.                 StringGridList.Cells[0, SelectedRow] :=  ArrRecord[SelectedRow - 1].Surname;
  320.                 StringGridList.Cells[1, SelectedRow] := IntToStr(ArrRecord[SelectedRow - 1].Number);
  321.                 StringGridList.Cells[2, SelectedRow] := ArrRecord[SelectedRow - 1].Discipline;
  322.                 StringGridList.Cells[3, SelectedRow] := FloatToStr(ArrRecord[SelectedRow - 1].Grade);
  323.             End;
  324.         finally
  325.             EditForm.Free;
  326.         end;
  327.     End;
  328. end;
  329.  
  330.  
  331. procedure TMainForm.StringGridListKeyDown(Sender: TObject; var Key: Word;
  332.   Shift: TShiftState);
  333. var
  334.     SelectedRow, I: Integer;
  335.     Student: TStudent;
  336. begin
  337.     If Key = VK_DELETE Then
  338.     Begin
  339.         SelectedRow := StringGridList.Row;
  340.         If SelectedRow > 0 Then
  341.         Begin
  342.             If Application.MessageBox('Вы действительно хотите удалить строку?', 'Удалить строку', MB_YESNO + MB_ICONQUESTION) = ID_YES Then
  343.             Begin
  344.                 Student.Surname := StringGridList.Cells[0, SelectedRow];
  345.                 Student.Number := StrToInt(StringGridList.Cells[1, SelectedRow]);
  346.                 Student.Discipline := StringGridList.Cells[2, SelectedRow];
  347.                 Student.Grade := StrToFloat(StringGridList.Cells[3, SelectedRow]);
  348.                 StringGridList.Rows[SelectedRow].Clear;
  349.  
  350.                 For I := SelectedRow to StringGridList.RowCount - 2 do
  351.                 Begin
  352.                     StringGridList.Cells[0, I] := StringGridList.Cells[0, I + 1];
  353.                     StringGridList.Cells[1, I] := StringGridList.Cells[1, I + 1];
  354.                     StringGridList.Cells[2, I] := StringGridList.Cells[2, I + 1];
  355.                     StringGridList.Cells[3, I] := StringGridList.Cells[3, I + 1];
  356.                 End;
  357.                 StringGridList.RowCount := StringGridList.RowCount - 1;
  358.                 SetLength(ArrRecord, StringGridList.RowCount - 1);
  359.  
  360.                 For I := 0 to StringGridList.RowCount - 2 do
  361.                 Begin
  362.                     ArrRecord[I].Surname := StringGridList.Cells[0, I + 1];
  363.                     ArrRecord[I].Number := StrToInt(StringGridList.Cells[1, I + 1]);
  364.                     ArrRecord[I].Discipline := StringGridList.Cells[2, I + 1];
  365.                     ArrRecord[I].Grade := StrToFloat(StringGridList.Cells[3, I + 1]);
  366.                 End;
  367.  
  368.             End;
  369.         End;
  370.     End;
  371.     If (StringGridList.RowCount > 1) And (ComboBox1.Text <> '') Then
  372.         ButtonInfo.Enabled := True
  373.     Else
  374.         ButtonInfo.Enabled := False;
  375.  
  376.     If StringGridList.RowCount = 1 Then
  377.         SaveF.Enabled := False;
  378. end;
  379.  
  380.  
  381. procedure TMainForm.StringGridListKeyPress(Sender: TObject; var Key: Char);
  382. begin
  383.     Key := #0;
  384. end;
  385.  
  386. procedure TMainForm.TaskClick(Sender: TObject);
  387. begin
  388.     Application.MessageBox('Сведения о том, какие из пяти, предлагаемых дисциплин по выбору, желает слушать студент', 'Условие', 0)
  389. end;
  390.  
  391. end.
  392.  
  393.  
  394.  
  395. unit Unit2;
  396.  
  397. interface
  398.  
  399. uses
  400.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  401.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
  402.  
  403. type
  404.   TAddForm = class(TForm)
  405.     Label1: TLabel;
  406.     Label2: TLabel;
  407.     Label3: TLabel;
  408.     Label4: TLabel;
  409.     EditName: TEdit;
  410.     EditGrade: TEdit;
  411.     ComboBoxDisc: TComboBox;
  412.     ButtonOk: TButton;
  413.     ButtonNo: TButton;
  414.     ComboBoxGroup: TComboBox;
  415.     MainMenu1: TMainMenu;
  416.     N1: TMenuItem;
  417.     N2: TMenuItem;
  418.     procedure ButtonOkClick(Sender: TObject);
  419.     procedure ButtonNoClick(Sender: TObject);
  420.     procedure EditGradeChange(Sender: TObject);
  421.     procedure EditGradeKeyPress(Sender: TObject; var Key: Char);
  422.     procedure ComboBoxDiscChange(Sender: TObject);
  423.     procedure EditNameChange(Sender: TObject);
  424.     procedure ComboBoxGroupChange(Sender: TObject);
  425.     procedure N2Click(Sender: TObject);
  426.     procedure N1Click(Sender: TObject);
  427.   private
  428.     { Private declarations }
  429.   public
  430.     { Public declarations }
  431.   end;
  432.  
  433. var
  434.   AddForm: TAddForm;
  435.   Bol1, Bol2, Bol3, Bol4: Boolean;
  436.  
  437. implementation
  438.  
  439. {$R *.dfm}
  440.  
  441.  
  442. procedure TAddForm.ButtonNoClick(Sender: TObject);
  443. begin
  444.     ModalResult := mrNo;
  445. end;
  446.  
  447. procedure TAddForm.ButtonOkClick(Sender: TObject);
  448.  
  449. begin
  450.     ModalResult := mrOk;
  451. end;
  452.  
  453. procedure TAddForm.ComboBoxDiscChange(Sender: TObject);
  454. begin
  455.     if ComboBoxDisc.ItemIndex > -1 then
  456.         Bol3 := True
  457.     Else
  458.         Bol3 := False;
  459.  
  460.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  461.     Begin
  462.         ButtonOk.Enabled := True;
  463.     End
  464.     Else
  465.         ButtonOk.Enabled := False;
  466.  
  467. end;
  468.  
  469. procedure TAddForm.ComboBoxGroupChange(Sender: TObject);
  470. begin
  471.     if ComboBoxGroup.ItemIndex > -1 then
  472.         Bol2 := True
  473.     Else
  474.         Bol2 := False;
  475.  
  476.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  477.     Begin
  478.         ButtonOk.Enabled := True;
  479.     End
  480.     Else
  481.         ButtonOk.Enabled := False;
  482.  
  483. end;
  484.  
  485. procedure TAddForm.EditGradeChange(Sender: TObject);
  486. var
  487.     Num: Real;
  488. begin
  489.     Bol4 := True;
  490.  
  491.     Try
  492.         Num := StrToFloat(EditGrade.Text);
  493.     Except
  494.         Bol4 := False;
  495.         EditGrade.Text := '';
  496.     End;
  497.     If Bol4 And ((Num > 10.0) Or (Num < 1.0)) Then
  498.     Begin
  499.         Bol4 := False;
  500.         EditGrade.Text := '';
  501.     End;
  502.  
  503.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  504.     Begin
  505.         ButtonOk.Enabled := True;
  506.     End
  507.     Else
  508.         ButtonOk.Enabled := False;
  509.  
  510. end;
  511.  
  512. procedure TAddForm.EditGradeKeyPress(Sender: TObject; var Key: Char);
  513. begin
  514.     If not (key in ['0'..'9', ',', #8, #13]) Then Key := #0;
  515. end;
  516.  
  517.  
  518. procedure TAddForm.EditNameChange(Sender: TObject);
  519. begin
  520.     If EditName.Text <> '' Then
  521.         Bol1 := True
  522.     Else
  523.         Bol1 := False;
  524.  
  525.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  526.     Begin
  527.         ButtonOk.Enabled := True;
  528.     End
  529.     Else
  530.         ButtonOk.Enabled := False;
  531. end;
  532.  
  533. procedure TAddForm.N1Click(Sender: TObject);
  534. const
  535.     Str1 = '1. Заполните все поля.';
  536.     Str2 = #13#10'2. Максимальная длина фамилии - 20 символов.';
  537.     Str3 = #13#10'3. Диапазон ввода среднего балла от 1.0 до 10.0';
  538.     Str4 = #13#10'  если будет введено число не из диапазона, поле очистится. ';
  539. begin
  540.     Application.MessageBox(Str1 + Str2 + Str3 + Str4, 'Инструкция', 0)
  541. end;
  542.  
  543. procedure TAddForm.N2Click(Sender: TObject);
  544. begin
  545.     Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0)
  546. end;
  547.  
  548. end.
  549.  
  550.  
  551.  
  552. unit Unit3;
  553.  
  554. interface
  555.  
  556. uses
  557.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  558.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
  559.  
  560. type
  561.   TEditForm = class(TForm)
  562.     Label1: TLabel;
  563.     Label2: TLabel;
  564.     Label3: TLabel;
  565.     Label4: TLabel;
  566.     EditName: TEdit;
  567.     EditGrade: TEdit;
  568.     ComboBoxDisc: TComboBox;
  569.     ButtonEdit: TButton;
  570.     ButtonCancel: TButton;
  571.     ComboBoxGroup: TComboBox;
  572.     MainMenu1: TMainMenu;
  573.     N1: TMenuItem;
  574.     N2: TMenuItem;
  575.     procedure ButtonEditClick(Sender: TObject);
  576.     procedure ButtonCancelClick(Sender: TObject);
  577.     procedure EditNameChange(Sender: TObject);
  578.     procedure ComboBoxGroupChange(Sender: TObject);
  579.     procedure ComboBoxDiscChange(Sender: TObject);
  580.     procedure EditGradeChange(Sender: TObject);
  581.     procedure EditGradeKeyPress(Sender: TObject; var Key: Char);
  582.     procedure N2Click(Sender: TObject);
  583.     procedure N1Click(Sender: TObject);
  584.   private
  585.     { Private declarations }
  586.   public
  587.     { Public declarations }
  588.   end;
  589.  
  590. var
  591.   EditForm: TEditForm;
  592.   Bol1, Bol2, Bol3, Bol4: Boolean;
  593.  
  594. implementation
  595.  
  596. {$R *.dfm}
  597.  
  598. procedure TEditForm.ButtonCancelClick(Sender: TObject);
  599. begin
  600.     ModalResult := mrNo;
  601. end;
  602.  
  603. procedure TEditForm.ButtonEditClick(Sender: TObject);
  604. begin
  605.     ModalResult := mrOk;
  606. end;
  607.  
  608.  
  609.  
  610. procedure TEditForm.ComboBoxDiscChange(Sender: TObject);
  611. begin
  612.     if ComboBoxDisc.ItemIndex > -1 then
  613.         Bol3 := True
  614.     Else
  615.         Bol3 := False;
  616.  
  617.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  618.     Begin
  619.         ButtonEdit.Enabled := True;
  620.     End
  621.     Else
  622.         ButtonEdit.Enabled := False;
  623. end;
  624.  
  625. procedure TEditForm.ComboBoxGroupChange(Sender: TObject);
  626. begin
  627.     if ComboBoxGroup.ItemIndex > -1 then
  628.         Bol2 := True
  629.     Else
  630.         Bol2 := False;
  631.  
  632.    If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  633.     Begin
  634.         ButtonEdit.Enabled := True;
  635.     End
  636.     Else
  637.         ButtonEdit.Enabled := False;
  638. end;
  639.  
  640. procedure TEditForm.EditGradeChange(Sender: TObject);
  641. var
  642.     Num: Real;
  643. begin
  644.     Bol4 := True;
  645.  
  646.     Try
  647.         Num := StrToFloat(EditGrade.Text);
  648.     Except
  649.         Bol4 := False;
  650.         EditGrade.Text := '';
  651.     End;
  652.     If (Num > 10.0) Or (Num < 1.0) Then
  653.     Begin
  654.         Bol4 := False;
  655.         EditGrade.Text := '';
  656.     End;
  657.  
  658.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  659.     Begin
  660.         ButtonEdit.Enabled := True;
  661.     End
  662.     Else
  663.         ButtonEdit.Enabled := False;
  664. end;
  665.  
  666. procedure TEditForm.EditGradeKeyPress(Sender: TObject; var Key: Char);
  667. begin
  668.     If not (key in ['0'..'9', ',', #8, #13]) Then Key := #0;
  669. end;
  670.  
  671. procedure TEditForm.EditNameChange(Sender: TObject);
  672. begin
  673.     If EditName.Text <> '' Then
  674.         Bol1 := True
  675.     Else
  676.         Bol1 := False;
  677.  
  678.     If (Bol1 = True) And (Bol2 = True) And (Bol3 = True) And (Bol4 = True) Then
  679.     Begin
  680.         ButtonEdit.Enabled := True;
  681.     End
  682.     Else
  683.         ButtonEdit.Enabled := False;
  684. end;
  685.  
  686. procedure TEditForm.N1Click(Sender: TObject);
  687. const
  688.     Str1 = '1. Все поля должны быть заполнены, чтобы нажать "редактировать".';
  689.     Str2 = #13#10'2. Максимальная длина фамилии - 20 символов.';
  690.     Str3 = #13#10'3. Диапазон ввода среднего балла от 1.0 до 10.0';
  691.     Str4 = #13#10'  если будет введено число не из диапазона, поле очистится.';
  692. begin
  693.     Application.MessageBox(Str1 + Str2 + Str3 + Str4, 'Инструкция', 0)
  694. end;
  695.  
  696. procedure TEditForm.N2Click(Sender: TObject);
  697. begin
  698.     Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0)
  699. end;
  700.  
  701. end.
  702.  
  703.  
  704.  
  705.  
  706. unit Unit4;
  707.  
  708. interface
  709.  
  710. uses
  711.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  712.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Unit1,
  713.   Vcl.Menus;
  714.  
  715. type
  716.  
  717.     TNewStud = record
  718.         Surname: String[20];
  719.         Group: Integer;
  720.         Disc: String[20];
  721.         Grade: Real;
  722.     end;
  723.     TArrStud = array of TNewStud;
  724.  
  725.  
  726.   TInfoForm = class(TForm)
  727.     StringGridInfo: TStringGrid;
  728.     LabelInfo: TLabel;
  729.     MainMenu1: TMainMenu;
  730.     N1: TMenuItem;
  731.     N2: TMenuItem;
  732.     procedure FormCreate(Sender: TObject);
  733.     procedure FormShow(Sender: TObject);
  734.     procedure N2Click(Sender: TObject);
  735.     procedure N1Click(Sender: TObject);
  736.   private
  737.     { Private declarations }
  738.   public
  739.     { Public declarations }
  740.   end;
  741.  
  742. const
  743.     SIZE = 8;
  744.  
  745. var
  746.   InfoForm: TInfoForm;
  747.   NewStud: TArrStud;
  748.  
  749. implementation
  750.  
  751. {$R *.dfm}
  752.  
  753.  
  754. procedure TInfoForm.FormCreate(Sender: TObject);
  755. var
  756.     I, J, CountRow: Integer;
  757. begin
  758.     LabelInfo.Caption := LabelInfo.Caption + ' "' + MainForm.ComboBox1.Text + '"';
  759.  
  760.     StringGridInfo.Cells[0, 0] := 'фамилия';
  761.     StringGridInfo.Cells[1, 0] := 'номер группы';
  762.     StringGridInfo.Cells[2, 0] := 'средний балл';
  763.  
  764.     SetLength(NewStud, MainForm.StringGridList.RowCount - 1);
  765.  
  766. end;
  767.  
  768. procedure SortGrade(var arr: TArrStud);
  769. var
  770.     i, j: integer;
  771.     temp: TNewStud;
  772. begin
  773.     for i := 0 to High(arr) - 1 do
  774.     begin
  775.         for j := 0 to High(arr) - i - 1 do
  776.         begin
  777.             if arr[j].Grade < arr[j + 1].Grade then
  778.             begin
  779.                 temp := arr[j];
  780.                 arr[j] := arr[j + 1];
  781.                 arr[j + 1] := temp;
  782.             end;
  783.         end;
  784.     end;
  785. end;
  786.  
  787. procedure TInfoForm.FormShow(Sender: TObject);
  788. var
  789.     I, Count, J: Integer;
  790. begin
  791.     I := 0;
  792.     For J := 0 to MainForm.StringGridList.RowCount - 1 do
  793.     Begin
  794.         If ArrRecord[J].Discipline = MainForm.ComboBox1.Text Then
  795.         Begin
  796.             NewStud[I].Surname := ArrRecord[J].Surname;
  797.             NewStud[I].Group := ArrRecord[J].Number;
  798.             NewStud[I].Grade := ArrRecord[J].Grade;
  799.             Inc(I);
  800.         End;
  801.     End;
  802.     Count := I;
  803.     StringGridInfo.RowCount := Count + 1;
  804.  
  805.     SortGrade(NewStud);
  806.  
  807.     If Count < SIZE Then
  808.     Begin
  809.         For J := 0 to StringGridInfo.RowCount - 1 do
  810.         Begin
  811.             StringGridInfo.Cells[0, J + 1] := NewStud[J].Surname;
  812.             StringGridInfo.Cells[1, J + 1] := IntToStr(NewStud[J].Group);
  813.             StringGridInfo.Cells[2, J + 1] := FloatToStr(NewStud[J].Grade);
  814.         End;
  815.     End
  816.     Else
  817.     Begin
  818.         StringGridInfo.RowCount := SIZE + 1;
  819.         For J := 0 to SIZE - 1 do
  820.         Begin
  821.             StringGridInfo.Cells[0, J + 1] := NewStud[J].Surname;
  822.             StringGridInfo.Cells[1, J + 1] := IntToStr(NewStud[J].Group);
  823.             StringGridInfo.Cells[2, J + 1] := FloatToStr(NewStud[J].Grade);
  824.         End;
  825.     End;
  826.  
  827. end;
  828.  
  829. procedure TInfoForm.N1Click(Sender: TObject);
  830. const
  831.     Str1 = '1. Здесь отображена информация о студентах желающих прослушать'#13#10'данную дисциплину';
  832.     Str2 = #13#10'2. Студенты выведены по успеваемости:';
  833.     Str3 = #13#10'  от большего среднего балла к меньшему.';
  834.     Str4 = #13#10'3. Максимальное количество студентов равно 8.';
  835. begin
  836.     Application.MessageBox(Str1 + Str2 + Str3 + Str4, 'Инструкция', 0)
  837. end;
  838.  
  839. procedure TInfoForm.N2Click(Sender: TObject);
  840. begin
  841.     Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0)
  842. end;
  843.  
  844. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement