logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
prol  
#1 Posted : Thursday, September 8, 2016 8:52:13 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Hi,

I have two doubts in this topic.
Please consider that I don't know c#, I'm just familiar with things that I find similar in Java.

  • I'm using Enum for month and year restrictions for a report grouped by this two values, but they can't be static, I need to set current year and last 4 months when the user haven't select a month or year, for example.

    I tried this:
    Code:
    
    if(model.GetRestrictionByName("year").Value1 == null) {
       model.GetRestrictionByName("year").Value1 = DateTime.Now.Year.ToString();
    }


    It kinda worked, but if I add another report on the same page that uses the same restriction, both of them wont work.


    I don't know exactly how to set the last four months, so I don't have any code example.



  • I need to show on a single report the total columns (average and sum), but the report designer only let me choose one. So, what I tried was to add the same column twice to achieve both aggregations.
    Now I have two columns with repeated values, and I need to remove one column. I was trying c# on post and final script section, but didn't got it right.



Thanks!

epf  
#2 Posted : Friday, September 9, 2016 7:40:42 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
Well, good questions...
For the first point you should know that restriction values are not stored in Value1, Value2, Value3, Value4 but in a List<string> EnumValues.
So you should probably do this:
Code:

if (model.GetRestrictionByName("year").EnumValues.Count == 0) { 
   model.GetRestrictionByName("year").EnumValues.Add(DateTime.Now.Year.ToString());
}


You can check a sample at this post: https://sealreport.org/forum/default.aspx?g=posts&t=149#post330

For your second point, an approach could be to customize the presentation template of your main view:
Select your Model HTML View and edit the template text:
In you case you can modify the code at the end of the script to build up the HTML table you want (you should understand the object model of the results).
You have to change the <thead>, <tbody> and <tfoot>, here is a sample for the <tbody> to skip some columns:
Code:
                        <tbody>
                            @for (int row = page.DataTable.BodyStartRow; row < page.DataTable.BodyEndRow; row++)
                            {
                                ResultCell[] line = page.DataTable.Lines[row];
                                <tr class="@((row-page.DataTable.BodyStartRow)%2 == 1 ? " " : " odd")">
                                    @for (int col = 0; col < line.Length; col++)
                                    {
                                        ResultCell cell = line[col];
										if (cell.Element != null && !cell.IsTotal && cell.Element.DisplayName == "Amount2") {
											continue;
										}
                                        string className = cell.IsTitle && col == 0 ? "cell_title" : "cell_value";
                                        className = cell.IsTotal ? "cell_value_total" : className;
                                        <td class='@className' style='@cell.CellCssStyle' @Raw(GetNavigation(cell))>@Raw(cell.HTMLValue)</td>
                                    }
                                </tr>
                            }
                        </tbody>


I just added these lines of code to filter the column having the name "Amount2":
Code:
if (cell.Element != null && !cell.IsTotal && cell.Element.DisplayName == "Amount2") {
   continue;
}

Note also that there is a bug when you show totals per column: the aggregate is always Sum (hopefully will be fixed in next release) but it works for totals in rows.

I will check if we can do that using the Final Script of the model and rebuild the ResultTable page.DataTable without the unwanted columns...perhaps it is finally simpler.

Edited by user Friday, September 9, 2016 7:50:51 PM(UTC)  | Reason: Not specified

prol  
#3 Posted : Monday, September 19, 2016 1:35:39 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Hi epf!

Thank you for helping me out, and sorry for responding just now, it's because last week I was trying these solutions suggested by you and other stuffs at work.

The first one, about restrictions worked perfectly!
The example that I used, gave me the illusion that it was working because I used a date where there wasn't data in the database, so I thought it was applying the restriction.

In case anyone need it, here are the sample for getting the last four months in the current year:

Code:

/**
 * Mark current year in Enum list
 */
if (model.GetRestrictionByName("Year").EnumValues.Count == 0) { 
model.GetRestrictionByName("Year").EnumValues.Add(DateTime.Now.Year.ToString());
}


Code:

/**
 * Mark last four months in Enum list
 * If the year has less then four months, it will mark the quantity available.
 */
if(model.GetRestrictionByName("Month").EnumValues.Count == 0) {
	int  monthCounter = 0;
	do {
		if(DateTime.Now.Year != DateTime.Now.AddMonths(-monthCounter).Year){
			break;
		}
        model.GetRestrictionByName("Month").EnumValues.Add(DateTime.Now.AddMonths(-monthCounter).Month.ToString());
		monthCounter++;
	} while(monthCounter < 4);
}




The second part I was not able to implement yet, because it's a bit more complex. I will try to finish this week.
Oh! If you discovered how to do with Final Script, please let me know.



Thank you again!

Edited by user Wednesday, September 21, 2016 5:22:27 PM(UTC)  | Reason: Correcting code example.

epf  
#4 Posted : Wednesday, September 21, 2016 7:25:26 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
Thank you for your comments.

I made a try to use the final script to achieve your second point and here is how to do it:

The idea is to recreate the ResultTable but without the unwanted columns...

I created 2 elements in Data from Amount, I renamed one with "Min." and set the Totals to Min agregate function.
Then I just added the following code in the Final Script of the model:

Code:
//Create a new result table
ResultTable newTable = new ResultTable() { BodyStartRow = dataTable.BodyStartRow, BodyStartColumn = dataTable.BodyStartColumn, BodyEndRow = dataTable.BodyEndRow };
var lastLine = dataTable.Lines[dataTable.Lines.Count-1];
foreach (var line in dataTable.Lines)
{
	List<ResultCell> newLine = new List<ResultCell>();
	for (int col = 0; col < line.Length; col++)
	{
		//Test if we skip the column
		if (lastLine[col].Element != null && !lastLine[col].IsTotalTotal && lastLine[col].Element.DisplayName == "Min.") {
			continue;
		}				
		newLine.Add(line[col]);
	}
	newTable.Lines.Add(newLine.ToArray());
}
page.DataTable = newTable;


And it works...

This methods is better than modifying the template script of the view.

Edited by user Wednesday, September 21, 2016 7:25:57 AM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
prol on 2/22/2017(UTC)
prol  
#5 Posted : Wednesday, September 21, 2016 6:54:27 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Hi!

Yesterday I've finished the code following your first example.
Basically I stored the positions of the column that I need to suppress and then start to check in each table section (thead, tbody and tfoot).

Much more code than this new example you just posted.
I will try this new approach and post about it when I finish.


Thank you for the help!
prol  
#6 Posted : Thursday, February 23, 2017 7:26:12 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Originally Posted by: epf Go to Quoted Post
Thank you for your comments.

I made a try to use the final script to achieve your second point and here is how to do it:

The idea is to recreate the ResultTable but without the unwanted columns...

I created 2 elements in Data from Amount, I renamed one with "Min." and set the Totals to Min agregate function.
Then I just added the following code in the Final Script of the model:

Code:
//Create a new result table
ResultTable newTable = new ResultTable() { BodyStartRow = dataTable.BodyStartRow, BodyStartColumn = dataTable.BodyStartColumn, BodyEndRow = dataTable.BodyEndRow };
var lastLine = dataTable.Lines[dataTable.Lines.Count-1];
foreach (var line in dataTable.Lines)
{
	List<ResultCell> newLine = new List<ResultCell>();
	for (int col = 0; col < line.Length; col++)
	{
		//Test if we skip the column
		if (lastLine[col].Element != null && !lastLine[col].IsTotalTotal && lastLine[col].Element.DisplayName == "Min.") {
			continue;
		}				
		newLine.Add(line[col]);
	}
	newTable.Lines.Add(newLine.ToArray());
}
page.DataTable = newTable;


And it works...

This methods is better than modifying the template script of the view.



Hi epf!

I tried this code to simplify things e achieve another thing that I need, but when I execute the report, the column that is removed is the "total" and the ones that I intend to remove, remain in the report.

I couldn't figure it out why. I tried to change the condition to !lastLine[col].IsTotal, but it didn't work. Beside that, your logic seems correct to me.

Can you shed some light on this?

Just to exemplify, this is the original structure to generate both aggregation types:

Code:

|        | MONTHS  |       |          |       | Total
|        | January |       | February |       | Average | Total |
| STORES | Sales   | Sales | Sales    | Sales |         |       |
| st1    |         |       |          |       |         |       |
| st2    |         |       |          |       |         |       |
| Total  |         |       |          |       |         |       |



This is the stricture a need:

Code:

|        | MONTHS  |          | Total
|        | January | February | Average | Total |
| STORES | Sales   | Sales    |         |       |
| st1    |         |          |         |       |
| st2    |         |          |         |       |
| Total  |         |          |         |       |


This is the one I'm getting with your example:

Code:

|        | MONTHS  |       |          |       |
|        | January |       | February |       | Total |
| STORES | Sales   | Sales | Sales    | Sales |       |
| st1    |         |       |          |       |       |
| st2    |         |       |          |       |       |
| Total  |         |       |          |       |       |



Thanks for your help!
epf  
#7 Posted : Friday, February 24, 2017 10:38:22 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
From 3.0, did you check the sample "54-Final Script - Change result table.srex" ?
prol  
#8 Posted : Friday, February 24, 2017 6:09:34 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
No! Didn't even cross my mind about the examples after update to 3.0.

After some tries with the example I finally notice what was wrong. Both data columns were showing totals for rows and columns and in my report, only one was configured like that.

Thanks!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.