unit barras;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogos,
  ExtCtrls, Buttons, Menus, StdCtrls,Conver,checa,Printers, Dialogs,
  ComCtrls, TeeProcs, TeEngine, Chart, Series, BubbleCh,describe, Spin,dbtables,
  Db, Grids, DBGrids;

type
  TFormaBarras = class(TForm)
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Panel2: TPanel;
    BotonGrafica: TSpeedButton;
    BotonReporte: TSpeedButton;
    BotonPie: TSpeedButton;
    BotonImprime: TSpeedButton;
    BotonExporta: TSpeedButton;
    Guardar: TSaveDialog;
    BotonAnterior: TSpeedButton;
    BotonSiguiente: TSpeedButton;
    BotonColor: TSpeedButton;
    BarradeEstado: TStatusBar;
    Concentrado: TRichEdit;
    Impresora: TPrintDialog;
    BotonSonido: TSpeedButton;
    ModuloGrafica: TChart;
    Series1: TBarSeries;
    Series2: TPieSeries;
    Series4: TBubbleSeries;
    BotonLineas: TSpeedButton;
    Series3: TLineSeries;
    BotonAutomatico: TSpeedButton;
    Timer1: TTimer;
    MainMenu2: TMainMenu;
    Archivo1: TMenuItem;
    Salir1: TMenuItem;
    Grficas1: TMenuItem;
    Barras1: TMenuItem;
    Pie1: TMenuItem;
    Lineas1: TMenuItem;
    Reporte1: TMenuItem;
    Exportar1: TMenuItem;
    Ver1: TMenuItem;
    Anterior1: TMenuItem;
    Siguiente1: TMenuItem;
    CambiaColor1: TMenuItem;
    Sonido1: TMenuItem;
    AvanceAutomtico1: TMenuItem;
    Imprimir1: TMenuItem;
    Label1: TLabel;
    TamanoFuente: TSpinEdit;
    Fuente1: TMenuItem;
    TipodeLetra1: TMenuItem;
    Fuentes: TFontDialog;
    Primeracolumna1: TMenuItem;
    SegundaColumna1: TMenuItem;
    TerceraColumna1: TMenuItem;
    N1: TMenuItem;
    N2: TMenuItem;
    TablaSQL: TQuery;
    Detalle: TDBGrid;
    DataSource1: TDataSource;
    procedure BotonPieClick(Sender: TObject);
    procedure BotonReporteClick(Sender: TObject);
    procedure BotonImprimeClick(Sender: TObject);
    procedure BotonExportaClick(Sender: TObject);
    procedure BotonSiguienteClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BotonAnteriorClick(Sender: TObject);
    procedure BotonColorClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BotonSonidoClick(Sender: TObject);
    procedure BotonLineasClick(Sender: TObject);
    procedure ModuloGraficaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonAutomaticoClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure BotonGraficaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonPieMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonLineasMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonReporteMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonExportaMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonAnteriorMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonSiguienteMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BotonColorMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonSonidoMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BotonAutomaticoMouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BotonImprimeMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Salir1Click(Sender: TObject);
    procedure BotonGraficaClick(Sender: TObject);
    procedure TamanoFuenteChange(Sender: TObject);
    procedure TipodeLetra1Click(Sender: TObject);
    procedure TerceraColumna1Click(Sender: TObject);
    procedure Primeracolumna1Click(Sender: TObject);
    procedure SegundaColumna1Click(Sender: TObject);
  private
    { Private declarations }
  public
  procedure VentanaMueve(var M: TWMNCHitTest);
    { Public declarations }
  end;



eti=record
orden,nombre:String[25];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;

tiposcampo=record
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;

Anchos=record
ord,nom,c1,c2,c3,c4,c5,c6,c7,c8:word;
end;


var

  FormaBarras: TFormaBarras;
  pag,reduce,ancho,anchobarra,ultimapagina:integer;
  total1,total2,total3,total4,total5,total6,total7,total8: Currency;
  opcion,numerobarras,numerodelineas:word;

  etiquetas,tipocam:eti;
  anch:Anchos;
  A:Array[1..10]of word;
  ExisteReporte:Boolean;
  anterior,siguiente:string;
  suma1,suma2,suma3,suma4,suma5,suma6,suma7,suma8:currency;
  SaldoBloque:String;
//  TablaSQL:TQuery;

//procedure ReporteSQL(SqlTexto,SqlTexto2,CamposSumas:String);
procedure parametrosgrafica(titulo:String;ejex,ejey:string;barra:word);
implementation

uses advierte;

{$R *.DFM}

{procedure ReporteSQL(SqlTexto,SqlTexto2,CamposSumas:String);
begin
//****************
//TablaSQL:=TQuery.Create(TablaSQL);
FormaAdvertencia.Show;
FormaAdvertencia.Label1.Caption:='Espere un momento por Favor...';
FormaAdvertencia.Refresh;

FormaBarras.TablaSQL.SQL.Text:=SqlTexto;
FormaBarras.TablaSQL.SQL.Text:=FormaBarras.TablaSQL.SQL.Text+SqlTexto2;
MuestraMensaje(FormaBarras.TablaSQL.SQL.Text);
FormaBarras.TablaSQL.Open;

FormaAdvertencia.Close;
FormaBarras.Detalle.Visible:=True;
FormaBarras.ShowModal;
FormaBarras.Detalle.Visible:=False;

//TablaSQL.Free;
end;}


procedure TFormaBarras.VentanaMueve(var M: TWMNCHitTest);
 var P: TPoint;
begin
 inherited;
 GetCursorPos(P);
 P.X := P.X - Left;
 P.Y := P.Y - Top;
 with Panel1 do
  if (P.X > Left) and (P.X < (Left + Width)) and (P.Y > Top) and (P.Y < (Top + Height)) then
   M.Result := htCaption;
end;


function mayorcero(valor:Real):Boolean;
begin
if valor>0 then mayorcero:=True
else
mayorcero:=False;

end;

procedure saldoscero;
begin
  total1:=0;total2:=0;total3:=0;total4:=0;
  total5:=0;total6:=0;total7:=0;total8:=0;
end;

function numerodeetiquetas:word;
begin
{AssignFile(arch2,leeruta+'\tempo\congra.gra');
Reset(arch2);
Readln(arch2,max);
Readln(arch2,barras);
CloseFile(arch2);

 }
end;



function ajuste(aux:String;n:Integer):string;
var i:integer;
valoraux:string[50];
aux2:string;

begin
aux2:='';
for i:=1 to n do
aux2:=aux2+'X';

{MuestraMensaje('tamano '+IntToStr(length(aux)));}
for i:=1 to length(aux) do
begin
if Ord(aux[i])<30 then
aux[i]:=' ';

end;

valoraux:=aux;
aux:=valoraux;
if length(aux)<n then
begin
for i:=length(aux) to n do
aux:=aux+' ';
end
else
begin
if (FormaBarras.Concentrado.Font.Name='MS Sans Serif')or(FormaBarras.Concentrado.Font.Name='Courier New') then
begin
aux:='';
for i:=1 to n do
aux:=aux+valoraux[i];
aux:=aux+' ';
end;//if

end;
//****calcula los valores para el ulltimo ajuste
FormaBarras.Canvas.Font.Name:=FormaBarras.Concentrado.Font.Name;
//showMessage('entro '+FormaBarras.Concentrado.Font.Name);
if (FormaBarras.Concentrado.Font.Name<>'MS Sans Serif')and(FormaBarras.Concentrado.Font.Name<>'Courier New') then
begin

while FormaBarras.Canvas.TextWidth(aux)<FormaBarras.Canvas.TextWidth(aux2) do
begin
aux:=aux+' ';
end;

end;


ajuste:=aux;
end;

function ver(cad1,cad2:string):string;
begin
if not (cad2='') then
begin
if (cad2[1]<>'-') then
ver:=cad1
else
ver:=ajuste(' ',20);
end
else
ver:=cad2;

end;


{***funciones para ver los datos****}

function visiblenum(valor:String{Real};eti:string;tipo:String;largo:word):string;
var i:integer;
aux:string[40];
begin
aux:='';

if ((tipo='f')or(tipo='e'))and (eti<>'C') then
begin

if (eti<>'')and (eti[1]<>'-') then
aux:=ConvierteAjustado('###,###,##0.00',{FloatToStr(}valor{)},'$',FormaBarras.Canvas)
else
begin
if eti<>'' then
begin
if eti[1]='-' then
aux:=convierteAjustado('###,###,##0.00',{FloatToStr(}valor{)},'', FormaBarras.Canvas);
end
else
aux:='';

end;
//ShowMessage(aux);
visiblenum:=ajuste(aux,largo);
//visiblenum:=aux;
//aux:=ajuste(aux,largo);

end//primer if
else
begin

if (tipo='x') then
begin
visiblenum:='';
//ShowMessage(tipo);
end
else
begin
//if (eti='C')and ((aux='$          0.00')or(aux='          0.00'))then
//ShowMessage(valor);
if (valor='0')or(valor='') then
visiblenum:='';
visiblenum:=ajuste(valor,largo);

end;

end;






end;


function VisibleTotal(valor:String{Real};eti:string;tipo:String;largo:word):string;
var i:integer;
aux:string[30];
begin
aux:='';
if (eti<>'')and (eti[1]<>'-') then
begin
aux:=convierteAjustado('###,###,##0.00',{FloatToStr(}valor{)},'$', FormaBarras.Canvas);
visibleTotal:=ajuste(aux,largo);
end
else
visibleTotal:=ajuste(' ',largo);

end;

{********************************************}

procedure ValoresPaginas;
var
arch2:File of Eti;
arch3:File of Anchos;
begin

if FileExists(leeruta+'\tempo\anchos.tmp') then
begin
AssignFile(arch3,leeruta+'\tempo\anchos.tmp');
ReSet(arch3);
Read(arch3,anch);
A[1]:=anch.ord;
A[2]:=anch.nom;
A[3]:=anch.c1;
A[4]:=anch.c2;
A[5]:=anch.c3;
A[6]:=anch.c4;
A[7]:=anch.c5;
A[8]:=anch.c6;
A[9]:=anch.c7;
A[10]:=anch.c8;
CloseFile(arch3);

end;

{***************************}

AssignFile(arch2,leeruta+'\tempo\etique.tmp');
ReSet(arch2);
Read(arch2,etiquetas);
tipocam.orden:='FGG';
SaldoBloque:='dfdg';
Read(arch2,tipocam);
//Read(arch2,tipocam);
SaldoBloque:=tipocam.orden;
CloseFile(arch2);

{********************************}
if FileExists(leeruta+'\tempo\final.tmp') then
ExisteReporte:=True
else
ExisteReporte:=False;

end;



procedure ChecaAnterior(ant,sig:string;c1,c2,c3,c4,c5,c6,c7,c8:currency);
begin


end;



procedure pagina(p:integer);
type
registros=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:String[25]{Real};
end;



var
arch:File of registros;
{arch2:File of Eti;
arch3:File of Anchos;}

dato:registros;
{etiquetas,tipocam:eti;
ancho:Anchos;}

j,mas,tamanoactual:integer;
coloractual:TColor;
LineaInserta:String;
{A:array[1..10]of word;}

{tipocam:tiposcampo;}
begin

with FormaBarras do
begin
if p=0 then
ValoresPaginas;


if ExisteReporte{FileExists(leeruta+'\tempo\final.tmp')} then
begin
AssignFile(arch,leeruta+'\tempo\final.tmp');


Reset(arch);
mas:=0;
{MuestraMensaje('entra a paginas tamaño '+IntToStr(FileSize(arch)));}
if (P*50)<FileSize(arch) then
begin
if (FileSize(arch) mod 50) <>0 then
mas:=1;
BarradeEstado.Panels[0].Text:='Página '+IntToStr(p+1)+' de  '+IntToStr(Trunc(FileSize(arch)/50)+mas);
ultimapagina:=Trunc(FileSize(arch)/50)+mas;
Concentrado.visible:=True;
Concentrado.Clear;

{*********************}

 coloractual:=Concentrado.Font.Color;
 tamanoactual:=Concentrado.Font.Size;
  with Concentrado.SelAttributes do
  begin
    Color := clRed;
    Height := 20;
//    Font.Pitch:=fpFixed;
  end;
  concentrado.Lines.Add(FormaBarras.Caption);

  with Concentrado.SelAttributes do
  begin
    Color := coloractual;
    Height := tamanoactual+3;
//    Font.Pitch:=fpFixed;
  end;

{Concentrado.DefAttributes.Color :=coloractual;
Concentrado.DefAttributes.Height :=tamanoactual;}

{Concentrado.Font.Color:=coloractual;
Concentrado.Font.Size:=tamanoactual;}
{********************}
{Atributos.Color:=clRed;}
Concentrado.Lines.Add(ajuste(etiquetas.orden,A[1]{20})+ajuste(etiquetas.nombre,A[2]{20})+ajuste(etiquetas.c1,A[3]{20})+ajuste(etiquetas.c2,A[4]{20})+ajuste(etiquetas.c3,A[5]{20})+ajuste(etiquetas.c4,A[6]{20})+ajuste(etiquetas.c5,a[7]{20})+ajuste(etiquetas.c6,A[8]{20})+ajuste(etiquetas.c7,A[9]{20})+ajuste(etiquetas.c8,A[10]{20}));
{Atributos.Color:=Concentrado.Color;}
Seek(arch,(p*50){+1});
j:=0;
{MuestraMensaje('Entra a leer datos');}

siguiente:='fff';
anterior:='';

while (not eof(arch))and(j<numerodelineas) do
begin
Read(arch,dato);

//***calcula el anterior y el siguiente

//*****anterior y siguiente***********



if (dato.orden<>'*')and(dato.orden<>'') then
begin
{MuestraMensaje('Entra a leer datos  '+dato.orden);}
//*******xxxxx

if SaldoBloque='DC' then
begin

siguiente:=dato.orden;
if (anterior=siguiente) then
begin
suma1:=suma1+Flotante(dato.c1);
suma2:=suma2+Flotante(dato.c2);
suma3:=suma3+Flotante(dato.c3);
suma4:=suma4+Flotante(dato.c4);
suma5:=suma5+Flotante(dato.c5);
suma6:=suma6+Flotante(dato.c6);
suma7:=suma7+Flotante(dato.c7);
suma8:=suma8+Flotante(dato.c8);
end
else
begin

if (anterior<>'') then
begin
LineaInserta:=ajuste('Importes_____________',A[1])+ajuste('______________________',a[2])+visibletotal(FloatToStr(suma1),etiquetas.c1,tipocam.c4,A[3])+visibletotal(FloatToStr(suma2),etiquetas.c2,tipocam.c4,A[2])+visibletotal(FloatToStr(suma3),etiquetas.c3,tipocam.c4,A[3])+
visibletotal(FloatToStr(suma4),etiquetas.c4,tipocam.c4,A[4])+visibletotal(FloatToStr(suma5),etiquetas.c5,tipocam.c4,A[5])+visibletotal(FloatToStr(suma6),etiquetas.c4,tipocam.c6,A[6])+visibletotal(FloatToStr(suma7),etiquetas.c7,tipocam.c4,A[7])+visibletotal(FloatToStr(suma8),etiquetas.c8,tipocam.c4,A[8]);
if LineaInserta<>'' then
Concentrado.Lines.Add(LineaInserta);

LineaInserta:=ajuste(' ',A[1])+ajuste('    ',a[2])+visiblenum('0',etiquetas.c1,'x',A[3])+visiblenum(FloatToStr(suma2),etiquetas.c2,'x',A[4])+visiblenum(FloatToStr(suma3),etiquetas.c3,'x',A[5])+
visiblenum(FloatToStr(suma4),etiquetas.c4,'x',A[6])+visiblenum(FloatToStr(suma5),etiquetas.c5,'x',A[7])+visiblenum(FloatToStr(suma6),etiquetas.c6,'x',A[8])+visiblenum(FloatToStr(suma7),etiquetas.c7,'x',A[9])+visiblenum(FloatToStr(suma8),'x',tipocam.c8,A[10]);
Concentrado.Lines.Add(LineaInserta);
end;

suma1:=0;suma2:=0;suma3:=0;suma4:=0;suma5:=0;suma6:=0;suma7:=0;suma8:=0;

suma1:=suma1+Flotante(dato.c1);
suma2:=suma2+Flotante(dato.c2);
suma3:=suma3+Flotante(dato.c3);
suma4:=suma4+Flotante(dato.c4);
suma5:=suma5+Flotante(dato.c5);
suma6:=suma6+Flotante(dato.c6);
suma7:=suma7+Flotante(dato.c7);
suma8:=suma8+Flotante(dato.c8);



end;


anterior:=siguiente;

end;//tremina if saldobloque
//**********xxxxxxxxx
//ChecaAnterior(anterior,siguiente,Flotante(dato.c1),Flotante(dato.c2),Flotante(dato.c3),Flotante(dato.c4),Flotante(dato.c5),Flotante(dato.c6),Flotante(dato.c7),Flotante(dato.c8));


LineaInserta:=ajuste(dato.orden,A[1])+ajuste(dato.nombre,a[2])+visiblenum(dato.c1,etiquetas.c1,tipocam.c1,A[3])+visiblenum(dato.c2,etiquetas.c2,tipocam.c2,A[4])+visiblenum(dato.c3,etiquetas.c3,tipocam.c3,A[5])+
visiblenum(dato.c4,etiquetas.c4,tipocam.c4,A[6])+visiblenum(dato.c5,etiquetas.c5,tipocam.c5,A[7])+visiblenum(dato.c6,etiquetas.c6,tipocam.c6,A[8])+visiblenum(dato.c7,etiquetas.c7,tipocam.c7,A[9])+visiblenum(dato.c8,etiquetas.c8,tipocam.c8,A[10]);
//MuestraMensaje(LineaInserta);
if LineaInserta<>'' then
Concentrado.Lines.Add(LineaInserta);
if BotonSonido.Tag=1 then sonido(10);
if (tipocam.c1='f')or(tipocam.c1='e')then total1:=total1+Flotante(dato.c1);
if (tipocam.c2='f')or(tipocam.c2='e')then total2:=total2+Flotante(dato.c2);
if (tipocam.c3='f')or(tipocam.c3='e')then total3:=total3+Flotante(dato.c3);
if (tipocam.c4='f')or(tipocam.c4='e')then total4:=total4+Flotante(dato.c4);
if (tipocam.c5='f')or(tipocam.c5='e')then total5:=total5+Flotante(dato.c5);
if (tipocam.c6='f')or(tipocam.c6='e')then total6:=total6+Flotante(dato.c6);
if (tipocam.c7='f')or(tipocam.c7='e')then total7:=total7+Flotante(dato.c7);
if (tipocam.c8='f')or(tipocam.c8='e')then total8:=total8+Flotante(dato.c8);
end;
j:=j+1;
end;
if  Eof(arch) then
begin
Timer1.enabled:=False;

//****pone los valores del ultimo acumulado
if SaldoBloque='DC' then
begin
//MuestraMensaje('imprime el total');
LineaInserta:=ajuste('Importes_____________',A[1])+ajuste('______________________',a[2])+visibletotal(FloatToStr(suma1),etiquetas.c1,tipocam.c4,A[3])+visibletotal(FloatToStr(suma2),etiquetas.c2,tipocam.c4,A[2])+visibletotal(FloatToStr(suma3),etiquetas.c3,tipocam.c4,A[3])+
visibletotal(FloatToStr(suma4),etiquetas.c4,tipocam.c4,A[4])+visibletotal(FloatToStr(suma5),etiquetas.c3,tipocam.c4,A[5])+visibletotal(FloatToStr(suma6),etiquetas.c4,tipocam.c6,A[6])+visibletotal(FloatToStr(suma7),etiquetas.c7,tipocam.c4,A[7])+visibletotal(FloatToStr(suma8),etiquetas.c8,tipocam.c4,A[8]);
Concentrado.Lines.Add(LineaInserta);
LineaInserta:=ajuste(' ',A[1])+ajuste('    ',a[2])+visiblenum('0',etiquetas.c1,'x',A[3])+visiblenum(FloatToStr(suma2),etiquetas.c2,'x',A[4])+visiblenum(FloatToStr(suma3),etiquetas.c3,'x',A[5])+
visiblenum(FloatToStr(suma4),etiquetas.c4,'x',A[6])+visiblenum(FloatToStr(suma5),etiquetas.c5,'x',A[7])+visiblenum(FloatToStr(suma6),etiquetas.c6,'x',A[8])+visiblenum(FloatToStr(suma7),etiquetas.c7,'x',A[9])+visiblenum(FloatToStr(suma8),'x',tipocam.c8,A[10]);
Concentrado.Lines.Add(LineaInserta);
//end;

suma1:=0;suma2:=0;suma3:=0;suma4:=0;suma5:=0;suma6:=0;suma7:=0;suma8:=0;
end;




{MuestraMensaje('imprime el total');}
Concentrado.Lines.Add(ver(ajuste(' ',A[1]),etiquetas.orden)+ver(ajuste(' ',a[2]),etiquetas.nombre)+ver(ajuste('____________________',A[3]),etiquetas.c1)+ver(ajuste('____________________',A[4]),etiquetas.c2)+ver(ajuste('____________________',A[5]),etiquetas.c3)+ver(ajuste('____________________',A[6]),etiquetas.c4)+ver(ajuste('_____________________',A[7]),etiquetas.c5)+ver(ajuste('_____________________',A[8]),etiquetas.c6)+ver(ajuste('_____________________',A[9]),etiquetas.c7)+ver(ajuste('_____________________',A[10]),etiquetas.c8));
{Concentrado.Font.Color:=clRed;}
Concentrado.Lines.Add(ajuste('TOTALES',A[1])+ajuste('  ',A[2])+visibleTotal(FloatToStr(total1),etiquetas.c1,tipocam.c1,A[3])+visibleTotal(FloatToStr(total2),etiquetas.c2,tipocam.c2,A[4])+visibleTotal(FloatToStr(total3),etiquetas.c3,tipocam.c3,A[5])+
visibletotal(FloatToStr(total4),etiquetas.c4,tipocam.c4,A[6])+visibleTotal(FloatToStr(total5),etiquetas.c5,tipocam.c5,A[7])+visibleTotal(FloatToStr(total6),etiquetas.c6,tipocam.c6,A[8])+visibletotal(FloatToStr(total7),etiquetas.c7,tipocam.c7,A[9])+visibletotal(floatToStr(total8),etiquetas.c8,tipocam.c8,A[10]));
{Concentrado.Font.Color:=clBlack;}
saldoscero;
{pag:=pag-1;}
end
else
                                                                                                                                     begin
end;
end
else
pag:=Trunc(FileSize(arch)/50)+mas;
closeFile(arch);
end;

end;

{end;}
end;
{****************}

procedure parametrosgrafica(titulo:String;ejex,ejey:string;barra:word);
var
i:integer;
begin
FormaBarras.Tag:=0;
FormaBarras.Panel2.Tag:=0;
FormaBarras.botonGrafica.Tag:=1;
FormaBarras.Concentrado.Clear;


With FormaBarras do
begin
{ModuloGrafica.Visible:=True;}
ModuloGrafica.Title.Text.Delete(0);
ModuloGrafica.Title.Text.Add(titulo);
ModuloGrafica.BottomAxis.Title.Caption:=ejex;
ModuloGrafica.leftAxis.Title.Caption:=ejey;;
end;
numerobarras:=barra;
end;




procedure imprimegrafica;
var
ancho,largo:integer;
PapelOrientacion:TPrinterOrientation;
begin
PapelOrientacion:=Printer.Orientation;
Printer.Orientation:=poLandScape;

Printer.BeginDoc;
ancho:=Printer.PageWidth;
largo:=Printer.PageHeight;


with FormaBarras.ModuloGrafica do
begin
FormaBarras.ModuloGrafica.PrintResolution:=-100;
FormaBarras.ModuloGrafica.PrintPartial(Rect(50,50,ancho-50,largo-50));
end;


Printer.EndDoc;
 Printer.Orientation:=PapelOrientacion;

end;

procedure borralabarra;
var
i:integer;
begin

With FormaBarras do
begin

for i:=Series1.Count downto 1 do
begin
Series1.Delete(0);
end;

for i:=Series2.Count downto 1 do
begin
Series2.Delete(0);
end;

for i:=Series3.Count downto 1 do
begin
Series3.Delete(0);
end;



end;
end;

procedure cambiaejes;
var
i:integer;
begin

With FormaBarras do
begin
case FormaBarras.BotonGrafica.Tag of
0:with Series1.GetVertAxis do
begin
Automatic:=False;
Minimum:=0;
Maximum:=Series1.YValues.MaxValue+100;
ModuloGrafica.AxisVisible:=True;
end;

1:with Series1.GetVertAxis do
begin
Automatic:=False;
Minimum:=0;
Maximum:=Series1.YValues.MaxValue+100;
ModuloGrafica.AxisVisible:=True;
end;

5:with Series3.GetVertAxis do
begin
Automatic:=False;
Minimum:=0;
Maximum:=Series3.YValues.MaxValue+100;
ModuloGrafica.AxisVisible:=True;
end;

end;


end;
end;


procedure dibujalabarra(numero:integer;c:string;o1,o2,o3:Real;barras:integer);
begin

With FormaBarras do
begin
opcion:=1;

if BotonGrafica.Tag=1 then
with Series1 do
begin
case barras of
1:AddXY(numero,o1,c,clTeeColor);
2:begin
  AddXY((numero-1)*2,o1,c,clTeeColor);
  AddXY((numero-1)*2,o2,c,clTeeColor);
  end;
3:begin
  AddXY((numero-1)*3,o1,c,clTeeColor);
  AddXY((numero-1)*3+1,o2,c,clTeeColor);
  AddXY((numero-1)*3+2,o3,c,clTeeColor);
  end;
end;
end;

if BotonGrafica.Tag=0 then
with Series2 do
begin
case barras of
1:if mayorcero(o1) then AddXY(numero,o1,c,clTeeColor);
2:begin
  if mayorcero(o1) then AddXY((numero-1)*2,o1,c,clTeeColor);
  if mayorcero(o2) then AddXY((numero-1)*2,o2,c,clTeeColor);
  end;
3:begin
  if mayorcero(o1) then AddXY((numero-1)*3,o1,c,clTeeColor);
  if mayorcero(o2) then AddXY((numero-1)*3+1,o2,c,clTeeColor);
  if mayorcero(o3) then AddXY((numero-1)*3+2,o3,c,clTeeColor);
  end;
end;
end;

if BotonGrafica.Tag=5 then
with Series3 do
begin
case barras of
1:AddXY(numero,o1,c,clTeeColor);
2:begin
  AddXY((numero-1)*2,o1,c,clTeeColor);
  AddXY((numero-1)*2,o2,c,clTeeColor);
  end;
3:begin
  AddXY((numero-1)*3,o1,c,clTeeColor);
  AddXY((numero-1)*3+1,o2,c,clTeeColor);
  AddXY((numero-1)*3+2,o3,c,clTeeColor);
  end;
end;
{AddXY(numero,o1,c,clTeeColor);}
end;


end;
end;



procedure generaexel;
type
registros=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;

registros2=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:String[40];
end;

eti=record
orden,nombre:String[25];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;

{{tiposcampo=record
orden,nombre:String[25];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];

end;}

var
arch:File of registros;
arch3:TextFile;
arch2:File of Eti;
arch4:file of registros2;
dato:registros;
dato2:registros2;
etiquetas,tipocam:eti;
linea:string;
//tipocam:tiposcampo;
{total1,total2,total3,total4,total5,total6,total7,total8: Currency;}
begin
pag:=0;

total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;

AssignFile(arch2,leeruta+'\tempo\etique.tmp');
AssignFile(arch3,leeruta+'\tempo\exel.tmp');
ReSet(arch2);
Rewrite(arch3);

Read(arch2,etiquetas);
Read(arch2,tipocam);

linea:=(ajuste(etiquetas.orden,20)+char(9)+ajuste(etiquetas.c1,20)+char(9)+ajuste(etiquetas.c2,20)+char(9)+ajuste(etiquetas.c3,20)+char(9)+ajuste(etiquetas.c4,20)+char(9)+ajuste(etiquetas.c5,20)+char(9)+ajuste(etiquetas.c6,20)+char(9)+ajuste(etiquetas.c7,20)+char(9)+ajuste(etiquetas.c8,20));
Writeln(arch3,linea);
CloseFile(arch2);

if  FormaBarras.botonGrafica.Tag=3 then
begin
AssignFile(arch4,leeruta+'\tempo\final.tmp');
reset(arch4);
if Filesize(arch4)>0 then
begin
Read(arch4,dato2);
while not eof(arch4) do
begin
try
linea:=ajuste(dato2.orden,20)+char(9)+ajuste(dato2.nombre,40)+char(9)+visiblenum(dato2.c1,'C',tipocam.c1,30)+char(9)+visiblenum(dato2.c2,'C',tipocam.c2,20)+char(9)+visiblenum(dato2.c3,'C',tipocam.c3,20)+char(9)+
visiblenum(dato2.c4,'C',tipocam.c4,20)+char(9)+visiblenum(dato2.c5,'C',tipocam.c5,20)+char(9)+visiblenum(dato2.c6,'C',tipocam.c6,20)+char(9)+visiblenum(dato2.c7,'C',tipocam.c7,20)+
char(9)+visiblenum(dato2.c8,'C',tipocam.c8,20);
//ShowMessage(tipocam.c7);
Writeln(arch3,linea);
Read(arch4,dato2);
except
//nada
end;

end;//while

end;
 CloseFile(arch4);
end
else
begin
AssignFile(arch,leeruta+'\tempo\final.tmp');
Reset(arch);

if Filesize(arch)>0 then
begin
Read(arch,dato);
while not eof(arch)do
begin
try
linea:=ajuste(dato.orden,20)+char(9)+ajuste(dato.nombre,40)+char(9)+visiblenum(dato.c1,'C',tipocam.c1,30)+char(9)+visiblenum(dato.c2,'C',tipocam.c2,20)+char(9)+visiblenum(dato.c3,'C',tipocam.c3,20)+char(9)+
visiblenum(dato.c4,'C',tipocam.c4,20)+char(9)+visiblenum(dato.c5,'C',tipocam.c5,20)+char(9)+visiblenum(dato.c6,'C',tipocam.c6,20)+char(9)+visiblenum(dato.c7,'C',tipocam.c7,20)+
char(9)+visiblenum(dato.c8,'C',tipocam.c8,20);
//ShowMessage(tipocam.c7);
Writeln(arch3,linea);
Read(arch,dato);
except
//nada
end;

end;//while

end;//uif
closeFile(arch);
end;


closeFile(arch3);

end;


procedure imprime(inicio,fin:integer);
var i,linea,r,cuentapaginas:integer;
    ren:Real;
PapelOrientacion:TPrinterOrientation;
{****variables del titulo****}
rec:TRect;
begin
PapelOrientacion:=Printer.Orientation;
Printer.BeginDoc;
if Printer.Orientation=poPortrait then
numerodelineas:=50
else
numerodelineas:=36;

r:=Trunc(Printer.PageHeight/(53+4));
//Printer.Canvas.Font.Name:='Courier';
Printer.Canvas.Font.Name:=FormaBarras.Concentrado.Font.Name;
//Printer.Canvas.Font.Pitch:=fpFixed;
Printer.Canvas.Font.Size:=FormaBarras.TamanoFuente.Value;
//10;
if inicio >=1 then inicio:=inicio-1;
for cuentapaginas:=inicio to fin-1 do
begin
pagina(cuentapaginas);
linea:=0;
For i:=0 to FormaBarras.Concentrado.Lines.Count do
begin
{***imprime el encabezado*******}
if (i=0){and(inicio=0)} then
begin

Printer.Canvas.Font.Size:=14;
Printer.Canvas.Font.Name:='Arial';
{MuestraMensaje(IntToStr(Printer.Canvas.TextWidth(FormaBarras.Concentrado.Lines[i])));}
rec.Left:={8;}Trunc((Printer.PageWidth-Printer.Canvas.TextWidth(FormaBarras.Concentrado.Lines[i]))/2);
rec.Top:=Trunc(r*linea+(r*3)+10/2);
rec.Right:=Printer.PageWidth-10;
rec.Bottom:=r*linea+(r*3)+10;
{Printer.Canvas.Brush.Color:=clGray;}
Printer.Canvas.Brush.Color:=$00C0EFEB;
Printer.Canvas.Rectangle(8,10,Printer.PageWidth-10,r*linea+(r*3)+10);
Printer.Canvas.TextOut(rec.Left,Trunc((r*linea+(r*3))/2)-10,FormaBarras.Concentrado.Lines[i]);
{Printer.Canvas.TextRect(rec,8,10,FormaBarras.Concentrado.Lines[i]);}
Printer.Canvas.Font.Size:=FormaBarras.TamanoFuente.Value;
Printer.Canvas.TextOut(Printer.PageWidth-160,r*linea+(r*3)-40,'Pag '+IntToStr(cuentapaginas+1));

Printer.Canvas.Font.Name:=FormaBarras.Concentrado.Font.Name;
Printer.Canvas.Brush.Color:=clWhite;
end
else
Printer.Canvas.TextOut(10,r*linea+(r*3),FormaBarras.Concentrado.Lines[i]);
linea:=linea+1;
if (linea=53)  then
begin
Printer.NewPage;
linea:=0;
end;
end;
Printer.NewPage;

end;

Printer.EndDoc;
Printer.Orientation:=PapelOrientacion;


end;






{function ruta(linea:integer):String;
var
arch:TextFile;
aux:string;
i:integer;

begin
MuestraMensaje(leeempresa+'\General.cnf');
AssignFile(arch,leeempresa+'\General.cnf');
Reset(arch);
for i:=1 to linea do
Readln(arch,aux);
CloseFile(arch);
ruta:=aux;
end;}

{****************}

procedure dibujaejes(max:Real;salida:char);
var
i,ancho:integer;
begin
{With FormaBarras do
begin
if salida='p' then
begin}

{if Trunc(AreaGrafica.Height/(120+reduce))>5 then
AreaGrafica.Canvas.Font.Size:=Trunc(AreaGrafica.Height/(120+reduce))
else
AreaGrafica.Canvas.Font.Size:=6;

for i:=0 to 10 do
begin
AreaGrafica.Canvas.TextOut(1,10+(Trunc((AreaGrafica.Height-(reduce+10))/10)*i),IntToStr(Trunc(max-(Trunc(max/10)*i)))+'-');
AreaGrafica.Canvas.MoveTo(40,10+(Trunc((AreaGrafica.Height-(reduce+10))/10)*i));
AreaGrafica.Canvas.LineTo(AreaGrafica.Width-(ancho+10),10+(Trunc((AreaGrafica.Height-(reduce+10))/10)*i));
end;}
{AreaGrafica.Canvas.MoveTo(40,AreaGrafica.Height-(reduce+10));
AreaGrafica.Canvas.LineTo(40,10);

AreaGrafica.Canvas.MoveTo(AreaGrafica.Width-(ancho+10),AreaGrafica.Height-(reduce+10));
AreaGrafica.Canvas.LineTo(AreaGrafica.Width-(ancho+10),10);
end;

if salida='i' then
begin
if Trunc(Printer.PageHeight/(120+reduce))>5 then
Printer.Canvas.Font.Size:=Trunc(Printer.PageHeight/(120+reduce))
else
Printer.Canvas.Font.Size:=6;

Printer.Canvas.Font.Name:='Courier';
Printer.Canvas.Font.Size:=12;
for i:=0 to 10 do
begin
Printer.Canvas.TextOut(1,10+(Trunc((Printer.PageHeight-(reduce+10))/10)*i),IntToStr(Trunc(max-(Trunc(max/10)*i)))+'-');
Printer.Canvas.MoveTo(40,10+(Trunc((Printer.PageHeight-(reduce+10))/10)*i));
Printer.Canvas.LineTo(Printer.Pagewidth-(ancho+10),10+(Trunc((Printer.PageHeight-(reduce+10))/10)*i));
end; }
{Printer.Canvas.MoveTo(40,Printer.PageHeight-(reduce+10));
Printer.Canvas.LineTo(40,10);

Printer.Canvas.MoveTo(Printer.Pagewidth-(ancho+10),Printer.PageHeight-(reduce+10));
Printer.Canvas.LineTo(Printer.Pagewidth-(ancho+10),10);

end;

end; }
end;
{***llllll****}


procedure barra(coordenada:String;ordenada,valor:Real;pos:integer;tipo:Word;salida:char);
var
renglon:integer;
begin
{if salida='p' then
begin
FormaBarras.AreaGrafica.Canvas.Font.Name:='Courier';
FormaBarras.AreaGrafica.Canvas.Font.Pitch:=fpFixed;

if tipo=1 then
begin
if FormaBarras.AreaGrafica.Canvas.Brush.Color=clRed then
FormaBarras.AreaGrafica.Canvas.Brush.Color:=clBlue
else
FormaBarras.AreaGrafica.Canvas.Brush.Color:=clRed;
FormaBarras.AreaGrafica.Canvas.TextOut(pos*(40-anchobarra)+40,FormaBarras.AreaGrafica.Height-(reduce-2),coordenada);
if (FormaBarras.BotonAmbos.Tag=1)and (pos=1) then
begin
FormaBarras.AreaGrafica.Canvas.Brush.Color:=clWhite;
FormaBarras.AreaGrafica.Canvas.Rectangle(FormaBarras.AreaGrafica.Width-200,FormaBarras.AreaGrafica.Height-100,FormaBarras.AreaGrafica.Width-5,10);
FormaBarras.AreaGrafica.Canvas.TextOut(FormaBarras.AreaGrafica.Width-195,10+pos*15,ajuste(coordenada,6)+ajuste(convierte('###,###,##0.00',IntToStr(Trunc(valor)),0),10));
end;

if (FormaBarras.BotonAmbos.Tag=1) then
begin
FormaBarras.AreaGrafica.Canvas.TextOut(FormaBarras.AreaGrafica.Width-195,10+pos*15,ajuste(coordenada,6)+ajuste(convierte('###,###,##0.00',IntToStr(Trunc(valor)),0),10));
end;

FormaBarras.AreaGrafica.Canvas.Rectangle(pos*(40-anchobarra)+40,(FormaBarras.AreaGrafica.Height-(reduce+2))-Trunc(ordenada),(pos*(40-anchobarra))+(40-anchobarra)+40,(FormaBarras.AreaGrafica.Height-(reduce+2)));
end;

if tipo=0 then
begin
FormaBarras.AreaGrafica.Canvas.LineTo(pos*(40-anchobarra)+40,(FormaBarras.AreaGrafica.Height-(reduce+2))-Trunc(ordenada));
end;

FormaBarras.AreaGrafica.Canvas.Font.Pitch:=fpDefault;
FormaBarras.AreaGrafica.Canvas.Font.Name:='Arial';
end;

if salida='i' then
begin
Printer.Canvas.Brush.Style:=bsDiagCross;

ancho:=Trunc(Printer.PageHeight/14);
Printer.Canvas.Font.Name:='Courier';
Printer.Canvas.Font.Pitch:=fpFixed;
Printer.Canvas.Font.Size:=12;
renglon:=Trunc(Printer.PageWidth/35);

if tipo=1 then
begin
if Printer.Canvas.Brush.Color=clRed then
Printer.Canvas.Brush.Color:=clBlue
else
Printer.Canvas.Brush.Color:=clRed;
Printer.Canvas.TextOut(pos*(ancho-anchobarra)+ancho,(Printer.PageHeight-(reduce+2))-Trunc(ordenada),coordenada);

if (FormaBarras.BotonAmbos.Tag=1)and (pos=1) then
begin
Printer.Canvas.Brush.Color:=clWhite;
Printer.Canvas.Rectangle(Printer.Pagewidth-Trunc(Printer.Pagewidth/4.7),Printer.PageHeight-Trunc(Printer.PageHeight/4.4),Printer.Pagewidth-5,10);
Printer.Canvas.TextOut(Trunc(Printer.PageWidth/4),10,FormaBarras.Caption);
Printer.Canvas.TextOut(Printer.PageWidth-Trunc(Printer.Pagewidth/4.7)-10,10+pos*renglon,ajuste(coordenada,6)+ajuste(convierte('###,###,##0.00',IntToStr(Trunc(valor)),0),10));
Printer.Canvas.Brush.Color:=clRed;
end;

if (FormaBarras.BotonAmbos.Tag=1) then
begin
Printer.Canvas.TextOut(Printer.Pagewidth-Trunc(Printer.Pagewidth/4.7)-10,10+pos*renglon,ajuste(coordenada,6)+ajuste(convierte('###,###,##0.00',IntToStr(Trunc(valor)),0),10));
end;
Printer.Canvas.Rectangle(pos*(ancho-anchobarra)+ancho,(Printer.PageHeight-(reduce+2))-Trunc(ordenada),(pos*(ancho-anchobarra))+(ancho-anchobarra)+ancho,(Printer.PageHeight-(reduce+2)));
end;

if tipo=0 then
begin
Printer.Canvas.LineTo(pos*(40-anchobarra)+40,(Printer.PageHeight-(reduce+2))-Trunc(ordenada));
end;

Printer.Canvas.Font.Pitch:=fpDefault;
Printer.Canvas.Font.Name:='Arial';
Printer.Canvas.Brush.Style:=bsSolid;
end;
 }

end;


function calculaintervalo(max:Real):Real;
begin
if (Trunc(max)<1000000) and (Trunc(max)>100000) then
max:=1000000;
if (Trunc(max)<100000) and (Trunc(max)>10000) then
max:=100000;
if (Trunc(max)<10000) and (Trunc(max)>1000) then
max:=10000;
if (Trunc(max)<1000) and (Trunc(max)>100) then
max:=1000;
if (Trunc(max)<100) and (Trunc(max)>10) then
max:=100;
if (Trunc(max)<10) and (Trunc(max)>1) then
max:=10;
if max=0 then
max:=10;
calculaintervalo:=max;
end;

function NumeroValido(valor:string):boolean;
var
num:Real;
cod:integer;
begin

val(valor,num,cod);
if cod=0 then
NumeroValido:=True
else
NumeroValido:=False;

end;


procedure dibujagraficas(tipo:Integer;salida:char);
type
registros=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:String[25]{;Real};
end;

type
datos=record
c:String[10];
o1:Real;
o2:Real;
o3:Real;
end;

var
max,peso:Real;
dato,dato2:registros;
arch:file of registros;
arch2:TextFile;
cambio,pos,j,alfa,i,cuenta:integer;
ValorBarra:Array[1..3] of String[25];
Valor:Array[1..8] of String[25];
begin



FormaBarras.Concentrado.visible:=False;
max:=0;
cambio:=0;
pos:=0;

AssignFile(arch,leeruta+'\tempo\final.tmp');
Reset(arch);

if numerobarras<1 then numerobarras:=1;
alfa:=Trunc(12/numerobarras);
if pag*alfa<=FileSize(arch) then
begin
Seek(arch,(pag*alfa)+1);
j:=0;
borralabarra;

While  (not Eof(arch))and(j<alfa) do
begin
Read(arch,dato);
if dato.orden<>'*' then
begin
{******asigna los valores a un arreglo*****}
valor[1]:=dato.c1;
valor[2]:=dato.c2;
valor[3]:=dato.c3;
valor[4]:=dato.c4;
valor[5]:=dato.c5;
valor[6]:=dato.c6;
valor[7]:=dato.c7;
valor[8]:=dato.c8;

{*******checa los validos*****************}
valorBarra[1]:='0';
valorBarra[2]:='0';
valorBarra[3]:='0';
cuenta:=1;
for i:=1 to 8 do
begin
if (NumeroValido(valor[i]))and(cuenta<4) then
begin
valorBarra[cuenta]:=valor[i];
cuenta:=cuenta+1;
end;

end;
{***ejecuta el dibujado de barras*********}
{dibujalabarra(j+1,dato.orden,Flotante(dato.c1),Flotante(dato.c2),Flotante(dato.c3),numerobarras);}

dibujalabarra(j+1,dato.orden,Flotante(ValorBarra[1]),Flotante(ValorBarra[2]),Flotante(ValorBarra[3]),numerobarras);

end;
j:=j+1;
end;

cambiaejes;
{FormaBarras.Canvas.TextOut(Trunc(FormaBarras.AreaGrafica.Width/4),10,FormaBarras.Caption);}
end;

if  (Eof(arch)) then
begin
FormaBarras.Timer1.enabled:=False;
saldoscero;
end;

CloseFile(arch);


end;




procedure pagina2(p:integer);
type
registros=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:String[40];
end;

eti=record
orden,nombre:String[25];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;



var
arch:File of registros;
arch2:File of Eti;
dato:registros;
etiquetas:eti;
j,mas:integer;
begin
{if p<1 then
begin
total1:=0;
total2:=0;
total3:=0;
total4:=0;
total5:=0;
total6:=0;
total7:=0;
total8:=0;
p:=0;
end; }

with FormaBarras do
begin

AssignFile(arch2,leeruta+'\tempo\etique.tmp');

ReSet(arch2);


Read(arch2,etiquetas);
CloseFile(arch2);


AssignFile(arch,leeruta+'\tempo\final.tmp');
Reset(arch);
{if FileSize(arch)>0 then
begin}
mas:=0;
if (P*50)<FileSize(arch) then
begin
if (FileSize(arch) mod 50) <>0 then
mas:=1;
BarradeEstado.Panels[0].Text:='Página '+IntToStr(p+1)+' de  '+IntToStr(Trunc(FileSize(arch)/50)+mas);

Concentrado.visible:=True;
Concentrado.Clear;
Concentrado.Lines.Add(ajuste(etiquetas.orden,30)+ajuste(etiquetas.nombre,30)+ajuste(etiquetas.c1,30)+ajuste(etiquetas.c2,30)+ajuste(etiquetas.c3,30)+ajuste(etiquetas.c4,30)+ajuste(etiquetas.c5,30)+ajuste(etiquetas.c6,30)+ajuste(etiquetas.c7,30)+ajuste(etiquetas.c8,30));
Seek(arch,p*50);
j:=0;
while (not eof(arch))and(j<numerodelineas) do
begin
Read(arch,dato);
if dato.orden<>'*' then
begin

Concentrado.Lines.Add(ajuste(dato.orden,30)+ajuste(dato.nombre,30)+ajuste(dato.c1,30)+ajuste(dato.c2,30)+ajuste(dato.c3,30)+
ajuste(dato.c4,30)+ajuste(dato.c5,30)+ajuste(dato.c6,30)+ajuste(dato.c7,30)+ajuste(dato.c8,30));

{total1:=total1+dato.c1;
total2:=total2+dato.c2;
total3:=total3+dato.c3;
total4:=total4+dato.c4;
total5:=total5+dato.c5;
total6:=total6+dato.c6;
total7:=total7+dato.c7;
total8:=total8+dato.c8;}

end;
j:=j+1;
end;
if  Eof(arch) then
begin
saldoscero;
{Concentrado.Lines.Add(ver(ajuste('____________________',20),etiquetas.orden)+ver(ajuste('____________________',20),etiquetas.nombre)+ver(ajuste('____________________',20),etiquetas.c1)+ver(ajuste('____________________',20),etiquetas.c2)+ver(ajuste('____________________',20),etiquetas.c3)+ver(ajuste('____________________',20),etiquetas.c4)+ver(ajuste('_____________________',20),etiquetas.c5)+ver(ajuste('_____________________',20),etiquetas.c6)+ver(ajuste('_____________________',20),etiquetas.c7)+ver(ajuste('_____________________',20),etiquetas.c8));
Concentrado.Lines.Add(ajuste('TOTALES',20)+ajuste('  ',20)+visiblenum(total1,etiquetas.c1)+visiblenum(total2,etiquetas.c2)+visiblenum(total3,etiquetas.c3)+
visiblenum(total4,etiquetas.c4)+visiblenum(total5,etiquetas.c5)+visiblenum(total6,etiquetas.c6)+visiblenum(total7,etiquetas.c7)+visiblenum(total8,etiquetas.c8));}

end
else
begin
end;
end;
closeFile(arch);
end;

{end;}
end;
{*********************}

procedure TFormaBarras.BotonPieClick(Sender: TObject);
type
datos=record
c:String[10];
o1:Real;
o2:Real;
o3:Real;
end;

var
max,peso:Real;
dato,dato2:datos;
arch:file of datos;
arch2:TextFile;
cambio,pos,j:integer;
begin
Concentrado.Visible:=False;
ModuloGrafica.Visible:=True;

if BotonGrafica.Tag=2 then
begin
pag:=0;
saldoscero;
end;

total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;
BotonGrafica.Tag:=0;
dibujagraficas(BotonGrafica.Tag,'p');
end;


procedure TFormaBarras.BotonReporteClick(Sender: TObject);
type
registros=record
orden:String[100];
nombre:String[100];
c1,c2,c3,c4,c5,c6,c7,c8:Real;
end;

eti=record
orden:String[25];
c1,c2,c3,c4,c5,c6,c7,c8:String[25];
end;



var
arch:File of registros;
arch2:File of Eti;
dato:registros;
etiquetas:eti;
{total1,total2,total3,total4,total5,total6,total7,total8: Currency;}
begin
Concentrado.Visible:=True;
ModuloGrafica.Visible:=False;

if BotonGrafica.Tag<>2 then
begin
 pag:=0;
saldoscero;
end;
{pag:=0;}

total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;
BotonGrafica.Tag:=2;

{AssignFile(arch2,leeruta+'\tempo\etique.tmp');

ReSet(arch2);
Read(arch2,etiquetas);
CloseFile(arch2);

AssignFile(arch2,leeruta+'\tempo\concen.tmp');

Concentrado.visible:=True;
Concentrado.Clear;


Concentrado.Lines.Add(ajuste(etiquetas.orden,20)+char(9)+ajuste(etiquetas.c1,20)+Char(9)+ajuste(etiquetas.c2,20)+char(9)+ajuste(etiquetas.c3,20)+char(9)
+ajuste(etiquetas.c4,20)+char(9)+ajuste(etiquetas.c5,20)+char(9)+ajuste(etiquetas.c6,20)+char(9)+ajuste(etiquetas.c7,20)+char(9)+ajuste(etiquetas.c8,20));
AssignFile(arch,leeruta+'\tempo\final.tmp');
Reset(arch);

total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;


while not eof(arch)do
begin
Read(arch,dato);
Concentrado.Lines.Add(ajuste(dato.orden,20)+visiblenum(dato.c1,etiquetas.c1)+visiblenum(dato.c2,etiquetas.c2)+visiblenum(dato.c3,etiquetas.c3)+
visiblenum(dato.c4,etiquetas.c4)+visiblenum(dato.c5,etiquetas.c5)+visiblenum(dato.c6,etiquetas.c6)+visiblenum(dato.c7,etiquetas.c7)+visiblenum(dato.c8,etiquetas.c8));
total1:=total1+dato.c1;
total2:=total2+dato.c2;
total3:=total3+dato.c3;
total4:=total4+dato.c4;
total5:=total5+dato.c5;
total6:=total6+dato.c6;
total7:=total7+dato.c7;
total8:=total8+dato.c8;

end;


Concentrado.Lines.Add(ajuste('____________________',20)+char(9)+ajuste('____________________',20)+Char(9)+ajuste('____________________',20)+char(9)+ajuste('____________________',20)+char(9)
+ajuste('____________________',20)+char(9)+ajuste('____________________',20)+char(9)+ajuste('_____________________',20)+char(9)+ajuste('_____________________',20)+char(9)+ajuste('_____________________',20));

Concentrado.Lines.Add(ajuste('TOTALES',20)+visiblenum(total1,etiquetas.c1)+visiblenum(total2,etiquetas.c2)+visiblenum(total3,etiquetas.c3)+
visiblenum(total4,etiquetas.c4)+visiblenum(total5,etiquetas.c5)+visiblenum(total6,etiquetas.c6)+visiblenum(total7,etiquetas.c7)+visiblenum(total8,etiquetas.c8));

closeFile(arch);}

end;


procedure TFormaBarras.BotonImprimeClick(Sender: TObject);
begin
{ShowMessage(IntToStr(ultimapagina));}
{****pone los parametros dehojas****}

if ImpresoraLista then
begin
Impresora.MinPage:=1;
Impresora.MaxPage:=ultimapagina;
Impresora.FromPage:=1;
Impresora.ToPage:=ultimapagina;
{****termina parametros de hojas***}

if Impresora.Execute then
begin
Printer.Canvas.Font.Size:=FormaBarras.TamanoFuente.Value;

if Impresora.PrintRange=prAllPages then
begin
Impresora.MinPage:=1;
Impresora.MaxPage:=ultimapagina;
Impresora.FromPage:=1;
Impresora.ToPage:=ultimapagina;
end;
if (BotonGrafica.Tag=1)or(BotonGrafica.Tag=0)or(BotonGrafica.Tag=5) then
begin
pag:=pag-1;
{dibujagraficas(BotonGrafica.Tag,'i');
dibujagraficas(BotonGrafica.Tag,'p');}
imprimegrafica;
pag:=pag+1;
end
else
begin
saldoscero;
imprime(Impresora.FromPage,Impresora.ToPage);
end;

end;

end
else
MuestraMensaje('La Impresora No Se Encuentra Lista...');
end;

procedure TFormaBarras.BotonExportaClick(Sender: TObject);
var
arch2:TextFile;
fuente,destino:PChar;
nombre,nombre2:String[125];
f:longbool;
begin

if Guardar.Execute then
begin
generaexel;
if FileExists(PChar(Guardar.FileName)) then
DeleteFile(PChar(Guardar.FileName));
CopyFile(PChar(leeruta+'\tempo\exel.tmp'),PChar(Guardar.FileName),F);
end;


end;

procedure TFormaBarras.BotonSiguienteClick(Sender: TObject);
begin
if BotonSonido.Tag=1 then sonido(100);
case BotonGrafica.Tag of
0:dibujagraficas(BotonGrafica.Tag,'p');
1: dibujagraficas(BotonGrafica.Tag,'p');
3:pagina2(pag);
5:dibujagraficas(BotonGrafica.Tag,'p');
else
pagina(pag);
end;

pag:=pag+1;

end;

procedure TFormaBarras.FormCreate(Sender: TObject);
begin
FormatosPais;
pag:=0;
reduce:=10;
ancho:=0;
anchobarra:=0;
numerodelineas:=50;
//Tamanofuente.Value:=10;
end;

procedure TFormaBarras.BotonAnteriorClick(Sender: TObject);
begin
if BotonSonido.Tag=1 then sonido(100);
pag:=pag-1;

if pag<0 then
begin
pag:=0;
saldoscero;
end;

if (botonGrafica.Tag=1)or (botonGrafica.Tag=0)or(botonGrafica.Tag=5) then
dibujagraficas(BotonGrafica.Tag,'p')
else
begin
if (botonGrafica.Tag=2)and (BotonReporte.Tag=2) then
pagina2(pag)
else
begin
if botonGrafica.Tag=3 then
pagina2(pag)
else
pagina(pag);
end;

end;

end;

procedure TFormaBarras.BotonColorClick(Sender: TObject);
begin
if Concentrado.Color=clBlack then
begin
Concentrado.Color:=clWhite;
Concentrado.Font.Color:=clBlack;
end
else
begin
Concentrado.Color:=clBlack;
Concentrado.Font.Color:=clWhite;
end;
pagina(pag);
end;

procedure TFormaBarras.FormActivate(Sender: TObject);
begin
Refresh;
if Panel2.Tag=0 then
begin
pag:=0;
total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;
if (botonGrafica.Tag=1)or (botonGrafica.Tag=0) then
begin
dibujagraficas(BotonGrafica.Tag,'p');
{****************}
{BotonGrafica.Enabled:=True;
BotonPie.Enabled:=True;
BotonAmbos.Enabled:=True;
BotonCon.Enabled:=False;
BotonExporta.Enabled:=False;
BotonColor.Enabled:=False;}
{***************}

end
else
begin
{****************}
{Botongrafica.Enabled:=False;
BotonPie.Enabled:=False;
BotonAmbos.Enabled:=False;
BotonCon.Enabled:=True;
BotonExporta.Enabled:=True;
BotonColor.Enabled:=True;}
{***************}

if botonGrafica.Tag=3 then
pagina2(pag)
else
pagina(pag);
end;
pag:=pag+1;

end;
Panel2.tag:=1;

end;

procedure TFormaBarras.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
Panel2.tag:=0;
ModuloGrafica.Visible:=False;
Timer1.Enabled:=False;

//**borra todos los archivos temporales

DeleteFile(leeruta+'\tempo\anchos.tmp');
DeleteFile(leeruta+'\tempo\comentar.tmp');
DeleteFile(leeruta+'\tempo\etique.tmp');
DeleteFile(leeruta+'\tempo\exel.tmp');
DeleteFile(leeruta+'\tempo\final.tmp');
DeleteFile(leeruta+'\tempo\format.tmp');
DeleteFile(leeruta+'\tempo\orden.tmp');

end;


procedure TFormaBarras.BotonSonidoClick(Sender: TObject);
begin
if BotonSonido.Tag=1 then
BotonSonido.Tag:=0
else
BotonSonido.Tag:=1;
end;

procedure TFormaBarras.BotonLineasClick(Sender: TObject);
begin
if BotonGrafica.Tag=2 then
begin
pag:=0;
saldoscero;
end;

Concentrado.Visible:=False;
ModuloGrafica.Visible:=True;

BotonGrafica.Tag:=5;
dibujagraficas(BotonGrafica.Tag,'p');
end;

procedure TFormaBarras.ModuloGraficaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button= mbRight then
begin
if ModuloGrafica.View3D then
ModuloGrafica.View3D:=False
else
ModuloGrafica.View3D:=True;
end;

end;

procedure TFormaBarras.BotonAutomaticoClick(Sender: TObject);
begin
if Timer1.Enabled=False then
Timer1.Enabled:=True
else
Timer1.Enabled:=False;

end;

procedure TFormaBarras.Timer1Timer(Sender: TObject);
begin
if BotonSonido.Tag=1 then sonido(100);
case BotonGrafica.Tag of
0:dibujagraficas(BotonGrafica.Tag,'p');
1: dibujagraficas(BotonGrafica.Tag,'p');
{2:if (Botoncon.Tag=2) then pagina2(pag);}
3:pagina2(pag);
5:dibujagraficas(BotonGrafica.Tag,'p');
else
pagina(pag);
end;
pag:=pag+1;
end;

procedure TFormaBarras.BotonGraficaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonGrafica.Left,FormaBarras.Top+BotonGrafica.Top+BotonGrafica.Height,59);
end;

procedure TFormaBarras.BotonPieMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonPie.Left,FormaBarras.Top+BotonPie.Top+BotonPie.Height,60);
end;

procedure TFormaBarras.BotonLineasMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonLineas.Left,FormaBarras.Top+BotonLineas.Top+BotonLineas.Height,61);
end;

procedure TFormaBarras.BotonReporteMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonReporte.Left,FormaBarras.Top+BotonReporte.Top+BotonReporte.Height,62);
end;

procedure TFormaBarras.BotonExportaMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonExporta.Left,FormaBarras.Top+BotonExporta.Top+BotonExporta.Height,63);
end;

procedure TFormaBarras.BotonAnteriorMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonAnterior.Left,FormaBarras.Top+BotonAnterior.Top+BotonAnterior.Height,64);
end;

procedure TFormaBarras.BotonSiguienteMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonSiguiente.Left,FormaBarras.Top+BotonSiguiente.Top+BotonSiguiente.Height,65);
end;

procedure TFormaBarras.BotonColorMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonColor.Left,FormaBarras.Top+BotonColor.Top+BotonColor.Height,66);
end;

procedure TFormaBarras.BotonSonidoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonSonido.Left,FormaBarras.Top+BotonSonido.Top+BotonSonido.Height,67);
end;

procedure TFormaBarras.BotonAutomaticoMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonAutomatico.Left,FormaBarras.Top+BotonAutomatico.Top+BotonAutomatico.Height,68);
end;

procedure TFormaBarras.BotonImprimeMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaBarras.Left+BotonImprime.Left,FormaBarras.Top+BotonImprime.Top+BotonImprime.Height,69);
end;

procedure TFormaBarras.Salir1Click(Sender: TObject);
begin
close;
end;

procedure TFormaBarras.BotonGraficaClick(Sender: TObject);
type
datos=record
c:String[10];
o1:Real;
o2:Real;
o3:Real;
end;
var
max,peso:Real;
dato,dato2:datos;
arch:file of datos;
arch2:TextFile;
cambio,pos:integer;
begin
Concentrado.Visible:=False;
ModuloGrafica.Visible:=True;
if BotonGrafica.Tag=2 then
begin
pag:=0;
saldoscero;
end;
total1:=0;total2:=0;total3:=0;total4:=0;total5:=0;total6:=0;total7:=0;total8:=0;
BotonGrafica.Tag:=1;
dibujagraficas(BotonGrafica.Tag,'p');
end;

procedure TFormaBarras.TamanoFuenteChange(Sender: TObject);
begin
if Tamanofuente.Text='' then
TamanoFuente.Value:=1;
Concentrado.Font.Size:=Tamanofuente.Value;
pagina(pag);
end;

procedure TFormaBarras.TipodeLetra1Click(Sender: TObject);
begin
if Fuentes.Execute then
begin

 Concentrado.Font.Name:=Fuentes.Font.Name;
 Concentrado.Font.Size:=Fuentes.Font.Size;
 FormaBarras.Canvas.Font.Name:=FormaBarras.Concentrado.Font.Name;
 FormaBarras.Canvas.Font.Size:=Fuentes.Font.Size;
 pagina(pag);
end;

end;

procedure TFormaBarras.TerceraColumna1Click(Sender: TObject);
begin
if TerceraColumna1.Checked=False then
TerceraColumna1.Checked:=True
else
TerceraColumna1.Checked:=False;
end;

procedure TFormaBarras.Primeracolumna1Click(Sender: TObject);
begin
if PrimeraColumna1.Checked=False then
PrimeraColumna1.Checked:=True
else
PrimeraColumna1.Checked:=False;

end;

procedure TFormaBarras.SegundaColumna1Click(Sender: TObject);
begin
if SegundaColumna1.Checked=False then
SegundaColumna1.Checked:=True
else
SegundaColumna1.Checked:=False;

end;

end.
