Advertisement
ksyshshot

упозн 5

Jun 1st, 2023
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.78 KB | Source Code | 0 0
  1. unit UnitDish;
  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.Grids;
  8.  
  9. type
  10.   TFormDish = class(TForm)
  11.     Edit1: TEdit;
  12.     Edit2: TEdit;
  13.     Code: TLabel;
  14.     Name: TLabel;
  15.     ButtonAdd: TButton;
  16.     Ingr: TStringGrid;
  17.     Button1: TButton;
  18.     ComboBox: TComboBox;
  19.     LabelError: TLabel;
  20.     procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  21.     procedure Button1Click(Sender: TObject);
  22.     procedure IngrKeyPress(Sender: TObject; var Key: Char);
  23.     procedure IngrSelectCell(Sender: TObject; ACol, ARow: Integer;
  24.       var CanSelect: Boolean);
  25.     procedure Edit1Change(Sender: TObject);
  26.     procedure Edit2Change(Sender: TObject);
  27.     procedure ButtonAddClick(Sender: TObject);
  28.   private
  29.     { Private declarations }
  30.   public
  31.     { Public declarations }
  32.   end;
  33.  
  34. var
  35.   FormDish: TFormDish;
  36.  
  37. implementation
  38.  
  39. {$R *.dfm}
  40.  
  41. procedure TFormDish.Button1Click(Sender: TObject);
  42. var
  43.     I: Integer;
  44.     CanAdd: Boolean;
  45. begin
  46.     if Ingr.RowCount > 6 then
  47.     begin
  48.         CanAdd := false;
  49.     end
  50.     else
  51.     begin
  52.         CanAdd := true;
  53.     end;
  54.     if (CanAdd) and (ComboBox.Items[ComboBox.ItemIndex] <> '') then
  55.     begin
  56.         I := 1;
  57.         while (I < (Ingr.RowCount)) and (CanAdd) do
  58.         begin
  59.             if Ingr.Cells[0, I] = ComboBox.Items[ComboBox.ItemIndex] then
  60.             begin
  61.                 CanAdd := false;
  62.             end;
  63.             Inc(I);
  64.         end;
  65.         if (CanAdd) then
  66.         begin
  67.             Ingr.RowCount := Ingr.RowCount + 1;
  68.             Ingr.Cells[0, Ingr.RowCount - 1] := ComboBox.Items[ComboBox.ItemIndex];
  69.         end;
  70.     end;
  71.     if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1)
  72.       and (Ingr.RowCount < 7) then
  73.     begin
  74.         ButtonAdd.Enabled := true;
  75.         LabelError.Visible := false;
  76.     end
  77.     else
  78.     begin
  79.         ButtonAdd.Enabled := false;
  80.     end;
  81. end;
  82.  
  83. procedure TFormDish.ButtonAddClick(Sender: TObject);
  84. var
  85.     I: Integer;
  86.     IsEmpty: Boolean;
  87. begin
  88.     I := 1;
  89.     IsEmpty := false;
  90.     while (I < Ingr.RowCount) and not(IsEmpty) do
  91.     begin
  92.         if Ingr.Cells[1, I] = '' then
  93.         begin
  94.             IsEmpty := true;
  95.         end;
  96.         Inc(I);
  97.     end;
  98.     if not(IsEmpty) then
  99.     begin
  100.         LabelError.Visible := false;
  101.         ModalResult := mrOk;
  102.     end
  103.     else
  104.     begin
  105.         LabelError.Visible := true;
  106.     end;
  107. end;
  108.  
  109. procedure TFormDish.Edit1Change(Sender: TObject);
  110. begin
  111.     if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1) then
  112.     begin
  113.         ButtonAdd.Enabled := true;
  114.         LabelError.Visible := false;
  115.     end
  116.     else
  117.     begin
  118.         ButtonAdd.Enabled := false;
  119.     end;
  120. end;
  121.  
  122. procedure TFormDish.Edit1KeyPress(Sender: TObject; var Key: Char);
  123. begin
  124.     if not(Key in ['0'..'9', #8]) then
  125.         Key := #0;
  126. end;
  127.  
  128. procedure TFormDish.Edit2Change(Sender: TObject);
  129. begin
  130.     if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1) then
  131.     begin
  132.         ButtonAdd.Enabled := true;
  133.         LabelError.Visible := false;
  134.     end
  135.     else
  136.     begin
  137.         ButtonAdd.Enabled := false;
  138.     end;
  139. end;
  140.  
  141. procedure TFormDish.IngrKeyPress(Sender: TObject; var Key: Char);
  142. begin
  143.     if not(Key in ['0'..'9', #8]) then
  144.         Key := #0;
  145.     if (Length(Ingr.Cells[Ingr.Col, Ingr.Row]) = 0) and (Key = '0') then
  146.         Key := #0;
  147.     if (Length(Ingr.Cells[Ingr.Col, Ingr.Row]) = 2) and not(Key = #8) then
  148.         Key := #0;
  149. end;
  150.  
  151. procedure TFormDish.IngrSelectCell(Sender: TObject; ACol, ARow: Integer;
  152.   var CanSelect: Boolean);
  153. begin
  154.     if (ARow = 0) or (ACol = 0) then
  155.         CanSelect := false;
  156. end;
  157.  
  158. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement