-
Notifications
You must be signed in to change notification settings - Fork 651
Description
In my Report I have a DataBand with 3 Subreports (Month0, Month1 and Month2). I have a variable parIntMonthAdd and the DataSource SQL is
`SELECT C.FullTimeServiceEndDate, C.FullTimeServiceStartDate, C1.Firstname, C1.Name
FROM "FullTimeService" C INNER JOIN "User" C1 ON C.UserGuid = C1.UserGuid
WHERE C.FullTimeServiceStartDate <= CONVERT(datetime2, DATEADD(month,@parIntMonthAdd,CONVERT(DATE,GETDATE()))) AND
C.FullTimeServiceEndDate >= CONVERT(datetime2, DATEADD(month,@parIntMonthAdd,CONVERT(DATE,GETDATE())))`
In every subreport i have set the "BeforePrint"-Event (the aditional parameter parCurrentMonth is set when i need to print the actual month. otherwise i will start with the next month)
` // Allgemeine Hilfsmethode: setzt den Parameter im Subreport
private void SetSubreportMonthOffset(FastReport.Report subReport, int subOffset)
{
// Hauptreport-Parameter parCurrentMonth lesen (im Hauptreport vorhanden)
bool parPrintCurrentMonth = false;
if (this.Report != null && this.Report.Dictionary.Parameters != null)
{
foreach (FastReport.Data.Parameter p in this.Report.Dictionary.Parameters)
{
if (string.Equals(p.Name, "parPrintCurrentMonth", StringComparison.OrdinalIgnoreCase))
{
parPrintCurrentMonth = (p.Value is bool) ? (bool)p.Value : Convert.ToBoolean(p.Value);
break;
}
}
}
int baseShift = parPrintCurrentMonth ? 0 : 1;
int effectiveOffset = baseShift + subOffset;
// Subreport-Parameter parIntMonthAdd setzen (anlegen, falls nicht vorhanden)
FastReport.Data.Parameter found = null;
foreach (FastReport.Data.Parameter p in subReport.Dictionary.Parameters)
{
if (string.Equals(p.Name, "parIntMonthAdd", StringComparison.OrdinalIgnoreCase))
{
found = p;
break;
}
}
if (found == null)
{
var p = new FastReport.Data.Parameter();
p.Name = "parIntMonthAdd";
p.Value = effectiveOffset;
subReport.Dictionary.Parameters.Add(p);
}
else
{
found.Value = effectiveOffset;
}
}
// Für Subreport1 (aktueller Monat oder +1 wenn parCurrentMonth=false)
private void SubreportMonth0_BeforePrint(object sender, EventArgs e)
{
// Subreport-Objekt anpassen: z.B. Subreport1 ist der Name des Subreport-Steuerelements
var sub = Month0.Report;
if (sub != null) SetSubreportMonthOffset(sub, 0);
}
// Für Subreport2 (nächster Monat bzw. +2)
private void SubreportMonth1_BeforePrint(object sender, EventArgs e)
{
var sub = Month1.Report;
if (sub != null) SetSubreportMonthOffset(sub, 1);
}
// Für Subreport3 (übernächster Monat bzw. +3)
private void SubreportMonth2_BeforePrint(object sender, EventArgs e)
{
var sub = Month2.Report;
if (sub != null) SetSubreportMonthOffset(sub, 2);
}`
I have checked that the Event is fired - but all 3 subreports have the same result.
Please: where is the right place to set the parameter "parIntMonthAdd" to regnozied from the datasource-select