unit CadTipoConta;

interface

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

type
  TfrmCadTipoConta = class(TFrModeloCadastro)
    GroupBox2: TGroupBox;
    dbCodigo: TIB_Text;
    edtDescricao: TIB_Edit;
    IB_RadioGroup1: TIB_RadioGroup;
    qrPlanoConta: TIB_Query;
    dsrPlanoConta: TIB_DataSource;
    edtCodPlanoConta: TEdit;
    edtPlanoConta: TIB_LookupCombo;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    procedure FormCreate(Sender: TObject);
    procedure BtGravarClick(Sender: TObject);
    procedure BtInserirClick(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure BtCancelarClick(Sender: TObject);
    procedure BtAnteriorClick(Sender: TObject);
    procedure BtProximoClick(Sender: TObject);
    procedure BtExcluirClick(Sender: TObject);
    procedure BtEditarClick(Sender: TObject);
  private
    { Private declarations }
    procedure Atualiza_Tela;
  public
    { Public declarations }
  end;

var
  frmCadTipoConta: TfrmCadTipoConta;

implementation

uses Math, ModeloPesquisa, Rotinas;

{$R *.dfm}

procedure TfrmCadTipoConta.FormCreate(Sender: TObject);
begin
   Gera_Codigo := True;
   inherited;

   InicioDaTabela(qrPlanoConta);

end;

procedure TfrmCadTipoConta.Atualiza_Tela;
begin
   if not  qrPlanoConta.Locate('COD_PLANO_CONTA' , TbPrincipal.FieldByName('COD_PLANO_CONTA').Value  ,  [] ) then
      InicioDaTabela(qrPlanoConta);
end;

procedure TfrmCadTipoConta.BtAnteriorClick(Sender: TObject);
begin
  inherited;
Atualiza_Tela
end;

procedure TfrmCadTipoConta.BtCancelarClick(Sender: TObject);
begin
  inherited;
  Atualiza_Tela;
end;

procedure TfrmCadTipoConta.BtEditarClick(Sender: TObject);
begin
  inherited;
Atualiza_Tela
end;

procedure TfrmCadTipoConta.BtExcluirClick(Sender: TObject);
begin
  inherited;
  Atualiza_Tela
end;

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

   if edtPlanoConta.Text  <> '' then
      TbPrincipal.FieldByName('COD_PLANO_CONTA').Value := qrPlanoConta.FieldByName('COD_PLANO_CONTA').Value
   else
     TbPrincipal.FieldByName('COD_PLANO_CONTA').Value := NULL;

   inherited;

end;

procedure TfrmCadTipoConta.BtInserirClick(Sender: TObject);
begin
  inherited;
   TbPrincipal.FieldByName('TIPO').Value := 'D';
   Atualiza_Tela;
end;

procedure TfrmCadTipoConta.BtProximoClick(Sender: TObject);
begin
  inherited;
Atualiza_Tela
end;

procedure TfrmCadTipoConta.cxButton1Click(Sender: TObject);
begin
   frmModeloPesquisa        := TfrmModeloPesquisa.Create(Application);
   frmModeloPesquisa.Tabela := qrPlanoConta;
   frmModeloPesquisa.lblTitulo.Caption := 'Pesquisa Plano de Contas';
   if frmModeloPesquisa.ShowModal = mrOk then
      qrPlanoConta.Locate('COD_PLANO_CONTA' , frmModeloPesquisa.TbPrincipal.FieldByName('COD_PLANO_CONTA').Value , []);
   frmModeloPesquisa.Destroy;

   Screen.OnActiveControlChange := TrocaCor;


end;

procedure TfrmCadTipoConta.cxButton2Click(Sender: TObject);
var codigo : Integer;
begin
  inherited;
  codigo := SelecionarPlanoConta('');
  qrPlanoConta.Locate('cod_plano_conta', codigo , []);

end;

end.
