Kentico CMS 6.0 Developer's Guide

Managing report tables

Managing report tables

Previous topic Next topic Mail us feedback on this topic!  

Managing report tables

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a table and assigns it to a report.

 

private bool CreateReportTable()
{
    // Get report object by report code name
    ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");
 
    // If report exists
    if (report != null)
    {
        // Create new report table object
        ReportTableInfo newTable = new ReportTableInfo();
 
        // Set the properties
        newTable.TableDisplayName = "My new table";
        newTable.TableName = "MyNewTable";

       newTable.TableQuery = "SELECT TOP 10 DocumentName, DocumentID FROM CMS_Document";

        newTable.TableReportID = report.ReportID;
        newTable.TableQueryIsStoredProcedure = false;
 
        // Save the report table
        ReportTableInfoProvider.SetReportTableInfo(newTable);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a report table.

 

private bool GetAndUpdateReportTable()
{

  // Get the report table
  ReportTableInfo updateTable = ReportTableInfoProvider.GetReportTableInfo("MyNewTable");

    if (updateTable != null)
    {
        // Update the properties
        updateTable.TableDisplayName = updateTable.TableDisplayName.ToLower();
 
        // Save the changes
        ReportTableInfoProvider.SetReportTableInfo(updateTable);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates report tables.

 

private bool GetAndBulkUpdateReportTables()
{
    // Prepare the parameters
    string where = "TableName LIKE N'MyNewTable%'";
 
    // Get the data
    DataSet tables = ReportTableInfoProvider.GetTables(where, null);
    if (!DataHelper.DataSourceIsEmpty(tables))
    {
        // Loop through the individual items
        foreach (DataRow tableDr in tables.Tables[0].Rows)
        {
            // Create object from DataRow
            ReportTableInfo modifyTable = new ReportTableInfo(tableDr);
 
            // Update the properties
            modifyTable.TableDisplayName = modifyTable.TableDisplayName.ToUpper();
 
            // Save the changes
            ReportTableInfoProvider.SetReportTableInfo(modifyTable);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a report table.

 

private bool DeleteReportTable()
{

  // Get the report table
  ReportTableInfo deleteTable = ReportTableInfoProvider.GetReportTableInfo("MyNewTable");

 
    // Delete the report table
    ReportTableInfoProvider.DeleteReportTableInfo(deleteTable);

 
  return (deleteTable != null);
}