unit Unit16;

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
  TfClient = class(TForm)
    pTop: TPanel;
    tbMain: TToolBar;
    tbAdd: TToolButton;
    tbEdit: TToolButton;
    tbDelete: TToolButton;
    DBGridEh1: TDBGridEh;
    dsClient: TDataSource;
    procedure tbEditClick(Sender: TObject);
    procedure tbDeleteClick(Sender: TObject);
    procedure tbAddClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fClient: TfClient;

implementation

{$R *.dfm}

uses Unit2, Unit17;

procedure TfClient.tbAddClick(Sender: TObject);
begin
  DM.tClient.Append;
  if fClientEdit.ShowModal = mrOk then begin
    if DM.tClient.Modified then
      DM.tClient.Post;
   end;
   DM.tClient.Cancel;
   DM.tClient.Requery();
   DM.tClient.Last;
end;

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

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

end.
