Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   Reporte subtotalizado con datos SQLFirebird no funciona (https://www.clubdelphi.com/foros/showthread.php?t=96848)

delphi50jmb 22-09-2024 05:03:06

Reporte subtotalizado con datos SQLFirebird no funciona
 
Hola Estimados.
Esta pregunta la hice hace un a±o atras y no logre resolver el problema. Por eso vuelvo a platear la inquietud.

Estoy migrando mis aplicaciones desde Paradox a SQL. Tengo un reporte muy sencillo, con cuatro bandas de detalle. Una banda para los titulos, una banda para agrupar por una expresion, una banda para el detalle de productos, y una banda para los totales. Este reporte muestra los detalles de venta de un cliente, y subTotaliza por mes.

Este reporte funciona perfecto con delphi y paradox. Pero ahora al trabajar con SQL-Firebird, al poner un valor en la "propiedad Expresion" (Expresion = Mes) de la segunda banda (Banda tipo: TQRGroup), me aparece un mensaje que dice: "Operation not allowed on a unidirectional dataset". Si quito el valor en la propiedad "expresion", este funciona correctamente, pero obiamente no subtotaliza.

Con tablas paradox, el reporte funciona perfectamente. Pero la realizar el mismo con SQL-Firebird no funciona.

El archivo que estoy tratando de imprimir esta ordenado por el campo: Mes.

Esta es la consulta SQL. Funciona perfectamente. Lo que no funciona es el reporte subTotalizado.

Código SQL [-]
 SQL_String.Close;

   SQL_Text := 'SELECT DetFact.TipoDoc, DetFact.Rut, DetFact.CodAux, DetFact.Numero, ' +
                     'DetFact.FechaEmi, DetFact.Mes, DetFact.Codigo, DetFact.Descrip, DetFact.Cantidad, ' +
                     'DetFact.TotalLinDe, DetFact.Vendedor, Vendedores.Nombre ' +
                     'FROM DetFact '                                 +
                     'LEFT JOIN Vendedores '                            +
                     'ON Vendedores.Codigo=DetFact.Vendedor ' +
                                       'WHERE DetFact.FechaEmi>=' + QuotedStr( sFechaSel ) +  ' ' +
                     'ORDER BY Mes ASC ' + ';';

   SQL_String.CommandText := SQL_Text;
   SQL_String.Open;

Estoy usando componentes DbExpres.

Alguna idea de que pasa? , y como solucionar esto?

Gracias de antemano.

Saludos.
Jose Miguel B.

delphi50jmb 22-09-2024 05:36:06

Este es la estructura del reporte.

Código Delphi [-]
unit UQrDetDocVta;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Qrctrls, Db, QuickRpt, ExtCtrls;

type
  TFQrDetDocVta = class(TForm)
    QrDetDocVta: TQuickRep;
    QRBand2: TQRBand;
    QrBandDet: TQRBand;
    QRlNombEmpresa: TQRLabel;
    QRTitulo: TQRLabel;
    QRShape2: TQRShape;
    QRShape1: TQRShape;
    QrTipDoc: TQRLabel;
    QRPagina: TQRLabel;
    QRFecha: TQRLabel;
    QRBand1: TQRBand;
    QRShape3: TQRShape;
    QRHora: TQRLabel;
    QRSysHora: TQRSysData;
    QRLabel4: TQRLabel;
    QRMaxMinimo: TQRLabel;
    QrTotDoc: TQRLabel;
    QrNombre: TQRLabel;
    QRSysData1: TQRSysData;
    QRSysData2: TQRSysData;
    QrLabel1: TQRLabel;
    QrFecDoc: TQRLabel;
    QRLabel3: TQRLabel;
    QRGDetMes: TQRGroup;
    QRSubTotalMes: TQRBand;
    QrProveed: TQRLabel;
    qrNeto: TQRLabel;
    QRShape6: TQRShape;
    QRLabel2: TQRLabel;
    QrNumDoc: TQRLabel;
    QRLabel8: TQRLabel;
    QrCantDoc: TQRLabel;
    QrSubTitulo: TQRLabel;
    QrCodigo: TQRLabel;
    QRLabel7: TQRLabel;
    QRLabel5: TQRLabel;
    QrCostoDoc: TQRLabel;
    QRLabel9: TQRLabel;
    QrIva: TQRLabel;
    QrLabel20: TQRLabel;
    QrTotal: TQRLabel;
    QRLabel13: TQRLabel;
    procedure QrDetDocVtaBeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure QrBandDetBeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QrDetDocVtaStartPage(Sender: TCustomQuickRep);
    procedure FormActivate(Sender: TObject);

    procedure QRSubTotalMesBeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);

  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  FQrDetDocVta: TFQrDetDocVta;
  nPagina : Integer;
  iTTotal   : Extended;

implementation
uses UVarGlobales, ULibrerias, UDt1;

{$R *.DFM}



procedure TFQrDetDocVta.FormActivate(Sender: TObject);
begin
   nPagina :=0;
end;


procedure TFQrDetDocVta.QrDetDocVtaStartPage(Sender: TCustomQuickRep);
begin
   nPagina := nPagina + 1;
end;


procedure TFQrDetDocVta.QrDetDocVtaBeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);

begin
   sMenuOpc := 'Informe Detallado de Ventas';

   QRlNombEmpresa.Caption := sEmpresa;
   QrTitulo.Caption := sMenuOpc;
   QrSubTitulo.Caption := '(' + 'Desde: ' + sParam1 + ' Hasta: ' + sParam2 + ')';

   QrDetDocVta.DataSet := SQL_String;
   QRSysHora.Data      := qrsTime;
end;


procedure TFQrDetDocVta.QrBandDetBeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
   QrFecDoc.Caption   := SQL_String.FieldByName( 'FechaEmi'  ).AsString;
   QrTipDoc.Caption   := SQL_String.FieldByName( 'TipoDoc'  ).AsString;
   QrNumDoc.Caption   := SQL_String.FieldByName( 'Numero'  ).AsString;
   QrCodigo.Caption   := SQL_String.FieldByName( 'Codigo'  ).AsString;
   QrNombre.Caption   := SQL_String.FieldByName( 'Descrip'  ).AsString;
   QrCantDoc.Caption  := SQL_String.FieldByName( 'Cantidad' ).AsString;

   QrTotDoc.Caption   := Picture(SQL_String.FieldByName( 'TotalLinDe' ).AsString);

   itTotal := itTotal + StrToFloat(SQL_String.FieldByName( 'TotalLinDe' ).AsString);
end;



procedure TFQrDetDocVta.QRSubTotalMesBeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);          <------- Cuando entra aqui para subtotalizar por mes, se cae, y presenta el mensaje: "Operation not allowed on a unidirectional dataset".
begin
   QrTotal.Caption := FloatToStr(itTotal);
   itTotal := 0;
end;
end.

Gracias de antemano.
Saludos.
Jose Miguel B.

Casimiro Notevi 22-09-2024 10:48:10


delphi50jmb 22-09-2024 19:53:00

Hola Casimiro.
Agradesco tu respuesta. Pero estoy usando Componentes DbExpres, y el DataSet no tiene esa propiedad que me indicas.

Saludos.
Jose Miguel.

Casimiro Notevi 23-09-2024 10:32:44

¿Y cuál estás usando exactamente?

chenech 23-09-2024 12:07:07

DBExpress no tiene esa propiedad, por eso te da el error, yo lo solucioné pasando el SQL resultante del DBExpress a un TClientDataSet y este es el que enlazo con el reporte.
Un saludo.

Casimiro Notevi 23-09-2024 13:11:35

Es algo extraño, yo uso esos componentes (DbExpres) para informes con report manager y no tengo ese problema.
Es que además no tiene lógica, un informe no tiene que ir "hacia atrás y hacia adelante" en ningún momento.

chenech 23-09-2024 13:13:56

A mi me pasa solo con QuickReport, con Fastreport y otros no.

delphi50jmb 23-09-2024 21:48:35

Hola Chenech.

Como pasas el SQL resultante del DBExpress a un TClientDataSet?.. me podrias indicar?..

Yo estoy usando este formato en mi programa.

Código Delphi [-]
DataSource  --> ClienDataSet --> DataSetProvider --> SqlDataSet --> SqlConnecction

El DataSource en su propiedad: Dataset, apunta a: ClientDataSet.
El ClientDataSet en su propiedad: ProviderName, apunta a: DataSetProvider.
El DataSetProvider, en su propiedad: DataSet, apunta a: SQLDataSet.
El SQLDataSet, en su propiedad: SQLConnection, apunta a: SQLConnection.

SQL_String, es una variable global de tipo TSQLDataSet, que se inicializa de la siguiente manera:

Código Delphi [-]
   SQL_String := TSQLDataSet.Create(nil);
   SQL_String.SQLConnection := SQLConnection;

La consulta la hago de la siguiente forma:

Código Delphi [-]
procedure TFPreparaFile.TrasDetalleVentas;
begin
   sPar1Aux := Stuff(sFechaIni, SeparadorFecha, '.', 'A');

   Dt1.SQLDataSet.Close;

   SQL_Text := 'SELECT DetFact.Mes, DetFact.TipoDoc, DetFact.Rut, DetFact.CodAux, DetFact.Numero, ' +
                     'DetFact.FechaEmi, DetFact.Codigo, DetFact.Descrip, DetFact.Cantidad, ' +
                     'DetFact.TotalLinDe, DetFact.Vendedor, Vendedores.Nombre ' +
               'FROM DetFact '                                 +
               'LEFT JOIN Vendedores '                            +
               'ON Vendedores.Codigo=DetFact.Vendedor ' +
               'WHERE DetFact.FechaEmi>=' + QuotedStr( sPar1Aux ) + ' ' +
               'ORDER BY Mes ASC ' + ';';

   SQL_String := Dt1.SQLDataSet;
   SQL_String.Close;

   SQL_String.CommandText := SQL_Text;

   SQL_String.Open;
end;

y, luego el reporte. Que tiene un titulo, y solo 3 bandas para el detalle.

Esta es la estructura basica de mi reporte:

Código Delphi [-]
---------------------------------------------------------------------------------------
Fecha  TipoDoc Numero Codigo    Nombre                   Cantidad   Costo   Total
---------------------------------------------------------------------------------------
================================================
QRGDetMes - TQRGroup
Expression: Mes
FooterBand: QrSubTotalMes
LinkBand: QrBandDet
---------------------------------------------------------------------------------

=================================================================================
QrBandDet - TQrBand 
BandType: rbDetail
--------------------------------------------------------------------------------

================================================================================
QrSubTotalMes - TQrBand
BandType: rbGroupFooter
--------------------------------------------------------------------------------

Funciona bien hasta que tiene que hacer el corte para subtotalizar por mes, y se cae, con el mensaje: "Operation not allowed on a unidirectional dataset".

Código Delphi [-]
procedure TFQrDetDocVta.QRSubTotalMesBeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);          <------- Cuando entra aqui para subtotalizar por mes, se cae, y presenta el mensaje: "Operation not allowed on a unidirectional dataset".
begin
   QrTotal.Caption := FloatToStr(itTotal);
   itTotal := 0;
end;

El Reporte lo simplifique para que se entienda mejor.

Agradeceria si me pudieran ayudar.

Gracias.

Saludos.
Jose Miguel B.

chenech 23-09-2024 22:04:09

Por la estructura que estas usando ya tienes enlazado el ClientDataSet al resultado del SQL_String.
Pon el ClientDataSet.Active = false antes de la llamada al SQL y ClientDataSet.Active = true después del open del SQL.
Ya tendrías los datos en el ClientDataSet que es el que tendrías que asociar a los campos del QuickReport.

Si quieres simplificar mucho, usa FastReport u otro ya que QuickReport no tiene soporte ni saldrán nuevas versiones y por otro lado usa FireDac que creo será mas el futuro de Embarcadero que DBExpress.

delphi50jmb 24-09-2024 05:32:34

Hola Chenech.
Al cambiar el ClientDataSet.Active = true, me da el error: "Missing query, table or procedure name".

Creo que debe ser por la forma de enlazar los componentes. En Mi ClientDataSet, no tengo ninguna tabla ni parametros identificados. Solo conecto los componentes y cambio la siguientes propiedades:

El DataSource en su propiedad: Dataset, apunta a: ClientDataSet.
El ClientDataSet en su propiedad: ProviderName, apunta a: DataSetProvider.
El DataSetProvider, en su propiedad: DataSet, apunta a: SQLDataSet.
El SQLDataSet, en su propiedad: SQLConnection, apunta a: SQLConnection.

El resto tal como mencione mas arriba.

Alguna otra idea?

Saludos.
Jose Miguel B.

chenech 24-09-2024 11:05:41

Yo tengo el SQLConnection mas un SQLDataSet, este a un Provider, luego un ClientDataSet al mismo Provider, y un DataSource al ClientDataSet.
Creo que es tal como lo defines que lo tienes tu, igual.
En esta página tienes algo de eso:
https://docwiki.embarcadero.com/RADS...me_Application

delphi50jmb 25-09-2024 02:27:25

Mmm.. Entiendo.
Pero veo que el problema no esta en las conecciones de los datos. Sino que, existe al parecer, algun problema con el QuicReport..

Bueno. Seguire luchando para ver que consigo.

Gracias por todo.

Saludos.
Jose Miguel B.

chenech 26-09-2024 21:59:32

Encontré este código que crea el clientdataset y lo enlaza con el query a través de un provider, luego enlazar a quickreport el clientdataset.
Prueba a ver si te sirve:
Código:

Var
  DtStPrvdr : TDataSetProvider;
  ClntDtSt : TClientDataSet;
Begin
  Try
    DtStPrvdr := TDataSetProvider.Create;
    DtStPrvdr.DataSet := SqlQuery1;
    ClntDtSt := TClientDataSet.Create;
    ClntDtSt.SetProvider(DtStPrvdr);
    // Ligue aqui o seu relatório ao ClntDtSt, ao ínves de ligar a SqlQuery1;
    // ExibirRelatorio; //
  Finally
    FreeAndNil(DtStPrvdr);
    FreeAndNil(ClntDtst);
  End;
End;


delphi50jmb 27-09-2024 01:55:00

Hola Chenech.

No habia visto tu respuesta, pero te comento que logre enlazar el "SQLDataset" con el "ClientDataset", y este ultimo al QReport.
Ahora el reporte funciona, y hace el corte por mes. Pero el problema que se esta dando es que solo presenta un solo registro, y lo replica en todo el informe. No presenta los demas productos corespondientes (Pero si avanza en la base de datos, porque si reconoce el cambio de mes, y produce el corte).

Tienes alguna idea de lo que esta pasando.


De todas maneras revisare tu codigo, y te comentare como me va.

Gracias por tu ayuda.
Saludos.
Jose Miguel B.


La franja horaria es GMT +2. Ahora son las 23:27:02.

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