Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitMain;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;
- type
- TPElemDish = ^TPDish;
- TContent = record
- Code: Integer;
- Count: Integer;
- end;
- TIngrArr = Array[0..4] of TContent;
- TPDish = record
- Code: Integer;
- Name: String[20];
- Ingr: TIngrArr;
- Next: TPElemDish;
- end;
- TPElemIngredient = ^TPIngredient;
- TPIngredient = record
- Code: Integer;
- Name: String[20];
- ProteinCount: Integer;
- FatCount: Integer;
- CarbohydrateCount: Integer;
- ChangeCode: Integer;
- Next: TPElemIngredient;
- end;
- TPElemBanquet = ^TPBanquet;
- TPBanquet = record
- Code: Integer;
- Count: Integer;
- CanCook: Boolean;
- Next: TPElemBanquet;
- end;
- TFormMenu = class(TForm)
- LabelMenu: TLabel;
- Button1: TButton;
- Button4: TButton;
- Button7: TButton;
- Button8: TButton;
- Button9: TButton;
- Button10: TButton;
- procedure Button10Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button7Click(Sender: TObject);
- procedure Button9Click(Sender: TObject);
- procedure DeleteDish(Code: Integer);
- procedure DeleteIngredient(Code: Integer);
- procedure DeleteBanquet(Code: Integer);
- function GetArrDish(Code: Integer; Arr: TIngrArr): Boolean;
- procedure AddDish(var Prev: TPElemDish; Code: Integer; Name: String; Ingr: TIngrArr);
- procedure AddIngredient(var Prev: TPElemIngredient; Code, Protein,
- Fat, Car, ChCode: Integer; Name: String);
- procedure AddBanquet(var Prev: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
- function SearchIngredient(var SearchFor: TPElemIngredient; Code: Integer): Boolean;
- procedure ChangeIngredient(var Curr: TPELemIngredient; Name: String; Protein, Fat, Car, Change: Integer);
- function SearchDish(var SearchFor: TPElemDish; Code: Integer): Boolean;
- procedure ChangeDish(var Curr: TPElemDish; Name: String; Ingr: TIngrArr);
- function SearchBanquet(var SearchFor: TPElemBanquet; Code: Integer): Boolean;
- procedure ChangeBanquet(var Curr: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
- procedure Button8Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- private
- { Private declarations }
- public
- end;
- var
- FormMenu: TFormMenu;
- HeadDishes, CurrDish: TPElemDish;
- HeadIngredients, CurrIngredient: TPElemIngredient;
- HeadBanquet, CurrBanquet: TPElemBanquet;
- implementation
- {$R *.dfm}
- uses UnitChangeLists, UnitSpecialFunction, UnitSearch;
- const
- FileDishes = 'Dishes.rcd';
- FileIngr = 'Ingr.rcd';
- FileB = 'Banquet.rcd';
- function TFormMenu.GetArrDish(Code: Integer; Arr: TIngrArr): Boolean;
- var
- Curr: TPElemDish;
- begin
- Curr := HeadDishes^.Next;
- while (Curr.Code = Code) or (Curr = nil) do
- begin
- Curr := Curr^.Next;
- end;
- if Curr = nil then
- begin
- GetArrDish := false;
- end
- else
- begin
- Arr := Curr.Ingr;
- GetArrDish := true;
- end;
- end;
- procedure TFormMenu.DeleteDish(Code: Integer);
- var
- Curr: TPElemDish;
- IsDeleted: Boolean;
- begin
- Curr := HeadDishes;
- IsDeleted := false;
- while not(IsDeleted) or not(Curr^.Next = nil) do
- begin
- if Curr^.Next^.Code = Code then
- begin
- if Curr^.Next = CurrDish then
- begin
- IsDeleted := true;
- if Curr = HeadDishes then
- begin
- CurrDish := nil;
- HeadDishes^.Next := CurrDish;
- end
- else
- begin
- Curr^.Next := nil;
- CurrDish := Curr;
- end;
- end
- else
- begin
- Curr^.Next := Curr^.Next^.Next;
- IsDeleted := true;
- end;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- end;
- procedure TFormMenu.DeleteIngredient(Code: Integer);
- var
- Curr: TPElemIngredient;
- IsDeleted: Boolean;
- begin
- Curr := HeadIngredients;
- IsDeleted := false;
- while not(IsDeleted) or not(Curr^.Next = nil) do
- begin
- if Curr^.Next^.Code = Code then
- begin
- if Curr^.Next = CurrIngredient then
- begin
- IsDeleted := true;
- if Curr = HeadIngredients then
- begin
- CurrIngredient := nil;
- HeadIngredients^.Next := CurrIngredient;
- end
- else
- begin
- Curr^.Next := nil;
- CurrIngredient := Curr;
- end;
- end
- else
- begin
- Curr^.Next := Curr^.Next^.Next;
- IsDeleted := true;
- end;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- end;
- procedure TFormMenu.DeleteBanquet(Code: Integer);
- var
- Curr: TPElemBanquet;
- IsDeleted: Boolean;
- begin
- Curr := HeadBanquet;
- IsDeleted := false;
- while not(IsDeleted) or not(Curr^.Next = nil) do
- begin
- if Curr^.Next^.Code = Code then
- begin
- if Curr^.Next = CurrBanquet then
- begin
- IsDeleted := true;
- if Curr = HeadBanquet then
- begin
- CurrBanquet := nil;
- HeadBanquet^.Next := CurrBanquet;
- end
- else
- begin
- Curr^.Next := nil;
- CurrBanquet := Curr;
- end;
- end
- else
- begin
- Curr^.Next := Curr^.Next^.Next;
- IsDeleted := true;
- end;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- end;
- procedure TFormMenu.AddDish(var Prev: TPElemDish; Code: Integer; Name: String; Ingr: TIngrArr);
- var
- Temp: TPElemDish;
- begin
- New(Temp);
- Temp^.Code := Code;
- Temp^.Name := Name;
- Temp^.Ingr := Ingr;
- Temp^.Next := nil;
- if Prev = nil then
- begin
- Prev := Temp;
- CurrDish := Temp;
- HeadDishes^.Next := Temp;
- end
- else
- begin
- Prev^.Next := Temp;
- CurrDish := Temp;
- end;
- end;
- procedure TFormMenu.AddIngredient(var Prev: TPElemIngredient; Code, Protein,
- Fat, Car, ChCode: Integer; Name: String);
- var
- Temp: TPElemIngredient;
- begin
- New(Temp);
- Temp^.Code := Code;
- Temp^.Name := Name;
- Temp^.ProteinCount := Protein;
- Temp^.FatCount := Fat;
- Temp^.CarbohydrateCount := Car;
- Temp^.ChangeCode := ChCode;
- Temp^.Next := nil;
- if Prev = nil then
- begin
- Prev := Temp;
- CurrIngredient := Temp;
- HeadIngredients^.Next := Temp;
- end
- else
- begin
- Prev^.Next := Temp;
- CurrIngredient := Temp;
- end;
- end;
- procedure TFormMenu.AddBanquet(var Prev: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
- var
- Temp: TPElemBanquet;
- begin
- New(Temp);
- Temp^.Code := Code;
- Temp^.Count := Count;
- Temp^.CanCook := CanCook;
- Temp^.Next := nil;
- if Prev = nil then
- begin
- Prev := Temp;
- CurrBanquet := Temp;
- HeadBanquet^.Next := Temp;
- end
- else
- begin
- Prev^.Next := Temp;
- CurrBanquet := Temp;
- end;
- end;
- function TFormMenu.SearchDish(var SearchFor: TPElemDish; Code: Integer): Boolean;
- var
- Curr: TPElemDish;
- IsFound: Boolean;
- begin
- IsFound := false;
- Curr := HeadDishes^.Next;
- while (Curr <> nil) and not(IsFound) do
- begin
- if Curr^.Code = Code then
- begin
- SearchFor := Curr;
- IsFound := true;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- SearchDish := IsFound;
- end;
- function TFormMenu.SearchIngredient(var SearchFor: TPElemIngredient; Code: Integer): Boolean;
- var
- Curr: TPElemIngredient;
- IsFound: Boolean;
- begin
- IsFound := false;
- Curr := HeadIngredients^.Next;
- while (Curr <> nil) and not(IsFound) do
- begin
- if Curr^.Code = Code then
- begin
- SearchFor := Curr;
- IsFound := true;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- SearchIngredient := IsFound;
- end;
- function TFormMenu.SearchBanquet(var SearchFor: TPElemBanquet; Code: Integer): Boolean;
- var
- Curr: TPElemBanquet;
- IsFound: Boolean;
- begin
- IsFound := false;
- Curr := HeadBanquet^.Next;
- while (Curr <> nil) and not(IsFound) do
- begin
- if Curr^.Code = Code then
- begin
- SearchFor := Curr;
- IsFound := true;
- end
- else
- begin
- Curr := Curr^.Next;
- end;
- end;
- SearchBanquet := IsFound;
- end;
- procedure TFormMenu.ChangeDish(var Curr: TPElemDish; Name: String; Ingr: TIngrArr);
- begin
- Curr^.Name := Name;
- Curr^.Ingr := Ingr;
- end;
- procedure TFormMenu.ChangeIngredient(var Curr: TPELemIngredient; Name: String; Protein, Fat, Car, Change: Integer);
- begin
- Curr^.Name := Name;
- Curr^.ProteinCount := Protein;
- Curr^.FatCount := Fat;
- Curr^.CarbohydrateCount := Car;
- Curr^.ChangeCode := Change;
- end;
- procedure TFormMenu.ChangeBanquet(var Curr: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
- begin
- Curr^.Code := Code;
- Curr^.Count := Count;
- Curr^.CanCook := CanCook;
- end;
- procedure GetListDishFromFile(var Head: TPElemDish; path: String);
- var
- F: File of TPDish;
- Temp: TPElemDish;
- Dish: TPDish;
- begin
- AssignFile(F, path);
- Reset(F);
- Seek(F, 0);
- if Head^.Next <> nil then
- Temp := CurrDish
- else
- begin
- New(CurrDish);
- Temp := Head;
- end;
- while not(EoF(F)) do
- begin
- Read(F, Dish);
- FormMenu.AddDish(Temp, Dish.Code, Dish.Name, Dish.Ingr);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure GetListIngredientFromFile(var Head: TPElemIngredient; path: String);
- var
- F: File of TPIngredient;
- Temp: TPElemIngredient;
- Dish: TPIngredient;
- begin
- AssignFile(F, path);
- Reset(F);
- Seek(F, 0);
- if Head^.Next <> nil then
- Temp := CurrIngredient
- else
- begin
- New(CurrIngredient);
- Temp := Head;
- end;
- while not(EoF(F)) do
- begin
- Read(F, Dish);
- FormMenu.AddIngredient(Temp, Dish.Code, Dish.ProteinCount,
- Dish.FatCount, Dish.CarbohydrateCount, Dish.ChangeCode, Dish.Name);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure GetListBanquetFromFile(var Head: TPElemBanquet; path: String);
- var
- F: File of TPBanquet;
- Temp: TPElemBanquet;
- Dish: TPBanquet;
- begin
- AssignFile(F, path);
- Reset(F);
- Seek(F, 0);
- if Head^.Next <> nil then
- Temp := CurrBanquet
- else
- begin
- New(CurrBanquet);
- Temp := Head;
- end;
- while not(EoF(F)) do
- begin
- Read(F, Dish);
- FormMenu.AddBanquet(Temp, Dish.Code, Dish.Count, Dish.CanCook);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure TFormMenu.Button10Click(Sender: TObject);
- begin
- FormMenu.Close;
- end;
- procedure TFormMenu.Button1Click(Sender: TObject);
- begin
- try
- GetListDishFromFile(HeadDishes, FileDishes);
- GetListIngredientFromFile(HeadIngredients, FileIngr);
- GetListBanquetFromFile(HeadBanquet, FileB);
- finally
- Button1.Enabled := false;
- Button7Click(Sender);
- end;
- end;
- procedure TFormMenu.Button4Click(Sender: TObject);
- var
- Curr: TPElemIngredient;
- begin
- Curr := HeadIngredients^.Next;
- with UnitSearch.FormSearch do
- begin
- ComboBox.Items.Clear;
- SearchedList.Items.Clear;
- while Curr <> nil do
- begin
- ComboBox.Items.Add(IntToStr(Curr^.Code));
- Curr := Curr^.Next;
- end;
- ShowModal;
- end;
- end;
- procedure TFormMenu.Button7Click(Sender: TObject);
- var
- CurrI: TPElemIngredient;
- CurrD: TPElemDish;
- CurrB: TPElemBanquet;
- begin
- UnitChangeLists.FormLists.Ingredients.RowCount := 1;
- UnitChangeLists.FormLists.Dishes.RowCount := 1;
- UnitChangeLists.FormLists.Banquet.ColCount := 1;
- with UnitChangeLists.FormLists do
- begin
- Ingredients.Cells[0, 0] := 'Код';
- Ingredients.Cells[1, 0] := 'Название';
- Ingredients.Cells[2, 0] := 'Белки';
- Ingredients.Cells[3, 0] := 'Жиры';
- Ingredients.Cells[4, 0] := 'Углеводы';
- Ingredients.Cells[5, 0] := 'Замена';
- end;
- CurrI := HeadIngredients^.Next;
- while (CurrI <> nil) do
- begin
- UnitChangeLists.FormLists.AddIngrToStrGrid(UnitChangeLists.FormLists.Ingredients, CurrI);
- CurrI := CurrI^.Next;
- end;
- with UnitChangeLists.FormLists do
- begin
- Dishes.Cells[0, 0] := 'Код';
- Dishes.Cells[1, 0] := 'Название';
- Dishes.Cells[2, 0] := 'Ингредиенты: код(кол-во)';
- end;
- CurrD := HeadDishes^.Next;
- while (CurrD <> nil) do
- begin
- UnitChangeLists.FormLists.AddDishToStrGrid(UnitChangeLists.FormLists.Dishes, CurrD);
- CurrD := CurrD^.Next;
- end;
- with UnitChangeLists.FormLists do
- begin
- Banquet.Cells[0, 0] := 'Код салата';
- Banquet.Cells[0, 1] := 'Количество';
- Banquet.Cells[0, 2] := 'Возможно?';
- end;
- CurrB := HeadBanquet^.Next;
- while (CurrB <> nil) do
- begin
- UnitChangeLists.FormLists.AddBanquetToStrGrid(UnitChangeLists.FormLists.Banquet, CurrB);
- CurrB := CurrB^.Next;
- end;
- UnitChangeLists.FormLists.ShowModal;
- end;
- procedure TFormMenu.Button8Click(Sender: TObject);
- begin
- if (UnitChangeLists.FormLists.Ingredients.RowCount > 1) and
- (UnitChangeLists.FormLists.Dishes.RowCount > 1) and
- (UnitChangeLists.FormLists.Banquet.ColCount > 1) then
- begin
- with UnitSpecialFunction.FormSpecialFunction do
- begin
- IngredientsCount.RowCount := UnitChangeLists.FormLists.Ingredients.RowCount;
- IngredientsCount.Cols[0] := UnitChangeLists.FormLists.Ingredients.Cols[0];
- IngredientsCount.FixedRows := 0;
- IngredientsCount.Cells[1, 0] := 'Кол-во';
- GoodDishes.Cells[0, 0] := 'Салат';
- GoodDishes.Cells[1, 0] := 'БЖУ';
- ChangeDishes.Cells[0, 0] := 'Ингр.';
- ChangeDishes.Cells[1, 0] := 'Салат';
- ChangeDishes.Cells[2, 0] := 'Сколько';
- ShowModal;
- end;
- end;
- end;
- procedure SaveDishesToFile(Head: TPElemDish; path: String);
- var
- F: File of TPDish;
- Temp: TPElemDish;
- Writed: TPDish;
- begin
- AssignFile(F, Path);
- Rewrite(F);
- Temp := Head^.Next;
- while (Temp <> nil) do
- begin
- Writed.Code := Temp^.Code;
- Writed.Name := Temp^.Name;
- Writed.Ingr := Temp^.Ingr;
- write(F, Writed);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure SaveIngredientsToFile(Head: TPElemIngredient; path: String);
- var
- F: File of TPIngredient;
- Temp: TPElemIngredient;
- Writed: TPIngredient;
- begin
- AssignFile(F, Path);
- Rewrite(F);
- Temp := Head^.Next;
- while (Temp <> nil) do
- begin
- Writed.Code := Temp^.Code;
- Writed.Name := Temp^.Name;
- Writed.ProteinCount := Temp^.ProteinCount;
- Writed.FatCount := Temp^.FatCount;
- Writed.CarbohydrateCount := Temp^.FatCount;
- Writed.ChangeCode := Temp^.ChangeCode;
- write(F, Writed);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure SaveBanquetToFile(Head: TPElemBanquet; path: String);
- var
- F: File of TPBanquet;
- Temp: TPElemBanquet;
- Writed: TPBanquet;
- begin
- AssignFile(F, Path);
- Rewrite(F);
- Temp := Head^.Next;
- while (Temp <> nil) do
- begin
- Writed.Code := Temp^.Code;
- Writed.Count := Temp^.Count;
- Writed.CanCook := Temp^.CanCook;
- write(F, Writed);
- Temp := Temp^.Next;
- end;
- CloseFile(F);
- end;
- procedure TFormMenu.Button9Click(Sender: TObject);
- var
- IsCorrect: Boolean;
- begin
- IsCorrect := true;
- try
- SaveDishesToFile(HeadDishes, FileDishes);
- SaveIngredientsToFile(HeadIngredients, FileIngr);
- SaveBanquetToFile(HeadBanquet, FileB);
- except
- Button9.Enabled := false;
- IsCorrect := false;
- end;
- if (IsCorrect) then
- begin
- FormMenu.Close;
- end;
- end;
- procedure TFormMenu.FormCreate(Sender: TObject);
- begin
- New(HeadDishes);
- New(HeadIngredients);
- New(HeadBanquet);
- HeadDishes^.Next := nil;
- HeadIngredients^.Next := nil;
- HeadBanquet^.Next := nil;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement