unit UCondPgto;

interface

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

type

THackDBGrid = class(TDBGrid);

  Tfcondfatura = class(TForm)
    ScrollBox: TScrollBox;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    btnPrimeiro: TSpeedButton;
    btnVoltar: TSpeedButton;
    btnAvancar: TSpeedButton;
    btnUltimo: TSpeedButton;
    Panel7: TPanel;
    btnnovo: TSpeedButton;
    btngravar: TSpeedButton;
    btncancelar: TSpeedButton;
    Panel8: TPanel;
    Panel4: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    EditDescricao: TDBEdit;
    EditCondPgto: TDBEdit;
    EditCondPgto2: TDBEdit;
    EditCondPgto3: TDBEdit;
    EditCondPgto4: TDBEdit;
    Label10: TLabel;
    DBEdit1: TDBEdit;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label15: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    ActionList1: TActionList;
    novo: TAction;
    avancar: TAction;
    voltar: TAction;
    foco: TAction;
    Bevel1: TBevel;
    Label7: TLabel;
    Label8: TLabel;
    StatusBar1: TStatusBar;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    Panel3: TPanel;
    Label9: TLabel;
    Edit1: TEdit;
    SpeedButton21: TSpeedButton;
    ajuda: TAction;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnVoltarClick(Sender: TObject);
    procedure btnAvancarClick(Sender: TObject);
    procedure btnUltimoClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btncancelarClick(Sender: TObject);
    procedure DBEdit1Exit(Sender: TObject);
    procedure Label10Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure avancarExecute(Sender: TObject);
    procedure voltarExecute(Sender: TObject);
    procedure novoExecute(Sender: TObject);
    procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure focoExecute(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure SpeedButton21Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btnPrimeiroMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnVoltarMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnAvancarMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnUltimoMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnnovoMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btngravarMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btncancelarMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Panel4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure SpeedButton21MouseMove(Sender: TObject; Shift: TShiftState;
      X, Y: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure ajudaExecute(Sender: TObject);
  private
   procedure AppHint(Sender : TObject);
    { private declarations }
  public
  bok:boolean;
  st:string;
    { public declarations }
  end;

var
  fcondfatura: Tfcondfatura;

implementation

uses udm;



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



{$R *.DFM}

procedure Tfcondfatura.SpeedButton1Click(Sender: TObject);
begin
        novoexecute(self);
end;

procedure Tfcondfatura.SpeedButton2Click(Sender: TObject);
begin
        fdm.tbfatura.edit;
         fdm.tbfatura.post;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
end;

procedure Tfcondfatura.Edit1Change(Sender: TObject);
begin
        fdm.tbfatura.indexname := 'bydescricao';
         fdm.tbfatura.FindNearest ([edit1.text]);
end;

procedure Tfcondfatura.btnPrimeiroClick(Sender: TObject);
begin
        fdm.tbfatura.first;
end;

procedure Tfcondfatura.btnVoltarClick(Sender: TObject);
begin
        fdm.tbfatura.prior;
end;

procedure Tfcondfatura.btnAvancarClick(Sender: TObject);
begin
        fdm.tbfatura.next;
end;

procedure Tfcondfatura.btnUltimoClick(Sender: TObject);
begin
        fdm.tbfatura.last;
end;

procedure Tfcondfatura.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 Tfcondfatura.btncancelarClick(Sender: TObject);
begin
       fdm.tbfatura.cancel;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
end;

procedure Tfcondfatura.DBEdit1Exit(Sender: TObject);
begin
        if (DBEdit1.text = '') or (strtofloat(DBEdit1.text) > 4) then begin
         showmessage('Este campo não pode ficar vazio, nem maior que 4!!!');
          DBEdit1.setfocus;
           end;
end;

procedure Tfcondfatura.Label10Click(Sender: TObject);
begin
        BOK := inputquery('Localizar Parcelas','Entre com a quantidade:',ST);
         if BOK then
          if not fdm.tbfatura.Locate ('parcelas',ST,[]) then
           ShowMessage ('Item não localizado!!!');
            ST := '';
end;

procedure Tfcondfatura.Label2Click(Sender: TObject);
begin
        BOK := inputquery('Localizar descrição','Entre com a descrição :',ST);
         if BOK then
          if not fdm.tbfatura.Locate ('Descricao',ST,[]) then
           ShowMessage ('Descricao não localizada!!!');
            ST := '';
end;

procedure Tfcondfatura.avancarExecute(Sender: TObject);
begin
        fdm.tbfatura.next;
end;

procedure Tfcondfatura.voltarExecute(Sender: TObject);
begin
        btnvoltarclick(self);
end;

procedure Tfcondfatura.novoExecute(Sender: TObject);
begin

         fdm.tbfatura.Insert;
          btnGravar.Enabled:=True;
           btncancelar.Enabled := true;
            dbedit1.setfocus;

end;

procedure Tfcondfatura.DBEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = VK_F3 then
         Label10Click(Self);
end;

procedure Tfcondfatura.EditDescricaoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = VK_F1 then
         Label2Click(Self);
end;

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

procedure Tfcondfatura.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
        IF btngravar.Enabled = true then begin
         case application.MessageBox('Deseja salvar as alterações?', 'Sair de Cond. Fatura',mb_yesnocancel + MB_ICONQUESTION )of

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

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

         idcancel :
           canclose:=false;
end;
end;
end;

procedure Tfcondfatura.SpeedButton21Click(Sender: TObject);
begin
          if Application.MessageBox('Deseja excluir esta opção? ',
         'Confirme', 4 + MB_ICONQUESTION)= idYes then begin

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

end;

procedure Tfcondfatura.FormActivate(Sender: TObject);
begin
        THackDBGrid(DBGrid1).FixedCols := 2;
end;

procedure Tfcondfatura.btnPrimeiroMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Volta para o primeiro registro.';
end;

procedure Tfcondfatura.btnVoltarMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Volta 1 registro.';
end;

procedure Tfcondfatura.btnAvancarMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Avança 1 registro.';
end;

procedure Tfcondfatura.btnUltimoMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Vai para o último registro.';
end;

procedure Tfcondfatura.btnnovoMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Abre um registro novo.';
end;

procedure Tfcondfatura.btngravarMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Grava alterações processadas.';
end;

procedure Tfcondfatura.btncancelarMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Cancela alterações não gravadas.';
end;

procedure Tfcondfatura.Panel4MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Cadastra um novo e consulta já cadastrado.';
end;

procedure Tfcondfatura.DBGrid1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Navega entre registros.';
end;

procedure Tfcondfatura.Edit1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Localiza aproximadamente.';
end;

procedure Tfcondfatura.Label1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Consulta dando um clique, ou teclando F3, no campo.';
end;

procedure Tfcondfatura.SpeedButton21MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
        StatusBar1.Panels[0].Text := 'Apaga o registro.';
end;

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


	        Application.OnHint := nil;
end;

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

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

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);


end;

end.