unit Unit10;

interface

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

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

var
  fDevType: TfDevType;

implementation

{$R *.dfm}

uses Unit2, Unit11;

procedure TfDevType.tbAddChildClick(Sender: TObject);
  var
     parent : integer;
begin
  parent := DM.tDevTypeid.AsInteger;
  DM.tDevType.Append;
  DM.tDevTypeparent_id.AsInteger := parent;
  if fDevTypeEdit.ShowModal = mrOk then begin
    if DM.tDevType.Modified then
      DM.tDevType.Post;
   end;
   DM.tDevType.Cancel;
   DM.tDevType.Requery();
   DM.tDevType.Last;
end;

procedure TfDevType.tbAddClick(Sender: TObject);
begin
  DM.tDevType.Append;
  if fDevTypeEdit.ShowModal = mrOk then begin
    if DM.tDevType.Modified then
      DM.tDevType.Post;
   end;
   DM.tDevType.Cancel;
   DM.tDevType.Requery();
   DM.tDevType.Last;
end;

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

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

end.
