Advertisement
MaksNew

Untitled

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