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);


> Back to list of examples

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);
}


> Back to list of examples

Updating multiple report categories




// Gets the report categories whose code name starts with 'New'
var categories = ReportCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryCodeName", "New");

// 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);
}


> Back to list of examples

Deleting a report category




// Gets the report category
ReportCategoryInfo deleteCategory = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");

if (deleteCategory != null)
{
    // Deletes the report category
    ReportCategoryInfoProvider.DeleteReportCategoryInfo(deleteCategory);
}


> Back to list of examples

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);
}


> Back to list of examples

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);
}


> Back to list of examples

Updating multiple reports




// Gets a report category
ReportCategoryInfo category = ReportCategoryInfoProvider.GetReportCategoryInfo("NewCategory");

// Gets all reports within the specified category
var reports = ReportInfoProvider.GetReports().WhereEquals("ReportCategoryID", category.CategoryID);

// 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);
}


> Back to list of examples

Deleting a report




// Gets the report
ReportInfo deleteReport = ReportInfoProvider.GetReportInfo("NewReport");

if (deleteReport != null)
{
    // Deletes the report
    ReportInfoProvider.DeleteReportInfo(deleteReport);
}


> Back to list of examples

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);
}


> Back to list of examples

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);
}


> Back to list of examples

Updating multiple report components




// Gets a report
ReportInfo report = ReportInfoProvider.GetReportInfo("NewReport");                               

// Gets all graphs defined for the specified report
var graphs = ReportGraphInfoProvider.GetReportGraphs().WhereEquals("GraphReportID", 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);
}


> Back to list of examples

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);
}


> Back to list of examples

Deleting a report component




// Gets a report graph
ReportGraphInfo deleteGraph = ReportGraphInfoProvider.GetReportGraphInfo("NewGraph");

if (deleteGraph != null)
{
    // Deletes the report graph
    ReportGraphInfoProvider.DeleteReportGraphInfo(deleteGraph);
}


> Back to list of examples