unit Cliente;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  StdCtrls, Forms, DBCtrls, DB, DBTables, Mask, ExtCtrls, Buttons, Menus,
  Dialogos, ComCtrls, Tabnotbk,conver,dialogs,Tablas,Apertura,
  RepoSQL;

type
  TFormaClientes = class(TForm)
    Fuentetablacliente: TDataSource;
    TablaCliente: TTable;
    MainMenu1: TMainMenu;
    Archivo1: TMenuItem;
    Registro1: TMenuItem;
    Nuevo1: TMenuItem;
    Guardar1: TMenuItem;
    Imprimir1: TMenuItem;
    Modificar1: TMenuItem;
    Buscar1: TMenuItem;
    Salir1: TMenuItem;
    Reportes1: TMenuItem;
    Ayuda1: TMenuItem;
    Consulta1: TMenuItem;
    TablaFactura: TTable;
    Eliminar1: TMenuItem;
    BotonNuevo: TSpeedButton;
    BotonGuardar: TSpeedButton;
    BotonImprimir: TSpeedButton;
    BotonBuscar: TSpeedButton;
    BotonSalir: TSpeedButton;
    BotonCambios: TSpeedButton;
    Usuario: TLabel;
    Navegador: TDBNavigator;
    Panel2: TPanel;
    Caja: TScrollBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    EditCLCLI_C: TDBEdit;
    EditNOMBR_C: TDBEdit;
    EditTELEF_C: TDBEdit;
    EditRFCXX_C: TDBEdit;
    EditDIREC_C: TDBEdit;
    EditPOBLA_C: TDBEdit;
    EditCPXXX_C: TDBEdit;
    EditZONAX_C: TDBEdit;
    EditDCRED_C: TDBEdit;
    EditFULCO_C: TDBEdit;
    EditCLVEN_C: TDBEdit;
    EditSALDO_C: TDBEdit;
    EditCOMPR_C: TDBEdit;
    Uno: TLabel;
    Dos: TLabel;
    Cargo: TLabel;
    Abono: TLabel;
    VentasPorCliente1: TMenuItem;
    Ventas1: TMenuItem;
    Saldos1: TMenuItem;
    Bevel1: TBevel;
    TablaRepetido: TTable;
    Label17: TLabel;
    EditCURPX_C: TDBEdit;
    EditDIRE2_C: TDBEdit;
    SaldosPorZona1: TMenuItem;
    Formatos: TMenuItem;
    Bevel2: TBevel;
    Bevel3: TBevel;
    Bevel4: TBevel;
    Bevel5: TBevel;
    Bevel6: TBevel;
    Bevel7: TBevel;
    Bevel8: TBevel;
    Bevel9: TBevel;
    Bevel10: TBevel;
    Bevel11: TBevel;
    Bevel12: TBevel;
    Bevel13: TBevel;
    Bevel14: TBevel;
    Bevel15: TBevel;
    Bevel16: TBevel;
    Bevel17: TBevel;
    Bevel18: TBevel;
    Bevel19: TBevel;
    formato: TMenuItem;
    DiseaFormato1: TMenuItem;
    ListadodeClientes1: TMenuItem;
    ClienteyTelefono1: TMenuItem;
    Panel: TPanel;
    Estructura: TBatchMove;
    TablaAuxiliar: TTable;
    ImprimePantilla1: TMenuItem;
    Temas1: TMenuItem;
    ImprimeRango1: TMenuItem;
    CancelarMovimiento1: TMenuItem;
    BotonPreliminar: TSpeedButton;
    TablaContacto: TTable;
    DataSource1: TDataSource;
    SpeedButton1: TSpeedButton;
    Buscar2: TMenuItem;
    BuaquedaRpida1: TMenuItem;
    BusquedaNoIndexada1: TMenuItem;
    Bevel20: TBevel;
    Label18: TLabel;
    DBEdit1: TDBEdit;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    PresentacinPreliminar1: TMenuItem;
    Bevel21: TBevel;
    Label15: TLabel;
    EditHOREV_C: TDBEdit;
    Label19: TLabel;
    Bevel23: TBevel;
    Label20: TLabel;
    EditHOPAG_C: TDBEdit;
    Bevel24: TBevel;
    EditDREPA_C: TDBComboBox;
    EditDIPAG_C: TDBComboBox;
    Label16: TLabel;
    EtiEstado: TLabel;
    EditSTATU_C: TDBEdit;
    BotonObservacion: TSpeedButton;
    DBEdit2: TDBEdit;
    Label21: TLabel;
    Informacion1: TMenuItem;
    BotonSaldo: TBitBtn;
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure EditCLCLI_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BotonNuevoClick(Sender: TObject);
    procedure BotonGuardarClick(Sender: TObject);
    procedure BotonSalirClick(Sender: TObject);
    procedure Consulta1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BotonBuscarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BotonImprimirClick(Sender: TObject);
    procedure Eliminar1Click(Sender: TObject);
    procedure BotonCambiosClick(Sender: TObject);
    procedure EditCLCLI_CEnter(Sender: TObject);
    procedure EditNOMBR_CEnter(Sender: TObject);
    procedure EditTELEF_CEnter(Sender: TObject);
    procedure EditRFCXX_CEnter(Sender: TObject);
    procedure EditDIREC_CEnter(Sender: TObject);
    procedure EditPOBLA_CEnter(Sender: TObject);
    procedure EditCPXXX_CEnter(Sender: TObject);
    procedure EditDREPA_CEnter(Sender: TObject);
    procedure EditZONAX_CEnter(Sender: TObject);
    procedure EditDCRED_CEnter(Sender: TObject);
    procedure EditFULCO_CEnter(Sender: TObject);
    procedure EditCLVEN_CEnter(Sender: TObject);
    procedure EditSALDO_CEnter(Sender: TObject);
    procedure EditCOMPR_CEnter(Sender: TObject);
    procedure EditRFCXX_CMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure NavegadorClick(Sender: TObject; Button: TNavigateBtn);
    procedure VentasPorCliente1Click(Sender: TObject);
    procedure Ventas1Click(Sender: TObject);
    procedure Saldos1Click(Sender: TObject);
    procedure EditDREPA_CMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditFULCO_CMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure EditCURPX_CEnter(Sender: TObject);
    procedure EditCURPX_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDIRE2_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDIRE2_CEnter(Sender: TObject);
    procedure SaldosPorZona1Click(Sender: TObject);
    procedure formatoClick(Sender: TObject);
    procedure DiseaFormato1Click(Sender: TObject);
    procedure TablaClientePostError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure TablaClienteEditError(DataSet: TDataSet; E: EDatabaseError;
      var Action: TDataAction);
    procedure EditCLCLI_CExit(Sender: TObject);
    procedure EditNOMBR_CExit(Sender: TObject);
    procedure EditTELEF_CExit(Sender: TObject);
    procedure EditRFCXX_CExit(Sender: TObject);
    procedure EditCURPX_CExit(Sender: TObject);
    procedure EditDIREC_CExit(Sender: TObject);
    procedure EditDIRE2_CExit(Sender: TObject);
    procedure EditPOBLA_CExit(Sender: TObject);
    procedure EditCPXXX_CExit(Sender: TObject);
    procedure EditDREPA_CExit(Sender: TObject);
    procedure EditZONAX_CExit(Sender: TObject);
    procedure EditDCRED_CExit(Sender: TObject);
    procedure EditFULCO_CExit(Sender: TObject);
    procedure EditCLVEN_CExit(Sender: TObject);
    procedure EditSALDO_CExit(Sender: TObject);
    procedure EditCOMPR_CExit(Sender: TObject);
    procedure Panel3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure EditNOMBR_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditTELEF_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ListadodeClientes1Click(Sender: TObject);
    procedure ClienteyTelefono1Click(Sender: TObject);
    procedure BotonCambiosMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BotonNuevoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonGuardarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonBuscarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonImprimirMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel3StartDrag(Sender: TObject;
      var DragObject: TDragObject);
    procedure Panel3DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure Panel3DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Panel3EndDrag(Sender, Target: TObject; X, Y: Integer);
    procedure ImprimePantilla1Click(Sender: TObject);
    procedure Temas1Click(Sender: TObject);
    procedure ImprimeRango1Click(Sender: TObject);
    procedure EditFULCO_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure CancelarMovimiento1Click(Sender: TObject);
    procedure BotonPreliminarClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BusquedaNoIndexada1Click(Sender: TObject);
    procedure DBEdit1Enter(Sender: TObject);
    procedure DBEdit1Exit(Sender: TObject);
    procedure DBEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditRFCXX_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDIREC_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditPOBLA_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCPXXX_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDREPA_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditZONAX_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDCRED_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCLVEN_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditSALDO_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCOMPR_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEdit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCLCLI_CChange(Sender: TObject);
    procedure EditSALDO_CChange(Sender: TObject);
    procedure EditCOMPR_CChange(Sender: TObject);
    procedure EditHOREV_CEnter(Sender: TObject);
    procedure EditDIPAG_CEnter(Sender: TObject);
    procedure EditHOPAG_CEnter(Sender: TObject);
    procedure EditHOREV_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDIPAG_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditHOPAG_CKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditHOREV_CExit(Sender: TObject);
    procedure EditDIPAG_CExit(Sender: TObject);
    procedure EditHOPAG_CExit(Sender: TObject);
    procedure EditSTATU_CChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BotonObservacionClick(Sender: TObject);
    procedure Informacion1Click(Sender: TObject);
    procedure BotonSaldoClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { private declarations }
  public
  procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
  procedure MyOnGetText(Sender: TField; var Text: string; DisplayText: Boolean);
  procedure FormatoCampo(Tabla:TTable;campo,formatcadena:string);
    { public declarations }
  end;

var
  FormaClientes: TFormaClientes;
  i:integer;
  indice:integer;
  meses,comision:Array [1..12] of Real;
  formatonum:Word;
  color1:TColor;
  cadenarepite:string[20];
  nombreformato:string;
  FormatoCmp:String;
  ruta_8,lee_ruta:string;
  MyList: TList;

  procedure posicionacliente(clave:string);
  implementation

uses consulta, buscar, formatos, cerrar,formato, conven,checa, barras,
  AyuLinea,Describe,progreso,AyudaMod, imprime, edicion,
  Contacto,BusNoInd, advierte,Observa, Concobra, PoliClie;

{$R *.DFM}

{****Activa la tecla enter como tabulador******}

procedure DatosReporte(Tabla:TTable;
con1,con2,con3,con4,con5,con6,con7,con8,con9:Boolean;NombreTabla,
CampoDesde,TituloReporte,
eti1,eti2,eti3,eti4,eti5,eti6,eti7,eti8,eti9,eti10,eti11,
Fec1,Fec2,Fec3,Cam1,Cam2,Cam3,Cam4,Cam5,Cam6,Cam7,Cam8,Cam9,CampoMoneda,CampoCondicion:string;OpeCondicion:char;DatoCondicion,TipoCompresion:string;
anc1,anc2,anc3,anc4,anc5,anc6,anc7,anc8,anc9,anc10,anc11:word;
EjeX,EjeY:string;BarrasPorDato:word);
var
desde,hastavalor:string;
mone:string[10];
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);
FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(con1,con2,con3,con4,con5,con6,con7,con8,con9,NombreTabla);
Tabla.First;
desde:=Tabla.FieldByName(CampoDesde).AsString;
Tabla.Last;
hastavalor:=Tabla.FieldByName(CampoDesde).AsString;
valoresiniciales('','',desde,hastavalor);

// with Sender as TMenuItem do
//  begin
  desde:=TituloReporte;
//  end;

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
mone:='';
if FormaFormatos.Incluir1.Checked then mone:=CampoMoneda;

Concentrar(Tabla,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,Fec1,Fec2,Fec3,Cam1,Cam2,Cam3,Cam4,Cam5,Cam6,Cam7,Cam8,Cam9,mone,CampoCondicion,OpeCondicion,DatoCondicion,TipoCompresion);
poneetiquetas(eti1,eti2,eti3,eti4,eti5,eti6,eti7,eti8,eti9,eti10,eti11);
Poneanchos(anc1,anc2,anc3,anc4,anc5,anc6,anc7,anc8,anc9,anc10,anc11);
parametrosgrafica('Gráfica '+Desde,EjeX,EjeY,BarrasPorDato);
FormaBarras.Tag:=1;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;

FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte Consecutivo de Compras';
//******pone el titulo
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;
end;
Formaformatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;
end;

procedure BuscaTabOrder(Sender: TObject;tabO,Dire:integer);
type
  PMyList = ^AList;
  AList = record
    I: Integer;
    IC: Integer;
    C: string[15];

  end;


//var
//cadena:String;
//i{,j}{,cuenta}:integer;
//    clase:TObject;

//  ARecord{,BRecord}: PMyList;
//  B: Byte;
//  Y: Word;

begin
{ith FormaClientes do
begin
//
 New(ARecord);


 if Sender.ClassType=TDBEDit then
 with Sender as TDBEDit do TabO:=TabOrder;

 if Sender.ClassType=TMaskEDit then
 with Sender as TMaskEDit do TabO:=TabOrder;

  if Sender.ClassType=TEDit then
 with Sender as TEDit do TabO:=TabOrder;

  if Sender.ClassType=TDBComboBox then
 with Sender as TDBComboBox do TabO:=TabOrder;


 if Dire= 1 then
 begin
 if TabO+1>MyList.Count-1 then TabO:=MyList.Count-2 ;
 ARecord := MyList.Items[TabO+1]
 end
 else
 begin
 if TabO-1<0 then TabO:=1;
 ARecord := MyList.Items[TabO-1];
 end;

//ShowMessage(IntToStr(ARecord^.IC));

if (ARecord^.IC>=0)and(ARecord^.IC<=ComponentCount-1) then
begin

    if (Components[ARecord^.IC] is TDBEDit) then
    begin
   TDBEDit(Components[ARecord^.IC]).SetFocus;
      end;

    if (Components[ARecord^.IC] is TMaskEDit) then
    begin

    TMaskEDit(Components[ARecord^.IC]).SetFocus;
  end;

    if (Components[ARecord^.IC] is TEDit) then
    begin

   TEDit(Components[ARecord^.IC]).SetFocus;
   end;

    if (Components[ARecord^.IC] is TDBComboBox) then
    begin

    TDBComboBox(Components[ARecord^.IC]).SetFocus;
    end;

end;//if
end;}
end;

procedure FinalizaOrden;
var
b:Byte;
begin
 for B := 0 to (MyList.Count - 1) do
   begin

//     ARecord := MyList.Items[B];
//     Dispose(ARecord);
   end;

end;


procedure CreaTabOrder;
type
  PMyList = ^AList;
  AList = record
    I: Integer;
    IC:Integer;
    C: string[15];
  end;


var
cadena:String;
i{,j},cuenta:integer;


  ARecord,BRecord: PMyList;
  B: Byte;
//  Y: Word;
begin
with FormaClientes do
begin

  MyList := TList.Create;

cadena:='';
  cuenta:=0;

    MyList.Clear;
    for i:= 0 to ComponentCount -1 do
    begin
     if (Components[i] is TDBEDit)or(Components[i] is TMaskEDit)or(Components[i] is TEDit)
        or(Components[i] is TDBComboBox)  then
      begin

       New(BRecord);
       BRecord^.I :=100;
       BRecord^.IC :=100;
       BRecord^.C :='nulo';
       MyList.Add(BRecord);

      end;//if
    end;//for




  for i:= 0 to ComponentCount -1 do
    begin
     if (Components[i] is TDBEDit)or(Components[i] is TMaskEDit)or(Components[i] is TEDit)
             or(Components[i] is TDBComboBox)  then
      begin
       New(ARecord);

    if (Components[i] is TDBEDit) then
    cuenta:=TDBEDit(Components[I]).Taborder;

    if (Components[i] is TMaskEDit) then
    cuenta :=TMaskEDit(Components[I]).Taborder;

    if (Components[i] is TEDit) then
    cuenta :=TEDit(Components[I]).Taborder;

    if (Components[i] is TDBComboBox) then
    cuenta :=TDBComboBox(Components[I]).Taborder;

    ARecord^.I :=cuenta;
    ARecord^.IC :=i;
    ARecord^.C := Components[i].Name;
    //ShowMessage('insertando '+IntToStr(ARecord^.I)+'  '+ARecord^.C);
   // MyList.Insert(cuenta,ARecord);//
//    if
//    MyList.Delete(cuenta+1);

    //MyList.Move
    MyList.Add(ARecord);
//        ShowMessage('moviendo '+IntToStr(MyList.Count-1)+' a '+IntToStr(cuenta)+'  '+ARecord^.C);
     MyList.Exchange(MyList.Count-1,cuenta);
//    MyList.Move(MyList.Count-1,cuenta);
    MyList.Delete(MyList.Count-1);
    MyList.Pack;
      end;//if
    end;//for




  try
    for B := 0 to (MyList.Count - 1) do
    begin
      ARecord := MyList.Items[B];
      cadena:=cadena+ARecord^.C+'  '+IntToStr(ARecord^.I)+char(13);
    end;
//   ShowMessage(cadena);
    { Cleanup: must free the list items as well as the list }
{   for B := 0 to (MyList.Count - 1) do
   begin

     ARecord := MyList.Items[B];
     Dispose(ARecord);
   end;}
  finally
  //nada
  end;


//MuestraMensaje(cadena);
end;//with
end;

procedure poneDatosCliente;
begin
with FormaClientes do
begin
try

if (TablaCliente.FieldByName('CLCLI_C').AsString='')  and (TablaCliente.FieldByName('NOMBR_C').AsString='') then
begin
TablaCliente.Delete;
end;

Cargo.Caption:='Cargos '+convierte('###,###,##0.00',TablaCliente.FieldByName('CARGO_C').AsString,'$');
Abono.Caption:='Abonos '+convierte('###,###,##0.00',TablaCliente.FieldByName('ABONO_C').AsString,'$');
if (EditSTATU_C.Text='')or(EditSTATU_C.Text='A') then
   EtiEstado.Caption:='Activo'
   else
   EtiEstado.Caption:='Inactivo';
except
end;

end;
end;

function VerificaDato(cade:string):string;
var
aux:string;
i,nume,code:integer;
begin
val(cade,nume,code);
if code=0 then
begin
aux:=cade;
for i:=length(aux) to FormaClientes.TablaCliente.FieldByName('CLCLI_C').DataSize-2 do
aux:=' '+aux;
VerificaDato:=aux;
end
else
VerificaDato:=cade;
end;



procedure TFormaClientes.MyOnGetText(Sender: TField; var Text: string; DisplayText: Boolean);
var
aux:string;
begin
//DisplayText:=True;
aux:=Sender.AsString;
FormatoCmp:='#,###,###0.00';
text:=aux;
if aux<>'' then
begin
text:=FormatFloat(FormatoCmp,StrTofloat(aux));
end;

{Case Sender.DataType of
ftInteger:begin
text:=FormatFloat(FormatoCmp,StrTofloat(aux));
end;

ftFloat	:begin
text:=FormatFloat(FormatoCmp,StrTofloat(aux));
end;

ftString:begin
text:=aux;
end;

end;//case}

end;


procedure TFormaClientes.FormatoCampo(Tabla:TTable;campo,formatcadena:string);
begin
if (Tabla.State<>dsEdit) and (Tabla.State<>dsInsert) then
begin
//FormatoCmp:=formatcadena;
//FormatoCmp:=formatcadena;
//Tabla.Refresh;
Tabla.FieldByName(campo).OnGetText:=MyOnGetText;
//FormatoCmp:='#,###,##0.00';
end;
end;


function ClienteConsecutivo:string;
var
aux:string[12];
nume:longint;
i:integer;
begin
with FormaClientes do
begin

if not TablaCliente.IsEmpty then
begin
//TablaCliente.SetRange(['        '],[' 9999999']);
//TablaCliente.Refresh;
TablaCliente.Last;
aux:='';
aux:=TablaCliente.FieldByName('CLCLI_C').AsString;
if aux='' then aux:='0';

try
nume:=StrToInt(aux)+1;
aux:=IntToStr(nume);
for i:=length(aux) to TablaCliente.FieldByName('CLCLI_C').DataSize-2 do
aux:=' '+aux;
except
//
end;
ClienteConsecutivo:=aux;
//TablaCliente.CancelRange;
end
else
begin
//MuestraMensaje(IntToStr(TablaRepetido.FieldByName('CLCLI_C').DataSize-1));
aux:='';
for i:=1 to TablaCliente.FieldByName('CLCLI_C').DataSize-2 do
aux:=aux+' ';
aux:=aux+'1';
//MuestraMensaje(aux)
ClienteConsecutivo:=aux;

end;

end;
end;


procedure TFormaClientes.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
{with Form2 do
begin}
 if Msg.wParam = VK_RETURN then
 begin
 if ((Screen.ActiveControl) is TEdit)or((Screen.ActiveControl) is TDBEdit)
  and ((Screen.ActiveForm) is TFormaClientes) then
 Msg.wParam := VK_TAB;
 end;

{end;}
end;



{***termina procedimiento  de enter******}

{******}
procedure reportes(letrero:string);
begin
with FormaClientes do
begin
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
FormaBarras.Caption:=letrero;
FormaBarras.ShowModal;
FormaBarras.Tag:=0;

end;
end;

{*****activar botones}
procedure activabotones(cambios,nuevo,guardar,buscar,imprimir,navegar,cancela:boolean);
begin
with FormaClientes do
begin
BotonCambios.Enabled:=cambios;
Modificar1.Enabled:=cambios;

BotonNuevo.Enabled:=nuevo;
Nuevo1.Enabled:=nuevo;

BotonGuardar.Enabled:=guardar;
Guardar1.Enabled:=guardar;

BotonBuscar.Enabled:=buscar;

BotonImprimir.Enabled:=imprimir;

Navegador.Enabled:=navegar;
CancelarMovimiento1.Enabled:=cancela;
Eliminar1.Enabled:=nuevo;

Reportes1.Enabled:=not guardar;
Buscar1.Enabled:=not guardar;
Buscar2.Enabled:=not guardar;
ImprimeRango1.Enabled:=not guardar;

end;
end;

{*******************}

procedure borraauxiliar;
begin
with FormaClientes do
begin

Tablaauxiliar.First;
while not TablaAuxiliar.Eof do
begin
TablaAuxiliar.Delete;
end;
Fuentetablacliente.DataSet:=TablaCliente;
end;
end;



procedure agregacambios;
var
i:integer;
begin
with FormaClientes do
begin
Tablaauxiliar.Edit;
TablaAuxiliar.Post;
TablaCliente.Edit;
for i:=0 to TablaCliente.FieldCount-1 do
begin
TablaCliente.FieldByName(TablaAuxiliar.Fields[i].FieldName).AsString:=Tablaauxiliar.FieldByName(TablaAuxiliar.Fields[i].FieldName).AsString;
end;



{**************}
borraauxiliar;


end;
end;



procedure copiaregistro;
begin

with FormaClientes do
begin
TablaAuxiliar.Close;
Tablaauxiliar.DatabaseName:=lee_ruta;
Tablaauxiliar.TableName:='ClieAuxi.dbf';
Estructura.Execute;
Fuentetablacliente.DataSet:=TablaAuxiliar;
TablaAuxiliar.Open;
end;

{TablaAuxiliar.First;}

end;

procedure ponecolor(indi:integer;col1:TColor);
begin
with FormaClientes do
begin
color1:=col1;
TDBEdit(Components[indi]).Color:=ClAqua;
end;
end;

procedure quitacolor(indi:integer);
begin
with FormaClientes do
begin
TDBEdit(Components[indi]).Color:=Color1;

end;
end;


procedure asignatipo;
type
datos=record
archivo:String[60];
descrip:String[125];
end;
var
dat:datos;
faltan:Boolean;
arch,arch2:file of datos;
i:integer;
begin
with FormaConsulta do
begin
{MuestraMensaje(lee_ruta+'\report\Clientes.for');}
if fileExists(ruta(8)+'\report\Clientes.for') then
begin
AssignFile(arch,ruta(8)+'\report\Clientes.for');
Reset(arch);
Archivo.Items.Clear;
Descripcion.Clear;
faltan:=True;
for i:=0 to FileSize(arch)-1 do
begin
Read(arch,dat);
if FileExists(Dat.archivo) then
Archivo.Items.Append(Dat.archivo)
else
faltan:=False;
end;
CloseFile(arch);


if faltan=False then
begin
AssignFile(arch,ruta(8)+'\report\Clientes.for');
Reset(arch);
AssignFile(arch2,ruta(8)+'\report\Cliente2.for');
Rewrite(arch2);

for i:=0 to FileSize(arch)-1 do
begin
Read(arch,dat);
if FileExists(Dat.archivo) then
write(arch2,dat);
end;
CloseFile(arch);
CloseFile(arch2);
{******************}
AssignFile(arch,ruta(8)+'\report\Clientes.for');
Rewrite(arch);
AssignFile(arch2,ruta(8)+'\report\Cliente2.for');
Reset(arch2);

for i:=0 to FileSize(arch2)-1 do
begin
Read(arch2,dat);
if FileExists(Dat.archivo) then
write(arch,dat);
end;
CloseFile(arch);
CloseFile(arch2);
end;


Archivo.Text:=Archivo.Items[0];
Descripcion.lines.Add(Dat.Descrip);

//ReporteDe.Caption:='Reporte de Clientes';
Archi.Caption:='Clientes.for';
end;

end;
end;


procedure TamanoCampos(Tabla:TTable);
var
  I: Integer;
begin
with FormaClientes do
begin
Tabla.DatabaseName:=ruta_8;
Tabla.FieldDefs.Update;
    for I := 0 to ComponentCount -1 do
    begin
     if Components[I] is TStringField  then
     begin
       //('encontrado');
       try
//       ShowMessage(TStringField(Components[I]).FieldName+' '+inttostr(TablaCliente.FieldDefs.Items[TablaCliente.FieldDefs.IndexOf(TStringField(Components[I]).FieldName)].Size));
       TStringField(Components[I]).Size:=Tabla.FieldDefs.Items[Tabla.FieldDefs.IndexOf(TStringField(Components[I]).FieldName)].Size;
       except
//       MuestraMensaje('Ha Ocurrido un Error al Abrir una de las Bases de Datos.');
       end;
     end;
    end;
    end;


end;







procedure rutas;
var
  I: Integer;
begin

   ruta_8:=ruta(8);
//   MuestraMensaje(ruta_8);
   lee_ruta:=leeruta;

with FormaClientes do
begin
  for I := 0 to ComponentCount -1 do
    begin
     if Components[I] is TTable  then
     begin

     if TTable(Components[I]).TableName<>'ClieAuxi.dbf' then

        TTable(Components[I]).DatabaseName:=ruta_8
        else
        TTable(Components[I]).DatabaseName:=lee_ruta;

       try
//       TamanoCampos(TTable(Components[I]));
//       TTable(Components[I]).Open;
       AbreTablaTotal(TTable(Components[i]));
       except
       MuestraMensaje('Ha Ocurrido un Error al Abrir una de las Bases de Datos.'+TTable(Components[I]).TableName);
       end;
     end;
    end;
//****parametros de clientes
if ruta(34)='S' then
begin
EditCLCLI_C.ReadOnly:=True;
end;



end;

end;




procedure limpiar;
//var
  //I: Integer;
begin
{
with FormaClientes do
begin
  for I := 0 to ComponentCount -1 do
    begin
     if Components[I] is TDBEdit  then
       TDBEdit(Components[I]).Text :='';
     if Components[I] is TEdit  then
       TEdit(Components[I]).Text :='';

  end;
end;
 }
end;

procedure activa;
//var
  //I: Integer;
begin
with FormaClientes do
begin
{  for I := 0 to ComponentCount -1 do
    begin
     if Components[I] is TDBEdit  then
       TDBEdit(Components[I]).Enabled :=True;
     if Components[I] is TEdit  then
       TEdit(Components[I]).Enabled :=True;
     if Components[I] is TLabel then
       TLabel(Components[I]).Enabled :=True;
end;}
Caja.Enabled:=True;
end;
end;

procedure desactiva;
//var
 // I: Integer;
begin
with FormaClientes do
begin
Caja.Enabled:=False;
  {for I := 0 to ComponentCount -1 do
    begin
     if Components[I] is TDBEdit then
       TDBEdit(Components[I]).Enabled :=False;
     if Components[I] is TEdit then
       TEdit(Components[I]).Enabled :=False;
     if Components[I] is TLabel then
       TLabel(Components[I]).Enabled :=False;
end; }

end;
end;

procedure cursor1;
begin
{With FormaClientes do
begin
if indice > 20 then indice:=1;
if indice < 1 then indice:=1;
case indice of
1:EditCLCLI_C.SetFocus;
2:EditNOMBR_C.SetFocus;
3:EditTELEF_C.SetFocus;
4:DBEdit1.SetFocus;
5:EditRFCXX_C.SetFocus;
6:EditCURPX_C.SetFocus;
7:EditDIREC_C.SetFocus;
8:EditDIRE2_C.SetFocus;
9:EditPOBLA_C.SetFocus;
10:EditCPXXX_C.SetFocus;

11:EditDCRED_C.SetFocus;
12:EditDREPA_C.SetFocus;
13:EditHOREV_C.SetFocus;
14:EditZONAX_C.SetFocus;
15:EditDIPAG_C.SetFocus;
16:EditHOPAG_C.SetFocus;


17:EditFULCO_C.SetFocus;
18:EditCLVEN_C.SetFocus;
19:EditSALDO_C.SetFocus;
20:EditCOMPR_C.SetFocus;
//18:DBEdit3.SetFocus;
//19:DBEdit2.SetFocus;
end;
end;}
end;

procedure muevecursor(tecla:integer);

begin

{ith FormaClientes do

begin

case tecla of

 13:begin
    if i=ComponentCount-1 then i:=0 else i:=i+1;
    TDBEdit(Components[i]).SetFocus;
    end;

 40:begin
    if i=ComponentCount-1 then i:=0 else i:=i+1;
     TDBEdit(Components[i]).SetFocus;
    end;

 38:begin
    if i=0 then i:=0 else i:=i-1;
    TDBEdit(Components[i]).SetFocus;
    end;
   end;
  end;}
end;

{***posiciona desde catalogo****}

procedure posicionacliente(clave:string);
begin
with Formaclientes do
begin
if FormaClientes.Tag=0 then
begin
Refresh;

rutas;

desactiva;
limpiar;
activabotones(True,True,False,True,True,True,False);
indice:=1;
PoneDatoscliente;
end;
FormaClientes.Tag:=1;
TablaCliente.FindKey([clave]);

end;
end;



{****************************}


procedure TFormaClientes.FormCreate(Sender: TObject);
begin


// TamanoCampos(TablaCliente);
  FormatosPais;
  i:=0;
  BotonGuardar.Enabled:=False;
  Guardar1.Enabled:=False;
  formatonum:=12;
  lee_ruta:=leeruta;
  nombreformato:=lee_ruta+'\consulta\'+ruta(12);
  end;

procedure TFormaClientes.EditCLCLI_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
//  var
//   Msg: TMsg;
//   WControl: TWinControl;
//   aux:string;
//   MyList : TList;

begin

if key=112 then
muestraayuda('Clave','CL001-004','Cadena','10');

if (Key=13) or (Key=40) then
begin
//with Sender as TDBEdit do
BuscaTabOrder(Sender,TabOrder,1);
indice:=indice+1;
cursor1;

end;
if Key=38 then
begin
BuscaTabOrder(Sender,TabOrder,-1);
indice:=indice-1;
cursor1;
end;
end;

procedure TFormaClientes.BotonNuevoClick(Sender: TObject);
var
ultimo:string[10];
begin

if caso(StrToInt(usuario.Caption),11) then
begin

TablaCliente.IndexName:='ICLACLI';


if ruta(34)='S' then
begin
ultimo:=ClienteConsecutivo;
TablaCliente.Insert;
TablaCliente.FieldByName('CLCLI_C').AsString:=ultimo;
EditCLCLI_C.ReadOnly:=True;
end
else
TablaCliente.Insert;

//TablaCliente.Post;
//TablaCliente.Edit;

activa;
activabotones(False,False,True,False,False,False,True);
BotonCambios.Tag:=0;
BotonNuevo.Tag:=1;

{*********}
//Cargo.Caption:='Cargos '+convierte('###,###,##0.00','0','$');
//Abono.Caption:='Abonos '+convierte('###,###,##0.00','0','$');

{**********}

EditCLCLI_C.SetFocus;
Panel2.Color:=clRed;
end;
end;

procedure TFormaClientes.BotonGuardarClick(Sender: TObject);
var
//cadenauno:string[20];
ulti:string[20];
entra:Boolean;
begin
//MuestraMensaje(EditCLCLI_c.Text);
if EditCLCLI_C.Text<>'' then
begin
{XXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{*********************}
entra:=False;
if (BotonNuevo.Tag=1) then
begin
if TablaRepetido.FindKey([EditCLCLI_c.Text]) then
begin
MuestraMensaje('La Clave ya Existe Es Necesario Cambiarla');
EditCLCLI_c.SetFocus;
end
else
begin
entra:=True;
TablaCliente.Post;
TablaCliente.Refresh;
activabotones(True,True,False,True,True,True,False);
desactiva;
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
Panel2.Color:=clBlue;
end;
end;//nuevo
{*********************}

if (BotonCambios.Tag=1) then
begin

if EditCLCLI_C.Text=cadenarepite then
begin
agregacambios;
TablaCliente.Post;
TablaCliente.Refresh;
activabotones(True,True,False,True,True,True,False);
desactiva;
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
entra:=True;
Panel2.Color:=clBlue;
end
else
begin
{******}
if TablaRepetido.FindKey([EditCLCLI_c.Text]) then
begin
MuestraMensaje('La clave esta Repetida...');
EditCLCLI_C.SetFocus;
end
else
begin
agregacambios;
TablaCliente.Post;
TablaCliente.Refresh;
activabotones(True,True,False,True,True,True,False);
desactiva;
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
entra:=True;
end;
{********}
end;

end;//cambio

if (ruta(1)='NO')and(entra) then
begin
ulti:=EditCLCLI_C.Text;
//MuestraMensaje('guarda permanete');
GuardaPendientes(TablaCliente);
TablaCliente.FindKey([ulti]);
//ponedatos;
end;


{XXXXXXXXXXXXXXXXXXXXXXX*}
end
else
begin
MuestraMensaje('La Clave No Existe');
EditCLCLI_C.SetFocus;
end;

end;

procedure TFormaClientes.BotonSalirClick(Sender: TObject);
begin
Close;
end;

procedure TFormaClientes.Consulta1Click(Sender: TObject);
begin
FormaConsulta:=TFormaConsulta.Create(Application);
FormaConsulta.TablaConsulta.DataBaseName:=ruta_8;
//FormaConsulta.TablaConsulta.IndexName:='ICLACLI';
FormaConsulta.TablaConsulta.TableName:='cliente.dbf';

FormaConsulta.TablaConsulta.Open;
FormaConsulta.TablaConsulta.First;
//FormaConsulta.De.Text:=FormaConsulta.TablaConsulta.Fields[0].AsString;
FormaConsulta.TablaConsulta.Last;
//FormaConsulta.Hasta.Text:=FormaConsulta.TablaConsulta.Fields[0].AsString;
FormaConsulta.TablaConsulta.First;

//FormaConsulta.RutaCampos.Text:=lee_ruta+'\consulta\cliente.dbf';
//FormaConsulta.TipoVista.Text:=lee_ruta+'\consulta\cliente.vis';
//FormaConsulta.Destino.Text:=lee_ruta+'\tempo\repcli.rep';
FormaConsulta.NumCampo.Caption:='0';
asignatipo;
leearchivocampos('cliente.dbf','');
formaConsulta.ShowModal;
FormaConsulta.Free;
end;

procedure TFormaClientes.FormActivate(Sender: TObject);
begin

if FormaClientes.Tag=0 then
begin
{********}
{********}
rutas;
//Tablacliente.Fields[0].OnGetText
//TablaAuxiliar.Fields[0].EditMask:='###,##0.00';
//TablaClienteCLCLI_C.DisplayFormat:='###,##0.00';
desactiva;
{limpiar;}
BotonNuevo.Enabled:=True;
BotonGuardar.Enabled:=False;
{BotonImprimir.Enabled:=False;}
indice:=1;
//Cargo.Caption:='Cargos '+convierte('###,###,##0.00',TablaCliente.FieldByName('CARGO_C').AsString,'$');
//Abono.Caption:='Abonos '+convierte('###,###,##0.00',TablaCliente.FieldByName('ABONO_C').AsString,'$');
PoneDatosCliente;
Show;

end;
if (BotonNuevo.Tag<>1)and(BotonCambios.Tag<>1) then
TablaCliente.Refresh;
FormaClientes.Tag:=1;

end;

procedure TFormaClientes.BotonBuscarClick(Sender: TObject);
//var
//siguiente:String;
begin
{FormaClientes.Tag:=11;}
FormaBusqueda:=TFormaBusqueda.Create(Application);
FormaBusqueda.ShowModal;
if FormaBusqueda.Clave.Checked then
begin
TablaCliente.IndexName:='ICLACLI';
FormaClientes.Caption:='Consulta Cobranza Ordenado por Clave';
end
else
begin
TablaCliente.IndexName:='NOMBR_C';
FormaClientes.Caption:='Consulta Cobranza Ordenado por Nombre';
end;
try
TablaCliente.FindNearest([FormaBusqueda.CajaBuscar.Text]);
except
MuestraMensaje('Valor no Válido');
end;
//Cargo.Caption:='Cargos '+TablaCliente.FieldByName('CARGO_C').AsString;
//Abono.Caption:='Abonos '+TablaCliente.FieldByName('ABONO_C').AsString;
PoneDatosCliente;
FormaBusqueda.Free;
end;



procedure TFormaClientes.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
{MuestraMensaje('Cerrando');}
FormaCerrar:=TFormaCerrar.Create(Application);
if (BotonCambios.Tag=1)or (BotonNuevo.Tag=1) then
begin

FormaCerrar.ShowModal;

if FormaCerrar.Tag=1 then
begin
if BotonCambios.Tag=1 then
agregacambios;
TablaCliente.Post;
activabotones(True,True,False,True,True,True,False);
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
desactiva;
  MyList.Free;
end;

if FormaCerrar.Tag=2 then
begin
if BotonCambios.Tag=1 then
borraauxiliar;
TablaCliente.Cancel;
if BotonNuevo.Tag=1 then
begin
try
TablaCliente.Cancel;
//Tablacliente.Delete;
except
end;
  MyList.Free;
end;
activabotones(True,True,False,True,True,True,False);
BotonCambios.Tag:=0;
BotonNuevo.Tag:=0;
desactiva;
end;

if FormaCerrar.Tag=3 then
Action:=caNone;
FormaCerrar.Tag:=0;
end;
BotonSalir.Tag:=1000;
FormaCerrar.Free;
end;

procedure TFormaClientes.BotonImprimirClick(Sender: TObject);
begin

if ImpresoraLista then
begin
if FileExists(nombreformato) then
begin
UsuarioActual(Usuario.Caption);
forma(TablaCliente,TablaCliente,nombreformato,'i')
end
else
MuestraMensaje('El Formato '+nombreformato+' No Existe');
end
else
MuestraMensaje('La Impresora No Se Encuentra Lista...');
end;

procedure TFormaClientes.Eliminar1Click(Sender: TObject);
begin
FormaAdvertencia:=TFormaAdvertencia.Create(Application);
if caso(StrToInt(usuario.Caption),12) then
begin
if TablaCliente.FieldByName('SALDO_C').AsFloat=0 then
begin
FormaAdvertencia.Label1.Caption:='Esta Seguro de Eliminar este Registro ?';
FormaAdvertencia.ShowModal;
if FormaAdvertencia.Tag=1 then

TablaCliente.Delete;
FormaAdvertencia.Tag:=0;
end
else
MuestraMensaje('No se puede eliminar cliente con saldo');
end;
end;

procedure TFormaClientes.BotonCambiosClick(Sender: TObject);
begin
if caso(StrToInt(usuario.Caption),13) then
begin
TablaCliente.IndexName:='ICLACLI';
cadenarepite:=TablaCliente.FieldByName('CLCLI_C').AsString;
copiaregistro;

{if caso(StrToInt(usuario.Caption),13) then
begin}
{TablaCliente.Edit;}
TablaAuxiliar.Edit;
activa;
activabotones(False,False,True,False,False,False,True);




{Navegador.Enabled:=False;
BotonCambios.Enabled:=False;
BotonNuevo.Enabled:=False;
Nuevo1.Enabled:=False;
Modificar1.Enabled:=False;

Guardar1.Enabled:=True;
BotonGuardar.Enabled:=True;}
EditCLCLI_C.SetFocus;
BotonCambios.Tag:=1;
BotonNuevo.Tag:=0;
Panel2.Color:=clRed;
end;

end;

procedure TFormaClientes.EditCLCLI_CEnter(Sender: TObject);
begin
ponecolor(EditCLCLI_C.ComponentIndex,EditCLCLI_C.Color);
indice:=1;
Uno.Caption:=comenta(1,'clientes.des');
Dos.Caption:=comenta(2,'clientes.des');
end;

procedure TFormaClientes.EditNOMBR_CEnter(Sender: TObject);
//var
//lista:Tlist;
//aux:string;
//i:integer;
//contr:TWinControl;
begin
{ lista:=TList.Create;
 contr.Create(Application);
 caja.GetTabOrderList(lista);
 contr:=FindNextControl(caja,True,True,True);

  aux:=contr.Name;

//MuestraMensaje();
lista.Free;
contr.free;}
ponecolor(EditNOMBR_C.ComponentIndex,EditNOMBR_C.Color);
indice:=2;
Uno.Caption:=comenta(3,'clientes.des');
Dos.Caption:=comenta(4,'clientes.des');
end;

procedure TFormaClientes.EditTELEF_CEnter(Sender: TObject);
begin
ponecolor(EditTELEF_C.ComponentIndex,EditTELEF_C.Color);
indice:=3;
Uno.Caption:=comenta(5,'clientes.des');
Dos.Caption:=comenta(6,'clientes.des');

end;

procedure TFormaClientes.EditRFCXX_CEnter(Sender: TObject);
begin
ponecolor(EditRFCXX_C.ComponentIndex,EditRFCXX_C.Color);
indice:=5;
Uno.Caption:=comenta(7,'clientes.des');
Dos.Caption:=comenta(8,'clientes.des');
end;

procedure TFormaClientes.EditDIREC_CEnter(Sender: TObject);
begin
ponecolor(EditDIREC_C.ComponentIndex,EditDIREC_C.Color);
indice:=7;
Uno.Caption:=comenta(11,'clientes.des');
Dos.Caption:=comenta(12,'clientes.des');
end;

procedure TFormaClientes.EditPOBLA_CEnter(Sender: TObject);
begin
ponecolor(EditPOBLA_C.ComponentIndex,EditPOBLA_C.Color);
indice:=9;
Uno.Caption:=comenta(15,'clientes.des');
Dos.Caption:=comenta(16,'clientes.des');
end;

procedure TFormaClientes.EditCPXXX_CEnter(Sender: TObject);
begin
ponecolor(EditCPXXX_C.ComponentIndex,EditCPXXX_C.Color);
indice:=10;
Uno.Caption:=comenta(17,'clientes.des');
Dos.Caption:=comenta(18,'clientes.des');
end;

procedure TFormaClientes.EditDREPA_CEnter(Sender: TObject);
begin
ponecolor(EditDREPA_C.ComponentIndex,EditDREPA_C.Color);
indice:=12;
Uno.Caption:=comenta(19,'clientes.des');
Dos.Caption:=comenta(20,'clientes.des');
ponecolor(EditDCRED_C.ComponentIndex,EditDCRED_C.Color);


end;

procedure TFormaClientes.EditZONAX_CEnter(Sender: TObject);
begin
ponecolor(EditZONAX_C.ComponentIndex,EditZONAX_C.Color);
indice:=14;
Uno.Caption:=comenta(21,'clientes.des');
Dos.Caption:=comenta(22,'clientes.des');
end;

procedure TFormaClientes.EditDCRED_CEnter(Sender: TObject);
begin
ponecolor(EditDCRED_C.ComponentIndex,EditDCRED_C.Color);
indice:=11;
Uno.Caption:=comenta(23,'clientes.des');
Dos.Caption:=comenta(24,'clientes.des');
end;

procedure TFormaClientes.EditFULCO_CEnter(Sender: TObject);
begin
ponecolor(EditFULCO_C.ComponentIndex,EditFULCO_C.Color);
indice:=17;
Uno.Caption:=comenta(25,'clientes.des');
Dos.Caption:=comenta(26,'clientes.des');

end;

procedure TFormaClientes.EditCLVEN_CEnter(Sender: TObject);
begin
ponecolor(EditCLVEN_C.ComponentIndex,EditCLVEN_C.Color);
indice:=18;
Uno.Caption:=comenta(27,'clientes.des');
Dos.Caption:=comenta(28,'clientes.des');
end;

procedure TFormaClientes.EditSALDO_CEnter(Sender: TObject);
begin
ponecolor(EditSALDO_C.ComponentIndex,EditSALDO_C.Color);
indice:=19;
Uno.Caption:=comenta(29,'clientes.des');
Dos.Caption:=comenta(30,'clientes.des');
end;

procedure TFormaClientes.EditCOMPR_CEnter(Sender: TObject);
begin
ponecolor(EditCOMPR_C.ComponentIndex,EditCOMPR_C.Color);
indice:=20;
Uno.Caption:=comenta(31,'clientes.des');
Dos.Caption:=comenta(32,'clientes.des');
end;

procedure TFormaClientes.EditRFCXX_CMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(5,'clientes.des');
Dos.Caption:=comenta(6,'clientes.des');
end;

procedure TFormaClientes.NavegadorClick(Sender: TObject;
  Button: TNavigateBtn);
begin
PoneDatosCliente;
end;

procedure TFormaClientes.VentasPorCliente1Click(Sender: TObject);

begin
with Sender as TMenuItem do
begin
DatosReporte(TablaCliente,//tabla de datos
true,true,False,False,False,true,true,true,true,'cliente.dbf',//condiciones
'CLCLI_C',Caption,//campo desde/hasta y titulo
'Cliente','Nombre','Saldos','Compras Totales','','','','','','','', //etiquetas
'f','f','f','CLCLI_C','NOMBR_C','SALDO_C','COMPR_C','','','','','','','','X','','D',
20,20,20,20,20,20,20,20,20,20,0, //anchos
'Clave del Cliente','Total de Venta',1);//parametros de grafica

end;


{FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);
FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,False,False,true,true,true,true,'cliente.dbf');
TablaCliente.First;
desde:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
hastavalor:=TablaCliente.FieldByName('CLCLI_C').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
TablaCliente.First;
if FormaFormatos.Tag=1 then
begin
AsignaVariables('','','','','','','','','','','','','','','','');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
Concentrar(TablaCliente,Formaformatos.De.Text,FormaFormatos.Hasta.Text,'f','f','f','CLCLI_C','NOMBR_C','SALDO_C','COMPR_C','','','','','','','','X','','D');
poneetiquetas('Cliente','Nombre','Saldos','Cpras. Anuales','','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Ventas por Clientes','Clave del Cliente','Total de Venta',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte de Ventas por Cliente';
//******pone el titulo
 with Sender as TMenuItem do
  begin
  desde:=Caption;
  end;
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;

end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;}
end;

procedure TFormaClientes.Ventas1Click(Sender: TObject);

begin
with Sender as TMenuItem do
begin
DatosReporte(TablaCliente,//tabla de datos
true,true,False,False,False,true,true,true,true,'cliente.dbf',//condiciones
'CLCLI_C',Caption,//campo desde/hasta y titulo
'Cliente','-Nombre','Cargos','Abonos','Saldos','','','','','','', //etiquetas
'f','f','f','CLCLI_C','NOMBR_C','CARGO_C','ABONO_C','SALDO_C','','','','','','','X','','D',
20,20,20,20,20,20,20,20,20,20,0, //anchos
'Clave del Cliente','Saldos',3);//parametros de grafica

end;



{FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);
FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,False,False,true,true,true,true,'cliente.dbf');
TablaCliente.First;
desde:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
hastavalor:=TablaCliente.FieldByName('CLCLI_C').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
TablaCliente.First;
if FormaFormatos.Tag=1 then
begin
AsignaVariables('','','','','','','','','','','','','','','','');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
Concentrar(TablaCliente,Formaformatos.De.Text,Formaformatos.Hasta.Text,'f','f','f','CLCLI_C','NOMBR_C','CARGO_C','ABONO_C','SALDO_C','','','','','','','X','','D');
poneetiquetas('Cliente','-Nombre','Cargos','Abonos','Saldos','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Cargos y Abonos por Cliente','Clave del Cliente','Saldos',3);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte de Saldos';
//******pone el titulo
 with Sender as TMenuItem do
  begin
  desde:=Caption;
  end;
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;

end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;}

end;

procedure TFormaClientes.Saldos1Click(Sender: TObject);
//var
//desde{,hastavalor}:string;
begin
with Sender as TMenuItem do
begin
DatosReporte(TablaCliente,//tabla de datos
true,true,False,False,False,true,true,true,true,'cliente.dbf',//condiciones
'CLCLI_C',Caption,//campo desde/hasta y titulo
'Cliente','Nombre','Saldos','Compras Totales','','','','','','','', //etiquetas
'f','f','f','CLCLI_C','NOMBR_C','SALDO_C','','','','','','','','','X','','D',
20,20,20,20,20,20,20,20,20,20,0, //anchos
'Clave del Cliente','Total de Venta',1);//parametros de grafica

end;


{FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);
FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,False,False,true,true,true,true,'cliente.dbf');
TablaCliente.First;
desde:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
hastavalor:=TablaCliente.FieldByName('CLCLI_C').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
TablaCliente.First;
if FormaFormatos.Tag=1 then
begin
AsignaVariables('','','','','','','','','','','','','','','','');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
Concentrar(TablaCliente,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'f','f','f','CLCLI_C','NOMBR_C','SALDO_C','','','','','','','','','X','','D');
poneetiquetas('Cliente','Nombre','Saldo','','','','','','','','');
PoneAnchos(15,40,20,20,20,20,20,20,20,20,0);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte de Saldos';
//******pone el titulo
 with Sender as TMenuItem do
  begin
  desde:=Caption;
  end;
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;

end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;}
end;

procedure TFormaClientes.EditDREPA_CMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(13,'clientes.des');
Dos.Caption:=comenta(14,'clientes.des');
end;

procedure TFormaClientes.EditFULCO_CMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
Uno.Caption:=comenta(19,'clientes.des');
Dos.Caption:=comenta(20,'clientes.des');
end;

procedure TFormaClientes.EditCURPX_CEnter(Sender: TObject);
begin
ponecolor(EditCURPX_C.ComponentIndex,EditCURPX_C.Color);
indice:=6;
Uno.Caption:=comenta(9,'clientes.des');
Dos.Caption:=comenta(10,'clientes.des');

end;

procedure TFormaClientes.EditCURPX_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditDIRE2_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditDIRE2_CEnter(Sender: TObject);
begin
ponecolor(EditDIRE2_C.ComponentIndex,EditDIRE2_C.Color);
indice:=8;
Uno.Caption:=comenta(13,'clientes.des');
Dos.Caption:=comenta(14,'clientes.des');

end;

procedure TFormaClientes.SaldosPorZona1Click(Sender: TObject);
//var
//desde,hastavalor:string;

begin

with Sender as TMenuItem do
begin
DatosReporte(TablaCliente,//tabla de datos
true,true,False,False,False,true,true,true,true,'cliente.dbf',//condiciones
'CLCLI_C',Caption,//campo desde/hasta y titulo
'Zona','Nombre','Saldo','','','','','','','','', //etiquetas
'f','f','f','ZONAX_C','NOMBR_C','SALDO_C','','','','','','','','','X','','D',
20,20,20,20,20,20,20,20,20,20,0, //anchos
'Clave del Cliente','Saldos',1);//parametros de grafica

end;


{
FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);

DeleteFile(PChar(lee_ruta+'\tempo\concen.tmp'));
DeleteFile(PChar(lee_ruta+'\tempo\orden.tmp'));
DeleteFile(PChar(lee_ruta+'\tempo\etique.tmp'));
DeleteFile(PChar(lee_ruta+'\tempo\final.tmp'));


FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,False,False,true,true,true,true,'cliente.dbf');
TablaCliente.First;
desde:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
hastavalor:=TablaCliente.FieldByName('CLCLI_C').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
AsignaVariables('','','','','','','','','','','','','','','','');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
Concentrar(TablaCliente,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'f','f','f','ZONAX_C','NOMBR_C','SALDO_C','','','','','','','','','X','','D');
poneetiquetas('Zona','Nombre','Saldo','','','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);
parametrosgrafica('Gráfica de Saldos por Zona de Clientes','Clave del Cliente','Saldos',1);
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte de Saldos por Zona de Clientes';
//******pone el titulo
 with Sender as TMenuItem do
  begin
  desde:=Caption;
  end;
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;


end;
FormaFormatos.Tag:=0;
FormaFormatos.Free;
FormaBarras.Free;}
end;

procedure TFormaClientes.formatoClick(Sender: TObject);
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaFormatos.Tag:=3;
FormaFormatos.Rangos.Visible:=False;
FormaFormatos.Formatos.Visible:=True;
FormaFormatos.ShowModal;
if FormaFormatos.Tag=1 then
begin
if FileExists(Formaformatos.Rutas.Text) then
begin
nombreformato:=Formaformatos.ArchivoLista.FileName;
{forma(TablaCliente,TablaCliente,Formaformatos.Rutas.Text,'i')}

end
else
MuestraMensaje('El Formato '+nombreformato+' No Existe');
end;
 FormaFormatos.Tag:=1;
FormaFormatos.Free;
end;




















procedure TFormaClientes.DiseaFormato1Click(Sender: TObject);
begin
FormaFormatos:=TFormaFormatos.Create(Application);
FormaFormatos.Rangos.Visible:=False;
FormaFormatos.Formatos.Visible:=True;
FormaFormatos.BotonEdicionClick(Sender);

//FormaFormatos.ShowModal;
FormaFormatos.Free;
end;

procedure TFormaClientes.TablaClientePostError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
DatabaseError('No se Pueden Guardar los Datos ha Ocurrido un Error');
{MuestraMensaje('No se Pueden Guardar los Datos Registro en Uso');}
end;

procedure TFormaClientes.TablaClienteEditError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
DatabaseError('No se Pueden Editar los Datos Registro en Uso');
end;



procedure TFormaClientes.EditCLCLI_CExit(Sender: TObject);
begin
quitacolor(EditCLCLI_C.ComponentIndex);
if EditCLCLI_C.Text='' then
begin
MuestraMensaje('Es Necesario Escribir una Clave...');
try
EditCLCLI_C.SetFocus;
except
end;
end;
//EditCLCLI_C.Text:=VerificaDato(EditCLCLI_C.Text);
end;

procedure TFormaClientes.EditNOMBR_CExit(Sender: TObject);
begin
quitacolor(EditNOMBR_C.ComponentIndex);
end;

procedure TFormaClientes.EditTELEF_CExit(Sender: TObject);
begin
quitacolor(EditTELEF_C.ComponentIndex);
end;

procedure TFormaClientes.EditRFCXX_CExit(Sender: TObject);
begin
quitacolor(EditRFCXX_C.ComponentIndex);
end;

procedure TFormaClientes.EditCURPX_CExit(Sender: TObject);
begin
quitacolor(EditCURPX_C.ComponentIndex);
end;

procedure TFormaClientes.EditDIREC_CExit(Sender: TObject);
begin
quitacolor(EditDIREC_C.ComponentIndex);
end;

procedure TFormaClientes.EditDIRE2_CExit(Sender: TObject);
begin
quitacolor(EditDIRE2_C.ComponentIndex);
end;

procedure TFormaClientes.EditPOBLA_CExit(Sender: TObject);
begin
quitacolor(EditPOBLA_C.ComponentIndex);
end;

procedure TFormaClientes.EditCPXXX_CExit(Sender: TObject);
begin
quitacolor(EditCPXXX_C.ComponentIndex);
end;

procedure TFormaClientes.EditDREPA_CExit(Sender: TObject);
begin
quitacolor(EditDREPA_C.ComponentIndex);
end;

procedure TFormaClientes.EditZONAX_CExit(Sender: TObject);
begin
quitacolor(EditZONAX_C.ComponentIndex);
end;

procedure TFormaClientes.EditDCRED_CExit(Sender: TObject);
begin
quitacolor(EditDCRED_C.ComponentIndex);
end;

procedure TFormaClientes.EditFULCO_CExit(Sender: TObject);
begin
quitacolor(EditFULCO_C.ComponentIndex);
end;

procedure TFormaClientes.EditCLVEN_CExit(Sender: TObject);
begin
quitacolor(EditCLVEN_C.ComponentIndex);
end;

procedure TFormaClientes.EditSALDO_CExit(Sender: TObject);
begin
quitacolor(EditSALDO_C.ComponentIndex);
end;

procedure TFormaClientes.EditCOMPR_CExit(Sender: TObject);
begin
quitacolor(EditCOMPR_C.ComponentIndex);
end;

procedure TFormaClientes.Panel3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button= mbLeft then
begin
FormaClientes.Left:=FormaClientes.Left-1;
end;

end;

procedure TFormaClientes.EditNOMBR_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=112 then
muestraayuda('Nombre','Sistemas Neumáticos y de Control, S.A. de C.V.','Cadena','60');
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditTELEF_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=112 then
muestraayuda('Telefono','54-60-70-76','Cadena','20');

if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;


procedure TFormaClientes.ListadodeClientes1Click(Sender: TObject);
begin

with Sender as TMenuItem do
ReporteSIF(Caption,'CLCLI_C','','','',TablaCliente,
           '$'+FormaBarras.Caption+char(13)+
           '& Select CLCLI_C,NOMBR_C,TELEF_C,RFCXX_C,POBLA_C,CLCLI_C« from "'+ruta(8)+'\'+TablaCliente.TableName+'"'+char(13)+
           '?(CLCLI_C=CLCLI_C)'+'¿'+char(13)+
           '!CLCLI_C'+char(13)+
           '%c          c                  c               c                c'+char(13)+
           '#CLIENTE    NOMBRE             TELEFONO        R.F.C.           POBLACION          '+char(13)+
           '@'+char(13)
           ,0);


end;

procedure TFormaClientes.ClienteyTelefono1Click(Sender: TObject);
var
inicio,fin:string;
begin

//*******
TablaCliente.First;
inicio:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
fin:=TablaCliente.FieldByName('CLCLI_C').AsString;

with Sender as TMenuItem do
ReporteSIF(Caption,'CLCLI_C','','','',TablaCliente,
           '$'+FormaBarras.Caption+char(13)+
           '& Select CLCLI_C,NOMBR_C,TELEF_C from "'+ruta(8)+'\'+TablaCliente.TableName+'"'+char(13)+
           '?(CLCLI_C=CLCLI_C)'+'¿'+char(13)+
           '!CLCLI_C'+char(13)+
           '%c          c                  c'+char(13)+
           '#CLIENTE    NOMBRE             TELEFONO       '+char(13)+
           '@'+char(13)
           ,0);


{with Sender as TMenuItem do
begin
DatosReporte(TablaCliente,//tabla de datos
true,true,False,False,False,true,true,true,true,'cliente.dbf',//condiciones
'CLCLI_C',Caption,//campo desde/hasta y titulo
'Clave','Nombre','-Telefono','','','','','','','','', //etiquetas
'f','f','f','CLCLI_C','NOMBR_C','TELEF_C','','','','','','','','','X','','D',
20,20,20,20,20,20,20,20,20,20,0, //anchos
'','',1);//parametros de grafica

end;
                                }


{FormaFormatos:=TFormaFormatos.Create(Application);
FormaBarras:=TFormaBarras.Create(Application);
FormaFormatos.Rangos.Visible:=True;
FormaFormatos.Formatos.Visible:=False;
activacondiciones(true,true,False,False,False,true,true,true,true,'cliente.dbf');
TablaCliente.First;
desde:=TablaCliente.FieldByName('CLCLI_C').AsString;
TablaCliente.Last;
hastavalor:=TablaCliente.FieldByName('CLCLI_C').AsString;
valoresiniciales('','',desde,hastavalor);

FormaFormatos.ShowModal;
TablaCliente.First;
if FormaFormatos.Tag=1 then
begin
AsignaVariables('','','','','','','','','','','','','','','','');
condiciones(FormaFormatos.C1.Caption,tipooperador(FormaFormatos.Operador1.Text),FormaFormatos.Valor1.Text,FormaFormatos.T1.Caption,FormaFormatos.C2.Caption,tipooperador(FormaFormatos.Operador2.Text),FormaFormatos.Valor2.Text,FormaFormatos.T2.Caption,FormaFormatos.C3.Caption,tipooperador(FormaFormatos.Operador3.Text),FormaFormatos.Valor3.Text,FormaFormatos.T3.Caption,FormaFormatos.Conector.Text);
Concentrar(TablaCliente,FormaFormatos.De.Text,FormaFormatos.Hasta.Text,'f','f','f','NOMBR_C','TELEF_C','','','','','','','','','','X','','D');
poneetiquetas('Nombre','Telefono','','','','','','','','','');
Poneanchos(20,20,20,20,20,20,20,20,20,20,0);

FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=2;
FormaBarras.Concentrado.Clear;
//FormaBarras.Caption:='Reporte de Clientes';
//******pone el titulo
 with Sender as TMenuItem do
  begin
  desde:=Caption;
  end;
FormaBarras.Caption:=AgregaTitulo2('Reporte de '+desde,FormaFormatos.Titulo.Text);
//******termina pone el titulo

FormaBarras.ShowModal;
FormaBarras.Tag:=0;

end;
FormaFormatos.Tag:=0;

FormaFormatos.Free;
FormaBarras.Free;}


end;


procedure TFormaClientes.BotonCambiosMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

describir(Button,FormaClientes.Left+BotonCambios.Left,FormaClientes.Top+BotonCambios.Top+BotonCambios.Height,0);
end;

procedure TFormaClientes.BotonNuevoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaClientes.Left+BotonNuevo.Left,FormaClientes.Top+BotonNuevo.Top+BotonNuevo.Height,1);

end;

procedure TFormaClientes.BotonGuardarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaClientes.Left+BotonGuardar.Left,FormaClientes.Top+Botonguardar.Top+BotonGuardar.Height,2);

end;

procedure TFormaClientes.BotonBuscarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaClientes.Left+BotonBuscar.Left,FormaClientes.Top+BotonBuscar.Top+BotonBuscar.Height,3);

end;

procedure TFormaClientes.BotonImprimirMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaClientes.Left+BotonImprimir.Left,FormaClientes.Top+BotonImprimir.Top+BotonImprimir.Height,4);

end;

procedure TFormaClientes.Panel3StartDrag(Sender: TObject;
  var DragObject: TDragObject);
var
Boton: TMouseButton;
begin
if Boton= mbLeft then
begin
FormaClientes.Left:=FormaClientes.Left-1;
end;


end;

procedure TFormaClientes.Panel3DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
Boton: TMouseButton;
begin
if Boton= mbLeft then
begin
FormaClientes.Left:=FormaClientes.Left-1;
end;


end;

procedure TFormaClientes.Panel3DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var
Boton: TMouseButton;
begin
if Boton= mbLeft then
begin
FormaClientes.Left:=FormaClientes.Left-1;
end;

end;

procedure TFormaClientes.Panel3EndDrag(Sender, Target: TObject; X,
  Y: Integer);
var
Boton: TMouseButton;
begin
if Boton= mbLeft then
begin
FormaClientes.Left:=FormaClientes.Left-1;
end;


end;

procedure TFormaClientes.ImprimePantilla1Click(Sender: TObject);
begin
FormaClientes.Print;
end;

procedure TFormaClientes.Temas1Click(Sender: TObject);
begin

FormaAyudaLinea:=TFormaAyudaLinea.Create(Application);
PoneAyuda(lee_ruta+'\ayuda\clientes.rtf',0);
FormaAyudaLinea.Free;

end;

procedure TFormaClientes.ImprimeRango1Click(Sender: TObject);
begin
DialogoImprimir:=TDialogoImprimir.Create(Application);
DialogoImprimir.ShowModal;
if Tag=1 then
begin

TablaCliente.SetRange([DialogoImprimir.PrimeraPagina.Text],[DialogoImprimir.UltimaPagina.Text]);

while not TablaCliente.Eof do
begin
if FileExists(nombreformato) then
begin
UsuarioActual(Usuario.Caption);
forma(TablaCliente,TablaCliente,nombreformato,'i');
end;
TablaCliente.Next;
end;

TablaCliente.CancelRange;
{else
MuestraMensaje('El Formato '+lee_ruta+'\consulta\'+ruta(12)+'No Existe');}
end;
DialogoImprimir.Free;
end;

procedure TFormaClientes.EditFULCO_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.CancelarMovimiento1Click(Sender: TObject);
begin
if (BotonNuevo.Tag=1) then
begin
TablaCliente.Delete;
activabotones(True,True,False,True,True,True,False);
desactiva;
end;

if (BotonCambios.Tag=1) then
begin
TablaAuxiliar.Delete;
FuenteTablaCliente.DataSet:=TablaCliente;
activabotones(True,True,False,True,True,True,False);
desactiva;
end;
BotonNuevo.Tag:=0;

BotonCambios.Tag:=0;

end;


procedure TFormaClientes.BotonPreliminarClick(Sender: TObject);
begin
FormaEdicion:=TFormaEdicion.Create(Application);

FormaEdicion.BotonImprime.Tag:=0;
if FileExists(nombreformato) then
begin
UsuarioActual(Usuario.Caption);
forma(TablaCliente,TablaCliente,nombreformato,'p');
end
else
MuestraMensaje('El Formato '+nombreformato+' No Existe');
FormaEdicion.Hoja.Tag:=0;
FormaEdicion.ShowModal;
if FormaEdicion.BotonImprime.Tag=1 then
begin
UsuarioActual(Usuario.Caption);
forma(TablaCliente,TablaCliente,nombreformato,'i');
end;

FormaEdicion.Free;

end;


procedure TFormaClientes.SpeedButton1Click(Sender: TObject);
begin
MuestraContactos(EditCLCLI_C.Text);
{FormaContactos.ShowModal;}
end;

procedure TFormaClientes.BusquedaNoIndexada1Click(Sender: TObject);
begin
FormaBusquedaNoIndexada:=TFormaBusquedaNoIndexada.Create(Application);
PoneCamposBusqueda('cliente.dbf');
if FormaBusquedaNoIndexada.Tag=1 then
begin
try
if not TablaCliente.Locate(FormaBusquedaNoIndexada.Campo2.Text, FormaBusquedaNoIndexada.Valor.Text, [loPartialKey])then
MuestraMensaje('No se Encuentra');
except
MuestraMensaje('Valor no Válido Revise Por Favor');
end;

end;
FormaBusquedaNoIndexada.Free;
end;


procedure TFormaClientes.DBEdit1Enter(Sender: TObject);
begin
ponecolor(DBEdit1.ComponentIndex,DBEdit1.Color);
indice:=4;
end;

procedure TFormaClientes.DBEdit1Exit(Sender: TObject);
begin
quitacolor(DBEdit1.ComponentIndex);
end;

procedure TFormaClientes.DBEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditRFCXX_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditDIREC_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditPOBLA_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditCPXXX_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditDREPA_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditZONAX_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditDCRED_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditCLVEN_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;


if  (Key=113)and(indice=18) then
begin
FormaClientes.Tag:=1;
EditCLVEN_C.Text:=LeeVendedor(EditCLVEN_C.Text);
Tag:=15;
end;

end;

procedure TFormaClientes.EditSALDO_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.EditCOMPR_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.DBEdit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;
end;

procedure TFormaClientes.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

if Shift=[ssCtrl] then
begin
case key of
65:
begin
TablaCliente.Prior;

end;

83:begin
TablaCliente.Next;
end;
end;

end;

case Key of
13: begin
       Key := 0;
       Perform(WM_NEXTDLGCTL, 0, 0);              //MUEVE AL SIGUIENTE CONTROL
   end;

40: begin
       Key := 0;
       Perform(WM_NEXTDLGCTL, 0, 0);              //MUEVE AL SIGUIENTE CONTROL
   end;

  38:  begin
      Perform(WM_NEXTDLGCTL, 1,0 );              //MUEVE AL anterior CONTROL
//       Key := 0;
   end
end;//case

end;


procedure TFormaClientes.DBEdit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;



procedure TFormaClientes.EditCLCLI_CChange(Sender: TObject);
begin
//FormatoCampo(TablaCliente,'CLCLI_C','###,##0');
end;

procedure TFormaClientes.EditSALDO_CChange(Sender: TObject);
begin
FormatoCampo(TablaCliente,'SALDO_C','#,###,##0.00');
end;

procedure TFormaClientes.EditCOMPR_CChange(Sender: TObject);
begin
FormatoCampo(TablaCliente,'COMPR_C','#,###,##0.00');
end;






procedure TFormaClientes.EditHOREV_CEnter(Sender: TObject);
begin
ponecolor(EditHOREV_C.ComponentIndex,EditHOREV_C.Color);
indice:=13;
Uno.Caption:=comenta(23,'clientes.des');
Dos.Caption:=comenta(24,'clientes.des');

end;

procedure TFormaClientes.EditDIPAG_CEnter(Sender: TObject);
begin
ponecolor(EditDIPAG_C.ComponentIndex,EditDIPAG_C.Color);
indice:=15;
Uno.Caption:=comenta(23,'clientes.des');
Dos.Caption:=comenta(24,'clientes.des');

end;

procedure TFormaClientes.EditHOPAG_CEnter(Sender: TObject);
begin
ponecolor(EditHOPAG_C.ComponentIndex,EditHOPAG_C.Color);
indice:=16;
Uno.Caption:=comenta(23,'clientes.des');
Dos.Caption:=comenta(24,'clientes.des');

end;

procedure TFormaClientes.EditHOREV_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditDIPAG_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditHOPAG_CKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (Key=13) or (Key=40) then
begin
indice:=indice+1;
cursor1;
BuscaTabOrder(Sender,TabOrder,1);
end;
if Key=38 then
begin
indice:=indice-1;
cursor1;
BuscaTabOrder(Sender,TabOrder,-1);
end;

end;

procedure TFormaClientes.EditHOREV_CExit(Sender: TObject);
begin
quitacolor(EditHOREV_C.ComponentIndex);
end;

procedure TFormaClientes.EditDIPAG_CExit(Sender: TObject);
begin
quitacolor(EditDIPAG_C.ComponentIndex);
end;

procedure TFormaClientes.EditHOPAG_CExit(Sender: TObject);
begin
quitacolor(EditHOPAG_C.ComponentIndex);
end;

procedure TFormaClientes.EditSTATU_CChange(Sender: TObject);
begin
if (EditSTATU_C.Text='')or(EditSTATU_C.Text='A') then
   EtiEstado.Caption:='Activo'
   else
   EtiEstado.Caption:='Inactivo';
end;



procedure TFormaClientes.FormShow(Sender: TObject);
begin
//CreaTabOrder;
Panel2.Color:=clBlue;
end;


procedure TFormaClientes.BotonObservacionClick(Sender: TObject);
begin
BuscaObservacionN(EditCLCLI_C.Text,'CL',TablaCliente.DatabaseName);
end;

procedure TFormaClientes.Informacion1Click(Sender: TObject);
begin
AgregaAyuda(MainMenu1,FormaClientes.Name);
end;

procedure TFormaClientes.BotonSaldoClick(Sender: TObject);
begin
//FormaConsultaCobranza:=TFormaConsultaCobranza.Create(self);
FormaConsultaCobranza.Usuario.Caption:=Usuario.Caption;
if caso(StrToInt(usuario.Caption),6) then//cxc
begin

FormaConsultaCobranza.Show;
//AbreCliente(EditCLCLI_C.Text);
end;

end;

    
procedure TFormaClientes.BitBtn1Click(Sender: TObject);
begin
 AbreDescuentosCliente(TablaCliente.DatabaseName,EditCLCLI_C.Text);

end;


end.
