unit CadSetor;
                                        
interface

uses
  Windows, system.UItypes, IB_Access,  Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ModeloCadastro, Mask, IB_Controls, IB_Components, Grids,
  IB_Grid, StdCtrls, Buttons, ExtCtrls, ComCtrls, jpeg, AppEvnts, ImgList,
  UCBase, IB_EditButton, System.ImageList;

type
  TfrmCadSetor = class(TFrModeloCadastro)
    edtDescricao: TIB_Edit;
    GroupBox2: TGroupBox;
    dbCodigo: TIB_Text;
    procedure BtGravarClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtExcluirClick(Sender: TObject);
    procedure btnEditar2Click(Sender: TObject);
    procedure BtInserirClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCadSetor: TfrmCadSetor;

implementation

{$R *.dfm}

procedure TfrmCadSetor.BtGravarClick(Sender: TObject);
begin
   if edtDescricao.Text = '' then
   begin
      MessageDlg('Informe a descrição', mtWarning, [mbOK], 0);
      edtDescricao.SetFocus;
      Exit;
   end;

  if TbPrincipal.State in [dssInsert] then
     descricao_auditoria := 'CADASTROU O SETOR ' + TbPrincipal.FieldByName('COD_SETOR').AsString  + ' ' + TbPrincipal.FieldByName('DESCRICAO').AsString;

  if TbPrincipal.State in [dssEdit] then
     descricao_auditoria := 'ALTEROU O SETOR ' + TbPrincipal.FieldByName('COD_SETOR').OldAsString  + ' ' + TbPrincipal.FieldByName('DESCRICAO').OldAsString;

  inherited;

end;

procedure TfrmCadSetor.FormCreate(Sender: TObject);
begin
   Gera_Codigo      := True;
   Chave_Tabela     := 'COD_SETOR';
   Descricao_Unica  := True;
   Campo_Tabela     := 'DESCRICAO';
   inherited;
end;

procedure TfrmCadSetor.BtExcluirClick(Sender: TObject);
begin
   descricao_auditoria := 'EXCLUIU O SETOR ' + TbPrincipal.FieldByName('COD_SETOR').AsString + ' ' + TbPrincipal.FieldByName('DESCRICAO').AsString;
   inherited;
end;

procedure TfrmCadSetor.btnEditar2Click(Sender: TObject);
begin
   edtDescricao.SetFocus;
   inherited;

end;

procedure TfrmCadSetor.BtInserirClick(Sender: TObject);
begin
  inherited;
  try
     edtDescricao.SetFocus;
     except
  end;
end;

end.
