unit Unit14;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DBGridEhGrouping, ToolCtrlsEh,
  DBGridEhToolCtrls, DynVarsEh, Data.DB, EhLibVCL, GridsEh, DBAxisGridsEh,
  DBGridEh, Vcl.ComCtrls, Vcl.ToolWin, Vcl.ExtCtrls;

type
  TfBrand = class(TForm)
    pTop: TPanel;
    tbMain: TToolBar;
    tbAdd: TToolButton;
    tbEdit: TToolButton;
    tbDelete: TToolButton;
    DBGridEh1: TDBGridEh;
    dsBrand: TDataSource;
    procedure tbDeleteClick(Sender: TObject);
    procedure tbEditClick(Sender: TObject);
    procedure tbAddClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fBrand: TfBrand;

implementation

{$R *.dfm}

uses Unit2, Unit15;

procedure TfBrand.tbAddClick(Sender: TObject);
begin
  DM.tBrand.Append;
  if fBrandEdit.ShowModal = mrOk then begin
    if DM.tBrand.Modified then
      DM.tBrand.Post;
   end;
   DM.tBrand.Cancel;
   DM.tBrand.Requery();
   DM.tBrand.Last;
end;

procedure TfBrand.tbDeleteClick(Sender: TObject);
begin
  if Application.MessageBox('Удалить запись?', 'Подтверждение', MB_ICONQUESTION+MB_YESNO) = idYes then
    DM.tBrand.Delete;
end;

procedure TfBrand.tbEditClick(Sender: TObject);
  var
    id:integer;
begin
  id := DM.tBrand.RecNo;
  DM.tBrand.Edit;
  if fBrandEdit.ShowModal = mrOk then begin
    if DM.tBrand.Modified then
      DM.tBrand.Post;
  end;
  DM.tBrand.Cancel;
  DM.tBrand.Requery();
  DM.tBrand.MoveBy(id-1);
end;

end.
