Advertisement
gguuppyy

лаба41

Mar 19th, 2024 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 33.54 KB | Source Code | 0 0
  1. Unit MainUnit;
  2.  
  3. Interface
  4.  
  5. Uses
  6.     Winapi.Windows,
  7.     Winapi.Messages,
  8.     System.SysUtils,
  9.     System.Variants,
  10.     System.Classes,
  11.     Vcl.Graphics,
  12.     Vcl.Controls,
  13.     Vcl.Forms,
  14.     Vcl.Dialogs,
  15.     Vcl.ExtDlgs,
  16.     Vcl.Menus,
  17.     Vcl.StdCtrls,
  18.     ManualUnit,
  19.     DevInfUnit,
  20.     Vcl.Grids,
  21.     Vcl.Buttons,
  22.     Vcl.Mask,
  23.     Vcl.ExtCtrls,
  24.     Vcl.DBCtrls,
  25.     AddRecUnit,
  26.     ChangeRecUnit,
  27.     BackEndUnit,
  28.     FindRecUnit,
  29.     MiddUnit;
  30.  
  31. Type
  32.     TMainForm = Class(TForm)
  33.         MainMenu: TMainMenu;
  34.         FileButtonMenu: TMenuItem;
  35.         SaveButtonMenu: TMenuItem;
  36.         LineMenu: TMenuItem;
  37.         ExitButtonMenu: TMenuItem;
  38.         ManualButtonMenu: TMenuItem;
  39.         DeveloperButtonMenu: TMenuItem;
  40.         PopupMenu: TPopupMenu;
  41.         OpenTextFileDialog: TOpenTextFileDialog;
  42.         SaveTextFileDialog: TSaveTextFileDialog;
  43.         RecordsGrid: TStringGrid;
  44.         AddRecButton: TButton;
  45.         ChangeRecButton: TButton;
  46.         DelRecButton: TButton;
  47.         SearchRecButton: TButton;
  48.         Label1: TLabel;
  49.         MiddButton: TButton;
  50.         Procedure ManualButtonMenuClick(Sender: TObject);
  51.         Procedure DeveloperButtonMenuClick(Sender: TObject);
  52.         Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  53.         Procedure ExitButtonMenuClick(Sender: TObject);
  54.         Procedure SaveButtonMenuClick(Sender: TObject);
  55.         Procedure AddRecButtonClick(Sender: TObject);
  56.         Procedure FormCreate(Sender: TObject);
  57.         Procedure ChangeRecButtonClick(Sender: TObject);
  58.         Procedure RecordsGridDblClick(Sender: TObject);
  59.         Procedure DelRecButtonClick(Sender: TObject);
  60.         Procedure RecordsGridSelectCell(Sender: TObject; ACol, ARow: Integer; Var CanSelect: Boolean);
  61.         Procedure SearchRecButtonClick(Sender: TObject);
  62.         Procedure RecordsGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  63.         Function FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
  64.         Procedure MiddButtonClick(Sender: TObject);
  65.     Private
  66.         { Private declarations }
  67.     Public
  68.         { Public declarations }
  69.     End;
  70.  
  71. Type
  72.     ERRORS_CODE = (SUCCESS, INCORRECT_DATA_FILE, A_LOT_OF_DATA_FILE, OUT_OF_BORDER, OUT_OF_BORDER_SIZE);
  73.     TGridCracker = Class(TStringGrid);
  74.     IntArr = Array Of Integer;
  75.     Matrix = Array Of IntArr;
  76.  
  77. Var
  78.     MainForm: TMainForm;
  79.     IsSaved: Boolean = True;
  80.  
  81. Implementation
  82.  
  83. {$R *.dfm}
  84.  
  85. Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
  86. Begin
  87.     If Not IsSaved Then
  88.         Case Application.MessageBox('У вас есть не сохраненные изменения , сохранить ?', 'Выход',
  89.             MB_YESNOCANCEL + MB_ICONQUESTION + MB_DEFBUTTON3) Of
  90.             IDYES:
  91.                 Begin
  92.                     SaveButtonMenu.Click;
  93.                     CanClose := True;
  94.                 End;
  95.             IDNO:
  96.                 CanClose := True;
  97.             IDCANCEL:
  98.                 CanClose := False;
  99.         End
  100.     Else
  101.         Case Application.MessageBox('Вы действительно хотите выйти ?', 'Выход', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) Of
  102.             IDYES:
  103.                 CanClose := True;
  104.             IDNO:
  105.                 CanClose := False;
  106.         End;
  107.     If CanClose = True Then
  108.         DeleteFile(CORRECTION_FILE_PATH);
  109. End;
  110.  
  111. Procedure TMainForm.FormCreate(Sender: TObject);
  112. Var
  113.     StorageFile, CorrectionFile: TWorkersFile;
  114. Begin
  115.     OpenFile(STORAGE_FILE_PATH, StorageFile, FmReset);
  116.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmRewrite);
  117.  
  118.     CloneFileToAnother(StorageFile, CorrectionFile);
  119.  
  120.     CloseFile(StorageFile);
  121.     CloseFile(CorrectionFile);
  122.  
  123.     RecordsGrid.Cells[0, 0] := '¹';
  124.     RecordsGrid.Cells[1, 0] := 'Фамилия';
  125.     RecordsGrid.Cells[2, 0] := 'Цех';
  126.     RecordsGrid.Cells[3, 0] := 'A';
  127.     RecordsGrid.Cells[4, 0] := 'B';
  128.     RecordsGrid.Cells[5, 0] := 'C';
  129.     RecordsGrid.ColWidths[3] := 90;
  130.     RecordsGrid.ColWidths[4] := 90;
  131.     RecordsGrid.ColWidths[5] := 90;
  132.  
  133.     DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
  134. End;
  135.  
  136. Function TMainForm.FormHelp(Command: Word; Data: NativeInt; Var CallHelp: Boolean): Boolean;
  137. Begin
  138.     ManualButtonMenu.Click();
  139.     CallHelp := False;
  140. End;
  141.  
  142. Procedure TMainForm.SaveButtonMenuClick(Sender: TObject);
  143. Var
  144.     StorageFile, CorrectionFile: TWorkersFile;
  145. Begin
  146.     OpenFile(STORAGE_FILE_PATH, StorageFile, FmRewrite);
  147.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  148.  
  149.     CloneFileToAnother(CorrectionFile, StorageFile);
  150.     IsSaved := True;
  151.  
  152.     CloseFile(StorageFile);
  153.     CloseFile(CorrectionFile);
  154. End;
  155.  
  156. Procedure TMainForm.SearchRecButtonClick(Sender: TObject);
  157. Begin
  158.     FindRecForm := TFindRecForm.Create(Self);
  159.     FindRecForm.FormCreate(Self);
  160.     FindRecForm.ShowModal();
  161.     FindRecForm.Free();
  162. End;
  163.  
  164. Procedure TMainForm.ManualButtonMenuClick(Sender: TObject);
  165. Begin
  166.     ManualForm := TManualForm.Create(Self);
  167.     ManualForm.ShowModal;
  168.     ManualForm.Free;
  169. End;
  170.  
  171. Procedure TMainForm.MiddButtonClick(Sender: TObject);
  172. Begin
  173.     MiddForm := TMiddForm.Create(Self);
  174.     FindRecForm.FormCreate(Self);
  175.     MiddForm.ShowModal();
  176.     MiddForm.Free();
  177. End;
  178.  
  179. Procedure TMainForm.RecordsGridDblClick(Sender: TObject);
  180. Begin
  181.     If ChangeRecButton.Enabled Then
  182.         ChangeRecButton.Click();
  183. End;
  184.  
  185. Procedure TMainForm.RecordsGridKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  186. Begin
  187.     If (Key = VK_DELETE) And (DelRecButton.Enabled) Then
  188.         DelRecButton.Click
  189. End;
  190.  
  191. Procedure TMainForm.RecordsGridSelectCell(Sender: TObject; ACol, ARow: Integer; Var CanSelect: Boolean);
  192. Begin
  193.     If ARow = 0 Then
  194.     Begin
  195.         DelRecButton.Enabled := False;
  196.         ChangeRecButton.Enabled := False;
  197.     End
  198.     Else
  199.     Begin
  200.         (Sender As TStringGrid).FixedRows := 1;
  201.         ChangeRecButton.Enabled := True;
  202.         DelRecButton.Enabled := True;
  203.     End;
  204. End;
  205.  
  206. Procedure TMainForm.AddRecButtonClick(Sender: TObject);
  207. Var
  208.     Res: TModalResult;
  209. Begin
  210.     AddRecForm := TAddRecForm.Create(Self);
  211.     Res := AddRecForm.ShowModal();
  212.     If Res = MrOk Then
  213.         IsSaved := False;
  214.     AddRecForm.Free();
  215.     DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
  216. End;
  217.  
  218. Procedure TMainForm.ChangeRecButtonClick(Sender: TObject);
  219. Var
  220.     RecIndex: Integer;
  221.     Res: TModalResult;
  222. Begin
  223.     RecIndex := RecordsGrid.Row - 1;
  224.     ChangeRecForm := TChangeRecForm.Create(Self);
  225.     ChangeRecForm.FormCreate(RecIndex, Self);
  226.     Res := ChangeRecForm.ShowModal();
  227.     If Res = MrOk Then
  228.         IsSaved := False;
  229.     ChangeRecForm.Free();
  230.     DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
  231. End;
  232.  
  233. Procedure TMainForm.DelRecButtonClick(Sender: TObject);
  234. Var
  235.     CurRecIndex: Integer;
  236.     Choice: Integer;
  237. Begin
  238.     CurRecIndex := RecordsGrid.Row - 1;
  239.     Choice := Application.MessageBox('Вы точно хотите удалить ?',
  240.       'Удаление!', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2);
  241.     If (Choice = IDYES) Then
  242.     Begin
  243.         DeleteRec(CurRecIndex);
  244.         DrawRecordOnGrid(RecordsGrid, CORRECTION_FILE_PATH);
  245.         IsSaved := False;
  246.     End;
  247. End;
  248.  
  249. Procedure TMainForm.DeveloperButtonMenuClick(Sender: TObject);
  250. Begin
  251.     DeveloperForm := TDeveloperForm.Create(Self);
  252.     DeveloperForm.ShowModal;
  253.     DeveloperForm.Free;
  254. End;
  255.  
  256. Procedure TMainForm.ExitButtonMenuClick(Sender: TObject);
  257. Begin
  258.     Close();
  259. End;
  260.  
  261. End.
  262.  
  263.  
  264.  
  265. Unit AddRecUnit;
  266.  
  267. Interface
  268.  
  269. Uses
  270.     Winapi.Windows,
  271.     Winapi.Messages,
  272.     System.SysUtils,
  273.     System.Variants,
  274.     System.Classes,
  275.     Vcl.Graphics,
  276.     Vcl.Controls,
  277.     Vcl.Forms,
  278.     Vcl.Dialogs,
  279.     Vcl.StdCtrls,
  280.     BackEndUnit;
  281.  
  282. Type
  283.     TAddRecForm = Class(TForm)
  284.         NameLabel: TLabel;
  285.         OtdelLabel: TLabel;
  286.         SalareLabel: TLabel;
  287.         RecNameEdit: TEdit;
  288.         RecOtdelEdit: TEdit;
  289.         RecAEdit: TEdit;
  290.         AddRecButton: TButton;
  291.         RecBEdit: TEdit;
  292.         RecCEdit: TEdit;
  293.         Label1: TLabel;
  294.         Label2: TLabel;
  295.         Procedure RecAEditKeyPress(Sender: TObject; Var Key: Char);
  296.         Procedure RecBEditKeyPress(Sender: TObject; Var Key: Char);
  297.         Procedure RecCEditKeyPress(Sender: TObject; Var Key: Char);
  298.         Procedure AddRecButtonClick(Sender: TObject);
  299.         Function IsAllFieldCorrect(): Boolean;
  300.         Procedure AnyEditChange(Sender: TObject);
  301.         Procedure RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  302.         Procedure RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  303.         Procedure RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  304.         Procedure RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  305.         Procedure RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  306.     Private
  307.         { Private declarations }
  308.     Public
  309.     End;
  310.  
  311. Var
  312.     AddRecForm: TAddRecForm;
  313.  
  314. Implementation
  315.  
  316. {$R *.dfm}
  317.  
  318. Procedure TAddRecForm.AddRecButtonClick(Sender: TObject);
  319. Var
  320.     Workers: RWorkers;
  321. Begin
  322.     Workers.Name := RecNameEdit.Text;
  323.     Workers.Otdel := RecOtdelEdit.Text;
  324.     If RecAEdit.Text <> '' Then
  325.         Workers.A := StrToInt(RecAEdit.Text)
  326.     Else
  327.         Workers.A := 0;
  328.  
  329.     If RecBEdit.Text <> '' Then
  330.         Workers.B := StrToInt(RecBEdit.Text)
  331.     Else
  332.         Workers.B := 0;
  333.  
  334.     If RecCEdit.Text <> '' Then
  335.         Workers.C := StrToInt(RecCEdit.Text)
  336.     Else
  337.         Workers.C := 0;
  338.  
  339.     AddRecord(Workers);
  340. End;
  341.  
  342. Function TAddRecForm.IsAllFieldCorrect: Boolean;
  343. Var
  344.     LBorder, RBorder: Integer;
  345.     IsAllFilled, IsCorrect: Boolean;
  346. Begin
  347.     IsAllFilled := (RecNameEdit.Text <> '') And (RecOtdelEdit.Text <> '') And
  348.         ((RecAEdit.Text <> '') Or (RecBEdit.Text <> '') Or (RecCEdit.Text <> ''));
  349.     IsAllFieldCorrect := IsAllFilled;
  350. End;
  351.  
  352. Procedure TAddRecForm.AnyEditChange(Sender: TObject);
  353. Begin
  354.     AddRecButton.Enabled := IsAllFieldCorrect();
  355. End;
  356.  
  357. Procedure TAddRecForm.RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  358. Begin
  359.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  360.         Key := 0;
  361.     If Key = VK_DELETE Then
  362.         Key := 0;
  363.     If (Key = VK_RETURN) And AddRecButton.Enabled Then
  364.         AddRecButton.Click();
  365.     If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
  366.         RecOtdelEdit.SetFocus();
  367. End;
  368.  
  369. Procedure TAddRecForm.RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  370. Begin
  371.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  372.         Key := 0;
  373.     If Key = VK_DELETE Then
  374.         Key := 0;
  375.     If (Key = VK_RETURN) And AddRecButton.Enabled Then
  376.         AddRecButton.Click();
  377. End;
  378.  
  379. Procedure TAddRecForm.RecAEditKeyPress(Sender: TObject; Var Key: Char);
  380. Begin
  381.     With RecAEdit Do
  382.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  383. End;
  384.  
  385. Procedure TAddRecForm.RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  386. Begin
  387.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  388.         Key := 0;
  389.     If Key = VK_DELETE Then
  390.         Key := 0;
  391.     If (Key = VK_RETURN) And AddRecButton.Enabled Then
  392.         AddRecButton.Click();
  393. End;
  394.  
  395. Procedure TAddRecForm.RecBEditKeyPress(Sender: TObject; Var Key: Char);
  396. Begin
  397.     With RecBEdit Do
  398.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  399. End;
  400.  
  401. Procedure TAddRecForm.RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  402. Begin
  403.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  404.         Key := 0;
  405.     If Key = VK_DELETE Then
  406.         Key := 0;
  407.     If (Key = VK_RETURN) And AddRecButton.Enabled Then
  408.         AddRecButton.Click();
  409. End;
  410.  
  411. Procedure TAddRecForm.RecCEditKeyPress(Sender: TObject; Var Key: Char);
  412. Begin
  413.     With RecCEdit Do
  414.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  415. End;
  416.  
  417. Procedure TAddRecForm.RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  418. Begin
  419.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  420.         Key := 0;
  421.     If Key = VK_DELETE Then
  422.         Key := 0;
  423.     If (Key = VK_RETURN) And AddRecButton.Enabled Then
  424.         AddRecButton.Click();
  425.     If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
  426.         RecOtdelEdit.SetFocus();
  427. End;
  428.  
  429. End.
  430.  
  431. Unit BackEndUnit;
  432.  
  433. Interface
  434.  
  435. Uses
  436.     System.SysUtils,
  437.     Vcl.Grids;
  438.  
  439. Type
  440.     TFileMode = (FmReset, FmRewrite);
  441.  
  442.     RWorkers = Record
  443.         Name: String[20];
  444.         Otdel: String[20];
  445.         A, B, C: Integer;
  446.     End;
  447.  
  448.     TWorkersFile = File Of RWorkers;
  449.  
  450. Procedure TotalKeyPress(Var Key: Char; SelStart, SelLength: Integer; Const MIN, MAX: Integer; Text: String);
  451. Procedure AddRecord(Workers: RWorkers);
  452. Procedure CloneFileToAnother(Var FromFile, ToFile: TWorkersFile);
  453. Procedure OpenFile(Path: String; Var ThisFile: TWorkersFile; Mode: TFileMode);
  454. Function GetRecFromFile(Index: Integer): RWorkers;
  455. Procedure ChangeWorkers(Index: Integer; NewWorkers: RWorkers);
  456. Procedure DeleteRec(Index: Integer);
  457.  
  458. Procedure DrawRecordOnGrid(Grid: TStringGrid; Path: String);
  459.  
  460. Const
  461.     STORAGE_FILE_PATH = 'StorageFile.txt';
  462.     CORRECTION_FILE_PATH = 'CorrectionFile.txt';
  463.     BUFFER_FILE_PATH = 'BufferFile.txt';
  464.     VOID = #0;
  465.     BACKSPACE = #8;
  466.     MIN_KOL = 0;
  467.     MAX_KOL = 200000;
  468.  
  469. Implementation
  470.  
  471. Function IsWorkersCorrect(Workers: RWorkers): Boolean;
  472. Begin
  473.     With Workers Do
  474.         IsWorkersCorrect := (Length(Name) <= 21) And (Length(Otdel) <= 21) And ((A > 0) Or (B > 0) Or (C > 0));
  475. End;
  476.  
  477. Procedure DrawRecordOnGrid(Grid: TStringGrid; Path: String);
  478. Var
  479.     CorrectionFile: TWorkersFile;
  480.     RecCount, I: Integer;
  481.     Workers: RWorkers;
  482.     IsFileIncorrect: Boolean;
  483. Begin
  484.     OpenFile(Path, CorrectionFile, FmReset);
  485.     RecCount := FileSize(CorrectionFile);
  486.     IsFileIncorrect := False;
  487.     Grid.RowCount := RecCount + 1;
  488.     For I := 0 To RecCount - 1 Do
  489.     Begin
  490.         Read(CorrectionFile, Workers);
  491.         If IsWorkersCorrect(Workers) Then
  492.         Begin
  493.             Grid.Cells[0, I + 1] := IntToStr(I + 1) + '.';
  494.             With Workers Do
  495.             Begin
  496.                 Grid.Cells[1, I + 1] := Name;
  497.                 Grid.Cells[2, I + 1] := Otdel;
  498.                 Grid.Cells[3, I + 1] := IntToStr(A);
  499.                 Grid.Cells[4, I + 1] := IntToStr(B);
  500.                 Grid.Cells[5, I + 1] := IntToStr(C);
  501.             End;
  502.         End
  503.         Else
  504.         Begin
  505.             Grid.Cells[0, I + 1] := '';
  506.             Grid.Cells[1, I + 1] := 'Фамилия';
  507.             Grid.Cells[2, I + 1] := 'Цех';
  508.             Grid.Cells[3, I + 1] := 'A';
  509.             Grid.Cells[4, I + 1] := 'B';
  510.             Grid.Cells[5, I + 1] := 'C';
  511.             IsFileIncorrect := True;
  512.         End;
  513.     End;
  514.  
  515.     CloseFile(CorrectionFile);
  516.  
  517.     If IsFileIncorrect Then
  518.         DeleteFile(Path);
  519. End;
  520.  
  521. Procedure DeleteRec(Index: Integer);
  522. Var
  523.     CorrectionFile, BufferFile: TWorkersFile;
  524.     I: Integer;
  525.     Workers: RWorkers;
  526. Begin
  527.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  528.     OpenFile(BUFFER_FILE_PATH, BufferFile, FmRewrite);
  529.  
  530.     For I := 0 To FileSize(CorrectionFile) - 1 Do
  531.         If I <> Index Then
  532.         Begin
  533.             Read(CorrectionFile, Workers);
  534.             Write(BufferFile, Workers);
  535.         End
  536.         Else
  537.             Seek(CorrectionFile, FilePos(CorrectionFile) + 1);
  538.     CloseFile(CorrectionFile);
  539.     CloseFile(BufferFile);
  540.     DeleteFile(CORRECTION_FILE_PATH);
  541.     RenameFile(BUFFER_FILE_PATH, CORRECTION_FILE_PATH);
  542. End;
  543.  
  544. Procedure ChangeWorkers(Index: Integer; NewWorkers: RWorkers);
  545. Var
  546.     CorrectionFile: TWorkersFile;
  547. Begin
  548.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  549.     Seek(CorrectionFile, Index);
  550.     Write(CorrectionFile, NewWorkers);
  551.     CloseFile(CorrectionFile);
  552. End;
  553.  
  554. Function GetRecFromFile(Index: Integer): RWorkers;
  555. Var
  556.     CorrectionFile: TWorkersFile;
  557.     Workers: RWorkers;
  558. Begin
  559.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  560.     Seek(CorrectionFile, Index);
  561.     Read(CorrectionFile, Workers);
  562.     CloseFile(CorrectionFile);
  563.     GetRecFromFile := Workers;
  564. End;
  565.  
  566. Procedure OpenFile(Path: String; Var ThisFile: TWorkersFile; Mode: TFileMode);
  567. Begin
  568.     AssignFile(ThisFile, Path);
  569.     If Mode = FmReset Then
  570.     Begin
  571.         If Not(FileExists(Path)) Then
  572.             Rewrite(ThisFile)
  573.         Else
  574.             Reset(ThisFile);
  575.     End
  576.     Else
  577.         Rewrite(ThisFile);
  578. End;
  579.  
  580. Procedure CloneFileToAnother(Var FromFile, ToFile: TWorkersFile);
  581. Var
  582.     Workers: RWorkers;
  583. Begin
  584.     While Not EoF(FromFile) Do
  585.     Begin
  586.         Read(FromFile, Workers);
  587.         If IsWorkersCorrect(Workers) Then
  588.             Write(ToFile, Workers);
  589.     End;
  590. End;
  591.  
  592. Procedure AddRecord(Workers: RWorkers);
  593. Var
  594.     CorrectionFile: TWorkersFile;
  595. Begin
  596.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  597.     Seek(CorrectionFile, FileSize(CorrectionFile));
  598.     Write(CorrectionFile, Workers);
  599.     CloseFile(CorrectionFile);
  600. End;
  601.  
  602. Function InsertKey(Index: Integer; SubStr: Char; SelLen: Integer; Text: String): String;
  603. Var
  604.     ResultText: String;
  605. Begin
  606.     ResultText := Text;
  607.     If (SubStr = BACKSPACE) And (SelLen = 0) Then
  608.         Delete(ResultText, Index, 1)
  609.     Else
  610.     Begin
  611.         Delete(ResultText, Index + 1, SelLen);
  612.         If Substr <> BACKSPACE Then
  613.             ResultText.Insert(Index, String(SubStr));
  614.     End;
  615.  
  616.     InsertKey := ResultText;
  617. End;
  618.  
  619. Function CountOfSymbolInt(Num: Integer): Integer;
  620. Var
  621.     NumLen: Integer;
  622. Begin
  623.     NumLen := 0;
  624.     If Num < 0 Then
  625.         Inc(NumLen);
  626.     Repeat
  627.         Inc(NumLen);
  628.         Num := Num Div 10;
  629.     Until (Num = 0);
  630.     CountOfSymbolInt := NumLen;
  631. End;
  632.  
  633. Procedure TotalKeyPress(Var Key: Char; SelStart, SelLength: Integer; Const MIN, MAX: Integer; Text: String);
  634. Var
  635.     ResultNum, RBorder, NumLen: Integer;
  636.     Buffer, Output: String;
  637. Begin
  638.     Output := InsertKey(SelStart, Key, SelLength, Text);
  639.     If (Length(Output) <> 0) And (Output <> '-') Then
  640.     Begin
  641.         Try
  642.             ResultNum := StrToInt(Output);
  643.         Except
  644.             Key := VOID;
  645.         End;
  646.         If Key <> VOID Then
  647.         Begin
  648.             NumLen := CountOfSymbolInt(ResultNum);
  649.             If NumLen <> Length(Output) Then
  650.                 Key := VOID;
  651.             If (ResultNum > MAX) Or (ResultNum < MIN) Then
  652.                 Key := VOID;
  653.         End;
  654.     End
  655.     Else
  656.         If (Output = '-') And (MIN >= 0) Then
  657.             Key := VOID;
  658. End;
  659.  
  660. End.
  661.  
  662. Unit ChangeRecUnit;
  663.  
  664. Interface
  665.  
  666. Uses
  667.     Winapi.Windows,
  668.     Winapi.Messages,
  669.     System.SysUtils,
  670.     System.Variants,
  671.     System.Classes,
  672.     Vcl.Graphics,
  673.     Vcl.Controls,
  674.     Vcl.Forms,
  675.     Vcl.Dialogs,
  676.     Vcl.StdCtrls,
  677.     BackEndUnit;
  678.  
  679. Type
  680.     TChangeRecForm = Class(TForm)
  681.         NameLabel: TLabel;
  682.         CostLabel: TLabel;
  683.         CountLabel: TLabel;
  684.         RecNameEdit: TEdit;
  685.         RecOtdelEdit: TEdit;
  686.         RecAEdit: TEdit;
  687.         ChangeRecButton: TButton;
  688.         RecBEdit: TEdit;
  689.         RecCEdit: TEdit;
  690.         Label1: TLabel;
  691.         Label2: TLabel;
  692.         Procedure ChangeRecButtonClick(Sender: TObject);
  693.         Function IsAllFieldCorrect(): Boolean;
  694.         Procedure AnyEditChange(Sender: TObject);
  695.         Procedure RecAEditKeyPress(Sender: TObject; Var Key: Char);
  696.         Procedure FormCreate(RecIndex: Integer; Sender: TObject);
  697.         Procedure RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  698.         Procedure RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  699.         Procedure RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  700.         Procedure RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  701.         Procedure RecBEditKeyPress(Sender: TObject; Var Key: Char);
  702.         Procedure RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  703.         Procedure RecCEditKeyPress(Sender: TObject; Var Key: Char);
  704.     Private
  705.         CurIndex: Integer;
  706.     Public
  707.         { Public declarations }
  708.     End;
  709.  
  710. Var
  711.     ChangeRecForm: TChangeRecForm;
  712.  
  713. Implementation
  714.  
  715. {$R *.dfm}
  716.  
  717. Procedure TChangeRecForm.ChangeRecButtonClick(Sender: TObject);
  718. Var
  719.     CurWorkers: RWorkers;
  720. Begin
  721.     CurWorkers.Name := RecNameEdit.Text;
  722.     CurWorkers.Otdel := RecOtdelEdit.Text;
  723.     If RecAEdit.Text <> '' Then
  724.         CurWorkers.A := StrToInt(RecAEdit.Text)
  725.     Else
  726.         CurWorkers.A := 0;
  727.  
  728.     If RecBEdit.Text <> '' Then
  729.         CurWorkers.B := StrToInt(RecBEdit.Text)
  730.     Else
  731.         CurWorkers.B := 0;
  732.  
  733.     If RecCEdit.Text <> '' Then
  734.         CurWorkers.C := StrToInt(RecCEdit.Text)
  735.     Else
  736.         CurWorkers.C := 0;
  737.     ChangeWorkers(CurIndex, CurWorkers);
  738. End;
  739.  
  740. Procedure TChangeRecForm.FormCreate(RecIndex: Integer; Sender: TObject);
  741. Var
  742.     CurWorkers: RWorkers;
  743. Begin
  744.     CurIndex := RecIndex;
  745.     CurWorkers := GetRecFromFile(CurIndex);
  746.     RecNameEdit.Text := CurWorkers.Name;
  747.     RecOtdelEdit.Text := CurWorkers.Otdel;
  748.     RecAEdit.Text := IntToStr(CurWorkers.A);
  749.     RecBEdit.Text := IntToStr(CurWorkers.B);
  750.     RecCEdit.Text := IntToStr(CurWorkers.C);
  751. End;
  752.  
  753. function TChangeRecForm.IsAllFieldCorrect: Boolean;
  754. var
  755.   IsAllFilled: Boolean;
  756. begin
  757.   IsAllFilled := (RecNameEdit.Text <> '') and (RecOtdelEdit.Text <> '') and
  758.     (RecAEdit.Text <> '') and (RecBEdit.Text <> '') and (RecCEdit.Text <> '');
  759.  
  760.   Result := IsAllFilled;
  761. end;
  762.  
  763. Procedure TChangeRecForm.AnyEditChange(Sender: TObject);
  764. Begin
  765.     ChangeRecButton.Enabled := IsAllFieldCorrect();
  766. End;
  767.  
  768. Procedure TChangeRecForm.RecOtdelEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  769. Begin
  770.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  771.         Key := 0;
  772.     If Key = VK_DELETE Then
  773.         Key := 0;
  774.     If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
  775.         ChangeRecButton.Click();
  776.     If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
  777.         RecOtdelEdit.SetFocus();
  778. End;
  779.  
  780. Procedure TChangeRecForm.RecAEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  781. Begin
  782.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  783.         Key := 0;
  784.     If Key = VK_DELETE Then
  785.         Key := 0;
  786.     If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
  787.         ChangeRecButton.Click();
  788. End;
  789.  
  790. Procedure TChangeRecForm.RecAEditKeyPress(Sender: TObject; Var Key: Char);
  791. Begin
  792.     With RecAEdit Do
  793.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  794. End;
  795.  
  796. Procedure TChangeRecForm.RecBEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  797. Begin
  798.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  799.         Key := 0;
  800.     If Key = VK_DELETE Then
  801.         Key := 0;
  802.     If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
  803.         ChangeRecButton.Click();
  804. End;
  805.  
  806. Procedure TChangeRecForm.RecBEditKeyPress(Sender: TObject; Var Key: Char);
  807. Begin
  808.     With RecBEdit Do
  809.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  810. End;
  811.  
  812. Procedure TChangeRecForm.RecCEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  813. Begin
  814.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  815.         Key := 0;
  816.     If Key = VK_DELETE Then
  817.         Key := 0;
  818.     If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
  819.         ChangeRecButton.Click();
  820. End;
  821.  
  822. Procedure TChangeRecForm.RecCEditKeyPress(Sender: TObject; Var Key: Char);
  823. Begin
  824.     With RecCEdit Do
  825.         TotalKeyPress(Key, SelStart, SelLength, MIN_KOL, MAX_KOL, Text);
  826. End;
  827.  
  828. Procedure TChangeRecForm.RecNameEditKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  829. Begin
  830.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  831.         Key := 0;
  832.     If Key = VK_DELETE Then
  833.         Key := 0;
  834.     If (Key = VK_RETURN) And ChangeRecButton.Enabled Then
  835.         ChangeRecButton.Click();
  836.     If (Key = VK_RETURN) Or (Key = VK_DOWN) Then
  837.         RecOtdelEdit.SetFocus();
  838. End;
  839.  
  840. End.
  841.  
  842. Unit DevInfUnit;
  843.  
  844. Interface
  845.  
  846. Uses
  847.     Winapi.Windows,
  848.     Winapi.Messages,
  849.     System.SysUtils,
  850.     System.Variants,
  851.     System.Classes,
  852.     Vcl.Graphics,
  853.     Vcl.Controls,
  854.     Vcl.Forms,
  855.     Vcl.Dialogs,
  856.     Vcl.StdCtrls;
  857.  
  858. Type
  859.     TDeveloperForm = Class(TForm)
  860.         DevInfMemo: TMemo;
  861.     Private
  862.         { Private declarations }
  863.     Public
  864.         { Public declarations }
  865.     End;
  866.  
  867. Var
  868.     DeveloperForm: TDeveloperForm;
  869.  
  870. Implementation
  871.  
  872. {$R *.dfm}
  873. End.
  874.  
  875. Unit FindRecUnit;
  876.  
  877. Interface
  878.  
  879. Uses
  880.     Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  881.     System.Classes, Vcl.Graphics,
  882.     Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, BackEndUnit;
  883.  
  884. Type
  885.     TFindRecForm = Class(TForm)
  886.         RecordsGrid: TStringGrid;
  887.         NameCharacterLabel: TLabel;
  888.         OtdelCharacterLabel: TLabel;
  889.         NameEdit: TEdit;
  890.         OtdelEdit: TEdit;
  891.         FindButton: TButton;
  892.         Procedure Finder(Grid: TStringGrid; Path: String);
  893.         Procedure OtdelEditKeyDown(Sender: TObject; Var Key: Word;
  894.           Shift: TShiftState);
  895.         Procedure NameEditKeyDown(Sender: TObject; Var Key: Word;
  896.           Shift: TShiftState);
  897.         Procedure FormCreate(Sender: TObject);
  898.         Procedure AnyEditChange(Sender: TObject);
  899.         Procedure FindButtonClick(Sender: TObject);
  900.     Private
  901.         Procedure WriteCorrectRecToFile(Path: String);
  902.         Procedure Cleaning();
  903.         Function IsAllFieldCorrect(): Boolean;
  904.     Public
  905.         { Public declarations }
  906.     End;
  907.  
  908. Var
  909.     FindRecForm: TFindRecForm;
  910.  
  911. Implementation
  912.  
  913. {$R *.dfm}
  914.  
  915. Procedure TFindRecForm.WriteCorrectRecToFile(Path: String);
  916. Var
  917.     CorrectionFile, BufferFile: TWorkersFile;
  918.     I: Integer;
  919.     Name, Otdel: String;
  920.     Workers: RWorkers;
  921. Begin
  922.     Name := NameEdit.Text;
  923.     Otdel := OtdelEdit.Text;
  924.  
  925.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  926.     OpenFile(BUFFER_FILE_PATH, BufferFile, FmRewrite);
  927.  
  928.     For I := 1 To FileSize(CorrectionFile) Do
  929.     Begin
  930.         Read(CorrectionFile, Workers);
  931.         Write(BufferFile, Workers);
  932.     End;
  933.  
  934.     CloseFile(CorrectionFile);
  935.     CloseFile(BufferFile);
  936. End;
  937.  
  938. Procedure TFindRecForm.FormCreate(Sender: TObject);
  939. Begin
  940.     FindButton.Enabled := False;
  941.     // Draw FixedRow information
  942.     RecordsGrid.Cells[0, 0] := '¹';
  943.     RecordsGrid.Cells[1, 0] := 'Фамилия';
  944.     RecordsGrid.Cells[2, 0] := 'Цех';
  945.     RecordsGrid.Cells[3, 0] := 'A';
  946.     RecordsGrid.Cells[4, 0] := 'B';
  947.     RecordsGrid.Cells[5, 0] := 'C';
  948.     RecordsGrid.ColWidths[3] := 90;
  949.     RecordsGrid.ColWidths[4] := 90;
  950.     RecordsGrid.ColWidths[5] := 90;
  951.  
  952.     WriteCorrectRecToFile(BUFFER_FILE_PATH);
  953.  
  954. End;
  955.  
  956. Function TFindRecForm.IsAllFieldCorrect: Boolean;
  957. Var
  958.     IsCorrect: Boolean;
  959. Begin
  960.     If (OtdelEdit.Text <> '') Or (NameEdit.Text <> '') Then
  961.         IsCorrect := True
  962.     Else
  963.         IsCorrect := False;
  964.     IsAllFieldCorrect := IsCorrect;
  965. End;
  966.  
  967. Procedure TFindRecForm.FindButtonClick(Sender: TObject);
  968. Begin
  969.     Finder(RecordsGrid, BUFFER_FILE_PATH);
  970. End;
  971.  
  972. Procedure TFindRecForm.Finder(Grid: TStringGrid; Path: String);
  973. Var
  974.     CorrectionFile: TWorkersFile;
  975.     RecCount, I,J: Integer;
  976.     Workers: RWorkers;
  977.     IsFileIncorrect: Boolean;
  978. Begin
  979.     J:=0;
  980.     OpenFile(Path, CorrectionFile, FmReset);
  981.     RecCount := FileSize(CorrectionFile);
  982.     IsFileIncorrect := False;
  983.     Grid.RowCount := RecCount + 1;
  984.     For I := 1 To RecCount Do
  985.     Begin
  986.         Read(CorrectionFile, Workers);
  987.         Begin
  988.             With Workers Do
  989.             Begin
  990.                 If (NameEdit.Text = Name) Or (OtdelEdit.Text = Otdel) Then
  991.                 Begin
  992.                     Inc(J);
  993.                     Grid.Cells[0, J] := IntToStr(J) + '.';
  994.                     Grid.Cells[1, J] := Name;
  995.                     Grid.Cells[2, J] := Otdel;
  996.                     Grid.Cells[3, J] := IntToStr(A);
  997.                     Grid.Cells[4, J] := IntToStr(B);
  998.                     Grid.Cells[5, J] := IntToStr(C);
  999.                 End;
  1000.             End;
  1001.         End
  1002.     End;
  1003.     CloseFile(CorrectionFile);
  1004.     If IsFileIncorrect Then
  1005.         DeleteFile(Path);
  1006. End;
  1007.  
  1008. Procedure TFindRecForm.Cleaning();
  1009. Var
  1010. I : Integer ;
  1011. Begin
  1012.     for I := 1 to RecordsGrid.RowCount do
  1013.         Begin
  1014.             RecordsGrid.Cells[0, I] := '';
  1015.             RecordsGrid.Cells[1, I] := '';
  1016.             RecordsGrid.Cells[2, I] := '';
  1017.             RecordsGrid.Cells[3, I] := '';
  1018.             RecordsGrid.Cells[4, I] := '';
  1019.             RecordsGrid.Cells[5, I] := '';
  1020.         End;
  1021. End;
  1022.  
  1023. Procedure TFindRecForm.AnyEditChange(Sender: TObject);
  1024. Begin
  1025.     Cleaning();
  1026.     If IsAllFieldCorrect() Then
  1027.     Begin
  1028.         FindButton.Enabled := True;
  1029.     End
  1030.     Else
  1031.         FindButton.Enabled := False;
  1032. End;
  1033.  
  1034. Procedure TFindRecForm.NameEditKeyDown(Sender: TObject; Var Key: Word;
  1035.   Shift: TShiftState);
  1036. Begin
  1037.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And
  1038.       Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  1039.         Key := 0;
  1040.     If Key = VK_DELETE Then
  1041.         Key := 0;
  1042.     If (Key = VK_DOWN) Then
  1043.         OtdelEdit.SetFocus();
  1044. End;
  1045.  
  1046. Procedure TFindRecForm.OtdelEditKeyDown(Sender: TObject; Var Key: Word;
  1047.   Shift: TShiftState);
  1048. Begin
  1049.     If ((SsShift In Shift) Or (SsCtrl In Shift)) And
  1050.       Not((Key = VK_RIGHT) Or (Key = VK_LEFT)) Then
  1051.         Key := 0;
  1052.     If Key = VK_DELETE Then
  1053.         Key := 0;
  1054.     If (Key = VK_UP) Then
  1055.         NameEdit.SetFocus();
  1056. End;
  1057.  
  1058. End.
  1059.  
  1060. Unit ManualUnit;
  1061.  
  1062. Interface
  1063.  
  1064. Uses
  1065.     Winapi.Windows,
  1066.     Winapi.Messages,
  1067.     System.SysUtils,
  1068.     System.Variants,
  1069.     System.Classes,
  1070.     Vcl.Graphics,
  1071.     Vcl.Controls,
  1072.     Vcl.Forms,
  1073.     Vcl.Dialogs,
  1074.     Vcl.StdCtrls,
  1075.     Vcl.DBCtrls;
  1076.  
  1077. Type
  1078.     TManualForm = Class(TForm)
  1079.         ManualMemo: TMemo;
  1080.     Private
  1081.         { Private declarations }
  1082.     Public
  1083.         { Public declarations }
  1084.     End;
  1085.  
  1086. Var
  1087.     ManualForm: TManualForm;
  1088.  
  1089. Implementation
  1090.  
  1091. {$R *.dfm}
  1092. End.
  1093.  
  1094. Unit MiddUnit;
  1095.  
  1096. Interface
  1097.  
  1098. Uses
  1099.     Winapi.Windows,
  1100.     Winapi.Messages,
  1101.     System.SysUtils,
  1102.     System.Variants,
  1103.     System.Classes,
  1104.     Vcl.Graphics,
  1105.     Vcl.Controls,
  1106.     Vcl.Forms,
  1107.     Vcl.Dialogs,
  1108.     BackEndUnit,
  1109.     Vcl.Grids,
  1110.     Vcl.Menus;
  1111.  
  1112. Type
  1113.     Department = Record
  1114.         Otdel: String[20];
  1115.         Sum, Zp: Integer;
  1116.         SrZp: Double;
  1117.         Count: Integer;
  1118.     End;
  1119.  
  1120.     TMiddForm = Class(TForm)
  1121.         FinMiddGrid: TStringGrid;
  1122.         Procedure FormCreate(Sender: TObject);
  1123.     Private
  1124.         { Private declarations }
  1125.     Public
  1126.         { Public declarations }
  1127.     End;
  1128.  
  1129. Var
  1130.     MiddForm: TMiddForm;
  1131.  
  1132. Implementation
  1133.  
  1134. {$R *.dfm}
  1135.  
  1136. Procedure TMiddForm.FormCreate(Sender: TObject);
  1137. Var
  1138.     Workers: Array Of RWorkers;
  1139.     CorrectionFile: TWorkersFile;
  1140.     I, DepartmentCount, J: Integer;
  1141.     OtdelName: String;
  1142.     Found: Boolean;
  1143.     Departments: Array Of Department;
  1144.     Sa, Sb, Sc: Integer;
  1145.     TotalA, TotalB, TotalC, Total: Integer;
  1146.     TotalSalary: Integer;
  1147.     AverageSalary: Double;
  1148. Begin
  1149.     Sa := 50;
  1150.     Sb := 100;
  1151.     Sc := 150;
  1152.     FinMiddGrid.ColWidths[0] := 270;
  1153.     FinMiddGrid.ColWidths[1] := 170;
  1154.  
  1155.     OpenFile(CORRECTION_FILE_PATH, CorrectionFile, FmReset);
  1156.  
  1157.     While Not Eof(CorrectionFile) Do
  1158.     Begin
  1159.         SetLength(Workers, Length(Workers) + 1);
  1160.         Read(CorrectionFile, Workers[High(Workers)]);
  1161.     End;
  1162.  
  1163.     CloseFile(CorrectionFile);
  1164.  
  1165.     DepartmentCount := 0;
  1166.     OtdelName := '';
  1167.  
  1168.     For I := 0 To High(Workers) Do
  1169.     Begin
  1170.         Found := False;
  1171.         For J := 0 To DepartmentCount - 1 Do
  1172.         Begin
  1173.             If Workers[I].Otdel = Departments[J].Otdel Then
  1174.             Begin
  1175.                 Departments[J].Sum := Departments[J].Sum + Workers[I].A + Workers[I].B + Workers[I].C;
  1176.                 Departments[J].Zp := Departments[J].Zp + Workers[I].A * Sa + Workers[I].B * Sb + Workers[I].C * Sc;
  1177.                 Departments[J].Count := Departments[J].Count + 1;
  1178.                 Found := True;
  1179.                 Break;
  1180.             End;
  1181.         End;
  1182.         If Not Found Then
  1183.         Begin
  1184.             SetLength(Departments, DepartmentCount + 1);
  1185.             Departments[DepartmentCount].Otdel := Workers[I].Otdel;
  1186.             Departments[DepartmentCount].Sum := Workers[I].A + Workers[I].B + Workers[I].C;
  1187.             Departments[DepartmentCount].Zp := Departments[DepartmentCount].Zp + Workers[I].A * Sa + Workers[I].B * Sb + Workers[I].C * Sc;
  1188.             Departments[DepartmentCount].Count := 1;
  1189.             DepartmentCount := DepartmentCount + 1;
  1190.         End;
  1191.     End;
  1192.     FinMiddGrid.ColCount := DepartmentCount + 1;
  1193.  
  1194.     FinMiddGrid.Cells[0, 1] := 'Кол-во изделий';
  1195.     FinMiddGrid.Cells[0, 2] := 'Зп';
  1196.     FinMiddGrid.Cells[0, 3] := 'Средняя зп';
  1197.     For I := 0 To DepartmentCount - 1 Do
  1198.     Begin
  1199.         FinMiddGrid.Cells[I + 1, 0] := Departments[I].Otdel;
  1200.     End;
  1201.     For I := 0 To DepartmentCount - 1 Do
  1202.     Begin
  1203.         FinMiddGrid.Cells[I + 1, 1] := IntToStr(Departments[I].Sum);
  1204.         FinMiddGrid.Cells[I + 1, 2] := IntToStr(Departments[I].Zp);
  1205.     End;
  1206.     For I := 0 To DepartmentCount - 1 Do
  1207.     Begin
  1208.         If Departments[I].Count > 0 Then
  1209.             AverageSalary := Departments[I].Zp / Departments[I].Count
  1210.         Else
  1211.             AverageSalary := 0;
  1212.  
  1213.         FinMiddGrid.Cells[I + 1, 3] := FloatToStr(AverageSalary);
  1214.     End;
  1215. End;
  1216.  
  1217. End.
  1218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement