unit Unpagar;

interface

uses
  Windows, Messages, SysUtils, variants, Classes, Graphics, Controls, Forms, Dialogs,
  ActnList, Db, DBTables, Mask, CLIPBRD, StdCtrls, Grids, DBGrids, Buttons, ToolWin,
  ComCtrls, ExtCtrls, DBCtrls;

type

THackDBGrid = class(TDBGrid);

  Tfpagar = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    ScrollBox: TScrollBox;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label36: TLabel;
    EditData_Vencimento: TDBEdit;
    EditValor_Titulo: TDBEdit;
    EditNumero_Pedido: TDBEdit;
    EditCartorio: TDBEdit;
    EditCod_FAT: TDBEdit;
    DBEdit3: TDBEdit;
    GroupBox4: TGroupBox;
    Label33: TLabel;
    Label32: TLabel;
    Label31: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    Label2: TLabel;
    Label30: TLabel;
    Label11: TLabel;
    EditDocParcela: TDBEdit;
    EditCod_Cliente: TDBEdit;
    EditData_Emissao: TDBEdit;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    Panel2: TPanel;
    ToolBar1: TToolBar;
    btnPrimeiro: TSpeedButton;
    btnVoltar: TSpeedButton;
    btnAvancar: TSpeedButton;
    btnUltimo: TSpeedButton;
    Panel6: TPanel;
    Panel4: TPanel;
    btnnovo: TSpeedButton;
    Panel7: TPanel;
    btngravar: TSpeedButton;
    btncancelar: TSpeedButton;
    Panel8: TPanel;
    Panel5: TPanel;
    SpeedButton5: TSpeedButton;
    Panel3: TPanel;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    Label29: TLabel;
    Edit1: TEdit;
    TabSheet2: TTabSheet;
    DBGrid2: TDBGrid;
    ToolBar2: TToolBar;
    GroupBox5: TGroupBox;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    Label34: TLabel;
    Label35: TLabel;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    Panel9: TPanel;
    ActionList1: TActionList;
    totalizar: TAction;
    DBEdit4: TDBEdit;
    Label37: TLabel;
    DBEdit5: TDBEdit;
    novo: TAction;
    avancar: TAction;
    voltar: TAction;
    foco: TAction;
    DBEdit6: TDBEdit;
    Label19: TLabel;
    MemoInstruc: TDBMemo;
    DBComboBox1: TDBComboBox;
    EditCod_Agencia: TDBEdit;
    Label13: TLabel;
    DBEdit8: TDBEdit;
    Bevel1: TBevel;
    DBEdit7: TDBEdit;
    Label12: TLabel;
    DBEdit9: TDBEdit;
    Label14: TLabel;
    preencherdornecedor: TAction;
    StatusBar1: TStatusBar;
    SpeedButton21: TSpeedButton;
    Panel10: TPanel;
    formatar: TAction;
    Label15: TLabel;
    DBComboBox2: TDBComboBox;
    SpeedButton7: TSpeedButton;
    ajuda: TAction;
    procedure PageControl1Change(Sender: TObject);
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnVoltarClick(Sender: TObject);
    procedure btnAvancarClick(Sender: TObject);
    procedure btnUltimoClick(Sender: TObject);
    procedure btnnovoClick(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
    procedure btncancelarClick(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Label11Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure tbpagarAfterScroll(DataSet: TDataSet);
    procedure tbpagarBeforeEdit(DataSet: TDataSet);
    procedure MaskEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure totalizarExecute(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure novoExecute(Sender: TObject);
    procedure EditDocParcelaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCod_ClienteKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure avancarExecute(Sender: TObject);
    procedure voltarExecute(Sender: TObject);
    procedure tbpagarAfterPost(DataSet: TDataSet);
    procedure focoExecute(Sender: TObject);
    procedure MaskEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure DBEdit4Change(Sender: TObject);
    procedure EditCartorioExit(Sender: TObject);
    procedure EditCod_FATExit(Sender: TObject);
    procedure preencherdornecedorExecute(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton21Click(Sender: TObject);
    procedure DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBEdit4KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure formatarExecute(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure ajudaExecute(Sender: TObject);
    procedure DBEdit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCartorioKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCod_FATKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
 //   procedure DBGrid2DrawColumnCell1(Sender: TObject; const Rect: TRect;
   //   DataCol: Integer; Column: TColumn; State: TGridDrawState);

   procedure AppHint(Sender : TObject);
    { Private declarations }
  public
  bok:boolean;
  st:string;
  tot : real;
    { Public declarations }
  end;

var
  fpagar: Tfpagar;

implementation

uses UnitMenu, UnitRelatorioPagar, ulistafornecedor, udm;



procedure tfpagar.AppHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;

{$R *.DFM}

procedure Tfpagar.PageControl1Change(Sender: TObject);
begin
        fdm.tbpagar.filtered := false;

        if PageControl1.ActivePageIndex = 1 then
         keypreview := false
        else begin
        fdm.tbpagar.IndexFieldNames := 'docparcela';
        keypreview := true;
        end;
end;

procedure Tfpagar.btnPrimeiroClick(Sender: TObject);
begin
        fdm.tbpagar.first;
end;

procedure Tfpagar.btnVoltarClick(Sender: TObject);
begin
        fdm.tbpagar.Prior;
end;

procedure Tfpagar.btnAvancarClick(Sender: TObject);
begin
        fdm.tbpagar.Next;
end;

procedure Tfpagar.btnUltimoClick(Sender: TObject);
begin
        fdm.tbpagar.last;
end;

procedure Tfpagar.btnnovoClick(Sender: TObject);
begin
        novoexecute(self);

end;

procedure Tfpagar.btngravarClick(Sender: TObject);
begin
        fdm.tbpagar.edit;
         fdm.tbpagar.post;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
end;

procedure Tfpagar.btncancelarClick(Sender: TObject);
begin
        fdm.tbpagar.cancel;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
end;

procedure Tfpagar.Label1Click(Sender: TObject);
begin
        BOK := inputquery('Localizar Documento','Digite aqui, o documento a ser localizado:',ST);
         if BOK then
          if not fdm.tbpagar.Locate ('DocParcela',uppercase(ST),[]) then
           ShowMessage ('Documento não localizado !!!');
            ST := '';
end;

procedure Tfpagar.Label2Click(Sender: TObject);
begin
        BOK := inputquery('Localizar Código','Digite aqui, o código a ser localizado:',ST);
         if BOK then
          if not fdm.tbpagar.Locate ('Codigo',ST,[]) then
           ShowMessage ('Código não localizado !!!');
            ST := '';
end;

procedure Tfpagar.Label11Click(Sender: TObject);
begin
        BOK := inputquery('Localizar Cliente','Digite aqui, o nome a ser localizado:',ST);
         if BOK then
          if not fdm.tbpagar.Locate ('fantasia',ST,[]) then
           ShowMessage ('Nome não localizado !!!');
            ST := '';
end;

procedure Tfpagar.FormActivate(Sender: TObject);
begin

 THackDBGrid(DBGrid1).FixedCols := 2;
 THackDBGrid(DBGrid2).FixedCols := 8;
 btncancelarClick (self);

end;

procedure Tfpagar.Edit1Change(Sender: TObject);
begin
        fdm.tbpagar.IndexFieldNames :='DocParcela';
         fdm.tbpagar.findnearest([edit1.text]);

end;

procedure Tfpagar.tbpagarAfterScroll(DataSet: TDataSet);
begin
           btnAvancar.Enabled := True;
            btnUltimo.Enabled := True;
             btnPrimeiro.Enabled := True;
              btnVoltar.Enabled := True;

        if fdm.tbpagar.Bof then begin
         btnPrimeiro.Enabled := False;
          btnVoltar.Enabled := False;

             end;

        if fdm.tbpagar.Eof then begin

           btnAvancar.Enabled := False;
            btnUltimo.Enabled := False;
             end;

end;

procedure Tfpagar.tbpagarBeforeEdit(DataSet: TDataSet);
begin
       btnGravar.Enabled:=True;
       btncancelar.enabled := true;
end;

procedure Tfpagar.MaskEdit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = 13 then
         if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then begin
         fdm.tbpagar.Filtered := false;
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' + maskedit2.text + '''';
         fdm.tbpagar.filtered := true;
         totalizarexecute(self);
         end;

        if key = 27 then
         maskedit1.setfocus;         
end;

procedure Tfpagar.totalizarExecute(Sender: TObject);
var
bookmark : tbookmarkstr;
begin

     bookmark := fdm.tbpagar.Bookmark;

     try
      fdm.tbpagar.DisableControls;
      tot := 0;

    try
    fdm.tbpagar.First;

    while not fdm.tbpagar.Eof do begin

    tot := tot + (fdm.tbpagar.fieldbyname ('vrdesconto') as tfloatfield).Value ;
    fdm.tbpagar.next;
    end;
    finally

    fdm.tbpagar.EnableControls;
    end;
    finally
    fdm.tbpagar.Bookmark := bookmark;
    panel9.caption := 'Total: ' + format('%n',[tot]);
    end;


end;

procedure Tfpagar.SpeedButton1Click(Sender: TObject);
begin
       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' + maskedit2.text + ''' and Datapagamento>''01/01/1990'''
          else
         fdm.tbpagar.Filter:='datapagamento>''01/01/1990''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
end;

procedure Tfpagar.SpeedButton2Click(Sender: TObject);
begin
       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' + maskedit2.text + ''' and Datapagamento < ''01/01/1990'''
          else
         fdm.tbpagar.Filter:='datapagamento <''01/01/1990''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
end;

procedure Tfpagar.SpeedButton3Click(Sender: TObject);
begin
      if fdm.tbpagar['Fantasia'] <> null Then
       ST:= fdm.tbpagar['Fantasia'];

        BOK:= InputQuery ('Filtrar', 'Entre com o nome do fornecedor:', St);
      if BOK then begin

       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' +maskedit2.text + ''' and fantasia = '''+ UpperCase(st) + ''''
          else
         fdm.tbpagar.Filter:='fantasia = ''' + UpperCase(st) + '''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
       end;

end;

procedure Tfpagar.SpeedButton4Click(Sender: TObject);
begin
     if fdm.tbpagar['Fantasia'] <> null Then
       ST:= fdm.tbpagar['Fantasia'];

        BOK:= InputQuery ('Filtrar', 'Entre com o nome do fornecedor:', St);
      if BOK then begin

       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' +maskedit2.text + ''' and fantasia = '''+ UpperCase(st) + ''' and datapagamento > ''01/01/1900'''
          else
         fdm.tbpagar.Filter:='fantasia = ''' + UpperCase(st) + ''' and datapagamento > ''01/01/1900''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
       end;
end;

procedure Tfpagar.SpeedButton6Click(Sender: TObject);
begin
      if fdm.tbpagar['Fantasia'] <> null Then
       ST:= fdm.tbpagar['Fantasia'];

        BOK:= InputQuery ('Filtrar', 'Entre com o nome do fornecedor:', St);
      if BOK then begin

       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' +maskedit2.text + ''' and fantasia = '''+ UpperCase(st) + ''' and datapagamento < ''01/01/1900'''
          else
         fdm.tbpagar.Filter:='fantasia = ''' + UpperCase(st) + ''' and datapagamento < ''01/01/1900''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
       end;
end;

procedure Tfpagar.SpeedButton8Click(Sender: TObject);
begin
       fdm.tbpagar.filtered := false;
        Maskedit1.Clear;
         maskedit2.clear;
          totalizarexecute(self);
end;

procedure Tfpagar.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin
  Key := #0;
       Perform(WM_nextdlgctl,0,0)
 end else if Key = #27 then
   Perform(WM_nextdlgctl,1,0);
end;

procedure Tfpagar.novoExecute(Sender: TObject);
begin

        btngravar.enabled := true;
        btncancelar.Enabled := true;

        fdm.tbpagar.insert;
         fdm.tbpagar['dataemissao'] := datetostr(now);


        editdocparcela.setfocus;

end;

procedure Tfpagar.EditDocParcelaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = VK_F3 then
         Label1Click(Self);
end;

procedure Tfpagar.EditCod_ClienteKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = VK_F3 then
         Label2Click(Self);

        if key = vk_F12 then begin
         Application.CreateForm (Tflistafornecedor, flistafornecedor);
          fdm.tbfornecedor.open;
           flistafornecedor.controle :='pagar';
            flistafornecedor.show;
             end;

          if key = 13 then
           preencherdornecedorExecute(self);

         
end;

procedure Tfpagar.DBEdit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = VK_F3 then
         Label11Click(Self);
end;

procedure Tfpagar.avancarExecute(Sender: TObject);
begin
        fdm.tbpagar.next;
end;

procedure Tfpagar.voltarExecute(Sender: TObject);
begin
        fdm.tbpagar.prior;
end;

procedure Tfpagar.tbpagarAfterPost(DataSet: TDataSet);
begin
        btngravar.enabled := false;
        btncancelar.enabled := false;
end;

procedure Tfpagar.focoExecute(Sender: TObject);
begin
        if not edit1.Focused then
        edit1.setfocus
        else
        editdocparcela.setfocus;
end;

procedure Tfpagar.MaskEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = 13 then
         maskedit2.setfocus;
end;

procedure Tfpagar.SpeedButton5Click(Sender: TObject);
begin

     fdm.tbpagar.IndexFieldNames := 'DocParcela';
       totalizarexecute (self);
        application.CreateForm(tfrpagar, frpagar);

  fmenu.logotipoExecute(self);

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frpagar.image1.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
   frpagar.memo1.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

          frpagar.ltotal.caption := panel9.Caption;
           frpagar.quickrep1.preview;
end;

procedure Tfpagar.SpeedButton9Click(Sender: TObject);
begin

    fdm.tbpagar.IndexFieldNames := 'DocParcela';
        application.CreateForm(tfrpagar, frpagar);

  fmenu.logotipoExecute(self);

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frpagar.image1.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
   frpagar.memo1.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

          frpagar.ltotal.caption := panel9.Caption;
           frpagar.quickrep1.preview;
end;

procedure Tfpagar.DBEdit4Change(Sender: TObject);
begin

         if DBEdit4.Text = '  /  /    ' then begin
          fdm.tbpagar.edit;
           fdm.tbpagar.FieldByName('DataPagamento').Clear;
            end;
end;

procedure Tfpagar.EditCartorioExit(Sender: TObject);
begin

        if editcartorio.Text <> '' then begin
         fdm.tbpagar.edit;
          fdm.tbpagar['vrdesconto'] := (fdm.tbpagar.fieldbyname('Valordocumento') as tfloatfield).Value  -
           (fdm.tbpagar.fieldbyname ('Descmoeda') as tfloatfield).Value ;
           end;
end;

procedure Tfpagar.EditCod_FATExit(Sender: TObject);
begin

        if EditCod_FAT.Text <> '' then begin
         fdm.tbpagar.edit;
          fdm.tbpagar['vrdesconto'] := (fdm.tbpagar.fieldbyname('Valordocumento') as tfloatfield).Value  -
          ((fdm.tbpagar.fieldbyname ('Valordocumento') as tfloatfield).Value *
           (fdm.tbpagar.fieldbyname ('Descpercent') as tfloatfield).Value /100);


           end;

end;
procedure Tfpagar.preencherdornecedorExecute(Sender: TObject);
begin

          fdm.tbfornecedor.open;

               if fdm.tbfornecedor.Locate ('codigo',editcod_Cliente.text,[]) then begin
               fdm.tbpagar.edit;
              fdm.tbpagar['fantasia'] := fdm.tbfornecedor['fantasia'];
             fdm.tbpagar['nome'] := fdm.tbfornecedor['fornecedor'];
            fdm.tbpagar['contato'] := fdm.tbfornecedor['contato'];
           fdm.tbpagar['fone'] := fdm.tbfornecedor['fone'];
           fdm.tbfornecedor.close;
          dbedit1.setfocus;

          end else begin
          Showmessage('Não há nenhum fornecedor código: ' +  editcod_Cliente.text +' cadastrado !!!');
          editcod_Cliente.setfocus;
          end;

end;

procedure Tfpagar.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = vk_F8 then begin
         fdm.tbpagar['DataPagamento'] := datetostr (now);
          dbedit4.setfocus;
           end;
end;

procedure Tfpagar.FormClose(Sender: TObject; var Action: TCloseAction);
begin

       Application.OnHint := nil;

end;

procedure Tfpagar.FormShow(Sender: TObject);
begin
        fdm.tbpagar.Last;
end;

procedure Tfpagar.FormCreate(Sender: TObject);
begin
       Application.OnHint := AppHint;
end;

procedure Tfpagar.SpeedButton21Click(Sender: TObject);
begin
          if Application.MessageBox('Deseja excluir esta conta? ',
         'Confirme', 4  + MB_ICONQUESTION)= idYes then begin

        fdm.tbpagar.Delete;
        btngravar.Enabled := false;
        btncancelar.Enabled := false;
        end;

end;

procedure Tfpagar.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

  {if (Column.FieldName = 'DATAVENCIMENTO') then
    with DBGrid2.Canvas do begin
      if fdm.tbpagar.FieldByName('DATAPAGAMENTO').Value > EncodeDate(1900,1,1) then
        Font.Color := clNavy
      else
        Font.Color := clMaroon;
      FillRect(Rect);
      TextOut(Rect.Left+20,Rect.Top+20,Column.Field.DisplayText);
    end;}

end;

{procedure tfpagar.DBGrid2DrawColumnCell1(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

  if (Column.FieldName = 'DATAVENCIMENTO') then
    with DBGrid2.Canvas do begin
      if fdm.tbpagar.FieldByName('DATAPAGAMENTO').Value > EncodeDate(1900,1,1) then
        Font.Color := clNavy
      else
        Font.Color := clMaroon;
    end;
    DBGrid2.DefaultDrawDataCell(Rect,Column.Field,State);
end;                                                     }


procedure Tfpagar.DBEdit4KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
         fdm.tbpagar.edit;
           if (key = 8) or (key = 46) then
            fdm.tbpagar.FieldByName('datapagamento').Clear;
end;

procedure Tfpagar.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin

        IF btngravar.Enabled = true then begin
         case application.MessageBox('Deseja salvar as alterações?', 'Sair de conta a pagar',mb_yesnocancel + MB_ICONQUESTION )of

         idyes : begin
         fdm.tbpagar.edit;
          fdm.tbpagar.post;
           canclose:=true;
            end;

         idno : begin
          fdm.tbpagar.cancel;
           canclose:=true;
            end;

         idcancel :
           canclose:=false;
end;
end;

end;

procedure Tfpagar.formatarExecute(Sender: TObject);
begin
 (fdm.tbpagar.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
 (fdm.tbpagar.fieldbyname ('dataemissao') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbpagar.fieldbyname ('datavencimento') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbpagar.fieldbyname ('datapagamento') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbpagar.fieldbyname ('numeropedido') as tfloatfield).displayformat := '000000';
 (fdm.tbpagar.fieldbyname ('valortitulo') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbpagar.fieldbyname ('valordocumento') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbpagar.fieldbyname ('VrDesconto') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbpagar.fieldbyname ('docparcela') as tfloatfield).displayformat := '000000';

end;

procedure Tfpagar.SpeedButton7Click(Sender: TObject);
begin

      if fdm.tbpagar['tipoconta'] <> null Then
       ST:= fdm.tbpagar['tipoconta'];

        BOK:= InputQuery ('Filtrar', 'Entre com o tipo da conta:', St);
      if BOK then begin

       fdm.tbpagar.Filtered:=False;
        if (maskedit1.text <> '  /  /    ') and (maskedit2.text <> '  /  /    ') then
         fdm.tbpagar.Filter := 'datavencimento >=''' + maskedit1.text + ''' and datavencimento <=''' +maskedit2.text + ''' and tipoconta = '''+ UpperCase(st) + ''''
          else
         fdm.tbpagar.Filter:='tipoconta = ''' + UpperCase(st) + '''';
        fdm.tbpagar.filtered:=True;
       totalizarexecute(self);
       end;

end;


procedure Tfpagar.ajudaExecute(Sender: TObject);
var
  Comp: Trichedit; // * variável Comp da classe TMemo
  texto : string;
begin
  Comp := Trichedit.Create (Self);  // * cria o componente Memo
  Comp.Parent := Self;    // * exibe o componente criado

  if fileexists (extractfilepath(paramstr(0)) + '\ajuda\ajudacontas.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudacontas.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);

end;



procedure Tfpagar.DBEdit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if (editcartorio.Text ='') and (editcod_fat.Text = '' ) then begin
        fdm.tbpagar.Edit;
        fdm.tbpagar['vrdesconto'] := fdm.tbpagar['Valordocumento'];
        end;
end;

procedure Tfpagar.EditCartorioKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if EditCartorio.Text <> '' then
         editcod_fat.Clear;
end;

procedure Tfpagar.EditCod_FATKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
     if EditCod_FAT.Text<> '' then
      editcartorio.Clear;
end;

end.
