Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-03-2004
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 31
Lepe Va por buen camino
Bueno, aqui va una de código, ahh, si quereis optimizar el código... será bienvenido

Uso una funcion rarita... codigoutil.ifthen es la equivalente que tiene Delphi en la unidad Math, strutils, y en otra unidad más que no recuerdo, yo las he metido en un .pas llamado CodigoUtil .... muy original .... ya

Las Lineas que empiezan con FrmDebug.anade ... son llamadas a una ventana auxiliar para ver por donde iba el programa y como furulaba. (pueden obviarse esas lineas.

Código:
procedure AjustaDisplayWidth(D:TDataSet;const MaxAncho:Integer = 150);
var i, nIdx:Integer;
begin
if D.Active then
begin
  try
  D.DisableControls;
  D.First;
  nIdx:=0;
  while not D.Eof do
  begin
     for i:=0 to pred(D.FieldCount) do
     begin
          // en la 1ª vuelta reseteo el displayWidth existente
          if (nIdx = 0) then
            D.Fields[i].DisplayWidth  := 1;
          D.Fields[i].DisplayWidth  :=EnsureRange(
                                                  Max(  D.Fields[i].DisplayWidth,
                                                        Length(D.Fields[i].AsString)+
 codigoutil.IfThen(D.Fields[i].DataType = ftFloat, 3) 
// añadimos espacios para ,00
                                                      ),
                                                  0,MaxAncho);
     end;
     D.Next;
     Inc(nIdx);
  end;
  finally
    D.EnableControls;
  end;
end; // D.active
end;
Formatear los números para que salgan en los listados con 2 decimales y puntos de millar:
Código:
procedure FormatFloatFields(Rpt:TcustomQuickrep);
var j :Integer;
    Band : TQRcustomBand;
begin
  Band := Rpt.Bands.DetailBand;

  for j:=0 to Band.ControlCount -1 do
  if Band.Controls[j] is TQRExpr  then
  with TQRExpr(Band.Controls[j]) do
  begin
    if (Pos('percentiva',Expression) = 0)) then
      Mask := '#,##0.00'; // curosamente si es un texto lo que hay no le
                                 // afecta, solo he probado con campos de
                                //  Float, Texto, Boolean y enteros. con los demás no 
                               //  sé que hará exactamente.
  end;
end;
Añadir un SummaryBand en tiempo de ejecución (despues de la linea del QrcreateList) Esta funcion es un coñazo.... no está muy bien hecha . Además he encontrado algunos bugs menores que no sé como solucionarlos.

Código:
procedure AnadirSummaryBand(Rpt:TcustomQuickrep;const Data : TDataSet;const Campos:TStringList);

const SEP = 20;

var i :Integer;
    MaxLeft : Integer;
    CampoActual: TField;
    TotalLabel : TQRLabel;
    Total     : TQRExpr;
    Unidades: TQRUnit;
begin
// 9-03-2004  añadir totales al informe
  with Rpt do
  begin
    Unidades:= units;
    Units := Pixels;
    if not Bands.HasSummary then
    begin
       Bands.HasSummary:= True;
       with Bands.SummaryBand do
       begin
         Height:= 50;
         Frame.DrawTop:= True;
         Frame.DrawBottom:= True;

// El texto puede salirse a la dcha de la linea right
//         Frame.DrawLeft:= True;
//         Frame.DrawRight:= True;
      end;
    end;
    MaxLeft:=0;
    for i:=0 to pred(Campos.Count) do
    begin
      CampoActual := Data.FindField(Campos[i]);
      if CampoActual  <> nil then
      if CampoActual.DataType = ftfloat then
      begin
        if CampoActual.FieldName= 'percentiva' then
          Continue;

        TotalLabel := TQRLabel(Rpt.Bands.SummaryBand.AddPrintable(TQRLabel));
        TotalLabel.Top:= 10;
        TotalLabel.AutoSize:= True;
        TotalLabel.Caption:= LeftStr(CampoActual.DisplayLabel,10)+':';
      // Base Imponible se solapa con el siguiente campo que haya
        totallabel.Frame.DrawBottom:= True;
//        frmDebug.Anade(['left antes', 'maxleft '],[TotalLabel.Left, MaxLeft] );
        TotalLabel.Left:= MaxLeft; 

        total := TQRExpr(Bands.SummaryBand.AddPrintable(TQRExpr));
        total.Top:= 30;
        Total.AutoSize:= True;
        total.Expression:= 'SUM('+ CampoActual.FieldName+')';
        Total.Left:= TotalLabel.Left;
        Total.Mask:= '#,##0.00';
        MaxLeft := Max(Total.Width, TotalLabel.Width)+ MaxLeft+SEP;

//        frmDebug.Anade('pagina' + FloatToStr(Rpt.Page.Width)+' maxleft '+IntToStr(MaxLeft));

        if (Rpt.Page.Orientation = poportrait) and (MaxLeft >Rpt.Page.Width) then
          Rpt.Page.Orientation:= poLandscape;
      end;
    end;
  end;
// fin 9-03-2004  añadir totales al informe

  Rpt.Units:= Unidades;
end;
Cambiar el número de pagina poniendolo en español, despues de la linea del qrcreatelist
Código:
    with TQRExpr(V.pQuickreport.Bands.PageFooterBand.Controls[0]) do
      expression := QuotedStr('Página ') +'+ PAGENUMBER';
// PAGENUMBER es una variable que entiende QUICKREPORTS
La forma correcta de llamarlo sería asÍ:
Código:
V:=  TPrevi.Create(FrmMdi );
  FreeAndNil(V.pquickreport);
  qrextra.QRCreateList(tcustomquickrep(V.pQuickreport),v, DTM.qryAlb,
                        TituloListado ,ListaCampos);

  AjustaDisplayWidth(dtm.qryalb);
  AnadirSummaryBand(V.pQickReport,dtm.qryAlb,ListaCampos);
  FormatFloatFields(V.pQuickReport);


    with TQRExpr(V.pQuickreport.Bands.PageFooterBand.Controls[0]) do
      expression := QuotedStr('Página ') +'+ PAGENUMBER';
// PAGENUMBER es una variable que entiende QUICKREPORTS
  V.pQuickreport.units:= MM;
  V.pQuickreport.OnPreview:= ListadoOnPreview;
Los Uses que os puede pedir son estos:
Código:
uses  nkstrs,Forms,strutils, Windows,Graphics,Registry,dbtables, Classes,
      types, sysutils,DB, dbgrids, math ,Variants,
      QuickRpt,QRCTRLS, qrprntr, Controls,qrexpr,printers // anadirSummaryband
Espero no olvidarme de nada... Aunque no lo juro, ha sido copy y paste.

Cadetill: ojo al TPrevi.Create

Buen Provecho.
Responder Con Cita
  #2  
Antiguo 24-03-2004
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 31
Lepe Va por buen camino
Cita:
Empezado por cadetill
Siguiendo con el tema del QRCreateList, en la página de QuSoft hay una demo. Os dejo la URL
Bonito ejemplo

PD: Hace un par de semanas me habría venido de perlas ese enlace
Responder Con Cita
  #3  
Antiguo 29-09-2004
Avatar de yusnerqui
yusnerqui yusnerqui is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuba
Posts: 679
Poder: 23
yusnerqui Va por buen camino
Para Lepe

Desido reabrir este magnífico hilo ya que me ha serbido de mucho en mi actual aplicación.

Pero me quedé trabado despues de bajar de la página de el amigo Cadetill ese maravilloso componente del que tanto se ha hablado en el club e intentar visualizar mi reporte (creado con QRCreatelist) no me lo visualiza correctamente.

Mi pregunta es:

Que debo implementar el el procedimiento ListadoOnPreview

Cita:
Empezado por Lepe
Código Delphi [-]
  V.pQuickreport.OnPreview:= ListadoOnPreview;
De antemanos mil gracias

Un saludo a todos
__________________
Lo importante no es llegar primero, sino saber llegar.

Para que puedas llegar mejor lee la Guia de Estilo

Responder Con Cita
  #4  
Antiguo 30-09-2004
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 31
Lepe Va por buen camino
Todo un honor que se reabra un hilo en el que he participado.

como todo... hay varias formas de hacerlo, en su momento, y con prisas yo opté por hacerla de esta forma.

Código Delphi [-]
var :Tprevi;
implementation 
procedure botonClick(...)
begin
try
// introduzco en ListaCAmpos(stringlist) los campos que quiero que se vean de la tabla, despues

    v:=  TPrevi.Create(FrmMdi);
    FreeAndNil(v.pquickreport); 
    qrextra.QRCreateList(tcustomquickrep(v.pQuickreport) ,v , DTM.qryClientes,
                          'Clientes' ,ListaCampos);

    with TQRExpr(v.pQuickreport.Bands.PageFooterBand.Controls[0]) do
      expression := QuotedStr('Pág. ') +'+ PAGENUMBER   ';
// PAGENUMBER es una variable que entiende QUICKREPORTS


  v.pQuickreport.OnPreview:= ListadoOnPreview;
  v.pQuickreport.PreviewModal;//eless  ;

finally
  ListaCampos.Free;
end;


procedure tfrmclientes.ListadoOnPreview(Sender:TObject);
begin
  // en el evento Onpreview del TQuickRep
  // creado el previ al dar al boton imprimir
  with v do
  begin
    Caption := Caption + ' - Clientes';
//    pQuickReport := TQuickRep(Previ.pQuickreport);
    Preview.QRPrinter := TQRPrinter(Sender);
    pQuickreport.ReportTitle:= ' Clientes';
    pQuickreport.Font.Name:= 'Courier New';
    Show; // no uso preview, para que pueda continuar haciendo otras cosas
  end;
end;
Responder Con Cita
  #5  
Antiguo 30-09-2004
Avatar de yusnerqui
yusnerqui yusnerqui is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuba
Posts: 679
Poder: 23
yusnerqui Va por buen camino
Mucha gracias

Muchas gracias Lepe, poco después de postear encontré la solución. A propósito a continuación vioy a mostrar lo que hago para configurar la página del reporte en tiempo de ejecución, me funciona bien en Windows 98 no lo he probado en otros sistemas operativos
Código Delphi [-]
  procedure TReport.Vistaprevia;
var
  Title:string;
  I : Integer;
begin
  Previ := TPrevi.Create(Self);
 //Creo el pQuickreport y cambio sus propiedades a gusto del usuario!!
  Previ.pQuickreport := TQuickRep.Create(Previ); 
  with Previ.pQuickreport do
  begin
    Page.Units :=  MM;
    Page.PaperSize := Custom;
    Page.Width  := 420.0;//Puede ser un valor definido por el usuario
    Page.Length := 270.0;//   "                                    "
  end;

  
  Title:=Edit1.Text;

 try
   if Campos1.items.Count >0 then
   begin
     QRCreatelist(TCustomQuickRep(Previ.pQuickreport),Previ,RTabla,Title,Campos1.Items);
    try
      with Previ.pQuickreport do
      begin
       with Bands.ColumnHeaderBand  do
       begin
         Font.Size := 12;
         Font.Style:= [fsBold];
         Frame.DrawBottom := True;
         for i := 0 to ControlCount -1 do
           if Controls[i] is TQRLabel then
             TQRLabel(Controls[i]).Frame.DrawBottom := False;
       end;
       with Bands.DetailBand do
       begin
         Font.Size := 12;
         //aquí capturo los campos boolean para redireccionar su evento 
         //onPrint y no me imprima True y False sino los caracteres que yo 
        //espesifique
         for i := 0 to ControlCount -1 do
           if Controls[i] is TQRExpr then
           begin
             Title := TQRExpr(Controls[i]).Expression;
             Title := Copy(Title,2,Length(Title)-2);
             if ord(RTabla.FieldByName(Title).DataType) = 5 then
             begin
               TQRExpr(Controls[i]).Alignment := taCenter;
               TQRExpr(Controls[i]).OnPrint:= MyOnPrint;
             end;
           end;
       end;
         Previ.pQuickreport.OnPreview:= MyPreview;
         Previ.pQuickreport.Preview;
      end;
    finally
      //
    end;
  end;
 finally
 //
 end ;

Este código está en fase de depuración, ahora la impementación de MyPreview

Código Delphi [-]
procedure TReport.MyPreview(Sender : TObject);
begin
  with Previ do
  begin
    Preview.QRPrinter := TQRPrinter(Sender);
    Show;
  end;
end;

Por último, no me preocupo por el ancho de las columnas pues lo primero que hago es mostrar los campos seleccionados en un DBgrid donde el usuario puede ajustar el ancho de cada campo a su antojo
y es todo, espero que a alguien le sirva si lo que quiere es configurar página, márgenes etc les ser virá esta idea.

Un saludo
__________________
Lo importante no es llegar primero, sino saber llegar.

Para que puedas llegar mejor lee la Guia de Estilo

Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 23:10:40.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi