Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- Type
- InputType = (FromConsole, FromFile);
- Worker = Record
- Name: String[15];
- DetailsOnMonday: Integer;
- DetailsOnTuesday: Integer;
- DetailsOnWednesday: Integer;
- DetailsOnThursday: Integer;
- DetailsOnFriday: Integer;
- DetailsOnSaturday: Integer;
- End;
- AoW = Array of Worker;
- var
- MainForm: TMainForm;
- ACol, ADeletedRow: Integer;
- GlobalCorrect: Boolean;
- function IsMainStringGridCorrect(StringGrid: TStringGrid; SpinEdit: TSpinEdit):boolean;
- var
- I, J: Integer; //Проверка таблицы на корректность данных
- IsCorrect: Boolean;
- begin
- IsCorrect := True;
- I := 1;
- while ((I <= SpinEdit.Value) and (IsCorrect)) do
- begin
- J := 2;
- while ((J < 8) and (IsCorrect)) do
- Begin
- Try
- StrToInt(StringGrid.Cells[J, I])
- Except
- IsCorrect := False;
- End;
- Inc(J);
- End;
- Inc(I);
- end;
- IsMainStringGridCorrect := IsCorrect;
- end;
- procedure TMainForm.FindDialog1Find(Sender: TObject); //Вывод фамилии сборщика и общего количества деталей, собранного им за неделю
- var
- I, J, Sum: Integer;
- IsFound: Boolean;
- begin
- Sum := 0;
- IsFound := False;
- for I := 1 to SpinEditOfWorkers.Value do
- if MainStringGrid.Cells[1, i] = FindDialog1.FindText then
- begin
- for J := 2 to 7 do
- Sum := Sum + StrToInt(MainStringGrid.Cells[J, I]);
- IsFound := True;
- ShowMessage(FindDialog1.FindText + ' за шестидневную неделю в сумме сделал ' + IntToStr(Sum) + ' деталей');
- end;
- if not(IsFound) then
- ShowMessage(FindDialog1.FindText + ' не найден в списке!');
- end;
- function IsFileCorOfChangingCorrect(var FileCor: TextFile): boolean;
- var
- I, Index, Details: Integer;
- Name: AnsiString;
- IsCorrect: Boolean;
- RussianChars: set of ansichar; //Проверка файла корректур с даннымии для изменения ячеек
- begin
- IsCorrect := True;
- Details := 0;
- Reset(FileCor);
- RussianChars := ['A'..'Я', 'a'..'я'];
- while not(EoF(FileCor)) do
- begin
- Try
- Readln(FileCor, Index);
- Except
- IsCorrect := False;
- End;
- Readln(FileCor, Name);
- I := 1;
- while ((I <= Length(Name)) and (IsCorrect)) do
- begin
- if not(Name[I] in RussianChars) then
- IsCorrect := False;
- Inc(I)
- end;
- I := 1;
- while not(eoln(FileCor)) and IsCorrect do
- begin
- Try
- Read(FileCor, Details);
- Except
- IsCorrect := False;
- End;
- Inc(I)
- end;
- Readln(FileCor);
- end;
- CloseFile(FileCor);
- IsFileCorOfChangingCorrect := IsCorrect;
- end;
- procedure TMainForm.ChangeButtonClick(Sender: TObject); //Изменение таблицы с помощью файла корректур
- var
- FileCor:TextFile;
- I, J, Index: Integer;
- Name: AnsiString;
- Details: array[1..6] of integer;
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- if OpenDialogForTextFile.Execute then
- begin
- AssignFile(FileCor, OpenDialogForTextFile.FileName);
- if IsFileCorOfChangingCorrect(FileCor) then
- begin
- Reset(FileCor);
- while not(EoF(FileCor)) do
- begin
- Readln(FileCor, Index);
- Readln(FileCor, Name);
- I := 1;
- while not(eoln(FileCor)) do
- begin
- Read(FileCor, Details[I]);
- Inc(I)
- end;
- for I := 1 to SpinEditOfWorkers.Value do
- if I = Index then
- begin
- MainStringGrid.Cells[1, I] := Name;
- for J := 2 to 7 do
- MainStringGrid.Cells[J, I] := IntToStr(Details[J-1]);
- end;
- Readln(FileCor);
- end;
- CloseFile(FileCor)
- end
- else
- ShowMessage('Проверьте содержимое файла!');
- end
- end
- else
- ShowMessage('Проверьте таблицу!');
- end;
- function IsFileCorOfAddingCorrect(var FileCor: TextFile): boolean; //Проверка файла корректур с данными для добавления ячеек
- var
- I, Details: Integer;
- Name: AnsiString;
- IsCorrect: Boolean;
- RussianChars: set of ansichar;
- begin
- IsCorrect := True;
- Details := 0;
- Reset(FileCor);
- RussianChars := ['A'..'Я', 'a'..'я'];
- while not(EoF(FileCor)) do
- begin
- Readln(FileCor, Name);
- I := 1;
- while ((I <= Length(Name)) and (IsCorrect)) do
- begin
- if not(Name[I] in RussianChars) then
- IsCorrect := False;
- Inc(I)
- end;
- I := 1;
- while not(eoln(FileCor)) and IsCorrect do
- begin
- Try
- Read(FileCor, Details);
- Except
- IsCorrect := False;
- End;
- Inc(I)
- end;
- Readln(FileCor);
- end;
- CloseFile(FileCor);
- IsFileCorOfAddingCorrect := IsCorrect;
- end;
- procedure TMainForm.AddButtonClick(Sender: TObject); //Добавление ячеек таблицы при помощи файла корректур
- var
- FileCor:TextFile;
- I, J: Integer;
- Name: AnsiString;
- Deatils: array[1..6] of integer;
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- if OpenDialogForTextFile.Execute then
- begin
- AssignFile(FileCor, OpenDialogForTextFile.FileName);
- if IsFileCorOfAddingCorrect(FileCor) then
- begin
- Reset(FileCor);
- while not(EoF(FileCor)) do
- begin
- Readln(FileCor, Name);
- I := 1;
- while not(EoLn(FileCor)) do
- begin
- Read(FileCor, Deatils[I]);
- Inc(I)
- end;
- SpinEditOfWorkers.Value := SpinEditOfWorkers.Value + 1;
- MainStringGrid.Cells[1, SpinEditOfWorkers.Value] := Name;
- for J := 2 to 7 do
- MainStringGrid.Cells[J, SpinEditOfWorkers.Value] := IntToStr(Deatils[J-1]);
- Readln(FileCor);
- end;
- CloseFile(FileCor);
- end
- else
- ShowMessage('Проверьте содержимое файла!');
- end;
- end
- else
- ShowMessage('Проверьте таблицу');
- end;
- function IsFileCorOfDeleteCorrect(var FileCor: TextFile; MaxValue: Integer): boolean;
- var
- I, DeleteIndex: Integer;
- Name: AnsiString;
- IsCorrect: Boolean; //Проверка файла корректур с данными для удаления ячеек
- begin
- IsCorrect := True;
- DeleteIndex := 0;
- I := 1;
- Reset(FileCor);
- while not(EoF(FileCor)) do
- begin
- Try
- Readln(FileCor, DeleteIndex);
- Except
- IsCorrect := False;
- End;
- if IsCorrect then
- if DeleteIndex > MaxValue then
- IsCorrect := False;
- Inc(I);
- end;
- CloseFile(FileCor);
- if I > MaxValue then
- IsCorrect := False;
- IsFileCorOfDeleteCorrect := IsCorrect;
- end;
- procedure DeleteRow(var ArrayOfRecords: AoW; I, DeletedRow: Integer; var MainStringGrid: TStringGrid; SpinEditOfWorkers: TSpinEdit);
- begin
- while (I < DeletedRow) do
- begin
- ArrayOfRecords[I-1].Name := MainStringGrid.Cells[1, I];
- ArrayOfRecords[I-1].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
- ArrayOfRecords[I-1].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
- ArrayOfRecords[I-1].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
- ArrayOfRecords[I-1].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
- ArrayOfRecords[I-1].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
- ArrayOfRecords[I-1].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
- Inc(I);
- end;
- I := DeletedRow + 1;
- while (I <= SpinEditOfWorkers.Value) do
- begin
- ArrayOfRecords[I-2].Name := MainStringGrid.Cells[1, I];
- ArrayOfRecords[I-2].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
- ArrayOfRecords[I-2].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
- ArrayOfRecords[I-2].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
- ArrayOfRecords[I-2].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
- ArrayOfRecords[I-2].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
- ArrayOfRecords[I-2].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
- Inc(I);
- end;
- for I := 1 to 7 do
- MainStringGrid.Cells[I, SpinEditOfWorkers.Value] := ' ';
- SpinEditOfWorkers.Value := SpinEditOfWorkers.Value - 1;
- for I := 1 to SpinEditOfWorkers.Value do
- begin
- MainStringGrid.Cells[1, I] := ArrayOfRecords[I-1].Name;
- MainStringGrid.Cells[2, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnMonday);
- MainStringGrid.Cells[3, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnTuesday);
- MainStringGrid.Cells[4, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnWednesday);
- MainStringGrid.Cells[5, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnThursday);
- MainStringGrid.Cells[6, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnFriday);
- MainStringGrid.Cells[7, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnSaturday);
- end;
- end;
- procedure TMainForm.DeleteFromFileButtonClick(Sender: TObject); //Удаление ячеек таблицы при помощи файла корректур
- var
- FileCor:TextFile;
- DeletedRow, I, Buf: Integer;
- IsCorrect: Boolean;
- ArrayOfRecords: AoW;
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- if OpenDialogForTextFile.Execute then
- begin
- AssignFile(FileCor, OpenDialogForTextFile.FileName);
- if IsFileCorOfDeleteCorrect(FileCor, SpinEditOfWorkers.Value) then
- begin
- Reset(FileCor);
- SetLength(ArrayOfRecords, SpinEditOfWorkers.Value-1);
- I := 1;
- Buf := 0;
- DeletedRow := 0;
- While not(EoF(FileCor)) do
- begin
- Readln(FileCor, DeletedRow);
- if Buf > 0 then
- DeletedRow := DeletedRow-Buf;
- DeleteRow(ArrayOfRecords, I, DeletedRow, MainStringGrid, SpinEditOfWorkers);
- Inc(Buf);
- end;
- CloseFile(FileCor);
- end
- else
- ShowMessage('Проверьте содержимое файла!');
- end;
- end
- else
- ShowMessage('Проверьте таблицу!');
- end;
- procedure TMainForm.OpenFileButtonClick(Sender: TObject); //Открыть таблицу из файла
- var
- OpenedFile: File of Worker;
- I, J: Integer;
- IsCorrect: Boolean;
- ArrayOfRecords: AoW;
- begin
- if OpenDialogForStringGrid.Execute then
- begin
- for I := 1 to SpinEditOfWorkers.Value do
- for J := 1 to 7 do
- MainStringGrid.Cells[J, I] := '';
- AssignFile(OpenedFile, OpenDialogForStringGrid.FileName);
- Reset(OpenedFile);
- SpinEditOfWorkers.Value := FileSize(OpenedFile);
- for I := 1 to SpinEditOfWorkers.Value do
- MainStringGrid.Cells[0, I] := IntToStr(I);
- SetLength(ArrayOfRecords, SpinEditOfWorkers.Value);
- I := 0;
- While not(EoF(OpenedFile)) do
- Begin
- Read(OpenedFile, ArrayOfRecords[I]);
- Inc(I);
- End;
- for I := 1 to SpinEditOfWorkers.Value do
- begin
- MainStringGrid.Cells[1, I] := ArrayOfRecords[I-1].Name;
- MainStringGrid.Cells[2, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnMonday);
- MainStringGrid.Cells[3, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnTuesday);
- MainStringGrid.Cells[4, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnWednesday);
- MainStringGrid.Cells[5, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnThursday);
- MainStringGrid.Cells[6, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnFriday);
- MainStringGrid.Cells[7, I] := IntToStr(ArrayOfRecords[I-1].DetailsOnSaturday);
- end;
- CloseFile(OpenedFile);
- end;
- end;
- procedure TMainForm.SaveButtonClick(Sender: TObject); //Сохранить файл
- var
- I: Integer;
- SavedFile: File of Worker;
- ArrayOfRecords: AoW;
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- if SaveDialog.Execute then
- begin
- AssignFile(SavedFile, SaveDialog.FileName);
- Rewrite(SavedFile);
- SetLength(ArrayOfRecords, SpinEditOfWorkers.Value);
- for I := 1 to SpinEditOfWorkers.Value do
- begin
- ArrayOfRecords[I-1].Name := MainStringGrid.Cells[1, I];
- ArrayOfRecords[I-1].DetailsOnMonday := StrToInt(MainStringGrid.Cells[2, I]);
- ArrayOfRecords[I-1].DetailsOnTuesday := StrToInt(MainStringGrid.Cells[3, I]);
- ArrayOfRecords[I-1].DetailsOnWednesday := StrToInt(MainStringGrid.Cells[4, I]);
- ArrayOfRecords[I-1].DetailsOnThursday := StrToInt(MainStringGrid.Cells[5, I]);
- ArrayOfRecords[I-1].DetailsOnFriday := StrToInt(MainStringGrid.Cells[6, I]);
- ArrayOfRecords[I-1].DetailsOnSaturday := StrToInt(MainStringGrid.Cells[7, I]);
- end;
- for I := 0 to SpinEditOfWorkers.Value-1 do
- Write(SavedFile, ArrayOfRecords[I]);
- CloseFile(SavedFile);
- end;
- end
- else
- ShowMessage('Проверьте таблицу!');
- end;
- procedure TMainForm.WorkerAndDetailsOnWeekFindButtonClick(Sender: TObject); //Сборщик и детали за неделю
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- FindDialog1.Execute()
- else
- ShowMessage('Проверьте таблицу!');
- end;
- procedure TMainForm.BestWorkerFindButtonClick(Sender: TObject); //Сборщик-рекордсмен
- var
- ArrayOfSumOfProducts: array of integer;
- BestWorkman, BestDay: AnsiString;
- I, J, SumOfDetails, MaxDetails, BestBuf: Integer;
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- SetLength(ArrayOfSumOfProducts, SpinEditOfWorkers.Value);
- MaxDetails := 0;
- BestBuf := 0;
- for I := 0 to SpinEditOfWorkers.Value-1 do //находит сумму всех деталей каждого рабочего
- begin
- SumOfDetails := 0;
- for J := 2 to 7 do
- begin
- SumOfDetails := SumOfDetails + StrToInt(MainStringGrid.Cells[J,I+1]);
- end;
- ArrayOfSumOfProducts[I] := SumOfDetails;
- end;
- for I := 0 to SpinEditOfWorkers.Value-1 do // ищет максимум деталей среди рабочих и день высшей производительности
- begin
- if ((ArrayOfSumOfProducts[I] > ArrayOfSumOfProducts[I-1]) and (ArrayOfSumOfProducts[I] > MaxDetails)) then
- begin
- MaxDetails := ArrayOfSumOfProducts[I];
- BestWorkman := MainStringGrid.Cells[1, I+1];
- for J := 2 to 6 do
- if ((StrToInt(MainStringGrid.Cells[J, I+1]) > StrToInt(MainStringGrid.Cells[J+1,I+1])) and (StrToInt(MainStringGrid.Cells[J, I+1]) > BestBuf)) then
- begin
- BestDay := MainStringGrid.Cells[J,0];
- BestBuf := StrToInt(MainStringGrid.Cells[J, I+1])
- end;
- end;
- end;
- if MaxDetails > 0 then
- ShowMessage(BestWorkman + ' собрал ' + IntToStr(MaxDetails) + ' деталей, что является лучшим показателем! День высшей производительности: ' + BestDay)
- else
- ShowMessage('Таких нет!');
- end
- else
- ShowMessage('Проверьте таблицу!');
- end;
- procedure TMainForm.DeleteButtonClick(Sender: TObject); //Удаление поля таблицы
- var
- ArrayOfRecords: AoW;
- I: Integer;
- begin
- GlobalCorrect := False;
- if SpinEditOfWorkers.Value > 1 then
- begin
- if IsMainStringGridCorrect(MainStringGrid, SpinEditOfWorkers) then
- begin
- Setlength(ArrayOfRecords, SpinEditOfWorkers.Value-1);
- I := 1;
- DeleteRow(ArrayOfRecords, I, ADeletedRow, MainStringGrid, SpinEditOfWorkers);
- end
- else
- ShowMessage('Проверьте таблицу!');
- end
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement