Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
- type
- TFormAdd = class(TForm)
- ButtonAdd: TButton;
- ButtonList: TButton;
- EditCode: TEdit;
- EditName: TEdit;
- EditMark: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- procedure ButtonAddClick(Sender: TObject);
- procedure ButtonListClick(Sender: TObject);
- procedure EditCodeChange(Sender: TObject);
- procedure EditCodeKeyPress(Sender: TObject; var Key: Char);
- procedure EditMarkChange(Sender: TObject);
- procedure EditMarkKeyPress(Sender: TObject; var Key: Char);
- procedure EditNameChange(Sender: TObject);
- procedure EditNameKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- type
- PStudent = ^TStudent;
- TStudent = record
- code: Integer;
- name: String[20];
- mark: Real;
- next: PStudent;
- end;
- var
- FormAdd: TFormAdd;
- head: PStudent;
- bol1, bol2, bol3: Boolean;
- implementation
- {$R *.dfm}
- uses Unit2;
- procedure TFormAdd.ButtonAddClick(Sender: TObject);
- var
- I: Integer;
- begin
- I := FormMain.StringGridMain.RowCount;
- FormMain.StringGridMain.Cells[0,I] := EditCode.Text;
- FormMain.StringGridMain.Cells[1,I] := EditName.Text;
- FormMain.StringGridMain.Cells[2,I] := EditMark.Text;
- Inc(I);
- FormMain.StringGridMain.RowCount := I;
- EditCode.Clear;
- EditName.Clear;
- EditMark.Clear;
- end;
- procedure TFormAdd.ButtonListClick(Sender: TObject);
- var
- curr: PStudent;
- Size, I: Integer;
- begin
- Size := FormMain.StringGridMain.RowCount;
- new(curr);
- head := curr;
- For I := 1 to Size - 1 do
- Begin
- New(curr.next);
- curr := curr.next;
- curr.code := StrToInt(FormMain.StringGridMain.Cells[0,I]);
- curr.name := FormMain.StringGridMain.Cells[1, I];
- curr.mark := StrToFloat(FormMain.StringGridMain.Cells[2,I]);
- End;
- curr.next := nil;
- FormMain.ShowModal;
- //FormAdd.Close;
- end;
- procedure TFormAdd.EditCodeChange(Sender: TObject);
- var
- num: Integer;
- begin
- bol1 := True;
- try
- num := StrToInt(EditCode.Text);
- except
- bol1 := False;
- //Application.MessageBox('Проверьте коррекность введенных данных', 'Предупреждение', 0);
- EditCode.Text := '';
- end;
- if Length(EditCode.Text) > 3 Then
- bol1 := False;
- If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
- ButtonAdd.Enabled := True
- Else
- ButtonAdd.Enabled := False;
- end;
- procedure TFormAdd.EditCodeKeyPress(Sender: TObject; var Key: Char);
- begin
- If not (key in ['0'..'9', #8, #13]) Then
- Key := #0;
- If (Key = #13) And (ButtonAdd.Enabled = true) Then
- ButtonAdd.Click;
- end;
- procedure TFormAdd.EditMarkChange(Sender: TObject);
- var
- num: Real;
- begin
- bol3 := True;
- try
- num := StrToFloat(EditMark.Text);
- Except
- bol3 := False;
- EditMark.Text := '';
- end;
- If (num < 2) or (num > 10) Then
- bol3 := False;
- If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
- ButtonAdd.Enabled := True
- Else
- ButtonAdd.Enabled := False;
- end;
- procedure TFormAdd.EditMarkKeyPress(Sender: TObject; var Key: Char);
- begin
- If not (key in ['0'..'9', ',', #13, #8]) Then
- Key := #0;
- If (Key = #13) And (ButtonAdd.Enabled = true) Then
- ButtonAdd.Click;
- end;
- procedure TFormAdd.EditNameChange(Sender: TObject);
- begin
- bol2 := True;
- If Length(EditName.Text) > 20 Then
- Begin
- EditName.Text := '';
- bol2 := False;
- Application.MessageBox('Проверьте корректность данных', 'Ошибка', 0);
- End;
- If (bol1 = True) And (bol2 = True) and (bol3 = True) Then
- ButtonAdd.Enabled := True
- Else
- ButtonAdd.Enabled := False;
- end;
- procedure TFormAdd.EditNameKeyPress(Sender: TObject; var Key: Char);
- begin
- If (Key = #13) And (ButtonAdd.Enabled = true) Then
- ButtonAdd.Click;
- end;
- end.
- unit Unit2;
- 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
- TFormMain = class(TForm)
- StringGridMain: TStringGrid;
- ButtonInfo: TButton;
- ButtonAdd: TButton;
- MainMenu1: TMainMenu;
- Task: TMenuItem;
- Instr: TMenuItem;
- Develop: TMenuItem;
- FOpen: TMenuItem;
- FSave: TMenuItem;
- N7: TMenuItem;
- FOut: TMenuItem;
- F: TMenuItem;
- SaveDialog1: TSaveDialog;
- OpenDialog1: TOpenDialog;
- procedure FormCreate(Sender: TObject);
- procedure ButtonAddClick(Sender: TObject);
- procedure ButtonInfoClick(Sender: TObject);
- procedure StringGridMainDblClick(Sender: TObject);
- procedure StringGridMainKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure DevelopClick(Sender: TObject);
- procedure FSaveClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- {
- type
- PStudent = ^TStudent;
- TStudent = record
- code: Integer;
- name: String[20];
- mark: Integer;
- nexr: PStudent;
- end;
- }
- var
- FormMain: TFormMain;
- //head: PStudent;
- Path: String;
- implementation
- {$R *.dfm}
- uses Unit1, Unit3, Unit4;
- procedure TFormMain.ButtonAddClick(Sender: TObject);
- begin
- //FormAdd.ShowModal;
- FormMain.Close;
- //FormAdd.ShowModal;
- end;
- procedure TFormMain.ButtonInfoClick(Sender: TObject);
- var
- cur: PStudent;
- I: Integer;
- begin
- For I := 1 to FormInfo.StringGridInfo.RowCount - 1 do
- Begin
- FormInfo.StringGridInfo.Rows[I].Clear;
- End;
- FormInfo.StringGridInfo.RowCount := 1;
- cur := head;
- cur := cur.next;
- while cur <> nil do
- Begin
- I := FormInfo.StringGridInfo.RowCount;
- If cur.mark < 4 Then
- Begin
- FormInfo.StringGridInfo.Cells[0, I] := IntToStr(cur.code);
- FormInfo.StringGridInfo.Cells[1, I] := cur.name;
- FormInfo.StringGridInfo.Cells[2, I] := FloatToStr(cur.mark);
- Inc(I);
- FormInfo.StringGridInfo.RowCount := I;
- cur := cur.next;
- End
- else
- cur := cur.next
- End;
- If FormInfo.StringGridInfo.RowCount = 1 Then
- Begin
- FormInfo.Label1.Visible := True;
- FormInfo.StringGridInfo.Visible := False;
- End
- Else
- Begin
- FormInfo.Label1.Visible := False;
- FormInfo.StringGridInfo.Visible := True;
- End;
- FormInfo.ShowModal;
- end;
- procedure TFormMain.DevelopClick(Sender: TObject);
- begin
- Application.MessageBox('Выполнил студент группы 251004, Сымоник Вадим', 'О разработчике', 0);
- end;
- procedure TFormMain.FormCreate(Sender: TObject);
- begin
- StringGridMain.RowCount := 1;
- StringGridMain.Cells[0,0] := 'code';
- StringGridMain.Cells[1,0] := 'name';
- StringGridMain.Cells[2,0] := 'mark';
- end;
- procedure TFormMain.FSaveClick(Sender: TObject);
- var
- F: TextFile;
- I: Integer;
- Str: String;
- cur: PStudent;
- begin
- If (SaveDialog1.Execute) Then
- Begin
- Try
- Path := SaveDialog1.FileName;
- Str := ExtractFileExt(Path);
- If(Str = '') Then
- Path := Path + '.txt';
- AssignFile(F, path);
- Rewrite(F, Path);
- cur := head;
- cur := cur.next;
- While cur <> nil do
- Begin
- Writeln(F, cur.code);
- Writeln(F, cur.name);
- Writeln(F, cur.mark);
- cur := cur.next;
- End;
- CloseFile(F);
- Except
- Application.MessageBox('Некорректный файл!', 'Ошибка', MB_ICONSTOP);
- End;
- End;
- end;
- procedure TFormMain.StringGridMainDblClick(Sender: TObject);
- var
- cur: PStudent;
- SelectedRow, Size, J, I: Integer;
- EditForm: TFormEdit;
- begin
- J := 0;
- SelectedRow := StringGridMain.Row;
- if SelectedRow > 0 Then
- Begin
- EditForm := TFormEdit.Create(nil);
- try
- EditForm.EditCode.Text := StringGridMain.Cells[0, SelectedRow];
- EditForm.EditName.Text := StringGridMain.Cells[1, SelectedRow];
- EditForm.EditMark.Text := StringGridMain.Cells[2, SelectedRow];
- if EditForm.ShowModal = mrOK then
- Begin
- StringGridMain.Cells[0, SelectedRow] := EditForm.EditCode.Text;
- StringGridMain.Cells[1, SelectedRow] := EditForm.EditName.Text;
- StringGridMain.Cells[2, SelectedRow] := EditForm.EditMark.Text;
- Size := StringGridMain.RowCount;
- new(cur);
- head := cur;
- For I := 1 to Size - 1 do
- Begin
- New(cur.next);
- cur := cur.next;
- cur.code := StrToInt(StringGridMain.Cells[0,I]);
- cur.name := StringGridMain.Cells[1, I];
- cur.mark := StrToFloat(StringGridMain.Cells[2,I]);
- End;
- cur.next := nil;
- End;
- finally
- EditForm.Free;
- end;
- End;
- end;
- procedure TFormMain.StringGridMainKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- SelectedRow, Size, I: Integer;
- Cur: PStudent;
- begin
- If Key = VK_DELETE Then
- Begin
- SelectedRow := StringGridMain.Row;
- If SelectedRow > 0 Then
- Begin
- If Application.MessageBox('Вы действительно хотите удалить строку?', 'Удалить строку', MB_YESNO + MB_ICONQUESTION) = ID_YES Then
- Begin
- For I := SelectedRow to StringGridMain.RowCount - 2 do
- Begin
- StringGridMain.Cells[0, I] := StringGridMain.Cells[0, I + 1];
- StringGridMain.Cells[1, I] := StringGridMain.Cells[1, I + 1];
- StringGridMain.Cells[2, I] := StringGridMain.Cells[2, I + 1];
- End;
- StringGridMain.RowCount := StringGridMain.RowCount - 1;
- //SetLength(ArrRecord, StringGridList.RowCount - 1);
- Size := StringGridMain.RowCount;
- new(cur);
- head := cur;
- For I := 1 to Size - 1 do
- Begin
- New(cur.next);
- cur := cur.next;
- cur.code := StrToInt(StringGridMain.Cells[0,I]);
- cur.name := StringGridMain.Cells[1, I];
- cur.mark := StrToFloat(StringGridMain.Cells[2,I]);
- End;
- cur.next := nil;
- {
- New(cur);
- head := cur;
- For I := 0 to StringGridMain.RowCount - 2 do
- Begin
- New(cur.next);
- If I = SelectedRow Then
- cur.next := cur.next.next
- else
- cur := cur.next;
- End;
- }
- End;
- End;
- End;
- {
- If (StringGridMain.RowCount > 1) And (ComboBox1.Text <> '') Then
- ButtonInfo.Enabled := True
- Else
- ButtonInfo.Enabled := False;
- If StringGridList.RowCount = 1 Then
- SaveF.Enabled := False;
- }
- end;
- end.
- unit Unit3;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
- type
- TFormEdit = class(TForm)
- EditCode: TEdit;
- EditName: TEdit;
- EditMark: TEdit;
- ButtonEdit: TButton;
- ButtonCancel: TButton;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- MainMenu1: TMainMenu;
- procedure ButtonEditClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormEdit: TFormEdit;
- implementation
- {$R *.dfm}
- procedure TFormEdit.ButtonEditClick(Sender: TObject);
- begin
- ModalResult := MrOk
- end;
- end.
- unit Unit4;
- 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
- TFormInfo = class(TForm)
- StringGridInfo: TStringGrid;
- Label1: TLabel;
- //procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- type
- TArrRec = record
- code: Integer;
- name: String[20];
- mark: Real;
- end;
- TArray = array of TArrRec;
- var
- FormInfo: TFormInfo;
- implementation
- {$R *.dfm}
- uses unit1;
- procedure SortList();
- var
- I, J, Max: Integer;
- arr: TArray;
- Begin
- For I := 1 to FormInfo.StringGridInfo.RowCount - 2 do
- Begin
- Max := I;
- For J := 1 to FormInfo.StringGridInfo.RowCount - 2 do
- Begin
- End;
- End;
- End;
- procedure TFormInfo.FormCreate(Sender: TObject);
- begin
- StringGridInfo.RowCount := 1;
- StringGridInfo.Cells[0, 0] := 'код';
- StringGridInfo.Cells[1, 0] := 'фамилия';
- StringGridInfo.Cells[2, 0] := 'оценка';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement