How to get sum per page when using dynamic table?

edited 9:15AM in FastReport .NET
Hello! I've built my table using its ManualBuild event. I have some int values in each row and the point is I want to calculate their's sum for each page and display it at the bottom of page.
For instance

N Name Age
- - - - - - - - -
1 Mike 30 <- Page 1, the sum is 59
2 John 29
- - - - - - - - -
3 Kyle 35 <- Page 2, the sum is 35

My ManualBuild looks like this
private void tabContent_ManualBuild(object sender, EventArgs e)
{ 
  tabContent.PrintRow(0);
  cTabContentHead.Text = "№";
  tabContent.Columns[0].Width = 47.25f;
  tabContent.PrintColumn(0);
  foreach (KeyValuePair<string, Dictionary<string, string>> item in tabColsSetup)
  {
    if (tabColsSetup[item.Key]["Leng"] != "0")
    {
      cTabContentHead.Text = tabColsSetup[item.Key]["Head"];
      tabContent.Columns[0].Width = float.Parse(tabColsSetup[item.Key]["Leng"], System.Globalization.CultureInfo.CurrentCulture.NumberFormat);
      tabContent.Columns[0].Width += fWidthRaise;
      tabContent.Columns[0].Width *= Units.Centimeters;
      tabContent.PrintColumn(0);
    } 
  }  
  
  while (tabdata.HasMoreRows)
  { 
    tabContent.PrintRow(1);
    cTabContentContent.Text = rowN.ToString();
    tabContent.Columns[0].Width = 47.25f;
    tabContent.PrintColumn(0);
    foreach (KeyValuePair<string, Dictionary<string, string>> item in tabColsSetup)
    {   
      if (tabColsSetup[item.Key]["Leng"] != "0")
      {                          
        cTabContentContent.Text = tabdata[item.Key].ToString();                                                          
        tabContent.PrintColumn(0);
      }
      
      switch (item.Key)
      {
        case "SharesAmount": 
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSharesAmount);
          break;            
        case "SumFull":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSumFull);
          break;
        case "Tax":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dTax);
          break;
        case "SumMinusTax":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSumMinusTax);
          break;
      }
     
    }
    
    dPageTotalSharesAmount += dSharesAmount;
    dPageTotalSumFull += dSumFull;
    dPageTotalTax += dTax;
    dPageTotalSumMinusTax += dSumMinusTax;
    
    dTotalSharesAmount += dSharesAmount;
    dTotalSumFull += dSumFull;
    dTotalTax += dTax;
    dTotalSumMinusTax += dSumMinusTax;
    
    tabdata.Next();
    rowN++;
  }
}

The problem is I don't know how to catch the moment when page ends. I tried to go through ResultTable calculating and sum'ing row's heights and to make PageBreak when I'm out of FreeSpace, but each row had the same Height and CalcHeight even if visually rows were different. So this attemp failed. Also I tried using events of different bands such as PageFooter, DataBand and so on but with no success.
Do somebody have an idea how could I get sum per page in my case?

Comments

  • edited June 2018
  • edited 9:15AM
    ipong wrote: »
    ...

    Thanks for reply. Your example gave me an idea, but when I try to code it I face a problem which is Report.GetVariableValue("Page") returns 1 everytime.
    I think it's because of my table is dynamic and events might work some different way.
    I've rewritten my report, filled it with fish-data and removed some useless stuff.
    Could you check it? You'll see the problem because I've put the page number into Text1.

  • edited June 2018
    i give up with your approach [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> if possible: 1. catch user preferences with application code (winforms/wpf/webproject) 2. build report from code (report by code), this approach is to replace tableobject with manualbuild 3. datasource is business object, use linq to filter data based on user preferences 4. i know my approach is difficult to debug, at least can solve 'sum per page'[/img]
  • edited 9:15AM
    ipong wrote: »
    i give up with your approach [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> if possible: 1. catch user preferences with application code (winforms/wpf/webproject) 2. build report from code (report by code), this approach is to replace tableobject with manualbuild i have fastreport code generator, after you've designed report template, you could get the code easily 3. datasource is business object, use linq to filter data based on user preferences 4. i know my approach is difficult to debug, at least can solve 'sum per page'[/img]

    At first I thought it was necessary to use ManualBuild to build a table each column of which would stretch horizontally when some free space is on the page. Because it was shown in Fastreport's demo and I faced a lot of trouble. But at the end after I studied your example more carefully and read this "i give up with your approach [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> " I decided not to use ManualBuild and tried another approach. And you know it worked) It might be not very beatifull cause there is some hardcode coupling interface and logic but it works and could be used as start point for somebody who needs the same report. P.S. It would be great if FR team made some "cookbook" or provide "Class Reference" manual with some examples because it's really very few information about fastreport on internet and existing manuals are not enough if you want to do something not trivial.[/img]

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.