Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

User Preferences and Styling

By Brian K. McDonald,

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:

Readme - Create and Load Database Objects.txt | Style_Preferences.rdl
Total article views: 3142 | Views in the last 30 days: 5
 
Related Articles
ARTICLE

Create CNN-style Map in Reporting Services

This article demonstrates how to use US Census' TIGER/Line shapefile to display CNN-style map in Rep...

ARTICLE

Add Styles to Your Reporting Services Reports

Reporting Services provides a robust reporting platform that rivals many other products. New author ...

FORUM

Changing the report manager color (SKIN) by style sheet

Changing the style sheet of report manager

BLOG

SQL Server Reporting Services (SSRS) Templates and Styles

Ever wanted to change the default template and style for the Reporting Services Wizard?  Just think ...

ARTICLE

Reporting Services Styles in a Database Table

A follow-up on Adam Aspin's series about SSRS styles. I have emailed Adam the article because he sug...

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones