Exemple #1
0
    /// <summary>
    /// Creates report table. Called when the "Create table" button is pressed.
    /// </summary>
    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);
    }
Exemple #2
0
    /// <summary>
    /// Gets and bulk updates report tables. Called when the "Get and bulk update tables" button is pressed.
    /// Expects the CreateReportTable method to be run first.
    /// </summary>
    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);
    }
Exemple #3
0
    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);
    }
Exemple #4
0
    /// <summary>
    /// Deletes report table. Called when the "Delete table" button is pressed.
    /// Expects the CreateReportTable method to be run first.
    /// </summary>
    private bool DeleteReportTable()
    {
        // Get the report table
        ReportTableInfo deleteTable = ReportTableInfoProvider.GetReportTableInfo("MyNewTable");

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

        return(deleteTable != null);
    }
Exemple #5
0
    /// <summary>
    /// Returns true if graph belongs to report.
    /// </summary>
    /// <param name="report">Report to validate</param>
    public override bool IsValid(ReportInfo report)
    {
        ReportTableInfo rti = TableInfo;

        if ((report != null) && (rti != null) && (report.ReportID == rti.TableReportID))
        {
            return(true);
        }

        return(false);
    }
Exemple #6
0
    /// <summary>
    /// Get info from PersistentEditedObject and reload data
    /// </summary>
    private void ReloadDataAfrterRollback()
    {
        // Load rollbacked info
        GeneralizedInfo gi = PersistentEditedObject as GeneralizedInfo;

        if (gi != null)
        {
            tableInfo = gi.MainObject as ReportTableInfo;
        }
        LoadData();
    }
Exemple #7
0
    /// <summary>
    /// Gets and updates report table. Called when the "Get and update table" button is pressed.
    /// Expects the CreateReportTable method to be run first.
    /// </summary>
    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);
    }
Exemple #8
0
    protected void btnHdnDelete_Click(object sender, EventArgs e)
    {
        // Check 'Modify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
        {
            CMSReportingPage.RedirectToCMSDeskAccessDenied("cms.reporting", "Modify");
        }

        string itemName = "";

        if (hdnItemId.Value != "")
        {
            itemName = Report.ReportName + "." + ValidationHelper.GetString(hdnItemId.Value, "");

            if ((mItemType == ReportItemType.Graph) || (mItemType == ReportItemType.HtmlGraph))
            {
                ReportGraphInfo rgi = ReportGraphInfoProvider.GetReportGraphInfo(itemName);

                if (rgi != null)
                {
                    ReportGraphInfoProvider.DeleteReportGraphInfo(rgi.GraphID);
                }
            }
            else if (mItemType == ReportItemType.Table)
            {
                ReportTableInfo rti = ReportTableInfoProvider.GetReportTableInfo(itemName);

                if (rti != null)
                {
                    ReportTableInfoProvider.DeleteReportTableInfo(rti.TableID);
                }
            }
            else if (mItemType == ReportItemType.Value)
            {
                ReportValueInfo rvi = ReportValueInfoProvider.GetReportValueInfo(itemName);

                if (rvi != null)
                {
                    ReportValueInfoProvider.DeleteReportValueInfo(rvi.ValueID);
                }
            }
        }
    }
    /// <summary>
    /// Ensires teble info object.
    /// </summary>
    private void EnsureTableInfo()
    {
        ReportTableInfo rti = TableInfo;

        if (rti != null)
        {
            QueryIsStoredProcedure = rti.TableQueryIsStoredProcedure;

            // Resolve dynamic data macros
            if (DynamicMacros != null)
            {
                for (int i = 0; i <= DynamicMacros.GetUpperBound(0); i++)
                {
                    ContextResolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                }
            }

            QueryText = ResolveMacros(rti.TableQuery);
            TableInfo = rti;
        }
    }
    public static string GetReportItemName(string type, int id)
    {
        // Switch by type
        switch (ReportInfoProvider.StringToReportItemType(type))
        {
        // Graph
        case ReportItemType.Graph:
        case ReportItemType.HtmlGraph:
            ReportGraphInfo rgi = ReportGraphInfoProvider.GetReportGraphInfo(id);
            if (rgi != null)
            {
                return(rgi.GraphName);
            }
            break;

        // Table
        case ReportItemType.Table:
            ReportTableInfo rti = ReportTableInfoProvider.GetReportTableInfo(id);
            if (rti != null)
            {
                return(rti.TableName);
            }
            break;

        // Value
        case ReportItemType.Value:
            ReportValueInfo rvi = ReportValueInfoProvider.GetReportValueInfo(id);
            if (rvi != null)
            {
                return(rvi.ValueName);
            }
            break;
        }

        return(String.Empty);
    }
Exemple #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope               = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible        = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        txtQuery.Enabled = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries");

        versionList.OnAfterRollback += versionList_onAfterRollback;

        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.general")
        });

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.preview")
        });

        tabControlElem.UsePostback = true;

        rfvCodeName.ErrorMessage    = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");

        Save += (s, ea) =>
        {
            if (SetData(true))
            {
                ltlScript.Text += ScriptHelper.GetScript("window.RefreshContent();CloseDialog();");
            }
        };

        int  reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview  = QueryHelper.GetBoolean("preview", false);

        if (reportId > 0)
        {
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);

        if (isPreview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (mReportInfo != null) // Must be valid reportid parameter
            {
                int id = QueryHelper.GetInteger("objectid", 0);

                // Try to load tableName from hidden field (adding new graph & preview)
                if (id == 0)
                {
                    id = ValidationHelper.GetInteger(txtNewTableHidden.Value, 0);
                }

                if (id > 0)
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(id);
                    mReportTableInfo       = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            mReportTableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (mReportInfo != null)
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

            // Control text initializations
            if (mReportTableInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                mTableId            = mReportTableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(mReportTableInfo))
                {
                    tabControlElem.TabItems.Add(new UITabItem
                    {
                        Text = GetString("objectversioning.tabtitle")
                    });

                    versionList.Object     = mReportTableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value      = String.Empty;
                    txtPageSize.Text          = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked   = true;
                    chkSubscription.Checked   = true;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                ControlsHelper.FillListControlWithEnum <PagerButtons>(drpPageMode, "PagerButtons");
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload default parameters
            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);

            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow(false);
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Collect data and put them in table info
            SetData();
            ctrlReportTable.TableInfo = mReportTableInfo;
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
        CurrentMaster.PanelContent.RemoveCssClass("ModalDialogContent");
    }
Exemple #12
0
    /// <summary>
    /// Gets and bulk updates report tables. Called when the "Get and bulk update tables" button is pressed.
    /// Expects the CreateReportTable method to be run first.
    /// </summary>
    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;
    }
Exemple #13
0
    /// <summary>
    /// Creates report table. Called when the "Create table" button is pressed.
    /// </summary>
    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;
    }
 /// <summary>
 /// Get info from PersistentEditedObject and reload data
 /// </summary>
 private void ReloadDataAfrterRollback()
 {
     // Load rollbacked info
     GeneralizedInfo gi = PersistentEditedObject as GeneralizedInfo;
     if (gi != null)
     {
         tableInfo = gi.MainObject as ReportTableInfo ;
     }
     LoadData();
 }
    /// <summary>
    /// Saves data
    /// </summary>
    /// <returns></returns>
    protected bool Save(bool save)
    {
        string errorMessage = String.Empty;
        // Check 'Modify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
        {
            RedirectToAccessDenied("cms.reporting", "Modify");
        }

        if (save)
        {
            errorMessage = new Validator()
                .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                .NotEmpty(txtQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

            if ((errorMessage == "") && (!ValidationHelper.IsIdentifier(txtCodeName.Text.Trim())))
            {
                errorMessage = GetString("general.erroridentificatorformat");
            }

            string fullName = reportInfo.ReportName + "." + txtCodeName.Text.Trim();
            ReportTableInfo codeNameCheck = ReportTableInfoProvider.GetReportTableInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.TableID != tableId))
            {
                errorMessage = GetString("Reporting_ReportTable_Edit.ErrorCodeNameExist");
            }

        }

        // Test query in all cases
        if (errorMessage == String.Empty)
        {
            errorMessage = new Validator().NotEmpty(txtQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;
        }

        if ((errorMessage == "") && (txtPageSize.Text.Trim() != String.Empty) && (!ValidationHelper.IsInteger(txtPageSize.Text) || !ValidationHelper.IsPositiveNumber(txtPageSize.Text)))
        {
            errorMessage = GetString("Reporting_ReportTable_Edit.errorinvalidpagesize");
        }

        if ((errorMessage == ""))
        {
            // New table
            if (tableInfo == null)
            {
                tableInfo = new ReportTableInfo();
            }

            tableInfo.TableDisplayName = txtDisplayName.Text.Trim();
            tableInfo.TableName = txtCodeName.Text.Trim();

            if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                tableInfo.TableQuery = txtQuery.Text.Trim();
            }

            tableInfo.TableQueryIsStoredProcedure = chkIsProcedure.Checked;
            tableInfo.TableReportID = reportInfo.ReportID;

            tableInfo.TableSettings["SkinID"] = txtSkinID.Text.Trim();
            tableInfo.TableSettings["enablepaging"] = chkEnablePaging.Checked.ToString();
            tableInfo.TableSettings["pagesize"] = txtPageSize.Text;
            tableInfo.TableSettings["pagemode"] = drpPageMode.SelectedValue;
            tableInfo.TableSettings["QueryNoRecordText"] = txtQueryNoRecordText.Text;
            tableInfo.TableSettings["ExportEnabled"] = chkExportEnable.Checked.ToString();

            if (save)
            {
                ReportTableInfoProvider.SetReportTableInfo(tableInfo);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = errorMessage;
            return false;
        }

        return true;
    }
Exemple #16
0
    /// <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>";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        txtQuery.Enabled = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries");

        versionList.OnAfterRollback += versionList_onAfterRollback;

        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.general")
        });

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.preview")
        });

        tabControlElem.UsePostback = true;

        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");

        Save += (s, ea) =>
        {
            if (SetData(true))
            {
                ltlScript.Text += ScriptHelper.GetScript("window.RefreshContent();CloseDialog();");
            }
        };

        int reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview = QueryHelper.GetBoolean("preview", false);
        if (reportId > 0)
        {
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);
        if (isPreview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (mReportInfo != null) // Must be valid reportid parameter
            {
                int id = QueryHelper.GetInteger("objectid", 0);

                // Try to load tableName from hidden field (adding new graph & preview)
                if (id == 0)
                {
                    id = ValidationHelper.GetInteger(txtNewTableHidden.Value, 0);
                }

                if (id > 0)
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(id);
                    mReportTableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            mReportTableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (mReportInfo != null)
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

            // Control text initializations
            if (mReportTableInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                mTableId = mReportTableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(mReportTableInfo))
                {
                    tabControlElem.TabItems.Add(new UITabItem
                    {
                        Text = GetString("objectversioning.tabtitle")
                    });

                    versionList.Object = mReportTableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                    txtPageSize.Text = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked = true;
                    chkSubscription.Checked = true;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                ControlsHelper.FillListControlWithEnum<PagerButtons>(drpPageMode, "PagerButtons");
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload default parameters
            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);

            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow(false);
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Collect data and put them in table info
            SetData();
            ctrlReportTable.TableInfo = mReportTableInfo;
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
    }
Exemple #18
0
    /// <summary>
    /// Saves data
    /// </summary>
    /// <returns></returns>
    protected bool Save(bool save)
    {
        string errorMessage = String.Empty;

        // Check 'Modify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
        {
            RedirectToAccessDenied("cms.reporting", "Modify");
        }

        if (save)
        {
            errorMessage = new Validator()
                           .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                           .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                           .NotEmpty(txtQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

            if ((errorMessage == "") && (!ValidationHelper.IsIdentifier(txtCodeName.Text.Trim())))
            {
                errorMessage = GetString("general.erroridentificatorformat");
            }

            string          fullName      = reportInfo.ReportName + "." + txtCodeName.Text.Trim();
            ReportTableInfo codeNameCheck = ReportTableInfoProvider.GetReportTableInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.TableID != tableId))
            {
                errorMessage = GetString("Reporting_ReportTable_Edit.ErrorCodeNameExist");
            }
        }

        // Test query in all cases
        if (errorMessage == String.Empty)
        {
            errorMessage = new Validator().NotEmpty(txtQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;
        }

        if ((errorMessage == "") && (txtPageSize.Text.Trim() != String.Empty) && (!ValidationHelper.IsInteger(txtPageSize.Text) || !ValidationHelper.IsPositiveNumber(txtPageSize.Text)))
        {
            errorMessage = GetString("Reporting_ReportTable_Edit.errorinvalidpagesize");
        }

        if ((errorMessage == ""))
        {
            // New table
            if (tableInfo == null)
            {
                tableInfo = new ReportTableInfo();
            }

            tableInfo.TableDisplayName = txtDisplayName.Text.Trim();
            tableInfo.TableName        = txtCodeName.Text.Trim();

            if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                tableInfo.TableQuery = txtQuery.Text.Trim();
            }

            tableInfo.TableQueryIsStoredProcedure = chkIsProcedure.Checked;
            tableInfo.TableReportID = reportInfo.ReportID;

            tableInfo.TableSettings["SkinID"]            = txtSkinID.Text.Trim();
            tableInfo.TableSettings["enablepaging"]      = chkEnablePaging.Checked.ToString();
            tableInfo.TableSettings["pagesize"]          = txtPageSize.Text;
            tableInfo.TableSettings["pagemode"]          = drpPageMode.SelectedValue;
            tableInfo.TableSettings["QueryNoRecordText"] = txtQueryNoRecordText.Text;
            tableInfo.TableSettings["ExportEnabled"]     = chkExportEnable.Checked.ToString();

            if (save)
            {
                ReportTableInfoProvider.SetReportTableInfo(tableInfo);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
            return(false);
        }

        return(true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

        // Own javascript tab change handling -> because tab control raises changetab after prerender - too late
        // Own selected tab change handling
        RegisterTabScript(hdnSelectedTab.ClientID, tabControlElem);

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

        string[,] tabs = new string[4, 4];
        tabs[0, 0] = GetString("general.general");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'report_table_properties')";
        tabs[1, 0] = GetString("general.preview");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'report_table_properties')";

        tabControlElem.Tabs = tabs;
        tabControlElem.UsePostback = true;
        CurrentMaster.Title.HelpName = "helpTopic";
        CurrentMaster.Title.HelpTopicName = "report_table_properties";
        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";

        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        btnApply.Text = GetString("General.apply");
        btnOk.Text = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");

        int reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview = QueryHelper.GetBoolean("preview", false);
        if (reportId > 0)
        {
            reportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);
        if (isPreview && !RequestHelper.IsPostBack())
        {
            SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) // Must be valid reportid parameter
            {
                string tableName = ValidationHelper.GetString(Request.QueryString["itemname"], "");

                // Try to load tableName from hidden field (adding new graph & preview)
                if (tableName == String.Empty)
                {
                    tableName = txtNewTableHidden.Value;
                }

                if (ValidationHelper.IsIdentifier(tableName))
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(reportInfo.ReportName + "." + tableName);
                    tableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            tableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (reportInfo != null)
        {
            // Control text initializations
            if (tableInfo != null)
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/object.png");

                tableId = tableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(tableInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";

                    versionList.Object = tableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/new.png");

                if (!RequestHelper.IsPostBack())
                {
                    txtPageSize.Text = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked = true;
                }

                newTable = true;
            }

            // Set help key
            CurrentMaster.Title.HelpTopicName = "report_table_properties";

            if (!RequestHelper.IsPostBack())
            {
                DataHelper.FillListControlWithEnum(typeof(PagerButtons), drpPageMode, "PagerButtons.", null);
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload deafult parameters
            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow();
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Colect data and put them in talbe info
            Save(false);
            ctrlReportTable.TableInfo = tableInfo;
        }
    }
Exemple #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

        // Own javascript tab change handling -> because tab control raises changetab after prerender - too late
        // Own selected tab change handling
        RegisterTabScript(hdnSelectedTab.ClientID, tabControlElem);

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

        string[,] tabs = new string[4, 4];
        tabs[0, 0]     = GetString("general.general");
        tabs[0, 1]     = "SetHelpTopic('helpTopic', 'report_table_properties')";
        tabs[1, 0]     = GetString("general.preview");
        tabs[0, 1]     = "SetHelpTopic('helpTopic', 'report_table_properties')";

        tabControlElem.Tabs               = tabs;
        tabControlElem.UsePostback        = true;
        CurrentMaster.Title.HelpName      = "helpTopic";
        CurrentMaster.Title.HelpTopicName = "report_table_properties";
        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";

        rfvCodeName.ErrorMessage    = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        btnApply.Text  = GetString("General.apply");
        btnOk.Text     = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");

        int  reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview  = QueryHelper.GetBoolean("preview", false);

        if (reportId > 0)
        {
            reportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);

        if (isPreview && !RequestHelper.IsPostBack())
        {
            SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) // Must be valid reportid parameter
            {
                string tableName = ValidationHelper.GetString(Request.QueryString["itemname"], "");

                // Try to load tableName from hidden field (adding new graph & preview)
                if (tableName == String.Empty)
                {
                    tableName = txtNewTableHidden.Value;
                }

                if (ValidationHelper.IsIdentifier(tableName))
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(reportInfo.ReportName + "." + tableName);
                    tableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            tableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (reportInfo != null)
        {
            // Control text initializations
            if (tableInfo != null)
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportTable_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/object.png");

                tableId = tableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(tableInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";

                    versionList.Object     = tableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/new.png");

                if (!RequestHelper.IsPostBack())
                {
                    txtPageSize.Text          = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked   = true;
                }

                newTable = true;
            }

            // Set help key
            CurrentMaster.Title.HelpTopicName = "report_table_properties";

            if (!RequestHelper.IsPostBack())
            {
                DataHelper.FillListControlWithEnum(typeof(PagerButtons), drpPageMode, "PagerButtons.", null);
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload deafult parameters
            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow();
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Colect data and put them in talbe info
            Save(false);
            ctrlReportTable.TableInfo = tableInfo;
        }
    }
Exemple #21
0
    /// <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>";
    }