Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitChangeLists;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, UnitMain;
- type
- //TPElemIngredient = UnitMain.TPElemIngredient;
- TFormLists = class(TForm)
- Ingredients: TStringGrid;
- LabelIngredients: TLabel;
- BtAddIngr: TButton;
- BtDelIngr: TButton;
- BtChIngr: TButton;
- Dishes: TStringGrid;
- Banquet: TStringGrid;
- Label1: TLabel;
- Label2: TLabel;
- BtAddDishes: TButton;
- BtDelDishes: TButton;
- BtChDishes: TButton;
- BtAddBan: TButton;
- BtDelBan: TButton;
- BtChBan: TButton;
- procedure BtAddIngrClick(Sender: TObject);
- procedure BtAddBanClick(Sender: TObject);
- procedure BtAddDishesClick(Sender: TObject);
- procedure BtDelIngrClick(Sender: TObject);
- procedure BtDelDishesClick(Sender: TObject);
- procedure BtDelBanClick(Sender: TObject);
- procedure AddIngrToStrGrid(var StrGrid: TStringGrid; Ingr: TPElemIngredient);
- procedure AddBanquetToStrGrid(var StrGrid: TStringGrid; Ingr: TPElemBanquet);
- procedure BtChIngrClick(Sender: TObject);
- procedure IngredientsSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- procedure AddDishToStrGrid(var StrGrid: TStringGrid; Dish: TPElemDish);
- procedure BtChDishesClick(Sender: TObject);
- procedure DishesSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- procedure BanquetSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- procedure BtChBanClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormLists: TFormLists;
- implementation
- {$R *.dfm}
- uses UnitIngredient, UnitBanquet, UnitDish, UnitMessage;
- type
- TPElemIngredient = UnitMain.TPElemIngredient;
- TPElemDish = UnitMain.TPElemDish;
- TPElemBanquet = UnitMain.TPElemBanquet;
- procedure Deleting(var StrGrid: TStringGrid; ARow: Integer);
- var
- I: Integer;
- begin
- for I := ARow to (StrGrid.RowCount - 2) do
- StrGrid.Rows[I] := StrGrid.Rows[I + 1];
- StrGrid.RowCount := StrGrid.RowCount - 1;
- end;
- procedure DeletingBan(var StrGrid: TStringGrid; ACol: Integer);
- var
- I: Integer;
- begin
- for I := ACol to (StrGrid.ColCount - 2) do
- StrGrid.Cols[I] := StrGrid.Cols[I + 1];
- StrGrid.ColCount := StrGrid.ColCount - 1;
- end;
- procedure TFormLists.BanquetSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- begin
- if ACol = 0 then
- CanSelect := false;
- end;
- procedure TFormLists.BtAddBanClick(Sender: TObject);
- var
- Curr: TPElemBanquet;
- begin
- with UnitBanquet.FormBanquet do
- begin
- ComboBox.Items := Dishes.Cols[0];
- ComboBox.Items[0] := '';
- if ShowModal = mrOk then
- begin
- if not(UnitMain.FormMenu.SearchBanquet(Curr,
- StrToInt(ComboBox.Items[ComboBox.ItemIndex]))) then
- begin
- UnitMain.FormMenu.AddBanquet(CurrBanquet,
- StrToInt(ComboBox.Items[ComboBox.ItemIndex]),
- StrToInt(EditCount.Text), false);
- AddBanquetToStrGrid(Banquet, CurrBanquet);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Заказ с таким блюдом уже есть!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- end;
- end;
- procedure TFormLists.BtAddDishesClick(Sender: TObject);
- var
- IngrArr: TIngrArr;
- Curr: TPElemDish;
- I: Integer;
- begin
- with UnitDish.FormDish do
- begin
- Edit1.Enabled := true;
- Ingr.RowCount := 1;
- ComboBox.Items := Ingredients.Cols[0];
- ComboBox.Items[0] := '';
- Ingr.Cells[0, 0] := 'Код';
- Ingr.Cells[1, 0] := 'Количество';
- Edit1.Clear;
- Edit2.Clear;
- end;
- if UnitDish.FormDish.ShowModal = mrOk then
- begin
- if not(UnitMain.FormMenu.SearchDish(Curr, StrToInt(UnitDish.FormDish.Edit1.Text))) then
- begin
- with UnitDish.FormDish do
- begin
- for I := 1 to (Ingr.RowCount - 1) do
- begin
- IngrArr[I - 1].Code := StrToInt(Ingr.Cells[0, I]);
- IngrArr[I - 1].Count := StrToInt(Ingr.Cells[1, I]);
- end;
- I := Ingr.RowCount - 1;
- while I < 6 do
- begin
- IngrArr[I].Code := 0;
- IngrArr[I].Count := 0;
- Inc(I);
- end;
- UnitMain.FormMenu.AddDish(CurrDish, StrToInt(Edit1.Text),
- Edit2.Text, IngrArr);
- end;
- AddDishToStrGrid(Dishes, CurrDish);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Салат с таким кодом уже присутствует в списке!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- end;
- procedure TFormLists.AddIngrToStrGrid(var StrGrid: TStringGrid; Ingr: TPElemIngredient);
- begin
- StrGrid.RowCount := StrGrid.RowCount + 1;
- StrGrid.Cells[0, StrGrid.RowCount - 1] := IntToStr(Ingr.Code);
- StrGrid.Cells[1, StrGrid.RowCount - 1] := Ingr.Name;
- StrGrid.Cells[2, StrGrid.RowCount - 1] := IntToStr(Ingr.ProteinCount);
- StrGrid.Cells[3, StrGrid.RowCount - 1] := IntToStr(Ingr.FatCount);
- StrGrid.Cells[4, StrGrid.RowCount - 1] := IntToStr(Ingr.CarbohydrateCount);
- StrGrid.Cells[5, StrGrid.RowCount - 1] := IntToStr(Ingr.ChangeCode);
- end;
- procedure TFormLists.AddDishToStrGrid(var StrGrid: TStringGrid; Dish: TPElemDish);
- var
- I: Integer;
- begin
- StrGrid.RowCount := StrGrid.RowCount + 1;
- StrGrid.Cells[0, StrGrid.RowCount - 1] := IntToStr(Dish.Code);
- StrGrid.Cells[1, StrGrid.RowCount - 1] := Dish.Name;
- StrGrid.Cells[2, StrGrid.RowCount - 1] := '';
- I := 0;
- while (I < 5) do
- begin
- if (Dish.Ingr[I].Code <> 0) and (Dish.Ingr[I].Count <> 0) then
- begin
- StrGrid.Cells[2, StrGrid.RowCount - 1] := StrGrid.Cells[2, StrGrid.RowCount - 1] +
- IntToStr(Dish.Ingr[I].Code) + '(' + IntToStr(Dish.Ingr[I].Count) + '); ';
- end;
- Inc(I);
- end;
- end;
- procedure TFormLists.AddBanquetToStrGrid(var StrGrid: TStringGrid; Ingr: TPElemBanquet);
- begin
- StrGrid.ColCount := StrGrid.ColCount + 1;
- StrGrid.Cells[StrGrid.ColCount - 1, 0] := IntToStr(Ingr.Code);
- StrGrid.Cells[StrGrid.ColCount - 1, 1] := IntToStr(Ingr.Count);
- if Ingr.CanCook then
- begin
- StrGrid.Cells[StrGrid.ColCount - 1, 2] := 'да';
- end
- else
- begin
- StrGrid.Cells[StrGrid.ColCount - 1, 2] := 'нет';
- end;
- end;
- procedure TFormLists.BtAddIngrClick(Sender: TObject);
- var
- Curr: TPElemIngredient;
- CombBox: Integer;
- begin
- with UnitIngredient.FormIngredient do
- begin
- Edit1.Enabled := true;
- ComboBox.Items := Ingredients.Cols[0];
- ComboBox.Items[0] := '';
- Edit1.Clear;
- Edit2.Clear;
- Edit3.Clear;
- Edit4.Clear;
- Edit5.Clear;
- end;
- if UnitIngredient.FormIngredient.ShowModal = mrOk then
- begin
- if not (UnitMain.FormMenu.SearchIngredient(Curr,
- StrToInt(UnitIngredient.FormIngredient.Edit1.Text))) then
- begin
- with UnitIngredient.FormIngredient do
- begin
- if ComboBox.Items[ComboBox.ItemIndex] <> '' then
- begin
- CombBox := StrToInt(ComboBox.Items[ComboBox.ItemIndex]);
- end;
- UnitMain.FormMenu.AddIngredient(CurrIngredient, StrToInt(Edit1.Text),
- StrToInt(Edit3.Text), StrToInt(Edit4.Text), StrToInt(Edit5.Text),
- CombBox, Edit2.Text);
- end;
- AddIngrToStrGrid(Ingredients, CurrIngredient);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Ингредиент с таким кодом уже присутствует в списке!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- end;
- procedure TFormLists.BtChBanClick(Sender: TObject);
- var
- Curr: TPElemBanquet;
- begin
- with UnitBanquet.FormBanquet do
- begin
- ComboBox.Items := Banquet.Rows[0];
- ComboBox.ItemIndex := Banquet.Col;
- ComboBox.Enabled := false;
- EditCount.Text := Banquet.Cells[Banquet.Col, 1];
- ButtonAdd.Enabled := true;
- if UnitBanquet.FormBanquet.ShowModal = mrOk then
- begin
- Banquet.Cells[Banquet.Col, 0] := ComboBox.Items[ComboBox.ItemIndex];
- Banquet.Cells[Banquet.Col, 1] := EditCount.Text;
- UnitMain.FormMenu.SearchBanquet(Curr, StrToInt(ComboBox.Items[ComboBox.ItemIndex]));
- UnitMain.FormMenu.ChangeBanquet(Curr,
- StrToInt(ComboBox.Items[ComboBox.ItemIndex]), StrToInt(EditCount.Text),false);
- end;
- ComboBox.Enabled := true;
- ButtonAdd.Enabled := false;
- end;
- end;
- procedure TFormLists.BtChDishesClick(Sender: TObject);
- var
- Curr: TPElemDish;
- I: Integer;
- Count: Integer;
- IngrArr: TIngrArr;
- begin
- with UnitDish.FormDish do
- begin
- Ingr.RowCount := 1;
- Ingr.Cells[0, 0] := 'Код';
- Ingr.Cells[1, 0] := 'Количество';
- Edit1.Text := Dishes.Cells[0, Dishes.Row];
- Edit2.Text := Dishes.Cells[1, Dishes.Row];
- ComboBox.Items := Ingredients.Cols[0];
- ComboBox.Items[0] := '';
- Edit1.Enabled := false;
- ButtonAdd.Enabled := true;
- I := 1;
- Count := length(Dishes.Cells[2, Dishes.Row]);
- while I <= Count do
- begin
- Ingr.RowCount := Ingr.RowCount + 1;
- Ingr.Cells[0, Ingr.RowCount - 1] := Copy(Dishes.Cells[2, Dishes.Row], I, 3);
- if Dishes.Cells[2, Dishes.Row][I + 6] = ')' then
- begin
- Ingr.Cells[1, Ingr.RowCount - 1] := Copy(Dishes.Cells[2, Dishes.Row], (I + 4), 2);
- Inc(I, 9);
- end
- else
- begin
- Ingr.Cells[1, Ingr.RowCount - 1] := Copy(Dishes.Cells[2, Dishes.Row], (I + 4), 1);
- Inc(I, 8);
- end;
- end;
- end;
- if UnitDish.FormDish.ShowModal = mrOk then
- begin
- with UnitDish.FormDish do
- begin
- ButtonAdd.Enabled := false;
- Edit1.Enabled := true;
- for I := 1 to (Ingr.RowCount - 1) do
- begin
- IngrArr[I - 1].Code := StrToInt(Ingr.Cells[0, I]);
- IngrArr[I - 1].Count := StrToInt(Ingr.Cells[1, I]);
- end;
- while I < 5 do
- begin
- IngrArr[I].Code := 0;
- IngrArr[I].Count := 0;
- Inc(I);
- end;
- Dishes.Cells[1, Dishes.Row] := Edit2.Text;
- Dishes.Cells[2, Dishes.Row] := '';
- for I := Low(IngrArr) to High(IngrArr) do
- begin
- if (IngrArr[I].Code <> 0) and (IngrArr[I].Count <> 0) then
- begin
- Dishes.Cells[2, Dishes.Row] := Dishes.Cells[2, Dishes.Row] +
- IntToStr(IngrArr[I].Code) + '(' + IntToStr(IngrArr[I].Count) + '); ';
- end;
- end;
- UnitMain.FormMenu.SearchDish(Curr, StrToInt(Edit1.Text));
- UnitMain.FormMenu.ChangeDish(Curr, Edit2.Text, IngrArr);
- end;
- end;
- end;
- procedure TFormLists.BtChIngrClick(Sender: TObject);
- var
- Curr: TPElemIngredient;
- begin
- with UnitIngredient.FormIngredient do
- begin
- Edit1.Text := Ingredients.Cells[0, Ingredients.Row];
- Edit1.Enabled := false;
- Edit2.Text := Ingredients.Cells[1, Ingredients.Row];
- Edit3.Text := Ingredients.Cells[2, Ingredients.Row];
- Edit4.Text := Ingredients.Cells[3, Ingredients.Row];
- Edit5.Text := Ingredients.Cells[4, Ingredients.Row];
- ComboBox.Items := Ingredients.Cols[0];
- ComboBox.Items[0] := '';
- end;
- if UnitIngredient.FormIngredient.ShowModal = mrOk then
- begin
- with UnitIngredient.FormIngredient do
- begin
- Edit1.Enabled := true;
- Ingredients.Cells[1, Ingredients.Row] := Edit2.Text;
- Ingredients.Cells[2, Ingredients.Row] := Edit3.Text;
- Ingredients.Cells[3, Ingredients.Row] := Edit4.Text;
- Ingredients.Cells[4, Ingredients.Row] := Edit5.Text;
- if ComboBox.Items[ComboBox.ItemIndex] <> '' then
- begin
- Ingredients.Cells[5, Ingredients.Row] := ComboBox.Items[ComboBox.ItemIndex];
- end
- else
- begin
- Ingredients.Cells[5, Ingredients.Row] := '0';
- end;
- if Ingredients.Cells[5, Ingredients.Row] = Ingredients.Cells[0, Ingredients.Row] then
- begin
- Ingredients.Cells[5, Ingredients.Row] := '0';
- end;
- UnitMain.FormMenu.SearchIngredient(Curr,
- StrToInt(Ingredients.Cells[0, Ingredients.Row]));
- UnitMain.FormMenu.ChangeIngredient(Curr, Edit2.Text, StrToInt(Edit3.Text),
- StrToInt(Edit4.Text), StrToInt(Edit5.Text),
- StrToInt(Ingredients.Cells[5, Ingredients.Row]));
- end;
- end;
- end;
- procedure TFormLists.BtDelBanClick(Sender: TObject);
- begin
- if Banquet.ColCount > 1 then
- begin
- UnitMain.FormMenu.DeleteBanquet(StrToInt(Banquet.Cells[Banquet.Col, 0]));
- DeletingBan(Banquet, Banquet.Col);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Нет блюд на банкет для удаления!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- procedure TFormLists.BtDelDishesClick(Sender: TObject);
- begin
- if Dishes.RowCount > 1 then
- begin
- UnitMain.FormMenu.DeleteDish(StrToInt(Dishes.Cells[0, Dishes.Row]));
- Deleting(Dishes, Dishes.Row);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Нет салатов для удаления!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- procedure TFormLists.BtDelIngrClick(Sender: TObject);
- begin
- if Ingredients.RowCount > 1 then
- begin
- UnitMain.FormMenu.DeleteIngredient(StrToInt(Ingredients.Cells[0, Ingredients.Row]));
- Deleting(Ingredients, Ingredients.Row);
- end
- else
- begin
- UnitMessage.FormMessage.LabelMessage.Caption := 'Нет ингредиентов для удаления!';
- UnitMessage.FormMessage.ShowModal;
- UnitMessage.FormMessage.LabelMessage.Caption := '';
- end;
- end;
- procedure TFormLists.DishesSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- begin
- if ARow = 0 then
- CanSelect := false;
- end;
- procedure TFormLists.IngredientsSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- begin
- if ARow = 0 then
- CanSelect := false;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement