Page 1 of 1

Read the current Dataset from DataSources

Posted: Tue Dec 13, 2016 5:25 pm
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

Re: Read the current Dataset from DataSources

Posted: Wed Dec 14, 2016 7:46 am
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

Re: Read the current Dataset from DataSources

Posted: Wed Dec 14, 2016 2:42 pm
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