unit ConsCata;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, DBGrids, ExtCtrls,Checa, ComCtrls, StdCtrls, Buttons,
  DBCtrls,describe, Gauges,Printers,conver,Reporte2,dialogos, Menus;

type
  TFormaCatalogo = class(TForm)
    DetalleCatalogo: TDBGrid;
    DataSource1: TDataSource;
    BarraDeEstado: TStatusBar;
    Panel1: TPanel;
    BotonBuscar: TSpeedButton;
    BotonImprimir: TSpeedButton;
    BotonSalir: TSpeedButton;
    BotonOrden: TSpeedButton;
    Panel2: TPanel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    PaintBox1: TPaintBox;
    PaintBox2: TPaintBox;
    PaintBox3: TPaintBox;
    PaintBox4: TPaintBox;
    PanelProgreso: TPanel;
    BarraProgreso: TGauge;
    Imprimir: TPrintDialog;
    DBNavigator1: TDBNavigator;
    TablaConsulta: TTable;
    BotonReporte: TSpeedButton;
    BotonCambios: TSpeedButton;
    BotonIndices: TSpeedButton;
    Indices: TListBox;
    TodosCampos: TSpeedButton;
    MainMenu1: TMainMenu;
    Archivo1: TMenuItem;
    Orden1: TMenuItem;
    AsignaOrden1: TMenuItem;
    Ver1: TMenuItem;
    Salir1: TMenuItem;
    TodoslosCampos1: TMenuItem;
    Operaciones1: TMenuItem;
    Sumar1: TMenuItem;
    VerReporte1: TMenuItem;
    procedure Panel2Click(Sender: TObject);
    procedure DetalleCatalogoDblClick(Sender: TObject);
    procedure BotonSalirClick(Sender: TObject);
    procedure BotonBuscarClick(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DetalleCatalogoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BotonBuscarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonImprimirMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonOrdenMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TablaCuCobrarFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaCuePagarFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure BotonOrdenClick(Sender: TObject);
    procedure TablaClienteFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaVendedorFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaProveedoFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaFacturaFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaComprasFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaInventaFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure TablaMovinvFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure BotonImprimirClick(Sender: TObject);
    procedure BotonReporteClick(Sender: TObject);
    procedure BotonCambiosClick(Sender: TObject);
    procedure TablaConsultaFilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    procedure BotonIndicesClick(Sender: TObject);
    procedure TodosCamposClick(Sender: TObject);
    procedure DetalleCatalogoTitleClick(Column: TColumn);
    procedure Salir1Click(Sender: TObject);
    procedure Sumar1Click(Sender: TObject);
    procedure VerReporte1Click(Sender: TObject);
  private
    { Private declarations }
  public
{procedure FiltraPorTabla(DataSet: TDataSet;  var Accept: Boolean);}
    { Public declarations }
  end;

type
	camp=record
	numero:string[4];
	campo:String[10];
	descripcion:String[35];
	tipo:String[10];
	tamo:string[3];
	tabla:string[15];
end;


var
  FormaCatalogo: TFormaCatalogo;
  contador,tamodatos:longint;
  tablalocal:String;
  condfiltro:array[1..120] of String;
  campos,operadores,valores:array[1..30] of String;
 factorancho,factorlargo:integer;

 procedure poneparametros(tabla,c1,c2,c3,c4,c5,c6,c7,c8,c9,e1,e2,e3,e4,e5,e6,e7,e8,e9,t1,t2,t3,t4,t5,t6,t7,t8,t9:String);
procedure abretabla(tabla:string);
procedure abrepanelimagen;
procedure poneimagenes;
procedure MuestraCampos(cad:string);
procedure AsignaCampoMoneda1(campo_moneda:string);
implementation


{$R *.DFM}

uses Vendedor, Factu, Compras, Inven, movinv, Cliente, Proveedo, cxcd,
  Concobra, buscar, //antcli,
	//antpro, antven, antfac, antcom, antinv,  antmovin,
  filtros, OrdenPor, adminis, Tipos;

{****************************************}
procedure AsignaCampoMoneda1(campo_moneda:string);
begin
moneda_r:='';
moneda_r:=campo_moneda;

end;



function letraTipo(numero,moneda,cadena,no_visible:Boolean):Char;
begin
if numero then LetraTipo:='n';
if moneda then LetraTipo:='m';
if cadena then LetraTipo:='c';
if no_visible then LetraTipo:='i';
end;


function PalabraLinea(linea:string;num:integer):string;
var
i,cuenta:integer;
aux:string;
begin
aux:='';
cuenta:=1;
linea:=linea+',';
for i:=1 to length(linea) do
begin
if linea[i]=',' then
begin
if num=cuenta then
begin
PalabraLinea:=aux;
break;
end;
cuenta:=cuenta+1;
aux:='';
end
else
begin
aux:=aux+linea[i];

end;


end;


end;



procedure MuestraCampos(cad:string);
var
i:integer;
palab:string[15];
begin
cad:=cad+',';
with FormaCatalogo do
	begin
  for i:=0 to TablaConsulta.FieldCount-1 do
		TablaConsulta.Fields[i].Visible:=False;
	palab:='';
	for i:=1 to length(cad) do
		begin
		if cad[i]=',' then
			begin
			TablaConsulta.FieldByName(palab).Visible:=True;
			palab:='';
			end
		else
			begin
			palab:=palab+cad[i];
			end;
		end;
	end;
end;

procedure ActualizaEncabezados;
var
anchocolumna,numecampos,i,k,linea,paginasxancho,numerodepagina:integer;
tamoletra,sumaancho,ultimo,anchopagina,maximodelineas,ultimapagina:integer;
limites:Array[1..15] of integer;
rec:TRect;
inicio,fin:integer;

begin


inicio:=rangoscampos(FormaCatalogo.TablaConsulta.Tablename)*50;
fin:=inicio+49;
inicio:=inicio+1;
//ShowMessage(IntToStr(inicio));
k:=0;
for i:=inicio to inicio+FormaCatalogo.DetalleCatalogo.Columns.Count-1 do
begin
{DetaImpr.Columns.Items[i].Title.Caption:=encabezado[i];}
{DetaImpr.Columns.Items[i].DisplayName:=DetaImpr.Columns.Items[i].DisplayName+encabezado[i];}
{ShowMessage(encabezado[i]);}
try
FormaCatalogo.DetalleCatalogo.Columns.Items[k].Title.Caption:=leecampos(i,2);
k:=k+1;
except
//error
end;
end;


end;



function CalculaAncho:integer;
begin
if Printer.Orientation=poPortrait then
CalculaAncho:=110
else
Calculaancho:=150;


end;


function CalculaNumeroPaginas(campos:longint):integer;
var
pag:integer;
begin

if CalculaAncho=110 then
begin
Pag:=Trunc(campos/50);
if  campos Mod 50 <>0 then
Pag:=Pag+1;

end
else
begin
Pag:=Trunc(campos/38);
if  campos Mod 38 <>0 then
Pag:=Pag+1;

end;

CalculaNumeroPaginas:=Pag;

end;



procedure DibujaCelda(inicio,linea,ancho,tamoletra:integer;texto:string;relleno,colorletra:TColor;nombreletra:string;alin:char);
var
rec:TRect;
begin
rec.Left:=inicio*factorancho;
rec.Top:=10+(tamoletra*factorlargo);
rec.Right:=(inicio+ancho)*factorancho;
rec.Bottom:=10+factorlargo+(tamoletra*factorlargo);
{Printer.Canvas.Brush.Style:=bsDiagCross;}

{****parametros de cuadro y texto para impresion*****}
{Printer.Canvas.Brush.Color:=clYellow;}
Printer.Canvas.Pen.Width:=2;
Printer.Canvas.Font.Color:=colorletra;
Printer.Canvas.Font.Size:=tamoletra;
Printer.Canvas.Font.Name:=nombreletra;

if Texto<>'' then
if Texto[length(Texto)-2]='.' then
begin
texto:=convierte('#,###,##0.00',Texto,'$');
end;



{****terminan los parametros de impresion********}

{Printer.Canvas.TextRect(rec,1,3,texto);}
Printer.Canvas.Rectangle(inicio*factorancho,10+(linea*factorlargo),(inicio+ancho)*factorancho,10+factorlargo+(linea*factorlargo));
Printer.Canvas.TextOut(inicio*factorancho+5,10+factorlargo+(linea*factorlargo)-60,texto);

end;


procedure DibujaCeldaCanvas(inicio,tamoletra,ancho:integer;texto:string;relleno:TColor);
var
rec:TRect;
begin

rec.Left:=inicio*factorancho;
rec.Top:=10+(tamoletra*factorlargo);
rec.Right:=(inicio+ancho)*factorancho;
rec.Bottom:=10+factorlargo+(tamoletra*factorlargo);

{Printer.Canvas.Brush.Style:=bsDiagCross;}

end;



procedure ImprimeDetalle(DetaImpr:TDBGrid;inicio,fin:integer);
var
anchocolumna,numecampos,i,k,linea,paginasxancho,numerodepagina:integer;
tamoletra,sumaancho,ultimo,anchopagina,maximodelineas,ultimapagina:integer;
limites:Array[1..15] of integer;
rec:TRect;
alineacion:char;
begin

{****parametros globales de pagina***********}

Printer.BeginDoc;
numerodepagina:=0;
factorancho:=Trunc(Printer.PageWidth/CalculaAncho());
anchopagina:=Trunc(Printer.PageWidth);
factorlargo:=Trunc(Printer.PageHeight/50);
if CalculaAncho()=110 then
maximodelineas:=50
else
maximodelineas:=38;

ultimapagina:=fin;

{****calcula el numero de cam´pos por tratarse de un caso especial***********************}
numecampos:=0;
for i:=0 to 7 do
begin
if DetaImpr.Columns.Items[i].Title.Caption<>'' then
numecampos:=numecampos+1;
end;

{************}

{ShowMessage(IntToStr(numecampos));}

for i:=2 to 15 do
limites[i]:=numecampos-1;

{******calcula las paginas******}
sumaancho:=0;
k:=2;
limites[1]:=0;

for i:=0 to numecampos-1 do
begin
sumaancho:=sumaancho+DetaImpr.Fields[i].DisplayWidth;
{ShowMessage(IntToStr(i)+'  '+IntToStr(sumaancho));}
if sumaancho>=CalculaAncho() then
begin
{ShowMessage('entro '+IntToStr(sumaancho));}
DetaImpr.Columns.Items[i].Color:=clred;
{DetaImpr.Columns.Items[i].Title:=DetaImpr.Columns.Items.Title;}
DetaImpr.Columns.Items[i].DisplayName:=DetaImpr.Columns.Items[i].DisplayName+' >';
{DetaImpr.Columns.Items[i].DisplayName:=Encabezado[i];}

sumaancho:=DetaImpr.Fields[i].DisplayWidth;
limites[k]:=i;
k:=k+1;
end;
end;
{limites[k]:=numecampos-1;}
{limites[k+1]:=numecampos-1;}

{*********termina calculo de paginas**************************** }

sumaancho:=0;
ultimo:=0;
linea:=0;
{DibujaCelda(0,0,0,'');}

{********inicia impresion por paginas******}

paginasxancho:=k;
{ShowMessage('voy a imprimir '+IntToStr(k));}
for k:=2 to paginasxancho do
begin
numerodepagina:=0;
sumaancho:=0;
ultimo:=0;
linea:=0;

{***pone el cursor en la pagina coorecta****}
{FormaCatalogo.DataSource1.DataSet.Name}
FormaCatalogo.DataSource1.DataSet.First;
{ShowMessage('voy a imprimir 2');}
if CalculaAncho()=110 then
FormaCatalogo.DataSource1.DataSet.MoveBy(inicio*50)
else
FormaCatalogo.DataSource1.DataSet.MoveBy(inicio*38);
{*****termina la posicion*******************}

While (not FormaCatalogo.DataSource1.DataSet.Eof)and(numerodepagina<ultimapagina) do
begin
sumaancho:=0;
ultimo:=0;
{showmessage(IntToStr(limites[k]));}
for i:=limites[k-1] to limites[k] do
begin

sumaancho:=sumaancho+DetaImpr.Fields[i].DisplayWidth;
{ShowMessage('*'+DetaImpr.Fields[i].DisplayText);}

if sumaancho<CalculaAncho() then
begin
{ShowMessage(DetaImpr.Fields[i].Value);}
alineacion:='x';
Case DetaImpr.Fields[i].Alignment of
taLeftJustify:alineacion:='i';
taCenter:alineacion:='c';
taRightJustify:alineacion:='d';
end;


if linea=0 then
begin
DibujaCelda(ultimo,linea,DetaImpr.Fields[i].DisplayWidth,DetaImpr.Font.Size,DetaImpr.Columns.Items[i].Title.Caption,clGray,clBlack,'Arial','x');
{linea:=linea+1;}
end
else
DibujaCelda(ultimo,linea,DetaImpr.Fields[i].DisplayWidth,DetaImpr.Font.Size,DetaImpr.Fields[i].Text,clGray,clBlack,'Arial',alineacion);

end;

{DibujaCeldaCanvas(ultimo,linea,DetaImpr.Fields[i].DisplayWidth,DetaImpr.Font.Size,DetaImpr.Fields[i].AsString,clGray);}
ultimo:=sumaancho;
DetaImpr.SelectedIndex:=i;

end;
if linea<>0 then
FormaCatalogo.DataSource1.DataSet.Next;
linea:=linea+1;
{******checa por nueva pagina*****}
if linea=maximodelineas then
begin
Printer.NewPage;
linea:=0;
numerodepagina:=numerodepagina+1;
end;
{*********************************}

end;

{***checa si no ha cambiado de pagina*****}
if linea<>0 then
Printer.NewPage;
{*****************************************}
end;

Printer.EndDoc;
end;





{****************************************}




{para igualñ**************}
function tipofecha(tipo:string):Boolean;
begin

if tipo='ftDate' then
tipofecha:=True
else
tipofecha:=False;

end;

function BuscaCadena(cad1,cad2:string):boolean;
begin
if pos(cad2,FormaCatalogo.TablaConsulta.FieldByName(cad1).AsString)>0 then
BuscaCadena:=True
else
BuscaCadena:=False;
end;


procedure FiltraPorTabla(DataSet: TDataSet;  var Accept: Boolean);
var
i,cuenta:integer;
casos:array[1..30]of boolean;
casosaux:Boolean;
begin

casosaux:=True;

for i:=1 to 30 do
casos[i]:=True;

cuenta:=1;
i:=1;
while i<120 do
begin

if condfiltro[i+1]<>'' then
begin
if tipofecha(condfiltro[i+3]) then
begin
case tipooperador(condfiltro[i+1]) of
'=':casos[cuenta]:=(DataSet[condfiltro[i]]=StrToDateTime(condfiltro[i+2]));
'<':casos[cuenta]:=(DataSet[condfiltro[i]]<StrToDateTime(condfiltro[i+2]));
'>':casos[cuenta]:=(DataSet[condfiltro[i]]>StrToDateTime(condfiltro[i+2]));
'X':casos[cuenta]:=(DataSet[condfiltro[i]]<>StrToDateTime(condfiltro[i+2]));
'Y':casos[cuenta]:=(DataSet[condfiltro[i]]<=StrToDateTime(condfiltro[i+2]));
'Z':casos[cuenta]:=(DataSet[condfiltro[i]]>=StrToDateTime(condfiltro[i+2]));
end;

end
else
begin
case tipooperador(condfiltro[i+1]) of
'=':casos[cuenta]:=(DataSet[condfiltro[i]]=condfiltro[i+2]);
'<':casos[cuenta]:=(DataSet[condfiltro[i]]<condfiltro[i+2]);
'>':casos[cuenta]:=(DataSet[condfiltro[i]]>condfiltro[i+2]);
'X':casos[cuenta]:=(DataSet[condfiltro[i]]<>condfiltro[i+2]);
'Y':casos[cuenta]:=(DataSet[condfiltro[i]]<=condfiltro[i+2]);
'Z':casos[cuenta]:=(DataSet[condfiltro[i]]>=condfiltro[i+2]);
'W':casos[cuenta]:=BuscaCadena(condfiltro[i],condfiltro[i+2]);
end;


end;


cuenta:=cuenta+1;
end;
i:=i+4;
end;


{if condfiltro[2]='=' then casos[1]:=(DataSet[condfiltro[1]]=condfiltro[3]);
if condfiltro[5]='=' then casos[2]:=(DataSet[condfiltro[4]]=condfiltro[6]);
if condfiltro[8]='=' then casos[3]:=(DataSet[condfiltro[7]]=condfiltro[9]);
if condfiltro[11]='=' then casos[4]:=(DataSet[condfiltro[10]]=condfiltro[12]);
if condfiltro[14]='=' then casos[5]:=(DataSet[condfiltro[13]]=condfiltro[15]);
if condfiltro[17]='=' then casos[6]:=(DataSet[condfiltro[16]]=condfiltro[18]);

if condfiltro[2]='<' then casos[1]:=(DataSet[condfiltro[1]]<condfiltro[3]);
if condfiltro[5]='<' then casos[2]:=(DataSet[condfiltro[4]]<condfiltro[6]);
if condfiltro[8]='<' then casos[3]:=(DataSet[condfiltro[7]]<condfiltro[9]);
if condfiltro[11]='<' then casos[4]:=(DataSet[condfiltro[10]]<condfiltro[12]);
if condfiltro[14]='<' then casos[5]:=(DataSet[condfiltro[13]]<condfiltro[15]);
if condfiltro[17]='<' then casos[6]:=(DataSet[condfiltro[16]]<condfiltro[18]);

if condfiltro[2]='>' then casos[1]:=(DataSet[condfiltro[1]]>condfiltro[3]);
if condfiltro[5]='>' then casos[2]:=(DataSet[condfiltro[4]]>condfiltro[6]);
if condfiltro[8]='>' then casos[3]:=(DataSet[condfiltro[7]]>condfiltro[9]);
if condfiltro[11]='>' then casos[4]:=(DataSet[condfiltro[10]]>condfiltro[12]);
if condfiltro[14]='>' then casos[5]:=(DataSet[condfiltro[13]]>condfiltro[15]);
if condfiltro[17]='>' then casos[6]:=(DataSet[condfiltro[16]]>condfiltro[18]);}
for i:=1 to 30 do
begin
casosaux:=casosaux and casos[i];

end;
Accept:=casosaux;
{Accept:=casos[1]and casos[2] and casos[3] and casos[4]and casos[5] and casos[6];}
{FormaCatalogo.BarraProgreso.Progress:=Trunc((contador/Tamodatos)*100);
contador:=contador+1;}

end;


function FiltraPorTabla2:String;
var
i,cuenta:integer;
casos:array[1..30]of boolean;
casosaux:Boolean;
aux:string;
begin

casosaux:=True;

for i:=1 to 30 do
casos[i]:=True;

cuenta:=1;
i:=1;
aux:='';
while i<120 do
begin

if condfiltro[i+1]<>'' then
begin
if tipofecha(condfiltro[i+3]) then
begin
aux:=aux+condfiltro[i]+condfiltro[i+1]+char(39)+condfiltro[i+2]+char(39);
{case tipooperador(condfiltro[i+1]) of
'=':casos[cuenta]:=(DataSet[condfiltro[i]]=StrToDateTime(condfiltro[i+2]));
'<':casos[cuenta]:=(DataSet[condfiltro[i]]<StrToDateTime(condfiltro[i+2]));
'>':casos[cuenta]:=(DataSet[condfiltro[i]]>StrToDateTime(condfiltro[i+2]));
'X':casos[cuenta]:=(DataSet[condfiltro[i]]<>StrToDateTime(condfiltro[i+2]));
'Y':casos[cuenta]:=(DataSet[condfiltro[i]]<=StrToDateTime(condfiltro[i+2]));
'Z':casos[cuenta]:=(DataSet[condfiltro[i]]>=StrToDateTime(condfiltro[i+2]));
end;}

end
else
begin
aux:=aux+condfiltro[i]+condfiltro[i+1]+condfiltro[i+2];
{case tipooperador(condfiltro[i+1]) of
'=':casos[cuenta]:=(DataSet[condfiltro[i]]=condfiltro[i+2]);
'<':casos[cuenta]:=(DataSet[condfiltro[i]]<condfiltro[i+2]);
'>':casos[cuenta]:=(DataSet[condfiltro[i]]>condfiltro[i+2]);
'X':casos[cuenta]:=(DataSet[condfiltro[i]]<>condfiltro[i+2]);
'Y':casos[cuenta]:=(DataSet[condfiltro[i]]<=condfiltro[i+2]);
'Z':casos[cuenta]:=(DataSet[condfiltro[i]]>=condfiltro[i+2]);
end;}


end;


cuenta:=cuenta+1;
end;
i:=i+4;
end;

for i:=1 to 30 do
begin
casosaux:=casosaux and casos[i];

end;
MuestraMensaje(aux);

//Accept:=casosaux;
{Accept:=casos[1]and casos[2] and casos[3] and casos[4]and casos[5] and casos[6];}
{FormaCatalogo.BarraProgreso.Progress:=Trunc((contador/Tamodatos)*100);
contador:=contador+1;}

end;




procedure datosdefiltrado(cond:string);
var
i,pos:integer;
aux:String;
begin
{*************borra todoa la basura****}
for i:=1 to 120 do
begin
{campos[i]:='';
operadores[i]:='';
valores[i]:='';}
condfiltro[i]:='';
end;
{****************************}
pos:=1;
for i:=1 to length(cond) do
begin
if cond[i]='*' then
begin
condfiltro[pos]:=aux;
pos:=pos+1;
aux:='';
end
else
aux:=aux+cond[i];
{*****inicia la separacion****}

end;

end;

function filtratablatipo(nombredetabla:TDataSet):integer;
begin
with FormaCatalogo do
begin
TablaConsulta.Filtered:=True;






end;

end;



function tipodetabla(nombredetabla:string):String;
begin
with FormaCatalogo do
begin
if nombredetabla='cupagar.dbf' then
tipodetabla:='cuepagar.dbf';

if nombredetabla='cucobrar.dbf' then
tipodetabla:='cucobrar.dbf';

if nombredetabla='cliente.dbf' then
tipodetabla:='cliente.dbf';

if nombredetabla='vendedor.dbf' then
tipodetabla:='vendedor.dbf';

if nombredetabla='proveedo.dbf' then
tipodetabla:='proveedo.dbf';

if nombredetabla='facturae.dbf' then
tipodetabla:='facturae.dbf';

if nombredetabla='comprase.dbf' then
tipodetabla:='comprase.dbf';

if nombredetabla='inventar.dbf' then
tipodetabla:='inventar.dbf';

if nombredetabla='movinven.dbf' then
tipodetabla:='movinven.dbf';

end;

end;


function numerodetabla(nombredetabla:TDataSet;clave1:string):integer;
begin
with FormaCatalogo do
begin
{f nombredetabla=TablaCuePagar then
TablaCuePagar.FindNearest([clave1]);

if nombredetabla=TablaCuCobrar then
TablaCuCobrar.FindNearest([clave1]);

if nombredetabla=TablaCliente then
TablaCliente.FindNearest([clave1]);

if nombredetabla=TablaVendedor then
TablaVendedor.FindNearest([clave1]);

if nombredetabla=TablaProveedo then
TablaProveedo.FindNearest([clave1]);

if nombredetabla=TablaFactura then
TablaFactura.FindNearest([clave1]);

if nombredetabla=TablaCompras then
TablaCompras.FindNearest([clave1]);

if nombredetabla=TablaInventa then
TablaInventa.FindNearest([clave1]);

if nombredetabla=TablaMovinv then
TablaMovinv.FindNearest([clave1]);
}
end;
{if nombre=TablaCuePagar then numerodetabla:=1;
if nombre=TablaCuePagar then numerodetabla:=1;}



end;

procedure buscarcampo(clave1:string);
begin
with FormaCatalogo do
begin
{TablaAuxiliar.FindNearest([clave]);}
//TTable(Components[numerodetabla(DataSource1.DataSet)]).FindNearest([clave]);
TablaConsulta.FindNearest([clave1]);
//numerodetabla(DataSource1.DataSet,clave1);
end;
end;

procedure datosdelproducto;
begin
with FormaCatalogo do
begin
{***************************}
PaintBox1.Canvas.TextOut(10,15,'                                                                                          ');
PaintBox1.Canvas.TextOut(10,30,'                                                                                ');
PaintBox1.Canvas.TextOut(10,45,'                                                                               ');


PaintBox1.Canvas.TextOut(10,15,TablaConsulta.FieldByName('CLPRO_I').AsString);
PaintBox1.Canvas.TextOut(10,30,TablaConsulta.FieldByName('DSCPR_I').AsString);
PaintBox1.Canvas.TextOut(10,45,TablaConsulta.FieldByName('EXIST_I').AsString);
TablaConsulta.Next;

PaintBox2.Canvas.TextOut(10,15,'                                                                            ');
PaintBox2.Canvas.TextOut(10,30,'                                                                           ');
PaintBox2.Canvas.TextOut(10,45,'                                                                                  ');

PaintBox2.Canvas.TextOut(10,15,TablaConsulta.FieldByName('CLPRO_I').AsString);
PaintBox2.Canvas.TextOut(10,30,TablaConsulta.FieldByName('DSCPR_I').AsString);
PaintBox2.Canvas.TextOut(10,45,TablaConsulta.FieldByName('EXIST_I').AsString);
TablaConsulta.Next;

PaintBox3.Canvas.TextOut(10,15,'                                                                                      ');
PaintBox3.Canvas.TextOut(10,30,'                                                                                       ');
PaintBox3.Canvas.TextOut(10,45,'                                                                               ');

PaintBox3.Canvas.TextOut(10,15,TablaConsulta.FieldByName('CLPRO_I').AsString);
PaintBox3.Canvas.TextOut(10,30,TablaConsulta.FieldByName('DSCPR_I').AsString);
PaintBox3.Canvas.TextOut(10,45,TablaConsulta.FieldByName('EXIST_I').AsString);

TablaConsulta.Next;

PaintBox4.Canvas.TextOut(10,15,'                                                                                                             ');
PaintBox4.Canvas.TextOut(10,30,'                                                                                                                 ');
PaintBox4.Canvas.TextOut(10,45,'                                                                                                                 ');

PaintBox4.Canvas.TextOut(10,15,TablaConsulta.FieldByName('CLPRO_I').AsString);
PaintBox4.Canvas.TextOut(10,30,TablaConsulta.FieldByName('DSCPR_I').AsString);
PaintBox4.Canvas.TextOut(10,45,TablaConsulta.FieldByName('EXIST_I').AsString);

TablaConsulta.Next;

end;

end;


procedure poneimagenes;
begin
with FormaCatalogo do
begin
if FileExists(TablaConsulta.FieldByName('IMAGE_I').AsString) then
Image1.Picture.LoadFromFile(TablaConsulta.FieldByName('IMAGE_I').AsString)
else
Image1.Picture.LoadFromFile(leeruta+'\blanco.bmp');




TablaConsulta.Next;

if FileExists(TablaConsulta.FieldByName('IMAGE_I').AsString) then
Image2.Picture.LoadFromFile(TablaConsulta.FieldByName('IMAGE_I').AsString)
else
Image2.Picture.LoadFromFile(leeruta+'\blanco.bmp');

TablaConsulta.Next;

if FileExists(TablaConsulta.FieldByName('IMAGE_I').AsString) then
Image3.Picture.LoadFromFile(TablaConsulta.FieldByName('IMAGE_I').AsString)
else
Image3.Picture.LoadFromFile(leeruta+'\blanco.bmp');

TablaConsulta.Next;

if FileExists(TablaConsulta.FieldByName('IMAGE_I').AsString) then
Image4.Picture.LoadFromFile(TablaConsulta.FieldByName('IMAGE_I').AsString)
else
Image4.Picture.LoadFromFile(leeruta+'\blanco.bmp');


//TablaConsulta.Prior;
//TablaConsulta.Prior;
//TablaConsulta.Prior;
datosdelproducto;


end;

end;


procedure abredocumento(tabla:String);
var
cadena:string;
begin
with FormaCatalogo do
begin
{ShowMessage(tabla);}
cadena:=LowerCase(tabla);
if cadena='cliente.dbf' then
begin
posicionacliente(DetalleCatalogo.Fields[0].AsString);
FormaClientes.Show;
end;
{****************}
if cadena='proveedo.dbf' then
begin
FormaProveedo.Show;
end;
{****************}
if cadena='vendedor.dbf' then
begin
posicionavendedor(DetalleCatalogo.Fields[0].AsString);
FormaVendedor.Show;
end;
{****************}
if cadena='facturae.dbf' then
begin
FormaFactura:=TFormaFactura.Create(Application);
if LowerCase(FormaFactura.TablaFacturae.TableName)<>'facturae.dbf' then
begin
FormaFactura.TablaFacturae.Close;
FormaFactura.TablaFacturae.DataBaseName:=ruta(8);
FormaFactura.Base.Text:='Factura';
FormaFactura.TablaFacturae.TableName:='Facturae.dbf';
FormaFactura.TablaFacturae.Open;
FormaFactura.TablaFacturad.Close;
FormaFactura.TablaFacturad.DataBaseName:=ruta(8);
FormaFactura.TablaFacturad.TableName:='Facturad.dbf';
FormaFactura.TablaFacturad.Open;



end;
posicionafactura(DetalleCatalogo.Fields[0].AsString);
FormaFactura.ShowModal;
FormaFactura.Free;

end;

if cadena='remision.dbf' then
begin
FormaFactura:=TFormaFactura.Create(Application);
if LowerCase(FormaFactura.TablaFacturae.TableName)<>'remision.dbf' then
begin
FormaFactura.TablaFacturae.Close;
FormaFactura.TablaFacturae.DataBaseName:=ruta(8);
FormaFactura.Base.Text:='Remisión';
FormaFactura.TablaFacturae.TableName:='remision.dbf';
FormaFactura.TablaFacturae.Open;
FormaFactura.TablaFacturad.Close;
FormaFactura.TablaFacturad.TableName:='remisiod.dbf';
FormaFactura.TablaFacturad.DataBaseName:=ruta(8);
FormaFactura.TablaFacturad.Open;

end;

posicionafactura(DetalleCatalogo.Fields[0].AsString);
FormaFactura.ShowModal;
FormaFactura.Free;

end;


if cadena='pedido.dbf' then
begin
FormaFactura:=TFormaFactura.Create(Application);
if LowerCase(FormaFactura.TablaFacturae.TableName)<>'pedido.dbf' then
begin
FormaFactura.TablaFacturae.Close;
FormaFactura.TablaFacturae.DataBaseName:=ruta(8);
FormaFactura.Base.Text:='Pedido';
FormaFactura.TablaFacturae.TableName:='pedido.dbf';
FormaFactura.TablaFacturae.Open;
FormaFactura.TablaFacturad.Close;
FormaFactura.TablaFacturad.DataBaseName:=ruta(8);
FormaFactura.TablaFacturad.TableName:='pedidod.dbf';
FormaFactura.TablaFacturad.Open;

end;

posicionafactura(DetalleCatalogo.Fields[0].AsString);
FormaFactura.ShowModal;
FormaFactura.Free;

end;

if cadena='cotizaci.dbf' then
begin
FormaFactura:=TFormaFactura.Create(Application);
if LowerCase(FormaFactura.TablaFacturae.TableName)<>'cotizaci.dbf' then
begin
FormaFactura.TablaFacturae.Close;
FormaFactura.TablaFacturae.DataBaseName:=ruta(8);
FormaFactura.Base.Text:='Cotización';
FormaFactura.TablaFacturae.TableName:='cotizaci.dbf';
FormaFactura.TablaFacturae.Open;
FormaFactura.TablaFacturad.Close;
FormaFactura.TablaFacturad.DataBaseName:=ruta(8);
FormaFactura.TablaFacturad.TableName:='cotizacd.dbf';
FormaFactura.TablaFacturad.Open;

end;

posicionafactura(DetalleCatalogo.Fields[0].AsString);
FormaFactura.ShowModal;
FormaFactura.Free;
end;


{*********************}
if cadena='cucobrar.dbf' then
begin
FormaConsultaCobranza.Show;
FormaConsultaCobranza.Close;
posicionacxc(DetalleCatalogo.Fields[3].AsString);
FormaCxCDetalle.Show;
end;
{********************}

if cadena='comprase.dbf' then
begin
posicionacompras(DetalleCatalogo.Fields[0].AsString);
FormaCompras.Show;
end;
{******************}
if cadena='inventar.dbf' then
begin
posicionainventario(DetalleCatalogo.Fields[0].AsString);
FormaInventario.Show;
end;
{**************}
if cadena='movinven.dbf' then
begin
posicionamovimientos(DetalleCatalogo.Fields[0].AsString);
FormaMovimientosInventario.Show;
end;
{****************}
if cadena='cuepagar.dbf' then
begin
//posicionacxp(DetalleCatalogo.Fields[0].AsString);
//FormaCxPDetalle.Show;
end;

end;

end;


procedure abretabla(tabla:string);
begin
with FormaCatalogo do
begin
{********************************}
DetalleCatalogo.Visible:=True;
Panel2.Visible:=False;


{********************************}
if TablaConsulta.State=dsBrowse then
begin
TablaConsulta.Close;
end;
TablaConsulta.IndexName:='';

DataSource1.DataSet:=TablaConsulta;
if TablaConsulta.State=dsInactive then
begin
TablaConsulta.DataBaseName:=ruta(8);
TablaConsulta.TableName:=tabla;
TablaConsulta.Open;
TablaConsulta.GetIndexNames(Indices.Items);//obtengo una   listaindice
TablaConsulta.IndexName:=Indices.Items[0]; //asigna el primero
//BarraDeEstado.Panels[0].Text:='Registros  '+IntToStr(TablaConsulta.RecordCount);
//tamodatos:=TablaConsulta.RecordCount;
end;
tablalocal:=tabla;

ActualizaEncabezados;
{*********}
end;
end;


procedure abrepanelimagen;
var
imagen:TGraphic;
begin
{Imagen.}
with FormaCatalogo do
begin
DetalleCatalogo.Visible:=False;
Panel2.Visible:=True;

end;

end;

procedure poneparametros(tabla,c1,c2,c3,c4,c5,c6,c7,c8,c9,e1,e2,e3,e4,e5,e6,e7,e8,e9,t1,t2,t3,t4,t5,t6,t7,t8,t9:String);
begin

with FormaCatalogo do
begin
{if TablaCatalogo.State=dsBrowse then
begin
TablaCatalogo.Close;
TablaCatalogo.DatabaseName:=ruta(8);
TablaCatalogo.TableName:=tabla;}

if e1<>'e1' then DetalleCatalogo.Columns[0].Title.Caption:=e1
else DetalleCatalogo.Columns[0].Title.Caption:='';
if e2<>'e2' then DetalleCatalogo.Columns[1].Title.Caption:=e2
else DetalleCatalogo.Columns[1].Title.Caption:='';
if e3<>'e3' then DetalleCatalogo.Columns[2].Title.Caption:=e3
else DetalleCatalogo.Columns[2].Title.Caption:='';
if e4<>'e4' then DetalleCatalogo.Columns[3].Title.Caption:=e4
else DetalleCatalogo.Columns[3].Title.Caption:='';
if e5<>'e5' then DetalleCatalogo.Columns[4].Title.Caption:=e5
else DetalleCatalogo.Columns[4].Title.Caption:='';
if e6<>'e6' then DetalleCatalogo.Columns[5].Title.Caption:=e6
else DetalleCatalogo.Columns[5].Title.Caption:='';
if e7<>'e7' then DetalleCatalogo.Columns[6].Title.Caption:=e7
else DetalleCatalogo.Columns[6].Title.Caption:='';
if e8<>'e8' then DetalleCatalogo.Columns[7].Title.Caption:=e8
else DetalleCatalogo.Columns[7].Title.Caption:='';



if c1<>'c1' then DetalleCatalogo.Columns[0].FieldName:=c1;
if c2<>'c2' then DetalleCatalogo.Columns[1].FieldName:=c2;
if c3<>'c3' then DetalleCatalogo.Columns[2].FieldName:=c3;
if c4<>'c4' then DetalleCatalogo.Columns[3].FieldName:=c4;
if c5<>'c5' then DetalleCatalogo.Columns[4].FieldName:=c5;
if c6<>'c6' then DetalleCatalogo.Columns[5].FieldName:=c6;
if c7<>'c7' then DetalleCatalogo.Columns[6].FieldName:=c7;
if c8<>'c8' then DetalleCatalogo.Columns[7].FieldName:=c8;

{TablaCatalogo.Open;
end
else
begin
TablaCatalogo.DatabaseName:=ruta(8);
TablaCatalogo.TableName:=tabla;

if e1<>'e1' then DetalleCatalogo.Columns[0].Title.Caption:=e1
else DetalleCatalogo.Columns[0].Title.Caption:='';
if e2<>'e2' then DetalleCatalogo.Columns[1].Title.Caption:=e2
else DetalleCatalogo.Columns[1].Title.Caption:='';
if e3<>'e3' then DetalleCatalogo.Columns[2].Title.Caption:=e3
else DetalleCatalogo.Columns[2].Title.Caption:='';
if e4<>'e4' then DetalleCatalogo.Columns[3].Title.Caption:=e4
else DetalleCatalogo.Columns[3].Title.Caption:='';
if e5<>'e5' then DetalleCatalogo.Columns[4].Title.Caption:=e5
else DetalleCatalogo.Columns[4].Title.Caption:='';
if e6<>'e6' then DetalleCatalogo.Columns[5].Title.Caption:=e6
else DetalleCatalogo.Columns[5].Title.Caption:='';
if e7<>'e7' then DetalleCatalogo.Columns[6].Title.Caption:=e7
else DetalleCatalogo.Columns[6].Title.Caption:='';
if e8<>'e8' then DetalleCatalogo.Columns[7].Title.Caption:=e8
else DetalleCatalogo.Columns[7].Title.Caption:='';




if c1<>'c1' then DetalleCatalogo.Columns[0].FieldName:=c1;
if c2<>'c2' then DetalleCatalogo.Columns[1].FieldName:=c2;
if c3<>'c3' then DetalleCatalogo.Columns[2].FieldName:=c3;
if c4<>'c4' then DetalleCatalogo.Columns[3].FieldName:=c4;
if c5<>'c5' then DetalleCatalogo.Columns[4].FieldName:=c5;
if c6<>'c6' then DetalleCatalogo.Columns[5].FieldName:=c6;
if c7<>'c7' then DetalleCatalogo.Columns[6].FieldName:=c7;
if c8<>'c8' then DetalleCatalogo.Columns[7].FieldName:=c8;



TablaCatalogo.Open;

end;
}

end;

end;

procedure TFormaCatalogo.Panel2Click(Sender: TObject);
begin
Close;
end;


procedure TFormaCatalogo.DetalleCatalogoDblClick(Sender: TObject);
begin
abredocumento(tablalocal);
end;


procedure TFormaCatalogo.BotonSalirClick(Sender: TObject);
begin
Close;
end;


procedure TFormaCatalogo.BotonBuscarClick(Sender: TObject);
begin
if Tablaconsulta.IndexName<>'' then
begin
FormaBusqueda:=TFormaBusqueda.Create(Application);
FormaBusqueda.ShowModal;
buscarcampo(FormaBusqueda.CajaBuscar.Text);
FormaBusqueda.Free;
end
else
MuestraMensaje('No se ha Definido un Indice.');
end;


procedure TFormaCatalogo.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
if Panel2.Visible=True then
poneimagenes;

end;

procedure TFormaCatalogo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin

DetalleCatalogo.Visible:=False;
Panel2.Visible:=False;
TablaConsulta.Filtered:=False;
DetalleCatalogo.ReadOnly:=True;
end;

procedure TFormaCatalogo.DetalleCatalogoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if key=13 then
abredocumento(tablalocal);
//if (key<>38)and(key<>40){and(key<>38)and(key<>40)} then
//TablaConsulta.FindNearest([Char(key)]);

end;

procedure TFormaCatalogo.BotonBuscarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCatalogo.Left+BotonBuscar.Left,FormaCatalogo.Top+BotonBuscar.Top+BotonBuscar.Height,73);
end;

procedure TFormaCatalogo.BotonImprimirMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCatalogo.Left+BotonImprimir.Left,FormaCatalogo.Top+BotonImprimir.Top+BotonImprimir.Height,74);
end;

procedure TFormaCatalogo.BotonOrdenMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaCatalogo.Left+BotonOrden.Left,FormaCatalogo.Top+BotonOrden.Top+BotonOrden.Height,75);
end;

procedure TFormaCatalogo.TablaCuCobrarFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
Accept:=((DataSet['TIMOV_CC']='1')or(DataSet['TIMOV_CC']='2'));
end;

procedure TFormaCatalogo.TablaCuePagarFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
Accept:=DataSet['TIMOV_CP']='51';

end;

procedure TFormaCatalogo.BotonOrdenClick(Sender: TObject);
var
i:integer;
begin
FormaFiltros:=TFormaFiltros.Create(Application);
contador:=0;
{BarraProgreso.Progress:=0;}


for i:=1 to 120 do
begin
condfiltro[i]:='';
end;

ponecampos(LowerCase(TablaConsulta.TableName));
//
FormaFiltros.Tag:=0;
FormaFiltros.ShowModal;
DetalleCatalogo.Refresh;
if FormaFiltros.Tag=1 then
begin
datosdefiltrado(condiciones);
filtratablatipo(DataSource1.DataSet);
end
else
TablaConsulta.Filtered:=False;
//FiltraPorTabla2;
FormaFiltros.Free;

end;

procedure TFormaCatalogo.TablaClienteFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaVendedorFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaProveedoFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaFacturaFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaComprasFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaInventaFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;

procedure TFormaCatalogo.TablaMovinvFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
FiltraPorTabla(DataSet,Accept);
end;


procedure TFormaCatalogo.BotonImprimirClick(Sender: TObject);
begin

if ImpresoraLista then
begin
Imprimir.MinPage:=1;
Imprimir.MaxPage:=CalculaNumeroPaginas(DetalleCatalogo.DataSource.DataSet.RecordCount);
Imprimir.FromPage:=1;
Imprimir.ToPage:=CalculaNumeroPaginas(DetalleCatalogo.DataSource.DataSet.RecordCount);

if Imprimir.Execute then
begin
ImprimeDetalle(DetalleCatalogo,Imprimir.FromPage,Imprimir.ToPage);
end;

end;

end;



procedure TFormaCatalogo.BotonReporteClick(Sender: TObject);
begin
AsignaCampoMoneda(moneda_r);
AbreReporteVisual(DetalleCatalogo);

end;


procedure TFormaCatalogo.BotonCambiosClick(Sender: TObject);
begin
//if (DetalleCatalogo.ReadOnly) then
FormaAdministrador:=TFormaAdministrador.Create(Application);
 FormaAdministrador.ShowModal;
 if (FormaAdministrador.Tag=1)then
     DetalleCatalogo.ReadOnly:=False
 // end drr antes existia
 else
 begin
     MuestraMensaje('Password invalido, no se podra modificar campo'); //drr modif
     DetalleCatalogo.ReadOnly:=True;
 end;
     FormaAdministrador.Tag:=0;
FormaAdministrador.Free;     
end;

procedure TFormaCatalogo.TablaConsultaFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin
if TablaConsulta.TableName='cucobrar.dbf' then
Accept:=((DataSet['TIMOV_CC']='1')or(DataSet['TIMOV_CC']='2'))
else
FiltraPorTabla(DataSet,Accept);

end;


procedure TFormaCatalogo.BotonIndicesClick(Sender: TObject);
var
	dat:camp;
	arch:file of camp;
//indices:TListBox;
i,j,inicio,fin:integer;
aux,aux2:string;
//Indices: TStrings;
begin
FormaOrdenarpor:=TFormaOrdenarpor.Create(Application);
//Indices:=TListBox.Create(Indices);
Indices.Clear;
FormaOrdenarpor.Tag:=1; //drr modif antes 0

TablaConsulta.GetIndexNames(Indices.Items);
//TablaConsulta.
//Showmessage(IntToStr(Indices.Items.Count));
aux:='';
aux2:='';
for i:=0 to Indices.Items.Count-1 do
begin
	aux:=aux+Indices.Items[i]+',';
end;//for
//lee las descripcionesde los  indices
AssignFile(arch,leeruta+'\confcamp.cmp');
Reset(arch);

inicio:=rangoscampos(FormaCatalogo.TablaConsulta.Tablename)*50;
fin:=inicio+49;
inicio:=inicio+1;

for i:=0 to Indices.Items.Count-1 do
begin

for j:=inicio to fin do
begin
seek(arch,j);
read(arch,dat);
//72544
//if Indices.Items[i]=dat.campo then
if TablaConsulta.IndexDefs.Items[i].Fields=dat.campo then
begin
aux2:=aux2+dat.descripcion+',';
break;
end;

end;//for j

end;//for i

CloseFile(arch);
aux:=OrdenarPor(aux,aux2);

if FormaOrdenarpor.Tag=1 then
begin
if aux<>'' then
 TablaConsulta.IndexName:=aux
end;

FormaOrdenarpor.Free;
end;


procedure TFormaCatalogo.TodosCamposClick(Sender: TObject);
var
i:integer;
begin
  for i:=0 to TablaConsulta.FieldCount-1 do
		TablaConsulta.Fields[i].Visible:=True;

end;

procedure TFormaCatalogo.DetalleCatalogoTitleClick(Column: TColumn);
var
aux:string;
begin
FormaTipos:=TFormaTipos.Create(Application);
FormaTipos.Tag:=0;
FormaTipos.ShowModal;

if FormaTipos.Tag=1 then
begin
TipoDato[Column.Index]:=LetraTipo(FormaTipos.Numero.Checked,FormaTipos.Moneda.Checked,FormaTipos.Cadena.Checked,FormaTipos.NoVisible.Checked);
aux:='';
case TipoDato[Column.Index] of
'n':begin
if (DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftFloat)or(DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftInteger)
or(DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftSmallint) then
begin
DetalleCatalogo.Columns.Items[Column.Index].Title.Color:=clLime;
aux:=DetalleCatalogo.Columns.Items[Column.Index].Title.Caption;

if (FormaTipos.AcumulaNumerico.Checked)and (aux[1]<>'+') then
DetalleCatalogo.Columns.Items[Column.Index].Title.Caption:='+'+aux;
end
else
MuestraMensaje('La Columna no es Numérico...');
end;

'm':begin
if (DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftFloat)or(DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftInteger)
or(DetalleCatalogo.Columns.Items[Column.Index].Field.DataType=ftSmallint) then
begin
DetalleCatalogo.Columns.Items[Column.Index].Title.Color:=$000080FF;
aux:=DetalleCatalogo.Columns.Items[Column.Index].Title.Caption;
if (FormaTipos.AcumulaNumerico.Checked)and (aux[1]<>'+') then
DetalleCatalogo.Columns.Items[Column.Index].Title.Caption:='+'+aux;
end
else
MuestraMensaje('La Columna no es Numérico...');

end;
'c':DetalleCatalogo.Columns.Items[Column.Index].Title.Color:=$00FF8000;
'i':DetalleCatalogo.Fields[Column.Index].Visible:=False;

end;




{ShowMessage(IntToStr(Column.Index)+'  '+TipoDato[Column.Index]);}
end;

FormaTipos.Free;
end;

procedure TFormaCatalogo.Salir1Click(Sender: TObject);
begin
Close;
end;

procedure TFormaCatalogo.Sumar1Click(Sender: TObject);
var
suma:Currency;
begin
//MuestraMensaje(DetalleCatalogo.SelectedField.FieldName);

if (TablaConsulta.fieldByName(DetalleCatalogo.SelectedField.FieldName).DataType=ftFloat)or(TablaConsulta.fieldByName(DetalleCatalogo.SelectedField.FieldName).DataType=ftSmallint	) then
begin
Suma:=0;
TablaConsulta.First;
while not TablaConsulta.EOF do
begin
suma:=suma+TablaConsulta.fieldByName(DetalleCatalogo.SelectedField.FieldName).AsFloat;

TablaConsulta.Next;
end;//while
MuestraMensaje('La suma es = '+Convierte('##,###,##0.00',FloatToStr(suma),''));

end
else
MuestraMensaje('La columna no se puede sumar...');//if
end;

procedure TFormaCatalogo.VerReporte1Click(Sender: TObject);
begin
AsignaCampoMoneda(moneda_r);       //todo nuevo
AbreReporteVisual(DetalleCatalogo); //drr modif
end;


end.
