SQLServerCentral Article

User Preferences and Styling

,

Recently Adam Aspin posted some great articles on using stylesheets and custom code to help developers standardize the report presentation layer (Add Styles to Your Reporting Services Reports, Centralising Reporting Services Stylesheets, and Report Templates Using Stylesheets). The thought of each of us seeing the same exact thing can sometimes seem daunting and boring to users, which can lead to lack of absorption into the user community. Users often desire to be a little unique (or at least different than those sitting around them). As such, here is a way to allow reporting to pull user color preferences and render them in their desired color scheme.

1. Let's begin by setting up our table that will contain our color schemes:

CREATE TABLE SSRS_Styles
(
StyleID INT PRIMARY KEY IDENTITY(1,1)
, StyleName VARCHAR(50)
, ReportBGColor VARCHAR(100)
, ReportTitleColor VARCHAR(100)
, TableHeaderBGColor VARCHAR(100)
, TableHeaderFontColor VARCHAR(100)
, TableDetailsBGColor VARCHAR(100)
, TableDetailsFontColor VARCHAR(100)
)

* More values could be stored in this table as I am just using a few of the properties from the body and table objects *

2. Now I'm going to add a few standard color schemes into the table:

--Standard Theme 1
INSERT INTO SSRS_Styles
(StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
, TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Mono-Chrome','White','Black','#6ca6cd', 'White', 'White','Black') --Standard Theme 2
INSERT INTO SSRS_Styles
(StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
, TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Go-Green','White','Green','PaleGreen', 'Black', 'White','Black') --Standard Theme 3
INSERT INTO SSRS_Styles
(StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
, TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard McPorting','White','Blue','Red', 'White', 'White','Black') --Standard Theme 4
INSERT INTO SSRS_Styles
(StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
, TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Star Wars','Black','Silver','Gold', 'Black', 'Black','Silver')

The records now in the table should be as follows:

3. Now in order to make this work we need to store the preference for a particular user in another table:

CREATE TABLE SSRS_Style_Preferences
(
PreferenceID INT PRIMARY KEY IDENTITY(1,1)
, UserName VARCHAR(50)
, StyleID INT
, DateLastModified SMALLDATETIME DEFAULT GETDATE()
)

4. Insert some users and their preferences (a web form or report could be used to allow the user to change this setting later, but assigning StyleID = 1 as the default will set the report to the mono-chrome standard).

INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('Default',1)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('GreenMan',2)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('BrianMcDonald',3)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('DarthVader',4)

The records now in the SSRS_Style_Preferences table should be as follows:

5. Now it is time to switch over to Business Intelligence Development Studio (BIDS) to edit the report to use the "consumers" preferences.

Note that an assumption is made that the author of the report can create a report and return a resultset into a table control. So from within the report, we need to add two text boxes and a table control. Then we need to set some of the property values of the objects as follows:

Body
BackgroundColor = Fields!ReportBGColor.Value

ReportTitle Textbox (shows the title of the report)
BackgroundColor = Fields!ReportBGColor.Value
Color = Fields!ReportTitleColor.Value


CurrentUserPreference Textbox (shows what user was passed in and their preferred style)
BackgroundColor = Fields!ReportBGColor.Value
Color = Fields!ReportTitleColor.Value

Table
TableRow1 (header) BackgroundColor = Fields!TableHeaderBGColor.Value
TableRow1 (header) Color = Fields!TableHeaderFontColor.Value
TableRow2 (detail) Backgroundcolor = Fields!TableDetailsBGColor.Value
TableRow2 (detail Color = Fields!TableDetailsFontColor.Value

6. Preview the results for each user:

For my report, I set the available values of the report parameter to a query and got a listing of the usernames from the SSRS_Style_Preferences table. I have included the database object setup script and the rdl file that I created during this process for your enjoyment.

I hope you enjoyed my first article and hope to provide many more in the future.

Brian K. McDonald, MCSD, MCDBA

Database Administrator

Jacksonville, Florida

Resources

Rate

5 (7)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (7)

You rated this post out of 5. Change rating