Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit MainUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.ExtDlgs,
- Vcl.Menus,
- Vcl.StdCtrls,
- ManualUnit,
- DevInfUnit,
- Vcl.Grids,
- Vcl.Buttons,
- Vcl.Mask,
- Vcl.ExtCtrls,
- Vcl.DBCtrls,
- AddRecUnit,
- ChangeRecUnit,
- BackEndUnit,
- FindRecUnit,
- MiddUnit;
- Type
- TMainForm = Class(TForm)
- MainMenu: TMainMenu;
- FileButtonMenu: TMenuItem;
- SaveButtonMenu: TMenuItem;
- LineMenu: TMenuItem;
- ExitButtonMenu: TMenuItem;
- ManualButtonMenu: TMenuItem;
- DeveloperButtonMenu: TMenuItem;
- PopupMenu: TPopupMenu;
- OpenTextFileDialog: TOpenTextFileDialog;
- SaveTextFileDialog: TSaveTextFileDialog;
- RecordsGrid: TStringGrid;
- AddRecButton: TButton;
- ChangeRecButton: TButton;
- DelRecButton: TButton;
- SearchRecButton: TButton;
- Label1: TLabel;
- MiddButton: TButton;
- Procedure ManualButtonMenuClick(Sender: TObject);
- Procedure DeveloperButtonMenuClick(Sender: TObject);
- Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Procedure ExitButtonMenuClick(Sender: TObject);
- Procedure SaveButtonMenuClick(Sender: TObject);
- Procedure AddRecButtonClick(Sender: TObject);
- Procedure FormCreate(Sender: TObject);
- Procedure ChangeRecButtonClick(Sender: TObject);
- Procedure RecordsGridDblClick(Sender: TObject);
- Procedure DelRecButtonClick(Sender: TObject);
- Procedure RecordsGridSelectCell(Sender: TObject; ACol, ARow: Integer; Var CanSelect: Boolean);
- Procedure SearchRecButtonClick(Sender: TObject);
- Procedure RecordsGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Function FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
- Procedure MiddButtonClick(Sender: TObject);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Type
- ERRORS_CODE = (SUCCESS, INCORRECT_DATA_FILE, A_LOT_OF_DATA_FILE, OUT_OF_BORDER, OUT_OF_BORDER_SIZE);
- TGridCracker = Class(TStringGrid);
- IntArr = Array Of Integer;
- Matrix = Array Of IntArr;
- Var
- MainForm: TMainForm;
- IsSaved: Boolean = True;
- Implementation
- {$R *.dfm}
- Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Begin
- If Not IsSaved Then
- Case Application.MessageBox('У вас есть не сохраненные изменения , сохранить ?', 'Выход',
- MB_YESNOCANCEL + MB_ICONQUESTION + MB_DEFBUTTON3) Of
- IDYES:
- Begin
- SaveButtonMenu.Click;
- CanClose := True;
- End;
- IDNO:
- CanClose := True;
- IDCANCEL:
- CanClose := False;
- End
- Else
- Case Application.MessageBox('Вы действительно хотите выйти ?', 'Выход', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) Of
- IDYES:
- CanClose := True;
- IDNO:
- CanClose := False;
- End;
- If CanClose = True Then
- DeleteFile(CORRECTION_FILE_PATH);
- End;
- Procedure TMainForm.FormCreate(Sender: TObject);
- Var
- StorageFile, CorrectionFile: TWorkersFile;
- Begin
- OpenFile(STORAGE_FILE_PATH, StorageFile, FmReset);
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmRewrite);
- CloneFileToAnother(StorageFile, CorrectionFile);
- CloseFile(StorageFile);
- CloseFile(CorrectionFile);
- RecordsGrid.Cells[0, 0] := '¹';
- RecordsGrid.Cells[1, 0] := 'Фамилия';
- RecordsGrid.Cells[2, 0] := 'Цех';
- RecordsGrid.Cells[3, 0] := 'A';
- RecordsGrid.Cells[4, 0] := 'B';
- RecordsGrid.Cells[5, 0] := 'C';
- RecordsGrid.ColWidths[3] := 90;
- RecordsGrid.ColWidths[4] := 90;
- RecordsGrid.ColWidths[5] := 90;
- DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
- End;
- Function TMainForm.FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
- Begin
- ManualButtonMenu.Click();
- CallHelp := False;
- End;
- Procedure TMainForm.SaveButtonMenuClick(Sender: TObject);
- Var
- StorageFile, CorrectionFile: TWorkersFile;
- Begin
- OpenFile(STORAGE_FILE_PATH, StorageFile, FmRewrite);
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- CloneFileToAnother(CorrectionFile, StorageFile);
- IsSaved := True;
- CloseFile(StorageFile);
- CloseFile(CorrectionFile);
- End;
- Procedure TMainForm.SearchRecButtonClick(Sender: TObject);
- Begin
- FindRecForm := TFindRecForm.Create(Self);
- FindRecForm.FormCreate(Self);
- FindRecForm.ShowModal();
- FindRecForm.Free();
- End;
- Procedure TMainForm.ManualButtonMenuClick(Sender: TObject);
- Begin
- ManualForm := TManualForm.Create(Self);
- ManualForm.ShowModal;
- ManualForm.Free;
- End;
- Procedure TMainForm.MiddButtonClick(Sender: TObject);
- Begin
- MiddForm := TMiddForm.Create(Self);
- FindRecForm.FormCreate(Self);
- MiddForm.ShowModal();
- MiddForm.Free();
- End;
- Procedure TMainForm.RecordsGridDblClick(Sender: TObject);
- Begin
- If ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- End;
- Procedure TMainForm.RecordsGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If (Key = VK_DELETE) And (DelRecButton.Enabled) Then
- DelRecButton.Click
- End;
- Procedure TMainForm.RecordsGridSelectCell(Sender: TObject; ACol, ARow: Integer; Var CanSelect: Boolean);
- Begin
- If ARow = 0 Then
- Begin
- DelRecButton.Enabled := False;
- ChangeRecButton.Enabled := False;
- End
- Else
- Begin
- (Sender As TStringGrid).FixedRows := 1;
- ChangeRecButton.Enabled := True;
- DelRecButton.Enabled := True;
- End;
- End;
- Procedure TMainForm.AddRecButtonClick(Sender: TObject);
- Var
- Res: TModalResult;
- Begin
- AddRecForm := TAddRecForm.Create(Self);
- Res := AddRecForm.ShowModal();
- If Res = MrOk Then
- IsSaved := False;
- AddRecForm.Free();
- DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
- End;
- Procedure TMainForm.ChangeRecButtonClick(Sender: TObject);
- Var
- RecIndex: Integer;
- Res: TModalResult;
- Begin
- RecIndex := RecordsGrid.Row - 1;
- ChangeRecForm := TChangeRecForm.Create(Self);
- ChangeRecForm.FormCreate(RecIndex, Self);
- Res := ChangeRecForm.ShowModal();
- If Res = MrOk Then
- IsSaved := False;
- ChangeRecForm.Free();
- DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
- End;
- Procedure TMainForm.DelRecButtonClick(Sender: TObject);
- Var
- CurRecIndex: Integer;
- Choice: Integer;
- Begin
- CurRecIndex := RecordsGrid.Row - 1;
- Choice := Application.MessageBox('Вы точно хотите удалить ?',
- 'Удаление!', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2);
- If (Choice = IDYES) Then
- Begin
- DeleteRec(CurRecIndex);
- DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
- IsSaved := False;
- End;
- End;
- Procedure TMainForm.DeveloperButtonMenuClick(Sender: TObject);
- Begin
- DeveloperForm := TDeveloperForm.Create(Self);
- DeveloperForm.ShowModal;
- DeveloperForm.Free;
- End;
- Procedure TMainForm.ExitButtonMenuClick(Sender: TObject);
- Begin
- Close();
- End;
- End.
- Unit AddRecUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- BackEndUnit;
- Type
- TAddRecForm = Class(TForm)
- NameLabel: TLabel;
- OtdelLabel: TLabel;
- SalareLabel: TLabel;
- RecNameEdit: TEdit;
- RecOtdelEdit: TEdit;
- RecAEdit: TEdit;
- AddRecButton: TButton;
- RecBEdit: TEdit;
- RecCEdit: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Procedure RecAEditKeyPress(Sender: TObject; Var Key: Char);
- Procedure RecBEditKeyPress(Sender: TObject; Var Key: Char);
- Procedure RecCEditKeyPress(Sender: TObject; Var Key: Char);
- Procedure AddRecButtonClick(Sender: TObject);
- Function IsAllFieldCorrect(): Boolean;
- Procedure AnyEditChange(Sender: TObject);
- Procedure RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Private
- { Private declarations }
- Public
- End;
- Var
- AddRecForm: TAddRecForm;
- Implementation
- {$R *.dfm}
- Procedure TAddRecForm.AddRecButtonClick(Sender: TObject);
- Var
- Workers: RWorkers;
- Begin
- Workers.Name := RecNameEdit.Text;
- Workers.Otdel := RecOtdelEdit.Text;
- If RecAEdit.Text <> '' Then
- Workers.A := StrToInt(RecAEdit.Text)
- Else
- Workers.A := 0;
- If RecBEdit.Text <> '' Then
- Workers.B := StrToInt(RecBEdit.Text)
- Else
- Workers.B := 0;
- If RecCEdit.Text <> '' Then
- Workers.C := StrToInt(RecCEdit.Text)
- Else
- Workers.C := 0;
- AddRecord(Workers);
- End;
- Function TAddRecForm.IsAllFieldCorrect: Boolean;
- Var
- LBorder, RBorder: Integer;
- IsAllFilled, IsCorrect: Boolean;
- Begin
- IsAllFilled := (RecNameEdit.Text <> '') And (RecOtdelEdit.Text <> '') And
- ((RecAEdit.Text <> '') Or (RecBEdit.Text <> '') Or (RecCEdit.Text <> ''));
- IsAllFieldCorrect := IsAllFilled;
- End;
- Procedure TAddRecForm.AnyEditChange(Sender: TObject);
- Begin
- AddRecButton.Enabled := IsAllFieldCorrect();
- End;
- Procedure TAddRecForm.RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And AddRecButton.Enabled Then
- AddRecButton.Click();
- If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
- RecOtdelEdit.SetFocus();
- End;
- Procedure TAddRecForm.RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And AddRecButton.Enabled Then
- AddRecButton.Click();
- End;
- Procedure TAddRecForm.RecAEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecAEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TAddRecForm.RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And AddRecButton.Enabled Then
- AddRecButton.Click();
- End;
- Procedure TAddRecForm.RecBEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecBEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TAddRecForm.RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And AddRecButton.Enabled Then
- AddRecButton.Click();
- End;
- Procedure TAddRecForm.RecCEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecCEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TAddRecForm.RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And AddRecButton.Enabled Then
- AddRecButton.Click();
- If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
- RecOtdelEdit.SetFocus();
- End;
- End.
- Unit BackEndUnit;
- Interface
- Uses
- System.SysUtils,
- Vcl.Grids;
- Type
- TFileMode = (FmReset, FmRewrite);
- RWorkers = Record
- Name: String[20];
- Otdel: String[20];
- A, B, C: Integer;
- End;
- TWorkersFile = File Of RWorkers;
- Procedure TotalKeyPress(Var Key: Char; SelStart, SelLength: Integer; Const MIN, MAX: Integer; Text: String);
- Procedure AddRecord(Workers: RWorkers);
- Procedure CloneFileToAnother(Var FromFile, ToFile: TWorkersFile);
- Procedure OpenFile(Path: String; Var ThisFile: TWorkersFile; Mode: TFileMode);
- Function GetRecFromFile(Index: Integer): RWorkers;
- Procedure ChangeWorkers(Index: Integer; NewWorkers: RWorkers);
- Procedure DeleteRec(Index: Integer);
- Procedure DrawRecordOnGrid(Grid: TStringGrid; Path: String);
- Const
- STORAGE_FILE_PATH = 'StorageFile.txt';
- CORRECTION_FILE_PATH = 'CorrectionFile.txt';
- BUFFER_FILE_PATH = 'BufferFile.txt';
- VOID = #0;
- BACKSPACE = #8;
- MIN_KOL = 0;
- MAX_KOL = 200000;
- Implementation
- Function IsWorkersCorrect(Workers: RWorkers): Boolean;
- Begin
- With Workers Do
- IsWorkersCorrect := (Length(Name) <= 21) And (Length(Otdel) <= 21) And ((A > 0) Or (B > 0) Or (C > 0));
- End;
- Procedure DrawRecordOnGrid(Grid: TStringGrid; Path: String);
- Var
- CorrectionFile: TWorkersFile;
- RecCount, I: Integer;
- Workers: RWorkers;
- IsFileIncorrect: Boolean;
- Begin
- OpenFile(Path, CorrectionFile, FmReset);
- RecCount := FileSize(CorrectionFile);
- IsFileIncorrect := False;
- Grid.RowCount := RecCount + 1;
- For I := 0 To RecCount - 1 Do
- Begin
- Read(CorrectionFile, Workers);
- If IsWorkersCorrect(Workers) Then
- Begin
- Grid.Cells[0, I + 1] := IntToStr(I + 1) + '.';
- With Workers Do
- Begin
- Grid.Cells[1, I + 1] := Name;
- Grid.Cells[2, I + 1] := Otdel;
- Grid.Cells[3, I + 1] := IntToStr(A);
- Grid.Cells[4, I + 1] := IntToStr(B);
- Grid.Cells[5, I + 1] := IntToStr(C);
- End;
- End
- Else
- Begin
- Grid.Cells[0, I + 1] := '';
- Grid.Cells[1, I + 1] := 'Фамилия';
- Grid.Cells[2, I + 1] := 'Цех';
- Grid.Cells[3, I + 1] := 'A';
- Grid.Cells[4, I + 1] := 'B';
- Grid.Cells[5, I + 1] := 'C';
- IsFileIncorrect := True;
- End;
- End;
- CloseFile(CorrectionFile);
- If IsFileIncorrect Then
- DeleteFile(Path);
- End;
- Procedure DeleteRec(Index: Integer);
- Var
- CorrectionFile, BufferFile: TWorkersFile;
- I: Integer;
- Workers: RWorkers;
- Begin
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- OpenFile(BUFFER_FILE_PATH, BufferFile, FmRewrite);
- For I := 0 To FileSize(CorrectionFile) - 1 Do
- If I <> Index Then
- Begin
- Read(CorrectionFile, Workers);
- Write(BufferFile, Workers);
- End
- Else
- Seek(CorrectionFile, FilePos(CorrectionFile) + 1);
- CloseFile(CorrectionFile);
- CloseFile(BufferFile);
- DeleteFile(CORRECTION_FILE_PATH);
- RenameFile(BUFFER_FILE_PATH, CORRECTION_FILE_PATH);
- End;
- Procedure ChangeWorkers(Index: Integer; NewWorkers: RWorkers);
- Var
- CorrectionFile: TWorkersFile;
- Begin
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- Seek(CorrectionFile, Index);
- Write(CorrectionFile, NewWorkers);
- CloseFile(CorrectionFile);
- End;
- Function GetRecFromFile(Index: Integer): RWorkers;
- Var
- CorrectionFile: TWorkersFile;
- Workers: RWorkers;
- Begin
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- Seek(CorrectionFile, Index);
- Read(CorrectionFile, Workers);
- CloseFile(CorrectionFile);
- GetRecFromFile := Workers;
- End;
- Procedure OpenFile(Path: String; Var ThisFile: TWorkersFile; Mode: TFileMode);
- Begin
- AssignFile(ThisFile, Path);
- If Mode = FmReset Then
- Begin
- If Not(FileExists(Path)) Then
- Rewrite(ThisFile)
- Else
- Reset(ThisFile);
- End
- Else
- Rewrite(ThisFile);
- End;
- Procedure CloneFileToAnother(Var FromFile, ToFile: TWorkersFile);
- Var
- Workers: RWorkers;
- Begin
- While Not EoF(FromFile) Do
- Begin
- Read(FromFile, Workers);
- If IsWorkersCorrect(Workers) Then
- Write(ToFile, Workers);
- End;
- End;
- Procedure AddRecord(Workers: RWorkers);
- Var
- CorrectionFile: TWorkersFile;
- Begin
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- Seek(CorrectionFile, FileSize(CorrectionFile));
- Write(CorrectionFile, Workers);
- CloseFile(CorrectionFile);
- End;
- Function InsertKey(Index: Integer; SubStr: Char; SelLen: Integer; Text: String): String;
- Var
- ResultText: String;
- Begin
- ResultText := Text;
- If (SubStr = BACKSPACE) And (SelLen = 0) Then
- Delete(ResultText, Index, 1)
- Else
- Begin
- Delete(ResultText, Index + 1, SelLen);
- If Substr <> BACKSPACE Then
- ResultText.Insert(Index, String(SubStr));
- End;
- InsertKey := ResultText;
- End;
- Function CountOfSymbolInt(Num: Integer): Integer;
- Var
- NumLen: Integer;
- Begin
- NumLen := 0;
- If Num < 0 Then
- Inc(NumLen);
- Repeat
- Inc(NumLen);
- Num := Num Div 10;
- Until (Num = 0);
- CountOfSymbolInt := NumLen;
- End;
- Procedure TotalKeyPress(Var Key: Char; SelStart, SelLength: Integer; Const MIN, MAX: Integer; Text: String);
- Var
- ResultNum, RBorder, NumLen: Integer;
- Buffer, Output: String;
- Begin
- Output := InsertKey(SelStart, Key, SelLength, Text);
- If (Length(Output) <> 0) And (Output <> '-') Then
- Begin
- Try
- ResultNum := StrToInt(Output);
- Except
- Key := VOID;
- End;
- If Key <> VOID Then
- Begin
- NumLen := CountOfSymbolInt(ResultNum);
- If NumLen <> Length(Output) Then
- Key := VOID;
- If (ResultNum > MAX) Or (ResultNum < MIN) Then
- Key := VOID;
- End;
- End
- Else
- If (Output = '-') And (MIN >= 0) Then
- Key := VOID;
- End;
- End.
- Unit ChangeRecUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- BackEndUnit;
- Type
- TChangeRecForm = Class(TForm)
- NameLabel: TLabel;
- CostLabel: TLabel;
- CountLabel: TLabel;
- RecNameEdit: TEdit;
- RecOtdelEdit: TEdit;
- RecAEdit: TEdit;
- ChangeRecButton: TButton;
- RecBEdit: TEdit;
- RecCEdit: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Procedure ChangeRecButtonClick(Sender: TObject);
- Function IsAllFieldCorrect(): Boolean;
- Procedure AnyEditChange(Sender: TObject);
- Procedure RecAEditKeyPress(Sender: TObject; Var Key: Char);
- Procedure FormCreate(RecIndex: Integer; Sender: TObject);
- Procedure RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecBEditKeyPress(Sender: TObject; Var Key: Char);
- Procedure RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure RecCEditKeyPress(Sender: TObject; Var Key: Char);
- Private
- CurIndex: Integer;
- Public
- { Public declarations }
- End;
- Var
- ChangeRecForm: TChangeRecForm;
- Implementation
- {$R *.dfm}
- Procedure TChangeRecForm.ChangeRecButtonClick(Sender: TObject);
- Var
- CurWorkers: RWorkers;
- Begin
- CurWorkers.Name := RecNameEdit.Text;
- CurWorkers.Otdel := RecOtdelEdit.Text;
- If RecAEdit.Text <> '' Then
- CurWorkers.A := StrToInt(RecAEdit.Text)
- Else
- CurWorkers.A := 0;
- If RecBEdit.Text <> '' Then
- CurWorkers.B := StrToInt(RecBEdit.Text)
- Else
- CurWorkers.B := 0;
- If RecCEdit.Text <> '' Then
- CurWorkers.C := StrToInt(RecCEdit.Text)
- Else
- CurWorkers.C := 0;
- ChangeWorkers(CurIndex, CurWorkers);
- End;
- Procedure TChangeRecForm.FormCreate(RecIndex: Integer; Sender: TObject);
- Var
- CurWorkers: RWorkers;
- Begin
- CurIndex := RecIndex;
- CurWorkers := GetRecFromFile(CurIndex);
- RecNameEdit.Text := CurWorkers.Name;
- RecOtdelEdit.Text := CurWorkers.Otdel;
- RecAEdit.Text := IntToStr(CurWorkers.A);
- RecBEdit.Text := IntToStr(CurWorkers.B);
- RecCEdit.Text := IntToStr(CurWorkers.C);
- End;
- function TChangeRecForm.IsAllFieldCorrect: Boolean;
- var
- IsAllFilled: Boolean;
- begin
- IsAllFilled := (RecNameEdit.Text <> '') and (RecOtdelEdit.Text <> '') and
- (RecAEdit.Text <> '') and (RecBEdit.Text <> '') and (RecCEdit.Text <> '');
- Result := IsAllFilled;
- end;
- Procedure TChangeRecForm.AnyEditChange(Sender: TObject);
- Begin
- ChangeRecButton.Enabled := IsAllFieldCorrect();
- End;
- Procedure TChangeRecForm.RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
- RecOtdelEdit.SetFocus();
- End;
- Procedure TChangeRecForm.RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- End;
- Procedure TChangeRecForm.RecAEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecAEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TChangeRecForm.RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- End;
- Procedure TChangeRecForm.RecBEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecBEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TChangeRecForm.RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- End;
- Procedure TChangeRecForm.RecCEditKeyPress(Sender: TObject; Var Key: Char);
- Begin
- With RecCEdit Do
- TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
- End;
- Procedure TChangeRecForm.RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
- ChangeRecButton.Click();
- If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
- RecOtdelEdit.SetFocus();
- End;
- End.
- Unit DevInfUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls;
- Type
- TDeveloperForm = Class(TForm)
- DevInfMemo: TMemo;
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Var
- DeveloperForm: TDeveloperForm;
- Implementation
- {$R *.dfm}
- End.
- Unit FindRecUnit;
- Interface
- Uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, BackEndUnit;
- Type
- TFindRecForm = Class(TForm)
- RecordsGrid: TStringGrid;
- NameCharacterLabel: TLabel;
- OtdelCharacterLabel: TLabel;
- NameEdit: TEdit;
- OtdelEdit: TEdit;
- FindButton: TButton;
- Procedure Finder(Grid: TStringGrid; Path: String);
- Procedure OtdelEditKeyDown(Sender: TObject; Var Key: Word;
- Shift: TShiftState);
- Procedure NameEditKeyDown(Sender: TObject; Var Key: Word;
- Shift: TShiftState);
- Procedure FormCreate(Sender: TObject);
- Procedure AnyEditChange(Sender: TObject);
- Procedure FindButtonClick(Sender: TObject);
- Private
- Procedure WriteCorrectRecToFile(Path: String);
- Procedure Cleaning();
- Function IsAllFieldCorrect(): Boolean;
- Public
- { Public declarations }
- End;
- Var
- FindRecForm: TFindRecForm;
- Implementation
- {$R *.dfm}
- Procedure TFindRecForm.WriteCorrectRecToFile(Path: String);
- Var
- CorrectionFile, BufferFile: TWorkersFile;
- I: Integer;
- Name, Otdel: String;
- Workers: RWorkers;
- Begin
- Name := NameEdit.Text;
- Otdel := OtdelEdit.Text;
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- OpenFile(BUFFER_FILE_PATH, BufferFile, FmRewrite);
- For I := 1 To FileSize(CorrectionFile) Do
- Begin
- Read(CorrectionFile, Workers);
- Write(BufferFile, Workers);
- End;
- CloseFile(CorrectionFile);
- CloseFile(BufferFile);
- End;
- Procedure TFindRecForm.FormCreate(Sender: TObject);
- Begin
- FindButton.Enabled := False;
- // Draw FixedRow information
- RecordsGrid.Cells[0, 0] := '¹';
- RecordsGrid.Cells[1, 0] := 'Фамилия';
- RecordsGrid.Cells[2, 0] := 'Цех';
- RecordsGrid.Cells[3, 0] := 'A';
- RecordsGrid.Cells[4, 0] := 'B';
- RecordsGrid.Cells[5, 0] := 'C';
- RecordsGrid.ColWidths[3] := 90;
- RecordsGrid.ColWidths[4] := 90;
- RecordsGrid.ColWidths[5] := 90;
- WriteCorrectRecToFile(BUFFER_FILE_PATH);
- End;
- Function TFindRecForm.IsAllFieldCorrect: Boolean;
- Var
- IsCorrect: Boolean;
- Begin
- If (OtdelEdit.Text <> '') Or (NameEdit.Text <> '') Then
- IsCorrect := True
- Else
- IsCorrect := False;
- IsAllFieldCorrect := IsCorrect;
- End;
- Procedure TFindRecForm.FindButtonClick(Sender: TObject);
- Begin
- Finder(RecordsGrid, BUFFER_FILE_PATH);
- End;
- Procedure TFindRecForm.Finder(Grid: TStringGrid; Path: String);
- Var
- CorrectionFile: TWorkersFile;
- RecCount, I,J: Integer;
- Workers: RWorkers;
- IsFileIncorrect: Boolean;
- Begin
- J:=0;
- OpenFile(Path, CorrectionFile, FmReset);
- RecCount := FileSize(CorrectionFile);
- IsFileIncorrect := False;
- Grid.RowCount := RecCount + 1;
- For I := 1 To RecCount Do
- Begin
- Read(CorrectionFile, Workers);
- Begin
- With Workers Do
- Begin
- If (NameEdit.Text = Name) Or (OtdelEdit.Text = Otdel) Then
- Begin
- Inc(J);
- Grid.Cells[0, J] := IntToStr(J) + '.';
- Grid.Cells[1, J] := Name;
- Grid.Cells[2, J] := Otdel;
- Grid.Cells[3, J] := IntToStr(A);
- Grid.Cells[4, J] := IntToStr(B);
- Grid.Cells[5, J] := IntToStr(C);
- End;
- End;
- End
- End;
- CloseFile(CorrectionFile);
- If IsFileIncorrect Then
- DeleteFile(Path);
- End;
- Procedure TFindRecForm.Cleaning();
- Var
- I : Integer ;
- Begin
- for I := 1 to RecordsGrid.RowCount do
- Begin
- RecordsGrid.Cells[0, I] := '';
- RecordsGrid.Cells[1, I] := '';
- RecordsGrid.Cells[2, I] := '';
- RecordsGrid.Cells[3, I] := '';
- RecordsGrid.Cells[4, I] := '';
- RecordsGrid.Cells[5, I] := '';
- End;
- End;
- Procedure TFindRecForm.AnyEditChange(Sender: TObject);
- Begin
- Cleaning();
- If IsAllFieldCorrect() Then
- Begin
- FindButton.Enabled := True;
- End
- Else
- FindButton.Enabled := False;
- End;
- Procedure TFindRecForm.NameEditKeyDown(Sender: TObject; Var Key: Word;
- Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And
- Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_DOWN) Then
- OtdelEdit.SetFocus();
- End;
- Procedure TFindRecForm.OtdelEditKeyDown(Sender: TObject; Var Key: Word;
- Shift: TShiftState);
- Begin
- If ((SsShift In Shift) Or (SsCtrl In Shift)) And
- Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
- Key := 0;
- If Key = VK_DELETE Then
- Key := 0;
- If (Key = VK_UP) Then
- NameEdit.SetFocus();
- End;
- End.
- Unit ManualUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- Vcl.DBCtrls;
- Type
- TManualForm = Class(TForm)
- ManualMemo: TMemo;
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Var
- ManualForm: TManualForm;
- Implementation
- {$R *.dfm}
- End.
- Unit MiddUnit;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- BackEndUnit,
- Vcl.Grids,
- Vcl.Menus;
- Type
- Department = Record
- Otdel: String[20];
- Sum, Zp: Integer;
- SrZp: Double;
- Count: Integer;
- End;
- TMiddForm = Class(TForm)
- FinMiddGrid: TStringGrid;
- Procedure FormCreate(Sender: TObject);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Var
- MiddForm: TMiddForm;
- Implementation
- {$R *.dfm}
- Procedure TMiddForm.FormCreate(Sender: TObject);
- Var
- Workers: Array Of RWorkers;
- CorrectionFile: TWorkersFile;
- I, DepartmentCount, J: Integer;
- OtdelName: String;
- Found: Boolean;
- Departments: Array Of Department;
- Sa, Sb, Sc: Integer;
- TotalA, TotalB, TotalC, Total: Integer;
- TotalSalary: Integer;
- AverageSalary: Double;
- Begin
- Sa := 50;
- Sb := 100;
- Sc := 150;
- FinMiddGrid.ColWidths[0] := 270;
- FinMiddGrid.ColWidths[1] := 170;
- OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
- While Not Eof(CorrectionFile) Do
- Begin
- SetLength(Workers, Length(Workers) + 1);
- Read(CorrectionFile, Workers[High(Workers)]);
- End;
- CloseFile(CorrectionFile);
- DepartmentCount := 0;
- OtdelName := '';
- For I := 0 To High(Workers) Do
- Begin
- Found := False;
- For J := 0 To DepartmentCount - 1 Do
- Begin
- If Workers[I].Otdel = Departments[J].Otdel Then
- Begin
- Departments[J].Sum := Departments[J].Sum + Workers[I].A + Workers[I].B + Workers[I].C;
- Departments[J].Zp := Departments[J].Zp + Workers[I].A * Sa + Workers[I].B * Sb + Workers[I].C * Sc;
- Departments[J].Count := Departments[J].Count + 1;
- Found := True;
- Break;
- End;
- End;
- If Not Found Then
- Begin
- SetLength(Departments, DepartmentCount + 1);
- Departments[DepartmentCount].Otdel := Workers[I].Otdel;
- Departments[DepartmentCount].Sum := Workers[I].A + Workers[I].B + Workers[I].C;
- Departments[DepartmentCount].Zp := Departments[DepartmentCount].Zp + Workers[I].A * Sa + Workers[I].B * Sb + Workers[I].C * Sc;
- Departments[DepartmentCount].Count := 1;
- DepartmentCount := DepartmentCount + 1;
- End;
- End;
- FinMiddGrid.ColCount := DepartmentCount + 1;
- FinMiddGrid.Cells[0, 1] := 'Кол-во изделий';
- FinMiddGrid.Cells[0, 2] := 'Зп';
- FinMiddGrid.Cells[0, 3] := 'Средняя зп';
- For I := 0 To DepartmentCount - 1 Do
- Begin
- FinMiddGrid.Cells[I + 1, 0] := Departments[I].Otdel;
- End;
- For I := 0 To DepartmentCount - 1 Do
- Begin
- FinMiddGrid.Cells[I + 1, 1] := IntToStr(Departments[I].Sum);
- FinMiddGrid.Cells[I + 1, 2] := IntToStr(Departments[I].Zp);
- End;
- For I := 0 To DepartmentCount - 1 Do
- Begin
- If Departments[I].Count > 0 Then
- AverageSalary := Departments[I].Zp / Departments[I].Count
- Else
- AverageSalary := 0;
- FinMiddGrid.Cells[I + 1, 3] := FloatToStr(AverageSalary);
- End;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement