Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitDish;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids;
- type
- TFormDish = class(TForm)
- Edit1: TEdit;
- Edit2: TEdit;
- Code: TLabel;
- Name: TLabel;
- ButtonAdd: TButton;
- Ingr: TStringGrid;
- Button1: TButton;
- ComboBox: TComboBox;
- LabelError: TLabel;
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure Button1Click(Sender: TObject);
- procedure IngrKeyPress(Sender: TObject; var Key: Char);
- procedure IngrSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- procedure Edit1Change(Sender: TObject);
- procedure Edit2Change(Sender: TObject);
- procedure ButtonAddClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormDish: TFormDish;
- implementation
- {$R *.dfm}
- procedure TFormDish.Button1Click(Sender: TObject);
- var
- I: Integer;
- CanAdd: Boolean;
- begin
- if Ingr.RowCount > 6 then
- begin
- CanAdd := false;
- end
- else
- begin
- CanAdd := true;
- end;
- if (CanAdd) and (ComboBox.Items[ComboBox.ItemIndex] <> '') then
- begin
- I := 1;
- while (I < (Ingr.RowCount)) and (CanAdd) do
- begin
- if Ingr.Cells[0, I] = ComboBox.Items[ComboBox.ItemIndex] then
- begin
- CanAdd := false;
- end;
- Inc(I);
- end;
- if (CanAdd) then
- begin
- Ingr.RowCount := Ingr.RowCount + 1;
- Ingr.Cells[0, Ingr.RowCount - 1] := ComboBox.Items[ComboBox.ItemIndex];
- end;
- end;
- if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1)
- and (Ingr.RowCount < 7) then
- begin
- ButtonAdd.Enabled := true;
- LabelError.Visible := false;
- end
- else
- begin
- ButtonAdd.Enabled := false;
- end;
- end;
- procedure TFormDish.ButtonAddClick(Sender: TObject);
- var
- I: Integer;
- IsEmpty: Boolean;
- begin
- I := 1;
- IsEmpty := false;
- while (I < Ingr.RowCount) and not(IsEmpty) do
- begin
- if Ingr.Cells[1, I] = '' then
- begin
- IsEmpty := true;
- end;
- Inc(I);
- end;
- if not(IsEmpty) then
- begin
- LabelError.Visible := false;
- ModalResult := mrOk;
- end
- else
- begin
- LabelError.Visible := true;
- end;
- end;
- procedure TFormDish.Edit1Change(Sender: TObject);
- begin
- if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1) then
- begin
- ButtonAdd.Enabled := true;
- LabelError.Visible := false;
- end
- else
- begin
- ButtonAdd.Enabled := false;
- end;
- end;
- procedure TFormDish.Edit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if not(Key in ['0'..'9', #8]) then
- Key := #0;
- end;
- procedure TFormDish.Edit2Change(Sender: TObject);
- begin
- if (Length(Edit1.Text) = 3) and (Edit2.Text <> '') and (Ingr.RowCount > 1) then
- begin
- ButtonAdd.Enabled := true;
- LabelError.Visible := false;
- end
- else
- begin
- ButtonAdd.Enabled := false;
- end;
- end;
- procedure TFormDish.IngrKeyPress(Sender: TObject; var Key: Char);
- begin
- if not(Key in ['0'..'9', #8]) then
- Key := #0;
- if (Length(Ingr.Cells[Ingr.Col, Ingr.Row]) = 0) and (Key = '0') then
- Key := #0;
- if (Length(Ingr.Cells[Ingr.Col, Ingr.Row]) = 2) and not(Key = #8) then
- Key := #0;
- end;
- procedure TFormDish.IngrSelectCell(Sender: TObject; ACol, ARow: Integer;
- var CanSelect: Boolean);
- begin
- if (ARow = 0) or (ACol = 0) then
- CanSelect := false;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement