Read the current Dataset from DataSources

Stimulsoft Reports.WPF discussion
Post Reply
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Read the current Dataset from DataSources

Post by Prandl33 »

Hello,
I want to read the current dataset from Dictionary or DataSources, which was printed.
I tryed this in the following event

Code: Select all

StiGroupFooterBand stiGroupFooterZahlschein = (StiGroupFooterBand) Report.CompiledReport.GetComponents()["GroupFooterZahlschein"];
            if (stiGroupFooterZahlschein != null) {
                stiGroupFooterZahlschein.AfterPrint += new EventHandler(OnGroupFooterZahlschein_AfterPrint);
            }

.....

        private void OnGroupFooterZahlschein_AfterPrint(object sender, EventArgs e) {

            if (Report.CompiledReport.IsSecondPass) {
                int aktPosition = Report.CompiledReport.DataSources["Vorschreibung_Vorschreibungen_Empfaenger"].Position;
                var empfaenger = Report.CompiledReport.DataSources["Vorschreibung_Vorschreibungen_Empfaenger"];
                string vorname = empfaenger.DataTable.Rows[aktPosition].ItemArray[1].ToString();
                string nachname = empfaenger.DataTable.Rows[aktPosition].ItemArray[2].ToString();
                int pNr = Report.CompiledReport.PageNumber;
                int pNrTotoal = Report.CompiledReport.TotalPageCount;
            }

        }
The pagenumber and the TotolPageCount are correct. But the Position always is 0. And also the name is not the first
because it is sorted different. Is it possible to read the correct dataset?

When I try this in the code in designer it works fine and I have always the current dataset as the foliowing example shows:

Code: Select all

...
using System.Collections.Generic;


namespace Reports
{
    
    public class ZahlscheinVorschreibung: Stimulsoft.Report.StiReport
    {
        
    	public List<string> DuZuMetaDaten;
    	private string duzuMetadaten;
    	
        public ZahlscheinVorschreibung()
        {
            this.InitializeComponent();
            
            GroupFooterZahlschein.AfterPrint += GroupFooterZahlschein_AfterPrint;
            DuZuMetaDaten = new List<string>();            

		    Dictionary.Variables.Add(new Stimulsoft.Report.Dictionary.StiVariable("", "DuZuMetaDaten", "DuZuMetaDaten", "", typeof(List<string>), "", false, Stimulsoft.Report.Dictionary.StiVariableInitBy.Value, false));
            
        }       
    
        void GroupFooterZahlschein_AfterPrint(object sender, EventArgs e) {
			if (IsSecondPass) {
				duzuMetadaten = string.Format("{0}|{1}|{2}", PageNumber, 
				Vorschreibung_Vorschreibungen.Empfaenger.FirstName,
				Vorschreibung_Vorschreibungen.Empfaenger.LastName);
				DuZuMetaDaten.Add(duzuMetadaten);
			} 
        }

        #region StiReport Designer generated code - do not modify
....
Thank you
Prandl33
Posts: 40
Joined: Wed Nov 16, 2016 4:24 pm

Re: Read the current Dataset from DataSources

Post by Prandl33 »

Hello, I have a solution.
In the AfterPrint-Event from the groupfooter I declared the StiDataBand with GetComponentByName.
So I got the current dataset and his items with DataSource.GetData which was printed before the groupfooter.

Code: Select all

                StiDataBand databand = Report.CompiledReport.GetComponentByName("DataVorschreibung") as StiDataBand;
                // we use Business Objects for Datasource
                DuZuEmpfaenger empfaenger = (DuZuEmpfaenger) databand.DataSource.GetData("Empfaenger");
                persNr = empfaenger.PersNr.ToString();
                vorname = empfaenger.Vorname;
                nachname = empfaenger.Nachname;
                strasse = databand.DataSource.GetData("Strasse").ToString();
                zustellung = databand.DataSource.GetData("Zustellung").ToString();

                int pNr = Report.CompiledReport.PageNumber;
                int pNrTotal = Report.CompiledReport.TotalPageCount;
Maybe there is a better solution?
Thank you
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Read the current Dataset from DataSources

Post by HighAley »

Hello.

Why don't you just call the Data source by name?
Like Empfaenger.Position and so on.
But if your code works, you could leave it as is.

Thank you
Post Reply