Advertisement
SmnVadik

Lab 5.1

May 18th, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 13.65 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.Menus;
  8.  
  9. type
  10.   TFormAdd = class(TForm)
  11.     ButtonAdd: TButton;
  12.     ButtonList: TButton;
  13.     EditCode: TEdit;
  14.     EditName: TEdit;
  15.     EditMark: TEdit;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     procedure ButtonAddClick(Sender: TObject);
  20.     procedure ButtonListClick(Sender: TObject);
  21.     procedure EditCodeChange(Sender: TObject);
  22.     procedure EditCodeKeyPress(Sender: TObject; var Key: Char);
  23.     procedure EditMarkChange(Sender: TObject);
  24.     procedure EditMarkKeyPress(Sender: TObject; var Key: Char);
  25.     procedure EditNameChange(Sender: TObject);
  26.     procedure EditNameKeyPress(Sender: TObject; var Key: Char);
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33.  
  34. type
  35. PStudent = ^TStudent;
  36. TStudent = record
  37.     code: Integer;
  38.     name: String[20];
  39.     mark: Real;
  40.     next: PStudent;
  41. end;
  42.  
  43.  
  44. var
  45.     FormAdd: TFormAdd;
  46.     head: PStudent;
  47.     bol1, bol2, bol3: Boolean;
  48.  
  49. implementation
  50.  
  51. {$R *.dfm}
  52.  
  53. uses Unit2;
  54.  
  55. procedure TFormAdd.ButtonAddClick(Sender: TObject);
  56. var
  57.     I: Integer;
  58. begin
  59.     I := FormMain.StringGridMain.RowCount;
  60.     FormMain.StringGridMain.Cells[0,I] := EditCode.Text;
  61.     FormMain.StringGridMain.Cells[1,I] := EditName.Text;
  62.     FormMain.StringGridMain.Cells[2,I] := EditMark.Text;
  63.     Inc(I);
  64.     FormMain.StringGridMain.RowCount := I;
  65.  
  66.     EditCode.Clear;
  67.     EditName.Clear;
  68.     EditMark.Clear;
  69. end;
  70.  
  71. procedure TFormAdd.ButtonListClick(Sender: TObject);
  72. var
  73.     curr: PStudent;
  74.     Size, I: Integer;
  75. begin
  76.     Size := FormMain.StringGridMain.RowCount;
  77.     new(curr);
  78.     head := curr;
  79.     For I := 1 to Size - 1 do
  80.     Begin
  81.         New(curr.next);
  82.         curr := curr.next;
  83.         curr.code := StrToInt(FormMain.StringGridMain.Cells[0,I]);
  84.         curr.name := FormMain.StringGridMain.Cells[1, I];
  85.         curr.mark := StrToFloat(FormMain.StringGridMain.Cells[2,I]);
  86.     End;
  87.     curr.next := nil;
  88.     FormMain.ShowModal;
  89.     //FormAdd.Close;
  90. end;
  91.  
  92. procedure TFormAdd.EditCodeChange(Sender: TObject);
  93. var
  94.     num: Integer;
  95. begin
  96.     bol1 := True;
  97.     try
  98.         num := StrToInt(EditCode.Text);
  99.     except
  100.         bol1 := False;
  101.         //Application.MessageBox('Проверьте коррекность введенных данных', 'Предупреждение', 0);
  102.         EditCode.Text := '';
  103.     end;
  104.     if Length(EditCode.Text) > 3 Then
  105.         bol1 := False;
  106.  
  107.     If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
  108.         ButtonAdd.Enabled := True
  109.     Else
  110.         ButtonAdd.Enabled := False;
  111.  
  112. end;
  113.  
  114. procedure TFormAdd.EditCodeKeyPress(Sender: TObject; var Key: Char);
  115. begin
  116.     If not (key in ['0'..'9', #8, #13]) Then
  117.         Key := #0;
  118.     If (Key = #13) And (ButtonAdd.Enabled = true) Then
  119.         ButtonAdd.Click;
  120. end;
  121.  
  122. procedure TFormAdd.EditMarkChange(Sender: TObject);
  123. var
  124.     num: Real;
  125. begin
  126.     bol3 := True;
  127.     try
  128.         num := StrToFloat(EditMark.Text);
  129.     Except
  130.         bol3 := False;
  131.         EditMark.Text := '';
  132.     end;
  133.     If (num < 2) or (num > 10) Then
  134.         bol3 := False;
  135.  
  136.     If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
  137.         ButtonAdd.Enabled := True
  138.     Else
  139.         ButtonAdd.Enabled := False;
  140.  
  141. end;
  142.  
  143. procedure TFormAdd.EditMarkKeyPress(Sender: TObject; var Key: Char);
  144. begin
  145.     If not (key in ['0'..'9', ',', #13, #8]) Then
  146.         Key := #0;
  147.     If (Key = #13) And (ButtonAdd.Enabled = true) Then
  148.         ButtonAdd.Click;
  149. end;
  150.  
  151. procedure TFormAdd.EditNameChange(Sender: TObject);
  152. begin
  153.     bol2 := True;
  154.     If Length(EditName.Text) > 20 Then
  155.     Begin
  156.         EditName.Text := '';
  157.         bol2 := False;
  158.         Application.MessageBox('Проверьте корректность данных', 'Ошибка', 0);
  159.     End;
  160.  
  161.     If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
  162.         ButtonAdd.Enabled := True
  163.     Else
  164.         ButtonAdd.Enabled := False;
  165. end;
  166.  
  167. procedure TFormAdd.EditNameKeyPress(Sender: TObject; var Key: Char);
  168. begin
  169.     If (Key = #13) And (ButtonAdd.Enabled = true) Then
  170.         ButtonAdd.Click;
  171. end;
  172.  
  173. end.
  174.  
  175.  
  176. unit Unit2;
  177.  
  178. interface
  179.  
  180. uses
  181.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  182.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Vcl.Menus;
  183.  
  184. type
  185.   TFormMain = class(TForm)
  186.     StringGridMain: TStringGrid;
  187.     ButtonInfo: TButton;
  188.     ButtonAdd: TButton;
  189.     MainMenu1: TMainMenu;
  190.     Task: TMenuItem;
  191.     Instr: TMenuItem;
  192.     Develop: TMenuItem;
  193.     FOpen: TMenuItem;
  194.     FSave: TMenuItem;
  195.     N7: TMenuItem;
  196.     FOut: TMenuItem;
  197.     F: TMenuItem;
  198.     SaveDialog1: TSaveDialog;
  199.     OpenDialog1: TOpenDialog;
  200.     procedure FormCreate(Sender: TObject);
  201.     procedure ButtonAddClick(Sender: TObject);
  202.     procedure ButtonInfoClick(Sender: TObject);
  203.     procedure StringGridMainDblClick(Sender: TObject);
  204.     procedure StringGridMainKeyDown(Sender: TObject; var Key: Word;
  205.       Shift: TShiftState);
  206.     procedure DevelopClick(Sender: TObject);
  207.     procedure FSaveClick(Sender: TObject);
  208.   private
  209.     { Private declarations }
  210.   public
  211.     { Public declarations }
  212.   end;
  213.  
  214. {
  215. type
  216. PStudent = ^TStudent;
  217. TStudent = record
  218.     code: Integer;
  219.     name: String[20];
  220.     mark: Integer;
  221.     nexr: PStudent;
  222. end;
  223. }
  224.  
  225. var
  226.     FormMain: TFormMain;
  227.     //head: PStudent;
  228.     Path: String;
  229.  
  230. implementation
  231.  
  232. {$R *.dfm}
  233.  
  234. uses Unit1, Unit3, Unit4;
  235.  
  236. procedure TFormMain.ButtonAddClick(Sender: TObject);
  237. begin
  238.     //FormAdd.ShowModal;
  239.     FormMain.Close;
  240.     //FormAdd.ShowModal;
  241. end;
  242.  
  243. procedure TFormMain.ButtonInfoClick(Sender: TObject);
  244.  
  245. var
  246.     cur: PStudent;
  247.     I: Integer;
  248.  
  249. begin
  250.     For I := 1 to FormInfo.StringGridInfo.RowCount - 1 do
  251.     Begin
  252.         FormInfo.StringGridInfo.Rows[I].Clear;
  253.     End;
  254.     FormInfo.StringGridInfo.RowCount := 1;
  255.     cur := head;
  256.     cur := cur.next;
  257.     while cur <> nil do
  258.     Begin
  259.         I := FormInfo.StringGridInfo.RowCount;
  260.         If cur.mark < 4 Then
  261.         Begin
  262.             FormInfo.StringGridInfo.Cells[0, I] := IntToStr(cur.code);
  263.             FormInfo.StringGridInfo.Cells[1, I] := cur.name;
  264.             FormInfo.StringGridInfo.Cells[2, I] := FloatToStr(cur.mark);
  265.             Inc(I);
  266.             FormInfo.StringGridInfo.RowCount := I;
  267.             cur := cur.next;
  268.         End
  269.         else
  270.             cur := cur.next
  271.     End;
  272.  
  273.     If FormInfo.StringGridInfo.RowCount = 1 Then
  274.     Begin
  275.         FormInfo.Label1.Visible := True;
  276.         FormInfo.StringGridInfo.Visible := False;
  277.     End
  278.     Else
  279.     Begin
  280.         FormInfo.Label1.Visible := False;
  281.         FormInfo.StringGridInfo.Visible := True;
  282.     End;
  283.  
  284.     FormInfo.ShowModal;
  285.  
  286. end;
  287.  
  288. procedure TFormMain.DevelopClick(Sender: TObject);
  289. begin
  290.     Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0);
  291. end;
  292.  
  293. procedure TFormMain.FormCreate(Sender: TObject);
  294. begin
  295.     StringGridMain.RowCount := 1;
  296.     StringGridMain.Cells[0,0] := 'code';
  297.     StringGridMain.Cells[1,0] := 'name';
  298.     StringGridMain.Cells[2,0] := 'mark';
  299. end;
  300.  
  301. procedure TFormMain.FSaveClick(Sender: TObject);
  302. var
  303.     F: TextFile;
  304.     I: Integer;
  305.     Str: String;
  306.     cur: PStudent;
  307. begin
  308.     If (SaveDialog1.Execute) Then
  309.     Begin
  310.         Try
  311.             Path := SaveDialog1.FileName;
  312.             Str := ExtractFileExt(Path);
  313.             If(Str = '') Then
  314.                 Path := Path + '.txt';
  315.             AssignFile(F, path);
  316.             Rewrite(F, Path);
  317.             cur := head;
  318.             cur := cur.next;
  319.             While cur <> nil do
  320.             Begin
  321.                 Writeln(F, cur.code);
  322.                 Writeln(F, cur.name);
  323.                 Writeln(F, cur.mark);
  324.                 cur := cur.next;
  325.             End;
  326.             CloseFile(F);
  327.         Except
  328.             Application.MessageBox('Некорректный файл!', 'Ошибка', MB_ICONSTOP);
  329.         End;
  330.     End;
  331. end;
  332.  
  333. procedure TFormMain.StringGridMainDblClick(Sender: TObject);
  334. var
  335.     cur: PStudent;
  336.     SelectedRow, Size, J, I: Integer;
  337.     EditForm: TFormEdit;
  338. begin
  339.     J := 0;
  340.     SelectedRow := StringGridMain.Row;
  341.     if SelectedRow > 0 Then
  342.     Begin
  343.         EditForm := TFormEdit.Create(nil);
  344.         try
  345.             EditForm.EditCode.Text := StringGridMain.Cells[0, SelectedRow];
  346.             EditForm.EditName.Text := StringGridMain.Cells[1, SelectedRow];
  347.             EditForm.EditMark.Text := StringGridMain.Cells[2, SelectedRow];
  348.  
  349.             if EditForm.ShowModal = mrOK then
  350.             Begin
  351.                 StringGridMain.Cells[0, SelectedRow] := EditForm.EditCode.Text;
  352.                 StringGridMain.Cells[1, SelectedRow] := EditForm.EditName.Text;
  353.                 StringGridMain.Cells[2, SelectedRow] := EditForm.EditMark.Text;
  354.  
  355.                 Size := StringGridMain.RowCount;
  356.                 new(cur);
  357.                 head := cur;
  358.                 For I := 1 to Size - 1 do
  359.                 Begin
  360.                     New(cur.next);
  361.                     cur := cur.next;
  362.                     cur.code := StrToInt(StringGridMain.Cells[0,I]);
  363.                     cur.name := StringGridMain.Cells[1, I];
  364.                     cur.mark := StrToFloat(StringGridMain.Cells[2,I]);
  365.                 End;
  366.                 cur.next := nil;
  367.  
  368.             End;
  369.         finally
  370.             EditForm.Free;
  371.         end;
  372.     End;
  373. end;
  374.  
  375. procedure TFormMain.StringGridMainKeyDown(Sender: TObject; var Key: Word;
  376.   Shift: TShiftState);
  377. var
  378.     SelectedRow, Size, I: Integer;
  379.     Cur: PStudent;
  380. begin
  381.     If Key = VK_DELETE Then
  382.     Begin
  383.         SelectedRow := StringGridMain.Row;
  384.         If SelectedRow > 0 Then
  385.         Begin
  386.             If Application.MessageBox('Вы действительно хотите удалить строку?', 'Удалить строку', MB_YESNO + MB_ICONQUESTION) = ID_YES Then
  387.             Begin
  388.  
  389.                 For I := SelectedRow to StringGridMain.RowCount - 2 do
  390.                 Begin
  391.                     StringGridMain.Cells[0, I] := StringGridMain.Cells[0, I + 1];
  392.                     StringGridMain.Cells[1, I] := StringGridMain.Cells[1, I + 1];
  393.                     StringGridMain.Cells[2, I] := StringGridMain.Cells[2, I + 1];
  394.                 End;
  395.                 StringGridMain.RowCount := StringGridMain.RowCount - 1;
  396.                 //SetLength(ArrRecord, StringGridList.RowCount - 1);
  397.  
  398.  
  399.                 Size := StringGridMain.RowCount;
  400.                 new(cur);
  401.                 head := cur;
  402.                 For I := 1 to Size - 1 do
  403.                 Begin
  404.                     New(cur.next);
  405.                     cur := cur.next;
  406.                     cur.code := StrToInt(StringGridMain.Cells[0,I]);
  407.                     cur.name := StringGridMain.Cells[1, I];
  408.                     cur.mark := StrToFloat(StringGridMain.Cells[2,I]);
  409.                 End;
  410.                 cur.next := nil;
  411.  
  412.  
  413.                 {
  414.                 New(cur);
  415.                 head := cur;
  416.                 For I := 0 to StringGridMain.RowCount - 2 do
  417.                 Begin
  418.                     New(cur.next);
  419.                     If I = SelectedRow Then
  420.                         cur.next := cur.next.next
  421.                     else
  422.                         cur := cur.next;
  423.                 End;
  424.                 }
  425.  
  426.             End;
  427.         End;
  428.     End;
  429.  
  430.     {
  431.     If (StringGridMain.RowCount > 1) And (ComboBox1.Text <> '') Then
  432.         ButtonInfo.Enabled := True
  433.     Else
  434.         ButtonInfo.Enabled := False;
  435.  
  436.     If StringGridList.RowCount = 1 Then
  437.         SaveF.Enabled := False;
  438.     }
  439. end;
  440.  
  441. end.
  442.  
  443.  
  444. unit Unit3;
  445.  
  446. interface
  447.  
  448. uses
  449.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  450.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
  451.  
  452. type
  453.   TFormEdit = class(TForm)
  454.     EditCode: TEdit;
  455.     EditName: TEdit;
  456.     EditMark: TEdit;
  457.     ButtonEdit: TButton;
  458.     ButtonCancel: TButton;
  459.     Label1: TLabel;
  460.     Label2: TLabel;
  461.     Label3: TLabel;
  462.     MainMenu1: TMainMenu;
  463.     procedure ButtonEditClick(Sender: TObject);
  464.   private
  465.     { Private declarations }
  466.   public
  467.     { Public declarations }
  468.   end;
  469.  
  470. var
  471.   FormEdit: TFormEdit;
  472.  
  473. implementation
  474.  
  475. {$R *.dfm}
  476.  
  477. procedure TFormEdit.ButtonEditClick(Sender: TObject);
  478. begin
  479.     ModalResult := MrOk
  480. end;
  481.  
  482. end.
  483.  
  484.  
  485. unit Unit4;
  486.  
  487. interface
  488.  
  489. uses
  490.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  491.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;
  492.  
  493. type
  494.   TFormInfo = class(TForm)
  495.     StringGridInfo: TStringGrid;
  496.     Label1: TLabel;
  497.     //procedure Button1Click(Sender: TObject);
  498.     procedure FormCreate(Sender: TObject);
  499.   private
  500.     { Private declarations }
  501.   public
  502.     { Public declarations }
  503.   end;
  504.  
  505. type
  506. TArrRec = record
  507.     code: Integer;
  508.     name: String[20];
  509.     mark: Real;
  510. end;
  511. TArray = array of TArrRec;
  512.  
  513. var
  514.   FormInfo: TFormInfo;
  515.  
  516. implementation
  517.  
  518. {$R *.dfm}
  519.  
  520. uses unit1;
  521.  
  522. procedure SortList();
  523. var
  524.     I, J, Max: Integer;
  525.     arr: TArray;
  526. Begin
  527.     For I := 1 to FormInfo.StringGridInfo.RowCount - 2 do
  528.     Begin
  529.         Max := I;
  530.         For J := 1 to FormInfo.StringGridInfo.RowCount - 2 do
  531.         Begin
  532.  
  533.         End;
  534.     End;
  535. End;
  536.  
  537. procedure TFormInfo.FormCreate(Sender: TObject);
  538. begin
  539.     StringGridInfo.RowCount := 1;
  540.     StringGridInfo.Cells[0, 0] := 'код';
  541.     StringGridInfo.Cells[1, 0] := 'фамилия';
  542.     StringGridInfo.Cells[2, 0] := 'оценка';
  543. end;
  544.  
  545. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement