Advertisement
ksyshshot

упозн 1

Jun 1st, 2023 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 17.18 KB | Source Code | 0 0
  1. unit UnitMain;
  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.StdCtrls, Vcl.Menus;
  8.  
  9. type
  10.   TPElemDish = ^TPDish;
  11.   TContent = record
  12.     Code: Integer;
  13.     Count: Integer;
  14.   end;
  15.   TIngrArr = Array[0..4] of TContent;
  16.   TPDish = record
  17.     Code: Integer;
  18.     Name: String[20];
  19.     Ingr: TIngrArr;
  20.     Next: TPElemDish;
  21.   end;
  22.   TPElemIngredient = ^TPIngredient;
  23.   TPIngredient = record
  24.     Code: Integer;
  25.     Name: String[20];
  26.     ProteinCount: Integer;
  27.     FatCount: Integer;
  28.     CarbohydrateCount: Integer;
  29.     ChangeCode: Integer;
  30.     Next: TPElemIngredient;
  31.   end;
  32.   TPElemBanquet = ^TPBanquet;
  33.   TPBanquet = record
  34.     Code: Integer;
  35.     Count: Integer;
  36.     CanCook: Boolean;
  37.     Next: TPElemBanquet;
  38.   end;
  39.   TFormMenu = class(TForm)
  40.     LabelMenu: TLabel;
  41.     Button1: TButton;
  42.     Button4: TButton;
  43.     Button7: TButton;
  44.     Button8: TButton;
  45.     Button9: TButton;
  46.     Button10: TButton;
  47.     procedure Button10Click(Sender: TObject);
  48.     procedure FormCreate(Sender: TObject);
  49.     procedure Button1Click(Sender: TObject);
  50.     procedure Button7Click(Sender: TObject);
  51.     procedure Button9Click(Sender: TObject);
  52.     procedure DeleteDish(Code: Integer);
  53.     procedure DeleteIngredient(Code: Integer);
  54.     procedure DeleteBanquet(Code: Integer);
  55.     function GetArrDish(Code: Integer; Arr: TIngrArr): Boolean;
  56.     procedure AddDish(var Prev: TPElemDish; Code: Integer; Name: String; Ingr: TIngrArr);
  57.     procedure AddIngredient(var Prev: TPElemIngredient; Code, Protein,
  58.       Fat, Car, ChCode: Integer; Name: String);
  59.     procedure AddBanquet(var Prev: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
  60.     function SearchIngredient(var SearchFor: TPElemIngredient; Code: Integer): Boolean;
  61.     procedure ChangeIngredient(var Curr: TPELemIngredient; Name: String; Protein, Fat, Car, Change: Integer);
  62.     function SearchDish(var SearchFor: TPElemDish; Code: Integer): Boolean;
  63.     procedure ChangeDish(var Curr: TPElemDish; Name: String; Ingr: TIngrArr);
  64.     function SearchBanquet(var SearchFor: TPElemBanquet; Code: Integer): Boolean;
  65.     procedure ChangeBanquet(var Curr: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
  66.     procedure Button8Click(Sender: TObject);
  67.     procedure Button4Click(Sender: TObject);
  68.   private
  69.     { Private declarations }
  70.   public
  71.  
  72.   end;
  73.  
  74. var
  75.   FormMenu: TFormMenu;
  76.   HeadDishes, CurrDish: TPElemDish;
  77.   HeadIngredients, CurrIngredient: TPElemIngredient;
  78.   HeadBanquet, CurrBanquet: TPElemBanquet;
  79.  
  80. implementation
  81.  
  82. {$R *.dfm}
  83.  
  84. uses UnitChangeLists, UnitSpecialFunction, UnitSearch;
  85.  
  86. const
  87.     FileDishes = 'Dishes.rcd';
  88.     FileIngr = 'Ingr.rcd';
  89.     FileB = 'Banquet.rcd';
  90.  
  91. function TFormMenu.GetArrDish(Code: Integer; Arr: TIngrArr): Boolean;
  92. var
  93.     Curr: TPElemDish;
  94. begin
  95.     Curr := HeadDishes^.Next;
  96.     while (Curr.Code = Code) or (Curr = nil) do
  97.     begin
  98.         Curr := Curr^.Next;
  99.     end;
  100.     if Curr = nil then
  101.     begin
  102.         GetArrDish := false;
  103.     end
  104.     else
  105.     begin
  106.         Arr := Curr.Ingr;
  107.         GetArrDish := true;
  108.     end;
  109. end;
  110.  
  111. procedure TFormMenu.DeleteDish(Code: Integer);
  112. var
  113.     Curr: TPElemDish;
  114.     IsDeleted: Boolean;
  115. begin
  116.     Curr := HeadDishes;
  117.     IsDeleted := false;
  118.     while not(IsDeleted) or not(Curr^.Next = nil) do
  119.     begin
  120.         if Curr^.Next^.Code = Code then
  121.         begin
  122.             if Curr^.Next = CurrDish then
  123.             begin
  124.                 IsDeleted := true;
  125.                 if Curr = HeadDishes then
  126.                 begin
  127.                     CurrDish := nil;
  128.                     HeadDishes^.Next := CurrDish;
  129.                 end
  130.                 else
  131.                 begin
  132.                     Curr^.Next := nil;
  133.                     CurrDish := Curr;
  134.                 end;
  135.             end
  136.             else
  137.             begin
  138.                 Curr^.Next := Curr^.Next^.Next;
  139.                 IsDeleted := true;
  140.             end;
  141.         end
  142.         else
  143.         begin
  144.             Curr := Curr^.Next;
  145.         end;
  146.     end;
  147. end;
  148.  
  149. procedure TFormMenu.DeleteIngredient(Code: Integer);
  150. var
  151.     Curr: TPElemIngredient;
  152.     IsDeleted: Boolean;
  153. begin
  154.     Curr := HeadIngredients;
  155.     IsDeleted := false;
  156.     while not(IsDeleted) or not(Curr^.Next = nil) do
  157.     begin
  158.         if Curr^.Next^.Code = Code then
  159.         begin
  160.             if Curr^.Next = CurrIngredient then
  161.             begin
  162.                 IsDeleted := true;
  163.                 if Curr = HeadIngredients then
  164.                 begin
  165.                     CurrIngredient := nil;
  166.                     HeadIngredients^.Next := CurrIngredient;
  167.                 end
  168.                 else
  169.                 begin
  170.                     Curr^.Next := nil;
  171.                     CurrIngredient := Curr;
  172.                 end;
  173.             end
  174.             else
  175.             begin
  176.                 Curr^.Next := Curr^.Next^.Next;
  177.                 IsDeleted := true;
  178.             end;
  179.         end
  180.         else
  181.         begin
  182.             Curr := Curr^.Next;
  183.         end;
  184.     end;
  185. end;
  186.  
  187. procedure TFormMenu.DeleteBanquet(Code: Integer);
  188. var
  189.     Curr: TPElemBanquet;
  190.     IsDeleted: Boolean;
  191. begin
  192.     Curr := HeadBanquet;
  193.     IsDeleted := false;
  194.     while not(IsDeleted) or not(Curr^.Next = nil) do
  195.     begin
  196.         if Curr^.Next^.Code = Code then
  197.         begin
  198.             if Curr^.Next = CurrBanquet then
  199.             begin
  200.                 IsDeleted := true;
  201.                 if Curr = HeadBanquet then
  202.                 begin
  203.                     CurrBanquet := nil;
  204.                     HeadBanquet^.Next := CurrBanquet;
  205.                 end
  206.                 else
  207.                 begin
  208.                     Curr^.Next := nil;
  209.                     CurrBanquet := Curr;
  210.                 end;
  211.             end
  212.             else
  213.             begin
  214.                 Curr^.Next := Curr^.Next^.Next;
  215.                 IsDeleted := true;
  216.             end;
  217.         end
  218.         else
  219.         begin
  220.             Curr := Curr^.Next;
  221.         end;
  222.     end;
  223. end;
  224.  
  225. procedure TFormMenu.AddDish(var Prev: TPElemDish; Code: Integer; Name: String; Ingr: TIngrArr);
  226. var
  227.     Temp: TPElemDish;
  228. begin
  229.     New(Temp);
  230.     Temp^.Code := Code;
  231.     Temp^.Name := Name;
  232.     Temp^.Ingr := Ingr;
  233.     Temp^.Next := nil;
  234.     if Prev = nil then
  235.     begin
  236.         Prev := Temp;
  237.         CurrDish := Temp;
  238.         HeadDishes^.Next := Temp;
  239.     end
  240.     else
  241.     begin
  242.         Prev^.Next := Temp;
  243.         CurrDish := Temp;
  244.     end;
  245. end;
  246.  
  247. procedure TFormMenu.AddIngredient(var Prev: TPElemIngredient; Code, Protein,
  248.   Fat, Car, ChCode: Integer; Name: String);
  249. var
  250.     Temp: TPElemIngredient;
  251. begin
  252.     New(Temp);
  253.     Temp^.Code := Code;
  254.     Temp^.Name := Name;
  255.     Temp^.ProteinCount := Protein;
  256.     Temp^.FatCount := Fat;
  257.     Temp^.CarbohydrateCount := Car;
  258.     Temp^.ChangeCode := ChCode;
  259.     Temp^.Next := nil;
  260.     if Prev = nil then
  261.     begin
  262.         Prev := Temp;
  263.         CurrIngredient := Temp;
  264.         HeadIngredients^.Next := Temp;
  265.     end
  266.     else
  267.     begin
  268.         Prev^.Next := Temp;
  269.         CurrIngredient := Temp;
  270.     end;
  271. end;
  272.  
  273. procedure TFormMenu.AddBanquet(var Prev: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
  274. var
  275.     Temp: TPElemBanquet;
  276. begin
  277.     New(Temp);
  278.     Temp^.Code := Code;
  279.     Temp^.Count := Count;
  280.     Temp^.CanCook := CanCook;
  281.     Temp^.Next := nil;
  282.     if Prev = nil then
  283.     begin
  284.         Prev := Temp;
  285.         CurrBanquet := Temp;
  286.         HeadBanquet^.Next := Temp;
  287.     end
  288.     else
  289.     begin
  290.         Prev^.Next := Temp;
  291.         CurrBanquet := Temp;
  292.     end;
  293. end;
  294.  
  295. function TFormMenu.SearchDish(var SearchFor: TPElemDish; Code: Integer): Boolean;
  296. var
  297.     Curr: TPElemDish;
  298.     IsFound: Boolean;
  299. begin
  300.     IsFound := false;
  301.     Curr := HeadDishes^.Next;
  302.     while (Curr <> nil) and not(IsFound) do
  303.     begin
  304.         if Curr^.Code = Code then
  305.         begin
  306.             SearchFor := Curr;
  307.             IsFound := true;
  308.         end
  309.         else
  310.         begin
  311.             Curr := Curr^.Next;
  312.         end;
  313.     end;
  314.     SearchDish := IsFound;
  315. end;
  316.  
  317. function TFormMenu.SearchIngredient(var SearchFor: TPElemIngredient; Code: Integer): Boolean;
  318. var
  319.     Curr: TPElemIngredient;
  320.     IsFound: Boolean;
  321. begin
  322.     IsFound := false;
  323.     Curr := HeadIngredients^.Next;
  324.     while (Curr <> nil) and not(IsFound) do
  325.     begin
  326.         if Curr^.Code = Code then
  327.         begin
  328.             SearchFor := Curr;
  329.             IsFound := true;
  330.         end
  331.         else
  332.         begin
  333.             Curr := Curr^.Next;
  334.         end;
  335.     end;
  336.     SearchIngredient := IsFound;
  337. end;
  338.  
  339. function TFormMenu.SearchBanquet(var SearchFor: TPElemBanquet; Code: Integer): Boolean;
  340. var
  341.     Curr: TPElemBanquet;
  342.     IsFound: Boolean;
  343. begin
  344.     IsFound := false;
  345.     Curr := HeadBanquet^.Next;
  346.     while (Curr <> nil) and not(IsFound) do
  347.     begin
  348.         if Curr^.Code = Code then
  349.         begin
  350.             SearchFor := Curr;
  351.             IsFound := true;
  352.         end
  353.         else
  354.         begin
  355.             Curr := Curr^.Next;
  356.         end;
  357.     end;
  358.     SearchBanquet := IsFound;
  359. end;
  360.  
  361. procedure TFormMenu.ChangeDish(var Curr: TPElemDish; Name: String; Ingr: TIngrArr);
  362. begin
  363.     Curr^.Name := Name;
  364.     Curr^.Ingr := Ingr;
  365. end;
  366.  
  367. procedure TFormMenu.ChangeIngredient(var Curr: TPELemIngredient; Name: String; Protein, Fat, Car, Change: Integer);
  368. begin
  369.     Curr^.Name := Name;
  370.     Curr^.ProteinCount := Protein;
  371.     Curr^.FatCount := Fat;
  372.     Curr^.CarbohydrateCount := Car;
  373.     Curr^.ChangeCode := Change;
  374. end;
  375.  
  376. procedure TFormMenu.ChangeBanquet(var Curr: TPElemBanquet; Code: Integer; Count: Integer; CanCook: Boolean);
  377. begin
  378.     Curr^.Code := Code;
  379.     Curr^.Count := Count;
  380.     Curr^.CanCook := CanCook;
  381. end;
  382.  
  383. procedure GetListDishFromFile(var Head: TPElemDish; path: String);
  384. var
  385.     F: File of TPDish;
  386.     Temp: TPElemDish;
  387.     Dish: TPDish;
  388. begin
  389.     AssignFile(F, path);
  390.     Reset(F);
  391.     Seek(F, 0);
  392.     if Head^.Next <> nil then
  393.         Temp := CurrDish
  394.     else
  395.     begin
  396.         New(CurrDish);
  397.         Temp := Head;
  398.     end;
  399.     while not(EoF(F)) do
  400.     begin
  401.         Read(F, Dish);
  402.         FormMenu.AddDish(Temp, Dish.Code, Dish.Name, Dish.Ingr);
  403.         Temp := Temp^.Next;
  404.     end;
  405.     CloseFile(F);
  406. end;
  407.  
  408. procedure GetListIngredientFromFile(var Head: TPElemIngredient; path: String);
  409. var
  410.     F: File of TPIngredient;
  411.     Temp: TPElemIngredient;
  412.     Dish: TPIngredient;
  413. begin
  414.     AssignFile(F, path);
  415.     Reset(F);
  416.     Seek(F, 0);
  417.     if Head^.Next <> nil then
  418.         Temp := CurrIngredient
  419.     else
  420.     begin
  421.         New(CurrIngredient);
  422.         Temp := Head;
  423.     end;
  424.     while not(EoF(F)) do
  425.     begin
  426.         Read(F, Dish);
  427.         FormMenu.AddIngredient(Temp, Dish.Code, Dish.ProteinCount,
  428.         Dish.FatCount, Dish.CarbohydrateCount, Dish.ChangeCode, Dish.Name);
  429.         Temp := Temp^.Next;
  430.     end;
  431.     CloseFile(F);
  432. end;
  433.  
  434. procedure GetListBanquetFromFile(var Head: TPElemBanquet; path: String);
  435. var
  436.     F: File of TPBanquet;
  437.     Temp: TPElemBanquet;
  438.     Dish: TPBanquet;
  439. begin
  440.     AssignFile(F, path);
  441.     Reset(F);
  442.     Seek(F, 0);
  443.     if Head^.Next <> nil then
  444.         Temp := CurrBanquet
  445.     else
  446.     begin
  447.         New(CurrBanquet);
  448.         Temp := Head;
  449.     end;
  450.     while not(EoF(F)) do
  451.     begin
  452.         Read(F, Dish);
  453.         FormMenu.AddBanquet(Temp, Dish.Code, Dish.Count, Dish.CanCook);
  454.         Temp := Temp^.Next;
  455.     end;
  456.     CloseFile(F);
  457. end;
  458.  
  459. procedure TFormMenu.Button10Click(Sender: TObject);
  460. begin
  461.     FormMenu.Close;
  462. end;
  463.  
  464. procedure TFormMenu.Button1Click(Sender: TObject);
  465. begin
  466.     try
  467.         GetListDishFromFile(HeadDishes, FileDishes);
  468.         GetListIngredientFromFile(HeadIngredients, FileIngr);
  469.         GetListBanquetFromFile(HeadBanquet, FileB);
  470.     finally
  471.         Button1.Enabled := false;
  472.         Button7Click(Sender);
  473.     end;
  474. end;
  475.  
  476. procedure TFormMenu.Button4Click(Sender: TObject);
  477. var
  478.     Curr: TPElemIngredient;
  479. begin
  480.     Curr := HeadIngredients^.Next;
  481.     with UnitSearch.FormSearch do
  482.     begin
  483.         ComboBox.Items.Clear;
  484.         SearchedList.Items.Clear;
  485.         while Curr <> nil do
  486.         begin
  487.             ComboBox.Items.Add(IntToStr(Curr^.Code));
  488.             Curr := Curr^.Next;
  489.         end;
  490.         ShowModal;
  491.     end;
  492.  
  493. end;
  494.  
  495. procedure TFormMenu.Button7Click(Sender: TObject);
  496. var
  497.     CurrI: TPElemIngredient;
  498.     CurrD: TPElemDish;
  499.     CurrB: TPElemBanquet;
  500. begin
  501.     UnitChangeLists.FormLists.Ingredients.RowCount := 1;
  502.     UnitChangeLists.FormLists.Dishes.RowCount := 1;
  503.     UnitChangeLists.FormLists.Banquet.ColCount := 1;
  504.     with UnitChangeLists.FormLists do
  505.     begin
  506.         Ingredients.Cells[0, 0] := 'Код';
  507.         Ingredients.Cells[1, 0] := 'Название';
  508.         Ingredients.Cells[2, 0] := 'Белки';
  509.         Ingredients.Cells[3, 0] := 'Жиры';
  510.         Ingredients.Cells[4, 0] := 'Углеводы';
  511.         Ingredients.Cells[5, 0] := 'Замена';
  512.     end;
  513.     CurrI := HeadIngredients^.Next;
  514.     while (CurrI <> nil) do
  515.     begin
  516.         UnitChangeLists.FormLists.AddIngrToStrGrid(UnitChangeLists.FormLists.Ingredients, CurrI);
  517.         CurrI := CurrI^.Next;
  518.     end;
  519.     with UnitChangeLists.FormLists do
  520.     begin
  521.         Dishes.Cells[0, 0] := 'Код';
  522.         Dishes.Cells[1, 0] := 'Название';
  523.         Dishes.Cells[2, 0] := 'Ингредиенты: код(кол-во)';
  524.     end;
  525.     CurrD := HeadDishes^.Next;
  526.     while (CurrD <> nil) do
  527.     begin
  528.         UnitChangeLists.FormLists.AddDishToStrGrid(UnitChangeLists.FormLists.Dishes, CurrD);
  529.         CurrD := CurrD^.Next;
  530.     end;
  531.     with UnitChangeLists.FormLists do
  532.     begin
  533.         Banquet.Cells[0, 0] := 'Код салата';
  534.         Banquet.Cells[0, 1] := 'Количество';
  535.         Banquet.Cells[0, 2] := 'Возможно?';
  536.     end;
  537.     CurrB := HeadBanquet^.Next;
  538.     while (CurrB <> nil) do
  539.     begin
  540.         UnitChangeLists.FormLists.AddBanquetToStrGrid(UnitChangeLists.FormLists.Banquet, CurrB);
  541.         CurrB := CurrB^.Next;
  542.     end;
  543.     UnitChangeLists.FormLists.ShowModal;
  544. end;
  545.  
  546. procedure TFormMenu.Button8Click(Sender: TObject);
  547. begin
  548.     if (UnitChangeLists.FormLists.Ingredients.RowCount > 1) and
  549.       (UnitChangeLists.FormLists.Dishes.RowCount > 1) and
  550.       (UnitChangeLists.FormLists.Banquet.ColCount > 1) then
  551.     begin
  552.         with UnitSpecialFunction.FormSpecialFunction do
  553.         begin
  554.             IngredientsCount.RowCount := UnitChangeLists.FormLists.Ingredients.RowCount;
  555.             IngredientsCount.Cols[0] := UnitChangeLists.FormLists.Ingredients.Cols[0];
  556.             IngredientsCount.FixedRows := 0;
  557.             IngredientsCount.Cells[1, 0] := 'Кол-во';
  558.             GoodDishes.Cells[0, 0] := 'Салат';
  559.             GoodDishes.Cells[1, 0] := 'БЖУ';
  560.             ChangeDishes.Cells[0, 0] := 'Ингр.';
  561.             ChangeDishes.Cells[1, 0] := 'Салат';
  562.             ChangeDishes.Cells[2, 0] := 'Сколько';
  563.             ShowModal;
  564.         end;
  565.     end;
  566. end;
  567.  
  568. procedure SaveDishesToFile(Head: TPElemDish; path: String);
  569. var
  570.     F: File of TPDish;
  571.     Temp: TPElemDish;
  572.     Writed: TPDish;
  573. begin
  574.     AssignFile(F, Path);
  575.     Rewrite(F);
  576.     Temp := Head^.Next;
  577.     while (Temp <> nil) do
  578.     begin
  579.         Writed.Code := Temp^.Code;
  580.         Writed.Name := Temp^.Name;
  581.         Writed.Ingr := Temp^.Ingr;
  582.         write(F, Writed);
  583.         Temp := Temp^.Next;
  584.     end;
  585.     CloseFile(F);
  586. end;
  587.  
  588. procedure SaveIngredientsToFile(Head: TPElemIngredient; path: String);
  589. var
  590.     F: File of TPIngredient;
  591.     Temp: TPElemIngredient;
  592.     Writed: TPIngredient;
  593. begin
  594.     AssignFile(F, Path);
  595.     Rewrite(F);
  596.     Temp := Head^.Next;
  597.     while (Temp <> nil) do
  598.     begin
  599.         Writed.Code := Temp^.Code;
  600.         Writed.Name := Temp^.Name;
  601.         Writed.ProteinCount := Temp^.ProteinCount;
  602.         Writed.FatCount := Temp^.FatCount;
  603.         Writed.CarbohydrateCount := Temp^.FatCount;
  604.         Writed.ChangeCode := Temp^.ChangeCode;
  605.         write(F, Writed);
  606.         Temp := Temp^.Next;
  607.     end;
  608.     CloseFile(F);
  609. end;
  610.  
  611. procedure SaveBanquetToFile(Head: TPElemBanquet; path: String);
  612. var
  613.     F: File of TPBanquet;
  614.     Temp: TPElemBanquet;
  615.     Writed: TPBanquet;
  616. begin
  617.     AssignFile(F, Path);
  618.     Rewrite(F);
  619.     Temp := Head^.Next;
  620.     while (Temp <> nil) do
  621.     begin
  622.         Writed.Code := Temp^.Code;
  623.         Writed.Count := Temp^.Count;
  624.         Writed.CanCook := Temp^.CanCook;
  625.         write(F, Writed);
  626.         Temp := Temp^.Next;
  627.     end;
  628.     CloseFile(F);
  629. end;
  630.  
  631. procedure TFormMenu.Button9Click(Sender: TObject);
  632. var
  633.     IsCorrect: Boolean;
  634. begin
  635.     IsCorrect := true;
  636.     try
  637.         SaveDishesToFile(HeadDishes, FileDishes);
  638.         SaveIngredientsToFile(HeadIngredients, FileIngr);
  639.         SaveBanquetToFile(HeadBanquet, FileB);
  640.     except
  641.         Button9.Enabled := false;
  642.         IsCorrect := false;
  643.     end;
  644.     if (IsCorrect) then
  645.     begin
  646.         FormMenu.Close;
  647.     end;
  648. end;
  649.  
  650. procedure TFormMenu.FormCreate(Sender: TObject);
  651. begin
  652.     New(HeadDishes);
  653.     New(HeadIngredients);
  654.     New(HeadBanquet);
  655.     HeadDishes^.Next := nil;
  656.     HeadIngredients^.Next := nil;
  657.     HeadBanquet^.Next := nil;
  658. end;
  659.  
  660. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement