private bool InsertElementsToLayout() { // Get report object by report code name ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport"); // If report exists if (report != null) { ReportGraphInfo graph = ReportGraphInfoProvider.GetReportGraphInfo("MyNewGraph"); if (graph != null) { report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Graph + "?" + report.ReportName + "." + graph.GraphName + "%%<br/>"; } ReportTableInfo table = ReportTableInfoProvider.GetReportTableInfo("MyNewTable"); if (table != null) { report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Table + "?" + report.ReportName + "." + table.TableName + "%%<br/>"; } ReportValueInfo value = ReportValueInfoProvider.GetReportValueInfo("MyNewValue"); if (value != null) { report.ReportLayout += "<br/>%%control:Report" + ReportItemType.Value + "?" + report.ReportName + "." + value.ValueName + "%%<br/>"; } ReportInfoProvider.SetReportInfo(report); return(true); } return(false); }
/// <summary> /// Gets and bulk updates reports. Called when the "Get and bulk update reports" button is pressed. /// Expects the CreateReport method to be run first. /// </summary> private bool GetAndBulkUpdateReports() { // Prepare the parameters string where = "ReportName LIKE N'MyNewReport%'"; string orderby = ""; int topN = 0; string columns = ""; // Get the data DataSet reports = ReportInfoProvider.GetReports(where, orderby, topN, columns); if (!DataHelper.DataSourceIsEmpty(reports)) { // Loop through the individual items foreach (DataRow reportDr in reports.Tables[0].Rows) { // Create object from DataRow ReportInfo modifyReport = new ReportInfo(reportDr); // Update the properties modifyReport.ReportDisplayName = modifyReport.ReportDisplayName.ToUpper(); // Save the changes ReportInfoProvider.SetReportInfo(modifyReport); } return(true); } return(false); }
/// <summary> /// Creates report. Called when the "Create report" button is pressed. /// </summary> private bool CreateReport() { // Get the report category ReportCategoryInfo category = ReportCategoryInfoProvider.GetReportCategoryInfo("MyNewCategory"); if (category != null) { // Create new report object ReportInfo newReport = new ReportInfo(); // Set the properties newReport.ReportDisplayName = "My new report"; newReport.ReportName = "MyNewReport"; newReport.ReportCategoryID = category.CategoryID; newReport.ReportAccess = ReportAccessEnum.All; newReport.ReportLayout = ""; newReport.ReportParameters = ""; // Save the report ReportInfoProvider.SetReportInfo(newReport); return(true); } return(false); }
/// <summary> /// Gets and updates report. Called when the "Get and update report" button is pressed. /// Expects the CreateReport method to be run first. /// </summary> private bool GetAndUpdateReport() { // Get the report ReportInfo updateReport = ReportInfoProvider.GetReportInfo("MyNewReport"); if (updateReport != null) { // Update the properties updateReport.ReportDisplayName = updateReport.ReportDisplayName.ToLower(); // Save the changes ReportInfoProvider.SetReportInfo(updateReport); return(true); } return(false); }
private void editor_OnAfterDefinitionUpdate(object sender, EventArgs e) { // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify")) { RedirectToAccessDenied("cms.reporting", "Modify"); } ReportInfo ri = ReportInfoProvider.GetReportInfo(reportId); if (ri != null) { // Get new report parameters changed by fieldeditor ri.ReportParameters = editor.FormDefinition; // Update report parameters in database ReportInfoProvider.SetReportInfo(ri); } }
/// <summary> /// Sets data to database. /// </summary> protected void lnkSave_Click(object sender, EventArgs e) { // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify")) { RedirectToAccessDenied("cms.reporting", "Modify"); } string errorMessage = new Validator().NotEmpty(txtReportDisplayName.Text.Trim(), rfvReportDisplayName.ErrorMessage).NotEmpty(txtReportName.Text.Trim(), rfvReportName.ErrorMessage).Result; if ((errorMessage == "") && (!ValidationHelper.IsCodeName(txtReportName.Text.Trim()))) { errorMessage = GetString("general.invalidcodename"); } ReportAccessEnum reportAccess = ReportAccessEnum.All; if (!chkReportAccess.Checked) { reportAccess = ReportAccessEnum.Authenticated; } if (errorMessage == "") { ReportInfo reportInfo = ReportInfoProvider.GetReportInfo(reportId); ReportInfo nri = ReportInfoProvider.GetReportInfo(txtReportName.Text.Trim()); // If report with given name already exists show error message if ((nri != null) && (nri.ReportID != reportInfo.ReportID)) { lblError.Visible = true; lblError.Text = GetString("Report_New.ReportAlreadyExists"); return; } if (reportInfo != null) { reportInfo.ReportLayout = htmlTemplateBody.ResolvedValue; // If there was a change in report code name change codenames in layout if (reportInfo.ReportName != txtReportName.Text.Trim()) { // part of old macro string oldValue = "?" + reportInfo.ReportName + "."; string newValue = "?" + txtReportName.Text.Trim() + "."; reportInfo.ReportLayout = reportInfo.ReportLayout.Replace(oldValue, newValue); // Set updated text back to HTML editor htmlTemplateBody.ResolvedValue = reportInfo.ReportLayout; } int categoryID = ValidationHelper.GetInteger(selectCategory.Value, reportInfo.ReportCategoryID); // If there was a change in display name refresh category tree if ((reportInfo.ReportDisplayName != txtReportDisplayName.Text.Trim()) || (reportInfo.ReportCategoryID != categoryID)) { ltlScript.Text += ScriptHelper.GetScript(@"if ((parent != null) && (parent.Refresh != null)) {parent.Refresh();}"); } reportInfo.ReportDisplayName = txtReportDisplayName.Text.Trim(); reportInfo.ReportName = txtReportName.Text.Trim(); reportInfo.ReportAccess = reportAccess; reportInfo.ReportCategoryID = categoryID; ReportInfoProvider.SetReportInfo(reportInfo); lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, GetString("general.general")); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify")) { RedirectToAccessDenied("cms.reporting", "Modify"); } string errorMessage = new Validator().NotEmpty(txtReportDisplayName.Text.Trim(), rfvReportDisplayName.ErrorMessage).NotEmpty(txtReportName.Text.Trim(), rfvReportName.ErrorMessage).Result; if ((errorMessage == "") && (!ValidationHelper.IsCodeName(txtReportName.Text.Trim()))) { errorMessage = GetString("general.invalidcodename"); } if (ReportCategoryInfoProvider.GetReportCategoryInfo(categoryId) == null) { errorMessage = GetString("Report_General.InvalidReportCategory"); } ReportAccessEnum reportAccess = ReportAccessEnum.All; if (!chkReportAccess.Checked) { reportAccess = ReportAccessEnum.Authenticated; } if (errorMessage == "") { //if report with given name already exists show error message if (ReportInfoProvider.GetReportInfo(txtReportName.Text.Trim()) != null) { ShowError(GetString("Report_New.ReportAlreadyExists")); return; } ReportInfo ri = new ReportInfo(); ri.ReportDisplayName = txtReportDisplayName.Text.Trim(); ri.ReportName = txtReportName.Text.Trim(); ri.ReportCategoryID = categoryId; ri.ReportLayout = ""; ri.ReportParameters = ""; ri.ReportAccess = reportAccess; ri.ReportEnableSubscription = chkEnableSubscription.Checked; ReportInfoProvider.SetReportInfo(ri); ltlScript.Text += "<script type=\"text/javascript\">"; ltlScript.Text += @"if (parent.frames['reportcategorytree']) { parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"'; } if (parent.parent.frames['reportcategorytree']) { parent.parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"'; } this.location.href = 'Report_Edit.aspx?reportId=" + Convert.ToString(ri.ReportID) + @"&saved=1&categoryID=" + categoryId + @"' </script>"; } else { ShowError(errorMessage); } }
/// <summary> /// Sets data to database. /// </summary> protected void SaveReport() { // Check 'Modify' permission if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Modify")) { RedirectToAccessDenied("cms.reporting", "Modify"); } string errorMessage = new Validator().NotEmpty(txtReportDisplayName.Text.Trim(), rfvReportDisplayName.ErrorMessage).NotEmpty(txtReportName.Text.Trim(), rfvReportName.ErrorMessage).Result; if (String.IsNullOrEmpty(errorMessage) && (!ValidationHelper.IsCodeName(txtReportName.Text.Trim()))) { errorMessage = GetString("general.invalidcodename"); } ReportAccessEnum reportAccess = ReportAccessEnum.All; if (!chkReportAccess.Checked) { reportAccess = ReportAccessEnum.Authenticated; } if (String.IsNullOrEmpty(errorMessage)) { ReportInfo reportInfo = ReportInfoProvider.GetReportInfo(reportId); ReportInfo nri = ReportInfoProvider.GetReportInfo(txtReportName.Text.Trim()); // If report with given name already exists show error message if ((nri != null) && (nri.ReportID != reportInfo.ReportID)) { ShowError(GetString("Report_New.ReportAlreadyExists")); return; } if (reportInfo != null) { reportInfo.ReportLayout = htmlTemplateBody.ResolvedValue; // If there was a change in report code name change codenames in layout if (reportInfo.ReportName != txtReportName.Text.Trim()) { // part of old macro string oldValue = "?" + reportInfo.ReportName + "."; string newValue = "?" + txtReportName.Text.Trim() + "."; reportInfo.ReportLayout = reportInfo.ReportLayout.Replace(oldValue, newValue); // Set updated text back to HTML editor htmlTemplateBody.ResolvedValue = reportInfo.ReportLayout; } int categoryID = ValidationHelper.GetInteger(selectCategory.Value, reportInfo.ReportCategoryID); // If there was a change in display name refresh category tree if ((reportInfo.ReportDisplayName != txtReportDisplayName.Text.Trim()) || (reportInfo.ReportCategoryID != categoryID)) { ltlScript.Text += ScriptHelper.GetScript(@"if ((parent != null) && (parent.Refresh != null)) {parent.Refresh();}"); } reportInfo.ReportDisplayName = txtReportDisplayName.Text.Trim(); reportInfo.ReportName = txtReportName.Text.Trim(); reportInfo.ReportAccess = reportAccess; reportInfo.ReportCategoryID = categoryID; reportInfo.ReportEnableSubscription = chkEnableSubscription.Checked; reportInfo.ReportConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty); ReportInfoProvider.SetReportInfo(reportInfo); ShowChangesSaved(); // Reload header if changes were saved ScriptHelper.RefreshTabHeader(Page, reportInfo.ReportDisplayName); } } else { ShowError(errorMessage); } }
/// <summary> /// Clones the given report (including attachment files). /// </summary> /// <param name="reportId">Report id</param> protected void Clone(int reportId) { // Check 'Modify' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify")) { RedirectToAccessDenied("cms.reporting", "Modify"); } // Try to get report info ReportInfo oldri = ReportInfoProvider.GetReportInfo(reportId); if (oldri == null) { return; } DataSet graph_ds = ReportGraphInfoProvider.GetGraphs(reportId); DataSet table_ds = ReportTableInfoProvider.GetTables(reportId); DataSet value_ds = ReportValueInfoProvider.GetValues(reportId); // Duplicate report info object ReportInfo ri = new ReportInfo(oldri, false); ri.ReportID = 0; ri.ReportGUID = Guid.NewGuid(); // Duplicate report info string reportName = ri.ReportName; string oldReportName = ri.ReportName; string reportDispName = ri.ReportDisplayName; while (ReportInfoProvider.GetReportInfo(reportName) != null) { reportName = Increment(reportName, "_", "", 100); reportDispName = Increment(reportDispName, "(", ")", 450); } ri.ReportName = reportName; ri.ReportDisplayName = reportDispName; // Used to eliminate version from create object task using (CMSActionContext context = new CMSActionContext()) { context.CreateVersion = false; ReportInfoProvider.SetReportInfo(ri); } string name; // Duplicate graph data if (!DataHelper.DataSourceIsEmpty(graph_ds)) { foreach (DataRow dr in graph_ds.Tables[0].Rows) { // Duplicate the graph ReportGraphInfo rgi = new ReportGraphInfo(dr); rgi.GraphID = 0; rgi.GraphGUID = Guid.NewGuid(); rgi.GraphReportID = ri.ReportID; name = rgi.GraphName; // Replace layout based on HTML or regular graph type ri.ReportLayout = ReplaceMacro(ri.ReportLayout, rgi.GraphIsHtml ? REP_HTMLGRAPH_MACRO : REP_GRAPH_MACRO, rgi.GraphName, name, oldReportName, reportName); rgi.GraphName = name; ReportGraphInfoProvider.SetReportGraphInfo(rgi); } } // Duplicate table data if (!DataHelper.DataSourceIsEmpty(table_ds)) { foreach (DataRow dr in table_ds.Tables[0].Rows) { // Duplicate the table ReportTableInfo rti = new ReportTableInfo(dr); rti.TableID = 0; rti.TableGUID = Guid.NewGuid(); rti.TableReportID = ri.ReportID; name = rti.TableName; ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_TABLE_MACRO, rti.TableName, name, oldReportName, reportName); rti.TableName = name; ReportTableInfoProvider.SetReportTableInfo(rti); } } // Duplicate value data if (!DataHelper.DataSourceIsEmpty(value_ds)) { foreach (DataRow dr in value_ds.Tables[0].Rows) { // Duplicate the value ReportValueInfo rvi = new ReportValueInfo(dr); rvi.ValueID = 0; rvi.ValueGUID = Guid.NewGuid(); rvi.ValueReportID = ri.ReportID; name = rvi.ValueName; ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_VALUE_MACRO, rvi.ValueName, name, oldReportName, reportName); rvi.ValueName = name; ReportValueInfoProvider.SetReportValueInfo(rvi); } } List <Guid> convTable = new List <Guid>(); try { MetaFileInfoProvider.CopyMetaFiles(reportId, ri.ReportID, ReportingObjectType.REPORT, MetaFileInfoProvider.OBJECT_CATEGORY_LAYOUT, convTable); } catch (Exception e) { lblError.Visible = true; lblError.Text = e.Message; ReportInfoProvider.DeleteReportInfo(ri); return; } for (int i = 0; i < convTable.Count; i += 2) { Guid oldGuid = convTable[i]; Guid newGuid = convTable[i + 1]; ri.ReportLayout = ri.ReportLayout.Replace(oldGuid.ToString(), newGuid.ToString()); } ReportInfoProvider.SetReportInfo(ri); // Refresh tree ltlScript.Text += "<script type=\"text/javascript\">"; ltlScript.Text += @"if (parent.frames['reportcategorytree']) { parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"'; } if (parent.parent.frames['reportcategorytree']) { parent.parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"'; } this.location.href = 'Report_Edit.aspx?reportId=" + Convert.ToString(ri.ReportID) + @"&saved=1&categoryID=" + categoryId + @"' </script>"; }