Kentico CMS 6.0 Developer's Guide

Managing report categories

Managing report categories

Previous topic Next topic Mail us feedback on this topic!  

Managing report categories

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 report category.

 

private void CreateReportCategory()
{
    // Create new report category object
    ReportCategoryInfo newCategory = new ReportCategoryInfo();
 
    // Set the properties
    newCategory.CategoryDisplayName = "My new category";
    newCategory.CategoryCodeName = "MyNewCategory";
 
    // Save the report category
    ReportCategoryInfoProvider.SetReportCategoryInfo(newCategory);
}

 

The following example gets and updates a report category.

 

private bool GetAndUpdateReportCategory()
{

  // Get the report category
  ReportCategoryInfo updateCategory = ReportCategoryInfoProvider.GetReportCategoryInfo("MyNewCategory");

    if (updateCategory != null)
    {

      // Update the properties
       updateCategory.CategoryDisplayName = updateCategory.CategoryDisplayName.ToLower();

 
        // Save the changes
        ReportCategoryInfoProvider.SetReportCategoryInfo(updateCategory);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates report categories.

 

private bool GetAndBulkUpdateReportCategories()
{
    // Prepare the parameters
    string where = "CategoryCodeName LIKE N'MyNewCategory%'";
 
    // Get the data
    DataSet categories = ReportCategoryInfoProvider.GetCategories(where, null);
    if (!DataHelper.DataSourceIsEmpty(categories))
    {
        // Loop through the individual items
        foreach (DataRow categoryDr in categories.Tables[0].Rows)
        {

          // Create object from DataRow
          ReportCategoryInfo modifyCategory = new ReportCategoryInfo(categoryDr);
 
          // Update the properties
           modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();

 
            // Save the changes
            ReportCategoryInfoProvider.SetReportCategoryInfo(modifyCategory);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a report category.

 

private bool DeleteReportCategory()
{

  // Get the report category
  ReportCategoryInfo deleteCategory = ReportCategoryInfoProvider.GetReportCategoryInfo("MyNewCategory");

 
    // Delete the report category
    ReportCategoryInfoProvider.DeleteReportCategoryInfo(deleteCategory);
 
    return (deleteCategory != null);
}