Reporting
List of examples:
Report categories
Creating a report category
// Creates a new report category object
ReportCategoryInfo newCategory = new ReportCategoryInfo();
// Sets the report category properties
newCategory.CategoryDisplayName = "New category";
newCategory.CategoryCodeName = "NewCategory";
// Saves the report category to the database
ReportCategoryInfoProvider.SetReportCategoryInfo(newCategory);
Updating a report category
// Gets the report category
ReportCategoryInfo updateCategory = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");
if (updateCategory != null)
{
// Updates the report category properties
updateCategory.CategoryDisplayName = updateCategory.CategoryDisplayName.ToLower();
// Saves the updated report category to the database
ReportCategoryInfoProvider.SetReportCategoryInfo(updateCategory);
}
Updating multiple report categories
// Prepares a condition for loading all report categories whose code name starts with 'New'
string where = "CategoryCodeName LIKE N'New%'";
// Gets the report categories that fulfill the condition
InfoDataSet<ReportCategoryInfo> categories = ReportCategoryInfoProvider.GetCategories(where, null);
// Loops through individual report categories
foreach (ReportCategoryInfo category in categories)
{
// Updates the report category properties
category.CategoryDisplayName = category.CategoryDisplayName.ToUpper();
// Saves the updated report category to the database
ReportCategoryInfoProvider.SetReportCategoryInfo(category);
}
Deleting a report category
// Gets the report category
ReportCategoryInfo deleteCategory = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");
if (deleteCategory != null)
{
// Deletes the report category
ReportCategoryInfoProvider.DeleteReportCategoryInfo(deleteCategory);
}
Reports
Creating a report
// Gets a parent category for the report
ReportCategoryInfo category = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");
if (category != null)
{
// Creates a new report object
ReportInfo newReport = new ReportInfo();
// Sets the report properties
newReport.ReportDisplayName = "New report";
newReport.ReportName = "NewReport";
newReport.ReportCategoryID = category.CategoryID;
newReport.ReportAccess = ReportAccessEnum.All;
newReport.ReportLayout = "";
newReport.ReportParameters = "";
// Saves the report to the database
ReportInfoProvider.SetReportInfo(newReport);
}
Updating a report
// Gets the report
ReportInfo updateReport = ReportInfoProvider.GetReportInfo("NewReport");
if (updateReport != null)
{
// Updates the report properties
updateReport.ReportDisplayName = updateReport.ReportDisplayName.ToLower();
// Saves the modified report to the database
ReportInfoProvider.SetReportInfo(updateReport);
}
Updating multiple reports
// Gets a report category
ReportCategoryInfo category = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");
// Prepares a condition for loading all reports within the specified category
string where = "ReportCategoryID = " + category.CategoryID;
// Gets all reports that fulfill the condition
InfoDataSet<ReportInfo> reports = ReportInfoProvider.GetReports(where);
// Loops through individual reports
foreach (ReportInfo report in reports)
{
// Updates the report properties
report.ReportDisplayName = report.ReportDisplayName.ToUpper();
// Saves the modified report to the database
ReportInfoProvider.SetReportInfo(report);
}
Deleting a report
// Gets the report
ReportInfo deleteReport = ReportInfoProvider.GetReportInfo("NewReport");
if (deleteReport != null)
{
// Deletes the report
ReportInfoProvider.DeleteReportInfo(deleteReport);
}
Report components (graphs, tables, values)
Creating report components
// Gets the report
ReportInfo report = ReportInfoProvider.GetReportInfo("NewReport");
if (report != null)
{
// Creates a new report graph object
ReportGraphInfo newGraph = new ReportGraphInfo
{
// Sets the graph properties
GraphDisplayName = "New graph",
GraphName = "NewGraph",
GraphQuery = "SELECT TOP 10 DocumentName, DocumentID FROM CMS_Document",
GraphReportID = report.ReportID,
GraphQueryIsStoredProcedure = false,
GraphType = "bar"
};
// Saves the report graph to the database
ReportGraphInfoProvider.SetReportGraphInfo(newGraph);
// Creates a new report table object
ReportTableInfo newTable = new ReportTableInfo
{
// Sets the table properties
TableDisplayName = "New table",
TableName = "NewTable",
TableQuery = "SELECT TOP 10 DocumentName, DocumentID FROM CMS_Document",
TableReportID = report.ReportID,
TableQueryIsStoredProcedure = false
};
// Saves the report table to the database
ReportTableInfoProvider.SetReportTableInfo(newTable);
// Creates a new report value object
ReportValueInfo newValue = new ReportValueInfo
{
// Sets the report value properties
ValueDisplayName = "New value",
ValueName = "NewValue",
ValueQuery = "SELECT COUNT(DocumentName) FROM CMS_Document",
ValueQueryIsStoredProcedure = false,
ValueReportID = report.ReportID
};
// Saves the report value to the database
ReportValueInfoProvider.SetReportValueInfo(newValue);
}
Updating a report component
// Gets a report graph
ReportGraphInfo updateGraph = ReportGraphInfoProvider.GetReportGraphInfo("NewGraph");
if (updateGraph != null)
{
// Updates the graph properties
updateGraph.GraphDisplayName = updateGraph.GraphDisplayName.ToLower();
// Saves the updated report graph to the database
ReportGraphInfoProvider.SetReportGraphInfo(updateGraph);
}
Updating multiple report components
// Gets a report
ReportInfo report = ReportInfoProvider.GetReportInfo("NewReport");
// Gets all graphs graphs defined for the specified report
InfoDataSet<ReportGraphInfo> graphs = ReportGraphInfoProvider.GetGraphs(report.ReportID);
// Loops through individual report graphs
foreach (ReportGraphInfo graph in graphs)
{
// Updates the graph properties
graph.GraphDisplayName = graph.GraphDisplayName.ToUpper();
// Saves the updated report graph to the database
ReportGraphInfoProvider.SetReportGraphInfo(graph);
}
Adding components into the layout of a report
// Gets the report
ReportInfo report = ReportInfoProvider.GetReportInfo("NewReport");
if (report != null)
{
// Gets a report graph
ReportGraphInfo graph = ReportGraphInfoProvider.GetReportGraphInfo("NewGraph");
if (graph != null)
{
// Inserts the graph into the report's layout
report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Graph + "?" + report.ReportName + "." + graph.GraphName + "%%<br/>";
}
// Gets a report table
ReportTableInfo table = ReportTableInfoProvider.GetReportTableInfo("NewTable");
if (table != null)
{
// Inserts the table into the report's layout
report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Table + "?" + report.ReportName + "." + table.TableName + "%%<br/>";
}
// Gets a report value
ReportValueInfo value = ReportValueInfoProvider.GetReportValueInfo("NewValue");
if (value != null)
{
// Inserts the value into the report's layout
report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Value + "?" + report.ReportName + "." + value.ValueName + "%%<br/>";
}
// Saves the modified report to the database
ReportInfoProvider.SetReportInfo(report);
}
Deleting a report component
// Gets a report graph
ReportGraphInfo deleteGraph = ReportGraphInfoProvider.GetReportGraphInfo("NewGraph");
if (deleteGraph != null)
{
// Deletes the report graph
ReportGraphInfoProvider.DeleteReportGraphInfo(deleteGraph);
}