unit Unit6;

interface

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

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

var
  fFixPrice: TfFixPrice;

implementation

{$R *.dfm}

uses Unit2, Unit7;

procedure TfFixPrice.FormShow(Sender: TObject);
begin
  if DM.tDevType.Active then
     DM.tDevType.Close;
  DM.tDevType.Open;
end;

procedure TfFixPrice.tbAddClick(Sender: TObject);
begin
  DM.tFixPrice.Append;
  if fFixPriceEdit.ShowModal = mrOk then begin
    if DM.tFixPrice.Modified then
      DM.tFixPrice.Post;
   end;
   DM.tFixPrice.Cancel;
   DM.tFixPrice.Requery();
   DM.tFixPrice.Last;
end;

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

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

end.
