unit Conclie;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  StdCtrls, Forms, DBCtrls, DB, DBGrids, DBTables, Grids, ExtCtrls,checa,dialogos,
  Buttons,describe;

type
  TFormaConClientes = class(TForm)
    Detalle: TDBGrid;
    DBNavigator: TDBNavigator;
    Panel1: TPanel;
    Panel2: TPanel;
    DataSource2: TDataSource;
    BotonNuevo: TSpeedButton;
    BotonGuarda: TSpeedButton;
    BotonCambios: TSpeedButton;
    Shape1: TShape;
    Panel3: TPanel;
    Bevel20: TBevel;
    Bevel21: TBevel;
    Bevel22: TBevel;
    Panel4: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure DetalleDblClick(Sender: TObject);
    procedure DetalleKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BotonCambiosClick(Sender: TObject);
    procedure BotonNuevoClick(Sender: TObject);
    procedure BotonGuardaClick(Sender: TObject);
    procedure Panel4Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BotonCambiosMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonNuevoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonGuardaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormaConClientes: TFormaConClientes;

implementation

{$R *.DFM}
uses Factu, Cucobra;

procedure rutas;
var
  w: Integer;
begin

with FormaFactura do
begin
  for w := 0 to ComponentCount -1 do
    begin
     if Components[w] is TTable  then
     begin
       TTable(Components[w]).DatabaseName:=ruta(8);
       TTable(Components[w]).Open;
     end;
    end;
end;

end;

procedure TFormaConClientes.FormCreate(Sender: TObject);
begin
  {Query1.Open;}
end;

procedure TFormaConClientes.FormActivate(Sender: TObject);
begin
if FormaConClientes.Tag=100 then
begin
{MuestraMensaje(IntToStr(FormaConClientes.Tag));}
rutas;
end;
FormaFactura.TablaCliente.FindNearest([FormaFactura.EditCLCLI_F.Text]);
Detalle.SetFocus;
end;

procedure TFormaConClientes.DetalleDblClick(Sender: TObject);
begin
if FormaConClientes.Tag=200 then
begin
FormaFactura.EditCLCLI_F.Text:=FormaFactura.TablaCliente.FieldByName('CLCLI_C').AsString;
{FormaFactura.Nombre.Caption:=FormaFactura.TablaCliente.FieldByName('NOMBR_C').AsString;}
{FormaFactura.Direccion.Caption:=FormaFactura.TablaCliente.FieldByName('DIREC_C').AsString;
FormaFactura.Direc2.Caption:=FormaFactura.TablaCliente.FieldByName('DIRE2_C').AsString;
FormaFactura.Poblacion.Caption:=FormaFactura.TablaCliente.FieldByName('POBLA_C').AsString;}
end;
if FormaConClientes.Tag=100 then
begin
FormaCuCobra.EditCLCLI_CC.Text:=FormaFactura.TablaCliente.FieldByName('CLCLI_C').AsString;
end;
FormaConClientes.Close;
end;

procedure TFormaConClientes.DetalleKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Ord(Char(key))=13 then
begin
if FormaConClientes.Tag=200 then
begin
FormaFactura.EditCLCLI_F.Text:=FormaFactura.TablaCliente.FieldByName('CLCLI_C').AsString;
{FormaFactura.Nombre.Caption:=FormaFactura.TablaCliente.FieldByName('NOMBR_C').AsString;}
{FormaFactura.Direccion.Caption:=FormaFactura.TablaCliente.FieldByName('DIREC_C').AsString;
FormaFactura.Poblacion.Caption:=FormaFactura.TablaCliente.FieldByName('POBLA_C').AsString;}
end;
if FormaConClientes.Tag=100 then
begin
FormaCuCobra.EditCLCLI_CC.Text:=FormaFactura.TablaCliente.FieldByName('CLCLI_C').AsString;
end;
FormaConClientes.Close;
end;
if key=27 then
Close;

end;

procedure TFormaConClientes.BotonCambiosClick(Sender: TObject);
begin
Detalle.ReadOnly:=False;
FormaFactura.TablaCliente.Edit;
end;

procedure TFormaConClientes.BotonNuevoClick(Sender: TObject);
begin
Detalle.ReadOnly:=False;
FormaFactura.TablaCliente.Insert;

end;

procedure TFormaConClientes.BotonGuardaClick(Sender: TObject);
begin
if FormaFactura.TablaCliente.FieldByName('CLCLI_C').AsString<>'' then
begin
FormaFactura.TablaCliente.Post;
Detalle.ReadOnly:=True;
end
else
begin
MuestraMensaje('FALTAN DATOS EN LA ALTA DE CLIENTE');
Detalle.SetFocus;
end;

end;


procedure TFormaConClientes.Panel4Click(Sender: TObject);
begin
Close;
end;

procedure TFormaConClientes.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=27 then Close;
end;

procedure TFormaConClientes.BotonCambiosMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaConClientes.Left+BotonCambios.Left,FormaConClientes.Top+BotonCambios.Top+BotonCambios.Height,70);
end;

procedure TFormaConClientes.BotonNuevoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaConClientes.Left+BotonNuevo.Left,FormaConClientes.Top+BotonNuevo.Top+BotonNuevo.Height,71);
end;

procedure TFormaConClientes.BotonGuardaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaConClientes.Left+BotonGuarda.Left,FormaConClientes.Top+BotonGuarda.Top+BotonGuarda.Height,72);
end;

procedure TFormaConClientes.Panel3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaConClientes.Handle, WM_SYSCOMMAND, $F012, 0);
end;

procedure TFormaConClientes.Label2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaConClientes.Handle, WM_SYSCOMMAND, $F012, 0);
end;

end.
