Advertisement
MaksNew

Untitled

Feb 2nd, 2021
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 22.76 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.Menus, Vcl.StdCtrls,
  8.   Vcl.Samples.Spin, Vcl.Grids, Vcl.ExtDlgs, Vcl.WinXCtrls;
  9.  
  10. Type
  11.     Worker = Record
  12.         Name: String[15];
  13.         DetailsOnMonday: Integer;
  14.         DetailsOnTuesday: Integer;
  15.         DetailsOnWednesday: Integer;
  16.         DetailsOnThursday: Integer;
  17.         DetailsOnFriday: Integer;
  18.         DetailsOnSaturday: Integer;
  19.     End;
  20.     AoW = Array of Worker;
  21.  
  22. type
  23.   TMainForm = class(TForm)
  24.     MainMenu1: TMainMenu;
  25.     AboutProgramButton: TMenuItem;
  26.     LabelOfWorkers: TLabel;
  27.     SpinEditOfWorkers: TSpinEdit;
  28.     FileButton: TMenuItem;
  29.     OpenFileButton: TMenuItem;
  30.     SaveButton: TMenuItem;
  31.     OutputButton: TMenuItem;
  32.     WorkerAndDetailsOnWeekFindButton: TMenuItem;
  33.     BestWorkerFindButton: TMenuItem;
  34.     FindDialog1: TFindDialog;
  35.     MainStringGrid: TStringGrid;
  36.     PopupMenuForStringGrid: TPopupMenu;
  37.     DeleteButton: TMenuItem;
  38.     OpenDialogForStringGrid: TOpenDialog;
  39.     AdjustmentButton: TMenuItem;
  40.     ChangeButton: TMenuItem;
  41.     AddButton: TMenuItem;
  42.     DeleteFromFileButton: TMenuItem;
  43.     OpenDialogForTextFile: TOpenDialog;
  44.     SaveDialog: TSaveDialog;
  45.     HelpButton: TMenuItem;
  46.     procedure AboutProgramButtonClick(Sender: TObject);
  47.     procedure FormActivate(Sender: TObject);
  48.     procedure SpinEditOfWorkersChange(Sender: TObject);
  49.     procedure FindDialog1Find(Sender: TObject);
  50.     procedure WorkerAndDetailsOnWeekFindButtonClick(Sender: TObject);
  51.     procedure BestWorkerFindButtonClick(Sender: TObject);
  52.     procedure MainStringGridMouseDown(Sender: TObject; Button: TMouseButton;
  53.       Shift: TShiftState; X, Y: Integer);
  54.     procedure DeleteButtonClick(Sender: TObject);
  55.     procedure OpenFileButtonClick(Sender: TObject);
  56.     procedure ChangeButtonClick(Sender: TObject);
  57.     procedure AddButtonClick(Sender: TObject);
  58.     procedure DeleteFromFileButtonClick(Sender: TObject);
  59.     procedure SaveButtonClick(Sender: TObject);
  60.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  61.     procedure SpinEditOfWorkersClick(Sender: TObject);
  62.     procedure HelpButtonClick(Sender: TObject);
  63.   private
  64.     { Private declarations }
  65.   public
  66.     { Public declarations }
  67.   end;
  68.  
  69. var
  70.   MainForm: TMainForm;
  71.   ACol, ADeletedRow: Integer;
  72.   //GlobalBuf: Integer;
  73.  
  74.  
  75. implementation
  76.  
  77. {$R *.dfm}
  78. uses
  79.     Unit2, Unit3;
  80.  
  81. function IsMainStringGridCorrect(StringGrid: TStringGrid; SpinEdit: TSpinEdit):boolean;
  82. var
  83.     I, J: Integer;                                             //Проверка таблицы на корректность данных
  84.     IsCorrect: Boolean;
  85. begin
  86.     IsCorrect := True;
  87.     I := 1;
  88.     while ((I <= SpinEdit.Value) and (IsCorrect)) do
  89.     begin
  90.         J := 2;
  91.         while ((J < 8) and (IsCorrect)) do
  92.         Begin
  93.             Try
  94.                 StrToInt(StringGrid.Cells[J, I])
  95.             Except
  96.                 IsCorrect := False;
  97.             End;
  98.             Inc(J);
  99.         End;
  100.         Inc(I);
  101.     end;
  102.     IsMainStringGridCorrect := IsCorrect;
  103. end;
  104.  
  105. procedure TMainForm.FindDialog1Find(Sender: TObject); //Вывод фамилии сборщика и общего количества деталей, собранного им за неделю
  106. var
  107.     I, J, Sum: Integer;
  108.     IsFound: Boolean;
  109. begin
  110.     Sum := 0;
  111.     IsFound := False;
  112.     for I := 1 to SpinEditOfWorkers.Value do
  113.     if MainStringGrid.Cells[1, i] = FindDialog1.FindText then
  114.         begin
  115.             for J := 2 to 7 do
  116.                 Sum := Sum + StrToInt(MainStringGrid.Cells[J, I]);
  117.             IsFound := True;
  118.             ShowMessage(FindDialog1.FindText + ' за шестидневную неделю в сумме сделал ' + IntToStr(Sum) + ' деталей');
  119.         end;
  120.     if not(IsFound) then
  121.         ShowMessage(FindDialog1.FindText + ' не найден в списке!');
  122. end;
  123.  
  124. procedure TMainForm.FormActivate(Sender: TObject);
  125. begin
  126.     //MainStringGrid.Options := MainStringGrid.Options + [goRowSelect];
  127.     MainStringGrid.Cells[0,1]:= '1';
  128.     MainStringGrid.Cells[0,2]:= '2';
  129.     MainStringGrid.Cells[0,0]:= '№ записи';
  130.     MainStringGrid.Cells[1,0]:= 'Фамилия сборщика';
  131.     MainStringGrid.Cells[2,0]:= 'Понедельник';
  132.     MainStringGrid.Cells[3,0]:= 'Вторник';
  133.     MainStringGrid.Cells[4,0]:= 'Среда';
  134.     MainStringGrid.Cells[5,0]:= 'Четверг';
  135.     MainStringGrid.Cells[6,0]:= 'Пятница';
  136.     MainStringGrid.Cells[7,0]:= 'Суббота';
  137.     SpinEditOfWorkers.Value := 1;
  138.     //GlobalBuf := SpinEditOfWorkers.Value;
  139.     DeleteButton.Enabled := False;
  140.  
  141. end;
  142.  
  143. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  144. var
  145.     Choise: Integer;
  146. begin
  147.     Choise := Messagedlg('Вы уверены, что хотите выйти?', mtinformation, [mbYes, mbNo], 0);
  148.     case Choise of
  149.         mrYes: CanClose:= True;
  150.         mrNo: CanClose:= False;
  151.     end;
  152. end;
  153.  
  154. procedure TMainForm.HelpButtonClick(Sender: TObject);
  155. begin
  156.     Form3.Show;
  157. end;
  158.  
  159. function IsFileCorOfChangingCorrect(var FileCor: TextFile): boolean;
  160. var
  161.     I, Index, Details: Integer;
  162.     Name: AnsiString;
  163.     IsCorrect: Boolean;
  164.     RussianChars: set of ansichar;       //Проверка файла корректур с даннымии для изменения ячеек
  165. begin
  166.     IsCorrect := True;
  167.     Details := 0;
  168.     Reset(FileCor);
  169.     RussianChars := ['A'..'Я', 'a'..'я'];
  170.     while not(EoF(FileCor)) do
  171.     begin
  172.         Try
  173.             Readln(FileCor, Index);
  174.         Except
  175.             IsCorrect := False;
  176.         End;
  177.         Readln(FileCor, Name);
  178.         I := 1;
  179.         while ((I <= Length(Name)) and (IsCorrect)) do
  180.         begin
  181.             if not(Name[I] in RussianChars) then
  182.                 IsCorrect := False;
  183.             Inc(I)
  184.         end;
  185.         I := 1;
  186.         while not(eoln(FileCor)) and IsCorrect do
  187.         begin
  188.             Try
  189.                 Read(FileCor, Details);
  190.             Except
  191.                 IsCorrect := False;
  192.             End;
  193.             Inc(I)
  194.         end;
  195.         Readln(FileCor);
  196.     end;
  197.     CloseFile(FileCor);
  198.     IsFileCorOfChangingCorrect := IsCorrect;
  199. end;
  200.  
  201. procedure TMainForm.MainStringGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  202. begin
  203.   MainStringGrid.MouseToCell(X, Y, ACol, ADeletedRow); //Получаем индексы ячейки ACol и ARow
  204. end;
  205.  
  206. procedure TMainForm.ChangeButtonClick(Sender: TObject);  //Изменение таблицы с помощью файла корректур
  207. var
  208.     FileCor:TextFile;
  209.     I, J, Index: Integer;
  210.     Name: AnsiString;
  211.     Details: array[1..6] of integer;
  212. begin
  213.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  214.     begin
  215.         if OpenDialogForTextFile.Execute then
  216.         begin
  217.             AssignFile(FileCor, OpenDialogForTextFile.FileName);
  218.             if IsFileCorOfChangingCorrect(FileCor) then
  219.             begin
  220.                 Reset(FileCor);
  221.                 while not(EoF(FileCor)) do
  222.                 begin
  223.                     Readln(FileCor, Index);
  224.                     Readln(FileCor, Name);
  225.                     I := 1;
  226.                     while not(eoln(FileCor)) do
  227.                     begin
  228.                         Read(FileCor, Details[I]);
  229.                         Inc(I)
  230.                     end;
  231.                     for I := 1 to SpinEditOfWorkers.Value do
  232.                         if I = Index then
  233.                         begin
  234.                             MainStringGrid.Cells[1, I] := Name;
  235.                             for J := 2 to 7 do
  236.                                 MainStringGrid.Cells[J, I] := IntToStr(Details[J-1]);
  237.                         end;
  238.                     Readln(FileCor);
  239.                 end;
  240.                 CloseFile(FileCor)
  241.             end
  242.             else
  243.                 ShowMessage('Проверьте содержимое файла!');
  244.         end
  245.     end
  246.     else
  247.         ShowMessage('Проверьте таблицу!');
  248. end;
  249.  
  250. function IsFileCorOfAddingCorrect(var FileCor: TextFile): boolean; //Проверка файла корректур с данными для добавления ячеек
  251. var
  252.     I, Details: Integer;
  253.     Name: AnsiString;
  254.     IsCorrect: Boolean;
  255.     RussianChars: set of ansichar;
  256. begin
  257.     IsCorrect := True;
  258.     Details := 0;
  259.     Reset(FileCor);
  260.     RussianChars := ['A'..'Я', 'a'..'я'];
  261.     while not(EoF(FileCor)) do
  262.     begin
  263.         Readln(FileCor, Name);
  264.         I := 1;
  265.         while ((I <= Length(Name)) and (IsCorrect)) do
  266.         begin
  267.             if not(Name[I] in RussianChars) then
  268.                 IsCorrect := False;
  269.             Inc(I)
  270.         end;
  271.         I := 1;
  272.         while not(eoln(FileCor)) and IsCorrect do
  273.         begin
  274.             Try
  275.                 Read(FileCor, Details);
  276.             Except
  277.                 IsCorrect := False;
  278.             End;
  279.             Inc(I)
  280.         end;
  281.         Readln(FileCor);
  282.     end;
  283.     CloseFile(FileCor);
  284.     IsFileCorOfAddingCorrect := IsCorrect;
  285. end;
  286.  
  287. procedure TMainForm.AddButtonClick(Sender: TObject); //Добавление ячеек таблицы при помощи файла корректур
  288. var
  289.     FileCor:TextFile;
  290.     I, J: Integer;
  291.     Name: AnsiString;
  292.     Deatils: array[1..6] of integer;
  293. begin
  294.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  295.     begin
  296.         if OpenDialogForTextFile.Execute then
  297.         begin
  298.             AssignFile(FileCor, OpenDialogForTextFile.FileName);
  299.             if IsFileCorOfAddingCorrect(FileCor) then
  300.             begin
  301.                 Reset(FileCor);
  302.                 while not(EoF(FileCor)) do
  303.                 begin
  304.                     Readln(FileCor, Name);
  305.                     I := 1;
  306.                     while not(EoLn(FileCor)) do
  307.                     begin
  308.                         Read(FileCor, Deatils[I]);
  309.                         Inc(I)
  310.                     end;
  311.                     SpinEditOfWorkers.Value := SpinEditOfWorkers.Value + 1;
  312.                     MainStringGrid.Cells[1, SpinEditOfWorkers.Value] := Name;
  313.                     for J := 2 to 7 do
  314.                         MainStringGrid.Cells[J, SpinEditOfWorkers.Value] := IntToStr(Deatils[J-1]);
  315.                     Readln(FileCor);
  316.                 end;
  317.                 CloseFile(FileCor);
  318.             end
  319.             else
  320.                 ShowMessage('Проверьте содержимое файла!');
  321.         end;
  322.     end
  323.     else
  324.         ShowMessage('Проверьте таблицу');
  325. end;
  326.  
  327. function IsFileCorOfDeleteCorrect(var FileCor: TextFile; MaxValue: Integer): boolean;
  328. var
  329.     I, DeleteIndex: Integer;
  330.     Name: AnsiString;
  331.     IsCorrect: Boolean;      //Проверка файла корректур с данными для удаления ячеек
  332. begin
  333.     IsCorrect := True;
  334.     DeleteIndex := 0;
  335.     I := 1;
  336.     Reset(FileCor);
  337.     while not(EoF(FileCor)) do
  338.     begin
  339.         Try
  340.             Readln(FileCor, DeleteIndex);
  341.         Except
  342.             IsCorrect := False;
  343.         End;
  344.         if IsCorrect then
  345.             if DeleteIndex > MaxValue then
  346.                 IsCorrect := False;
  347.         Inc(I);
  348.     end;
  349.     CloseFile(FileCor);
  350.     if I > MaxValue then
  351.         IsCorrect := False;
  352.     IsFileCorOfDeleteCorrect := IsCorrect;
  353. end;
  354.  
  355. procedure DeleteRow(var ArrayOfRecords: AoW; I, DeletedRow: Integer; var MainStringGrid: TStringGrid; SpinEditOfWorkers: TSpinEdit);
  356. begin
  357.     while (I < DeletedRow) do
  358.     begin
  359.         ArrayOfRecords[I-1].Name := MainStringGrid.Cells[1, I];
  360.         ArrayOfRecords[I-1].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
  361.         ArrayOfRecords[I-1].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
  362.         ArrayOfRecords[I-1].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
  363.         ArrayOfRecords[I-1].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
  364.         ArrayOfRecords[I-1].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
  365.         ArrayOfRecords[I-1].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
  366.         Inc(I);
  367.     end;
  368.  
  369.     I := DeletedRow + 1;
  370.  
  371.     while (I <= SpinEditOfWorkers.Value) do
  372.     begin
  373.         ArrayOfRecords[I-2].Name := MainStringGrid.Cells[1, I];
  374.         ArrayOfRecords[I-2].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
  375.         ArrayOfRecords[I-2].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
  376.         ArrayOfRecords[I-2].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
  377.         ArrayOfRecords[I-2].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
  378.         ArrayOfRecords[I-2].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
  379.         ArrayOfRecords[I-2].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
  380.         Inc(I);
  381.     end;
  382.  
  383.     for I := 1 to 7 do
  384.         MainStringGrid.Cells[I, SpinEditOfWorkers.Value] := ' ';
  385.  
  386.     SpinEditOfWorkers.Value := SpinEditOfWorkers.Value - 1;
  387.     for I := 1 to SpinEditOfWorkers.Value do
  388.     begin
  389.         MainStringGrid.Cells[1, I] := ArrayOfRecords[I-1].Name;
  390.         MainStringGrid.Cells[2, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnMonday);
  391.         MainStringGrid.Cells[3, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnTuesday);
  392.         MainStringGrid.Cells[4, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnWednesday);
  393.         MainStringGrid.Cells[5, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnThursday);
  394.         MainStringGrid.Cells[6, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnFriday);
  395.         MainStringGrid.Cells[7, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnSaturday);
  396.     end;
  397. end;
  398.  
  399. procedure TMainForm.DeleteFromFileButtonClick(Sender: TObject); //Удаление ячеек таблицы при помощи файла корректур
  400. var
  401.     FileCor:TextFile;
  402.     DeletedRow, I, Buf: Integer;
  403.     IsCorrect: Boolean;
  404.     ArrayOfRecords: AoW;
  405. begin
  406.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  407.     begin
  408.         if OpenDialogForTextFile.Execute then
  409.         begin
  410.             AssignFile(FileCor, OpenDialogForTextFile.FileName);
  411.             if IsFileCorOfDeleteCorrect(FileCor, SpinEditOfWorkers.Value) then
  412.             begin
  413.                 Reset(FileCor);
  414.                 SetLength(ArrayOfRecords, SpinEditOfWorkers.Value-1);
  415.                 I := 1;
  416.                 Buf := 0;
  417.                 DeletedRow := 0;
  418.                 While not(EoF(FileCor)) do
  419.                 begin
  420.                     Readln(FileCor, DeletedRow);
  421.                     if Buf > 0 then
  422.                         DeletedRow := DeletedRow-Buf;
  423.                     DeleteRow(ArrayOfRecords, I, DeletedRow, MainStringGrid, SpinEditOfWorkers);
  424.                     Inc(Buf);
  425.                 end;
  426.                 CloseFile(FileCor);
  427.             end
  428.             else
  429.                 ShowMessage('Проверьте содержимое файла!');
  430.         end;
  431.     end
  432.     else
  433.         ShowMessage('Проверьте таблицу!');
  434. end;
  435.  
  436.  
  437.  
  438. procedure TMainForm.AboutProgramButtonClick(Sender: TObject);    //О программе
  439. begin
  440.    Form2.Show;
  441. end;
  442.  
  443. procedure TMainForm.OpenFileButtonClick(Sender: TObject); //Открыть таблицу из файла
  444. var
  445.     OpenedFile: File of Worker;
  446.     I, J: Integer;
  447.     IsCorrect: Boolean;
  448.     ArrayOfRecords: AoW;
  449. begin
  450.     if OpenDialogForStringGrid.Execute then
  451.     begin
  452.         for I := 1 to SpinEditOfWorkers.Value do
  453.             for J := 1 to 7 do
  454.                 MainStringGrid.Cells[J, I] := '';
  455.         AssignFile(OpenedFile, OpenDialogForStringGrid.FileName);
  456.         Reset(OpenedFile);
  457.         SpinEditOfWorkers.Value := FileSize(OpenedFile);
  458.         for I := 1 to SpinEditOfWorkers.Value do
  459.             MainStringGrid.Cells[0, I] := IntToStr(I);
  460.         SetLength(ArrayOfRecords, SpinEditOfWorkers.Value);
  461.         I := 0;
  462.         While not(EoF(OpenedFile)) do
  463.         Begin
  464.             Read(OpenedFile, ArrayOfRecords[I]);
  465.             Inc(I);
  466.         End;
  467.  
  468.         for I := 1 to SpinEditOfWorkers.Value do
  469.         begin
  470.             MainStringGrid.Cells[1, I] := ArrayOfRecords[I-1].Name;
  471.             MainStringGrid.Cells[2, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnMonday);
  472.             MainStringGrid.Cells[3, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnTuesday);
  473.             MainStringGrid.Cells[4, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnWednesday);
  474.             MainStringGrid.Cells[5, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnThursday);
  475.             MainStringGrid.Cells[6, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnFriday);
  476.             MainStringGrid.Cells[7, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnSaturday);
  477.         end;
  478.         CloseFile(OpenedFile);
  479.     end;
  480. end;
  481.  
  482. procedure TMainForm.SaveButtonClick(Sender: TObject);   //Сохранить файл
  483. var
  484.     I: Integer;
  485.     SavedFile: File of Worker;
  486.     ArrayOfRecords: AoW;
  487. begin
  488.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  489.     begin
  490.         if SaveDialog.Execute then
  491.         begin
  492.             AssignFile(SavedFile, SaveDialog.FileName);
  493.             Rewrite(SavedFile);
  494.             SetLength(ArrayOfRecords, SpinEditOfWorkers.Value);
  495.             for I := 1 to SpinEditOfWorkers.Value do
  496.             begin
  497.                 ArrayOfRecords[I-1].Name := MainStringGrid.Cells[1, I];
  498.                 ArrayOfRecords[I-1].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
  499.                 ArrayOfRecords[I-1].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
  500.                 ArrayOfRecords[I-1].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
  501.                 ArrayOfRecords[I-1].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
  502.                 ArrayOfRecords[I-1].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
  503.                 ArrayOfRecords[I-1].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
  504.             end;
  505.  
  506.             for I := 0 to SpinEditOfWorkers.Value-1 do
  507.                 Write(SavedFile, ArrayOfRecords[I]);
  508.             CloseFile(SavedFile);
  509.         end;
  510.     end
  511.     else
  512.         ShowMessage('Проверьте таблицу!');
  513. end;
  514.  
  515. procedure TMainForm.WorkerAndDetailsOnWeekFindButtonClick(Sender: TObject);  //Сборщик и детали за неделю
  516. begin
  517.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  518.         FindDialog1.Execute()
  519.     else
  520.         ShowMessage('Проверьте таблицу!');
  521. end;
  522.  
  523. procedure TMainForm.BestWorkerFindButtonClick(Sender: TObject);  //Сборщик-рекордсмен
  524. var
  525.     ArrayOfSumOfProducts: array of integer;
  526.     BestWorkman, BestDay: AnsiString;
  527.     I, J, SumOfDetails, MaxDetails, BestBuf: Integer;
  528. begin
  529.     if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  530.     begin
  531.         SetLength(ArrayOfSumOfProducts, SpinEditOfWorkers.Value);
  532.         MaxDetails := 0;
  533.         BestBuf := 0;
  534.         for I := 0 to SpinEditOfWorkers.Value-1 do //находит сумму всех деталей каждого рабочего
  535.         begin
  536.             SumOfDetails := 0;
  537.             for J := 2 to 7 do
  538.             begin
  539.                 SumOfDetails := SumOfDetails + StrToInt(MainStringGrid.Cells[J,I+1]);
  540.             end;
  541.             ArrayOfSumOfProducts[I] := SumOfDetails;
  542.         end;
  543.  
  544.         for I := 0 to SpinEditOfWorkers.Value-1 do   // ищет максимум деталей среди рабочих и день высшей производительности
  545.         begin
  546.             if ((ArrayOfSumOfProducts[I] > ArrayOfSumOfProducts[I-1]) and (ArrayOfSumOfProducts[I] > MaxDetails)) then
  547.             begin
  548.                 MaxDetails := ArrayOfSumOfProducts[I];
  549.                 BestWorkman := MainStringGrid.Cells[1, I+1];
  550.                 for J := 2 to 6 do
  551.                     if ((StrToInt(MainStringGrid.Cells[J, I+1]) > StrToInt(MainStringGrid.Cells[J+1,I+1])) and (StrToInt(MainStringGrid.Cells[J, I+1]) > BestBuf)) then
  552.                     begin
  553.                         BestDay := MainStringGrid.Cells[J,0];
  554.                         BestBuf := StrToInt(MainStringGrid.Cells[J, I+1])
  555.                     end;
  556.             end;
  557.         end;
  558.  
  559.         if MaxDetails > 0 then
  560.             ShowMessage(BestWorkman + ' собрал ' + IntToStr(MaxDetails) + ' деталей, что является лучшим показателем! День высшей производительности: ' + BestDay)
  561.         else
  562.             ShowMessage('Таких нет!');
  563.     end
  564.     else
  565.         ShowMessage('Проверьте таблицу!');
  566. end;
  567.  
  568. procedure TMainForm.DeleteButtonClick(Sender: TObject);   //Удаление поля таблицы
  569. var
  570.     ArrayOfRecords: AoW;
  571.     I: Integer;
  572. begin
  573.     //GlobalCorrect := False;
  574.     if SpinEditOfWorkers.Value > 1 then
  575.     begin
  576.         if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
  577.         begin
  578.             Setlength(ArrayOfRecords, SpinEditOfWorkers.Value-1);
  579.             I := 1;
  580.             DeleteRow(ArrayOfRecords, I, ADeletedRow, MainStringGrid, SpinEditOfWorkers);
  581.         end
  582.         else
  583.             ShowMessage('Проверьте таблицу!');
  584.     end
  585. end;
  586.  
  587. procedure TMainForm.SpinEditOfWorkersChange(Sender: TObject);
  588. var
  589.     UserHigh, I: Integer;
  590. begin
  591.   {  if ((GlobalCorrect) and (SpinEditOfWorkers.Value < GlobalBuf)) then
  592.         SpinEditOfWorkers.Value := GlobalBuf
  593.     else
  594.         GlobalBuf := SpinEditOfWorkers.Value;  }
  595.     UserHigh := 200;
  596.     if ((SpinEditOfWorkers.Value > 0) and (SpinEditOfWorkers.Value < 23)) then
  597.     begin
  598.         MainStringGrid.Cells[0,SpinEditOfWorkers.Value]:= IntToStr(SpinEditOfWorkers.Value);
  599.         MainStringGrid.Options := MainStringGrid.Options+[goEditing];
  600.         MainStringGrid.RowCount := SpinEditOfWorkers.Value+1;
  601.         MainStringGrid.Height := 36 * MainStringGrid.RowCount;
  602.         if (MainStringGrid.Height + MainStringGrid.Top < UserHigh) then
  603.             ClientHeight := UserHigh
  604.         else
  605.             ClientHeight := MainStringGrid.Height + MainStringGrid.Top + 10;
  606.     end
  607.     else
  608.         MainStringGrid.Options := MainStringGrid.Options-[goEditing];
  609.     if (SpinEditOfWorkers.Value > 1) then
  610.     begin
  611.         WorkerAndDetailsOnWeekFindButton.Enabled := True;
  612.         BestWorkerFindButton.Enabled := True;
  613.         DeleteButton.Enabled := True;
  614.         DeleteFromFileButton.Enabled := True
  615.     end
  616.     else
  617.     begin
  618.         WorkerAndDetailsOnWeekFindButton.Enabled := False;
  619.         BestWorkerFindButton.Enabled := False;
  620.         DeleteButton.Enabled := False;
  621.         DeleteFromFileButton.Enabled := False;
  622.     end;
  623. end;
  624.  
  625. procedure TMainForm.SpinEditOfWorkersClick(Sender: TObject);
  626. begin
  627.     //GlobalCorrect := True;
  628. end;
  629.  
  630. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement