unit UBoleto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, DB, DBTables, StdCtrls, Mask, DBCtrls, ComCtrls,
  Grids, DBGrids, Buttons, ToolWin, QRCtrls, QuickRpt, ActnList;

type
  Tfboleto = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Panel2: TPanel;
    ScrollBox: TScrollBox;
    dsboleto: TDataSource;
    Label1: TLabel;
    DBMemo1: TDBMemo;
    tbcomplemento: TTable;
    dscomplemento: TDataSource;
    Label18: TLabel;
    ToolBar2: TToolBar;
    btnPrimeiro: TSpeedButton;
    btnVoltar: TSpeedButton;
    btnAvancar: TSpeedButton;
    btnUltimo: TSpeedButton;
    Panel6: TPanel;
    Panel7: TPanel;
    btnnovo: TSpeedButton;
    Panel5: TPanel;
    btngravar: TSpeedButton;
    Panel8: TPanel;
    btncancelar: TSpeedButton;
    Panel12: TPanel;
    SpeedButton21: TSpeedButton;
    Panel11: TPanel;
    Panel3: TPanel;
    btnimprimir: TSpeedButton;
    Panel9: TPanel;
    Panel14: TPanel;
    Panel1: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    EditNlocal: TDBEdit;
    EditLocal: TDBEdit;
    Label4: TLabel;
    EditCedente: TDBEdit;
    EditNcedente: TDBEdit;
    Label5: TLabel;
    Label8: TLabel;
    EditEspecie: TDBEdit;
    EditNdocumento: TDBEdit;
    Label7: TLabel;
    EditDatadocumento: TDBEdit;
    Label6: TLabel;
    Label9: TLabel;
    EditAceite: TDBEdit;
    EditDataprocesso: TDBEdit;
    Label11: TLabel;
    EditUsobanco: TDBEdit;
    Bevel1: TBevel;
    EditCarteira: TDBEdit;
    Label12: TLabel;
    Label15: TLabel;
    EditCgccpf: TDBEdit;
    Label17: TLabel;
    EditCodigobaixa: TDBEdit;
    EditSacadoAvalista: TDBEdit;
    Label16: TLabel;
    EditSacado: TDBEdit;
    Label14: TLabel;
    Bevel2: TBevel;
    Label19: TLabel;
    EditVencimento: TDBEdit;
    Label23: TLabel;
    EditDesconto: TDBEdit;
    EditMulta: TDBEdit;
    Label24: TLabel;
    EditAgCodigoCedente: TDBEdit;
    Label20: TLabel;
    EditNossonumero: TDBEdit;
    Label21: TLabel;
    Label25: TLabel;
    EditTotal: TDBEdit;
    Label22: TLabel;
    EditValor: TDBEdit;
    Bevel3: TBevel;
    Label10: TLabel;
    Panel4: TPanel;
    Panel10: TPanel;
    Label26: TLabel;
    Edit1: TEdit;
    DBGrid1: TDBGrid;
    ActionList1: TActionList;
    formatar: TAction;
    ajuda: TAction;
    foco: TAction;
    QuickRep1: TQuickRep;
    QRBand1: TQRBand;
    QRDBText13: TQRDBText;
    QRDBText14: TQRDBText;
    LINSTRUCAO: TQRLabel;
    QRDBText12: TQRDBText;
    QRDBText17: TQRDBText;
    QRDBText18: TQRDBText;
    QRDBText19: TQRDBText;
    QRDBText20: TQRDBText;
    QRDBText22: TQRDBText;
    procedure DBMemo1Exit(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
    procedure btncancelarClick(Sender: TObject);
    procedure SpeedButton21Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormActivate(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnnovoClick(Sender: TObject);
    procedure btnVoltarClick(Sender: TObject);
    procedure btnAvancarClick(Sender: TObject);
    procedure btnUltimoClick(Sender: TObject);
    procedure btnimprimirClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure formatarExecute(Sender: TObject);
    procedure EditValorExit(Sender: TObject);
    procedure ajudaExecute(Sender: TObject);
    procedure focoExecute(Sender: TObject);
    procedure Label2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fboleto: Tfboleto;

implementation

uses udm;

{$R *.dfm}

procedure Tfboleto.DBMemo1Exit(Sender: TObject);
begin
        tbcomplemento.Edit;
         tbcomplemento.post;
end;

procedure Tfboleto.btngravarClick(Sender: TObject);
begin
         fdm.tbboleto.Edit;
          fdm.tbboleto.Post;
           btngravar.Enabled:=false;
            btncancelar.Enabled:=false;
end;

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

procedure Tfboleto.SpeedButton21Click(Sender: TObject);
begin
          if Application.MessageBox('Deseja excluir este cliente? ',
         'Confirme', 4)= idYes then begin

        fdm.tbboleto.delete;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
        end;

end;

procedure Tfboleto.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 Tfboleto.FormActivate(Sender: TObject);
begin

        pagecontrol1.ActivePageIndex := 0;
        formatarExecute(self);        
end;

procedure Tfboleto.Edit1Change(Sender: TObject);
begin
        fdm.tbboleto.FindNearest([edit1.text]);
end;

procedure Tfboleto.btnPrimeiroClick(Sender: TObject);
begin
        fdm.tbboleto.First;
end;

procedure Tfboleto.btnnovoClick(Sender: TObject);
begin
        fdm.tbboleto.Insert;
         editnlocal.SetFocus;
end;

procedure Tfboleto.btnVoltarClick(Sender: TObject);
begin
        fdm.tbboleto.Prior;
end;

procedure Tfboleto.btnAvancarClick(Sender: TObject);
begin
        fdm.tbboleto.Next;
end;

procedure Tfboleto.btnUltimoClick(Sender: TObject);
begin
        fdm.tbboleto.Last;
end;

procedure Tfboleto.btnimprimirClick(Sender: TObject);
var
bookmark : tbookmarkstr;
begin

     bookmark := fdm.tbboleto.Bookmark;

        linstrucao.Caption := dbmemo1.Text;

        fdm.tbboleto.Filter := 'sacado= ''' + editsacado.Text + '''';
        fdm.tbboleto.Filtered := true;

        quickrep1.PreviewModal;
        fdm.tbboleto.Filtered := false;

        fdm.tbboleto.Bookmark := bookmark;

end;

procedure Tfboleto.PageControl1Change(Sender: TObject);
begin
        IF pagecontrol1.ActivePageIndex = 0 then
         keypreview := true
          else
         keypreview := false;

end;

procedure Tfboleto.formatarExecute(Sender: TObject);
begin

 (fdm.tbboleto.fieldbyname ('nlocal') as tfloatfield).displayformat := '000';
 (fdm.tbboleto.fieldbyname ('datadocumento') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbboleto.fieldbyname ('dataprocesso') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbboleto.fieldbyname ('vencimento') as tdatetimefield).editmask := '99/99/9999';
 (fdm.tbboleto.fieldbyname ('valor') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbboleto.fieldbyname ('desconto') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbboleto.fieldbyname ('multa') as tfloatfield).displayformat := '###,##0.00';
 (fdm.tbboleto.fieldbyname ('total') as tfloatfield).displayformat := '###,##0.00';

end;

procedure Tfboleto.EditValorExit(Sender: TObject);

begin
       fdm.tbboleto.edit;
        fdm.tbboleto[ 'total'] := fdm.tbboleto['valor'] - fdm.tbboleto['desconto'] + fdm.tbboleto['multa'];
end;

procedure Tfboleto.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\ajudaboleto.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudaboleto.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);


end;

procedure Tfboleto.focoExecute(Sender: TObject);
begin
        if edit1.Focused = true then
         editnlocal.SetFocus
        else
        edit1.SetFocus; 
end;

procedure Tfboleto.Label2Click(Sender: TObject);
var
st:string;
begin
        if inputquery('Localizar boleto','Entre com o número:',ST) then
          if not fdm.tbboleto.Locate ('Nlocal',ST,[]) then
           ShowMessage ('Boleto não localizado !!!');

end;

end.
