Example #1
0
    /// <summary>
    /// Gets and bulk updates report values. Called when the "Get and bulk update values" button is pressed.
    /// Expects the CreateReportValue method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateReportValues()
    {
        // Prepare the parameters
        string where = "ValueName LIKE N'MyNewValue%'";

        // Get the data
        DataSet values = ReportValueInfoProvider.GetValues(where, null);

        if (!DataHelper.DataSourceIsEmpty(values))
        {
            // Loop through the individual items
            foreach (DataRow valueDr in values.Tables[0].Rows)
            {
                // Create object from DataRow
                ReportValueInfo modifyValue = new ReportValueInfo(valueDr);

                // Update the properties
                modifyValue.ValueDisplayName = modifyValue.ValueDisplayName.ToUpper();

                // Save the changes
                ReportValueInfoProvider.SetReportValueInfo(modifyValue);
            }

            return(true);
        }

        return(false);
    }
    private string GetReportValue(DataSet ds, ReportValueInfo rvi)
    {
        var value = "";
        var row   = ds.Tables[0].Rows[0];

        if (string.IsNullOrEmpty(rvi.ValueFormatString))
        {
            value = ValidationHelper.GetString(row[0], string.Empty);
        }
        else
        {
            try
            {
                value = string.Format(rvi.ValueFormatString, row.ItemArray);
            }
            catch (FormatException ex)
            {
                lblError.Visible = true;
                lblError.Text    = "Invalid format string: " + ex.Message;
                EventLogProvider.LogException("Report value", "E", ex);
            }
        }

        return(value);
    }
Example #3
0
    /// <summary>
    /// Creates report value. Called when the "Create value" button is pressed.
    /// </summary>
    private bool CreateReportValue()
    {
        // Get report object by report code name
        ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");

        // If report exists
        if (report != null)
        {
            // Create new report value object
            ReportValueInfo newValue = new ReportValueInfo();

            // Set the properties
            newValue.ValueDisplayName            = "My new value";
            newValue.ValueName                   = "MyNewValue";
            newValue.ValueQuery                  = "SELECT COUNT(DocumentName) FROM CMS_Document";
            newValue.ValueQueryIsStoredProcedure = false;
            newValue.ValueReportID               = report.ReportID;

            // Save the report value
            ReportValueInfoProvider.SetReportValueInfo(newValue);

            return(true);
        }
        return(false);
    }
Example #4
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);
    }
Example #5
0
    /// <summary>
    /// Deletes report value. Called when the "Delete value" button is pressed.
    /// Expects the CreateReportValue method to be run first.
    /// </summary>
    private bool DeleteReportValue()
    {
        // Get the report value
        ReportValueInfo deleteValue = ReportValueInfoProvider.GetReportValueInfo("MyNewValue");

        // Delete the report value
        ReportValueInfoProvider.DeleteReportValueInfo(deleteValue);

        return(deleteValue != null);
    }
    /// <summary>
    /// Returns true if graph belongs to report.
    /// </summary>
    /// <param name="report">Report to validate</param>
    public override bool IsValid(ReportInfo report)
    {
        ReportValueInfo rvi = ValueInfo;

        if ((report != null) && (rvi != null) && (report.ReportID == rvi.ValueReportID))
        {
            return(true);
        }

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

        if (gi != null)
        {
            mReportValueInfo = gi.MainObject as ReportValueInfo;
        }
        LoadData();
    }
Example #8
0
    /// <summary>
    /// Gets and updates report value. Called when the "Get and update value" button is pressed.
    /// Expects the CreateReportValue method to be run first.
    /// </summary>
    private bool GetAndUpdateReportValue()
    {
        // Get the report value
        ReportValueInfo updateValue = ReportValueInfoProvider.GetReportValueInfo("MyNewValue");

        if (updateValue != null)
        {
            // Update the properties
            updateValue.ValueDisplayName = updateValue.ValueDisplayName.ToLower();

            // Save the changes
            ReportValueInfoProvider.SetReportValueInfo(updateValue);

            return(true);
        }

        return(false);
    }
Example #9
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);
                }
            }
        }
    }
    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);
    }
    /// <summary>
    /// Save data.
    /// </summary>
    /// <param name="saveToDatabase">If true, data are saved into database</param>
    private bool SetData(bool saveToDatabase = false)
    {
        string errorMessage = String.Empty;
        if (saveToDatabase)
        {
            // Check 'Modify' permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            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.erroridentifierformat");
            }

            string fullName = mReportInfo.ReportName + "." + txtCodeName.Text.Trim();
            ReportValueInfo codeNameCheck = ReportValueInfoProvider.GetReportValueInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.ValueID != mValueId))
            {
                errorMessage = GetString("Reporting_ReportValue_Edit.ErrorCodeNameExist");
            }
        }

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

        if ((errorMessage == ""))
        {
            //new Value
            if (mReportValueInfo == null)
            {
                mReportValueInfo = new ReportValueInfo();
            }

            mReportValueInfo.ValueDisplayName = txtDisplayName.Text.Trim();
            mReportValueInfo.ValueName = txtCodeName.Text.Trim();

            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                mReportValueInfo.ValueQuery = txtQuery.Text.Trim();
            }

            mReportValueInfo.ValueQueryIsStoredProcedure = chkIsProcedure.Checked;
            mReportValueInfo.ValueFormatString = txtFormatString.Text.Trim();
            mReportValueInfo.ValueReportID = mReportInfo.ReportID;
            mReportValueInfo.ValueSettings["SubscriptionEnabled"] = chkSubscription.Checked.ToString();
            mReportValueInfo.ValueConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty);

            if (saveToDatabase)
            {
                ReportValueInfoProvider.SetReportValueInfo(mReportValueInfo);
            }
        }
        else
        {
            ShowError(errorMessage);
            return false;
        }
        return true;
    }
 /// <summary>
 /// Get info from PersistentEditedObject and reload data
 /// </summary>
 private void ReloadDataAfrterRollback()
 {
     // Load rollbacked info
     GeneralizedInfo gi = PersistentEditedObject as GeneralizedInfo;
     if (gi != null)
     {
         mReportValueInfo = gi.MainObject as ReportValueInfo;
     }
     LoadData();
 }
    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;

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

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

        tabControlElem.UsePostback = true;

        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

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

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

        if (mReportInfo != null) //must be valid reportid parameter
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

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

            if (PersistentEditedObject == null)
            {
                int id = QueryHelper.GetInteger("objectid", 0);
                if (id > 0)
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(id);
                    mReportValueInfo = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                mReportValueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (mReportValueInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportValue_Edit.TitleText");
                mValueId = mReportValueInfo.ValueID;

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

                    versionList.Object = mReportValueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                PageTitle.TitleText = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                chkSubscription.Checked = true;

                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            ShowError(GetString("Reporting_ReportValue_Edit.InvalidReportId"));
        }

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

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

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
    }
    /// <summary>
    /// Save data.
    /// </summary>
    /// <returns>return true if save was successfull</returns>
    protected bool Save(bool save)
    {
        string errorMessage = String.Empty;
        if (save)
        {
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            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.IsCodeName(txtCodeName.Text.Trim())))
            {
                errorMessage = GetString("general.erroridentificatorformat");
            }

            string fullName = reportInfo.ReportName + "." + txtCodeName.Text.Trim();
            ReportValueInfo codeNameCheck = ReportValueInfoProvider.GetReportValueInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.ValueID != valueId))
            {
                errorMessage = GetString("Reporting_ReportValue_Edit.ErrorCodeNameExist");
            }
        }

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

        if ((errorMessage == ""))
        {
            //new Value
            if (valueInfo == null)
            {
                valueInfo = new ReportValueInfo();
            }

            valueInfo.ValueDisplayName = txtDisplayName.Text.Trim();
            valueInfo.ValueName = txtCodeName.Text.Trim();

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

            valueInfo.ValueQueryIsStoredProcedure = chkIsProcedure.Checked;
            valueInfo.ValueFormatString = txtFormatString.Text.Trim();
            valueInfo.ValueReportID = reportInfo.ReportID;

            if (save)
            {
                ReportValueInfoProvider.SetReportValueInfo(valueInfo);
            }
        }
        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);

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

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

        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

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

        if (reportInfo != null) //must be valid reportid parameter
        {
            if (PersistentEditedObject == null)
            {

                string valueName = ValidationHelper.GetString(Request.QueryString["itemname"], "");
                if (ValidationHelper.IsCodeName(valueName))
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(reportInfo.ReportName + "." + valueName);
                    valueInfo = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                valueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (valueInfo != null)
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportValue_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/object.png");

                valueId = valueInfo.ValueID;

                if (ObjectVersionManager.DisplayVersionsTab(valueInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";
                    versionList.Object = valueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/new.png");

                newValue = true;
            }

            // set help key
            CurrentMaster.Title.HelpTopicName = "report_value_properties";

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            btnOk.Visible = false;
            lblError.Visible = true;
            lblError.Text = GetString("Reporting_ReportValue_Edit.InvalidReportId");
        }
        btnOk.Text = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text = GetString("General.Apply");

        if (preview)
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }
    }
Example #16
0
    /// <summary>
    /// Gets and bulk updates report values. Called when the "Get and bulk update values" button is pressed.
    /// Expects the CreateReportValue method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateReportValues()
    {
        // Prepare the parameters
        string where = "ValueName LIKE N'MyNewValue%'";

        // Get the data
        DataSet values = ReportValueInfoProvider.GetValues(where, null);
        if (!DataHelper.DataSourceIsEmpty(values))
        {
            // Loop through the individual items
            foreach (DataRow valueDr in values.Tables[0].Rows)
            {
                // Create object from DataRow
                ReportValueInfo modifyValue = new ReportValueInfo(valueDr);

                // Update the properties
                modifyValue.ValueDisplayName = modifyValue.ValueDisplayName.ToUpper();

                // Save the changes
                ReportValueInfoProvider.SetReportValueInfo(modifyValue);
            }

            return true;
        }

        return false;
    }
Example #17
0
    /// <summary>
    /// Creates report value. Called when the "Create value" button is pressed.
    /// </summary>
    private bool CreateReportValue()
    {
        // Get report object by report code name
        ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");

        // If report exists
        if (report != null)
        {

            // Create new report value object
            ReportValueInfo newValue = new ReportValueInfo();

            // Set the properties
            newValue.ValueDisplayName = "My new value";
            newValue.ValueName = "MyNewValue";
            newValue.ValueQuery = "SELECT COUNT(DocumentName) FROM CMS_Document";
            newValue.ValueQueryIsStoredProcedure = false;
            newValue.ValueReportID = report.ReportID;

            // Save the report value
            ReportValueInfoProvider.SetReportValueInfo(newValue);

            return true;
        }
        return false;
    }
Example #18
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>";
    }
Example #19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope               = PredefinedObjectType.REPORT;
        ConnectionStringRow.Visible        = CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

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

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

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

        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

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

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

        if (reportInfo != null) //must be valid reportid parameter
        {
            ucSelectString.DefaultConnectionString = reportInfo.ReportConnectionString;

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

            if (PersistentEditedObject == null)
            {
                int id = QueryHelper.GetInteger("itemid", 0);
                if (id > 0)
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(id);
                    valueInfo = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                valueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (valueInfo != null)
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportValue_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/object_light.png");

                valueId = valueInfo.ValueID;

                if (ObjectVersionManager.DisplayVersionsTab(valueInfo))
                {
                    tabs[2, 0]             = GetString("objectversioning.tabtitle");
                    tabs[2, 1]             = "SetHelpTopic('helpTopic', 'objectversioning_general');";
                    versionList.Object     = valueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/new_light.png");

                chkSubscription.Checked = true;
                newValue = true;

                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                }
            }

            // set help key
            CurrentMaster.Title.HelpTopicName = "report_value_properties";

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            btnOk.Visible = false;
            ShowError(GetString("Reporting_ReportValue_Edit.InvalidReportId"));
        }
        btnOk.Text     = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text  = GetString("General.Apply");

        if (preview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }
    }
Example #20
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>";
    }
Example #21
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        try
        {
            // Load value info object
            ReportValueInfo rvi = ValueInfo;

            if (rvi != null)
            {
                //Test security
                ReportInfo ri = ReportInfoProvider.GetReportInfo(rvi.ValueReportID);
                if (ri.ReportAccess != ReportAccessEnum.All)
                {
                    if (!CMSContext.CurrentUser.IsAuthenticated())
                    {
                        this.Visible = false;
                        return;
                    }
                }

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

                this.QueryIsStoredProcedure = rvi.ValueQueryIsStoredProcedure;
                this.QueryText = resolver.ResolveMacros(rvi.ValueQuery);

                //Set default parametrs directly if not set
                if (this.ReportParameters == null)
                {
                    if (ri != null)
                    {
                        FormInfo fi = new FormInfo(ri.ReportParameters);
                        // Get datarow with required columns
                        this.ReportParameters = fi.GetDataRow();
                        fi.LoadDefaultValues(this.ReportParameters, true);
                    }
                }
            }

            // Only use base parameters in case of stored procedure
            if (this.QueryIsStoredProcedure)
            {
                this.AllParameters = SpecialFunctions.ConvertDataRowToParams(this.ReportParameters, null);
            }

            // Load data
            DataSet ds = this.LoadData();

            // If datasource is emptry, create empty dataset
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Set literal text
                string value = rvi.ValueFormatString;
                if ((value == null) || (value == ""))
                {
                    value = ValidationHelper.GetString(ds.Tables[0].Rows[0][0], "");
                }
                else
                {
                    value = string.Format(value, ds.Tables[0].Rows[0].ItemArray);
                }

                lblValue.Text = HTMLHelper.HTMLEncode(ResolveMacros(value));
            }
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text    = "[ReportValue.ascx] Error loading the data: " + ex.Message;
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Report value", "E", ex);
        }
    }
Example #22
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;

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

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

        tabControlElem.UsePostback = true;

        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

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

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

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

        if (mReportInfo != null) //must be valid reportid parameter
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

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

            if (PersistentEditedObject == null)
            {
                int id = QueryHelper.GetInteger("objectid", 0);
                if (id > 0)
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(id);
                    mReportValueInfo       = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                mReportValueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (mReportValueInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportValue_Edit.TitleText");
                mValueId            = mReportValueInfo.ValueID;

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

                    versionList.Object     = mReportValueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                PageTitle.TitleText     = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                chkSubscription.Checked = true;

                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            ShowError(GetString("Reporting_ReportValue_Edit.InvalidReportId"));
        }

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

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

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
        CurrentMaster.PanelContent.RemoveCssClass("ModalDialogContent");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope = PredefinedObjectType.REPORT;
        ConnectionStringRow.Visible = CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

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

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

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

        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

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

        if (reportInfo != null) //must be valid reportid parameter
        {
            ucSelectString.DefaultConnectionString = reportInfo.ReportConnectionString;

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

            if (PersistentEditedObject == null)
            {
                int id = QueryHelper.GetInteger("itemid", 0);
                if (id > 0)
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(id);
                    valueInfo = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                valueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (valueInfo != null)
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportValue_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/object_light.png");

                valueId = valueInfo.ValueID;

                if (ObjectVersionManager.DisplayVersionsTab(valueInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";
                    versionList.Object = valueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/new_light.png");

                chkSubscription.Checked = true;
                newValue = true;

                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                }
            }

            // set help key
            CurrentMaster.Title.HelpTopicName = "report_value_properties";

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            btnOk.Visible = false;
            ShowError(GetString("Reporting_ReportValue_Edit.InvalidReportId"));
        }
        btnOk.Text = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text = GetString("General.Apply");

        if (preview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }
    }
Example #24
0
    /// <summary>
    /// Save data.
    /// </summary>
    /// <param name="saveToDatabase">If true, data are saved into database</param>
    private bool SetData(bool saveToDatabase = false)
    {
        string errorMessage = String.Empty;

        if (saveToDatabase)
        {
            // Check 'Modify' permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            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.erroridentifierformat");
            }

            string          fullName      = mReportInfo.ReportName + "." + txtCodeName.Text.Trim();
            ReportValueInfo codeNameCheck = ReportValueInfoProvider.GetReportValueInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.ValueID != mValueId))
            {
                errorMessage = GetString("Reporting_ReportValue_Edit.ErrorCodeNameExist");
            }
        }

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

        if ((errorMessage == ""))
        {
            //new Value
            if (mReportValueInfo == null)
            {
                mReportValueInfo = new ReportValueInfo();
            }

            mReportValueInfo.ValueDisplayName = txtDisplayName.Text.Trim();
            mReportValueInfo.ValueName        = txtCodeName.Text.Trim();

            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                mReportValueInfo.ValueQuery = txtQuery.Text.Trim();
            }

            mReportValueInfo.ValueQueryIsStoredProcedure = chkIsProcedure.Checked;
            mReportValueInfo.ValueFormatString           = txtFormatString.Text.Trim();
            mReportValueInfo.ValueReportID = mReportInfo.ReportID;
            mReportValueInfo.ValueSettings["SubscriptionEnabled"] = chkSubscription.Checked.ToString();
            mReportValueInfo.ValueConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty);

            if (saveToDatabase)
            {
                ReportValueInfoProvider.SetReportValueInfo(mReportValueInfo);
            }
        }
        else
        {
            ShowError(errorMessage);
            return(false);
        }
        return(true);
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        // Load value info object
        ReportValueInfo rvi = ValueInfo;

        if (rvi == null)
        {
            return;
        }

        ri = ReportInfoProvider.GetReportInfo(rvi.ValueReportID);
        if (ri == null)
        {
            return;
        }

        // Check security settings
        if (!(CheckReportAccess(ri) && CheckEmailModeSubscription(ri, ValidationHelper.GetBoolean(ValueInfo.ValueSettings["SubscriptionEnabled"], true))))
        {
            Visible = false;
            return;
        }

        // Prepare query attributes
        QueryIsStoredProcedure = rvi.ValueQueryIsStoredProcedure;
        QueryText = rvi.ValueQuery;

        // Init parameters
        InitParameters(ri.ReportParameters);

        // Init macro resolver
        InitResolver();

        DataSet ds = null;

        // Ensure report item name for caching
        if (String.IsNullOrEmpty(ReportItemName))
        {
            ReportItemName = String.Format("{0};{1}", ri.ReportName, rvi.ValueName);
        }

        try
        {
            // Load data
            ds = LoadData();
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text    = "Error loading the data: " + ex.Message;
            EventLogProvider.LogException("Report value", "E", ex);
        }

        string value;

        // If data source or result is empty, send an empty dataset
        if (DataHelper.DataSourceIsEmpty(ds) || string.IsNullOrEmpty(value = GetReportValue(ds, rvi)))
        {
            if (EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
            }

            return;
        }

        if (EmailMode)
        {
            ltlEmail.Text    = HTMLHelper.HTMLEncode(ResolveMacros(value));
            ltlEmail.Visible = true;
            menuCont.Visible = false;
        }
        else
        {
            lblValue.Text = HTMLHelper.HTMLEncode(ResolveMacros(value));
        }
    }
Example #26
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);

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

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

        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

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

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

        if (reportInfo != null) //must be valid reportid parameter
        {
            if (PersistentEditedObject == null)
            {
                string valueName = ValidationHelper.GetString(Request.QueryString["itemname"], "");
                if (ValidationHelper.IsIdentifier(valueName))
                {
                    PersistentEditedObject = ReportValueInfoProvider.GetReportValueInfo(reportInfo.ReportName + "." + valueName);
                    valueInfo = PersistentEditedObject as ReportValueInfo;
                }
            }
            else
            {
                valueInfo = PersistentEditedObject as ReportValueInfo;
            }

            if (valueInfo != null)
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportValue_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/object.png");

                valueId = valueInfo.ValueID;

                if (ObjectVersionManager.DisplayVersionsTab(valueInfo))
                {
                    tabs[2, 0]             = GetString("objectversioning.tabtitle");
                    tabs[2, 1]             = "SetHelpTopic('helpTopic', 'objectversioning_general');";
                    versionList.Object     = valueInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else //new item
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportValue_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportValue/new.png");

                newValue = true;
            }

            // set help key
            CurrentMaster.Title.HelpTopicName = "report_value_properties";

            if (!RequestHelper.IsPostBack())
            {
                LoadData();
            }
        }
        else
        {
            btnOk.Visible    = false;
            lblError.Visible = true;
            lblError.Text    = GetString("Reporting_ReportValue_Edit.InvalidReportId");
        }
        btnOk.Text     = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text  = GetString("General.Apply");

        if (preview)
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        // Load value info object
        ReportValueInfo rvi = ValueInfo;

        if (rvi == null)
        {
            return;
        }

        ri = ReportInfoProvider.GetReportInfo(rvi.ValueReportID);
        if (ri == null)
        {
            return;
        }

        // Check security settings
        if (!(CheckReportAccess(ri) && CheckEmailModeSubscription(ri, ValidationHelper.GetBoolean(ValueInfo.ValueSettings["SubscriptionEnabled"], true))))
        {
            Visible = false;
            return;
        }

        // Prepare query attributes
        QueryIsStoredProcedure = rvi.ValueQueryIsStoredProcedure;
        QueryText = rvi.ValueQuery;

        // Init parameters
        InitParameters(ri.ReportParameters);

        // Init macro resolver
        InitResolver();

        DataSet ds = null;

        try
        {
            // Load data
            ds = LoadData();
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text    = "[ReportValue.ascx] Error loading the data: " + ex.Message;
            EventLogProvider.LogException("Report value", "E", ex);
        }

        // If datasource is emptry, create empty dataset
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Set literal text
            string value = rvi.ValueFormatString;
            if (String.IsNullOrEmpty(value))
            {
                value = ValidationHelper.GetString(ds.Tables[0].Rows[0][0], String.Empty);
            }
            else
            {
                value = string.Format(value, ds.Tables[0].Rows[0].ItemArray);
            }

            if (EmailMode)
            {
                ltlEmail.Text    = HTMLHelper.HTMLEncode(ResolveMacros(value));
                ltlEmail.Visible = true;
                menuCont.Visible = false;
            }
            else
            {
                lblValue.Text = HTMLHelper.HTMLEncode(ResolveMacros(value));
            }
        }
        else if (EmailMode && SendOnlyNonEmptyDataSource)
        {
            Visible = false;
        }
    }
Example #28
0
    /// <summary>
    /// Save data.
    /// </summary>
    /// <returns>return true if save was successfull</returns>
    protected bool Save(bool save)
    {
        string errorMessage = String.Empty;

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

            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();
            ReportValueInfo codeNameCheck = ReportValueInfoProvider.GetReportValueInfo(fullName);

            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.ValueID != valueId))
            {
                errorMessage = GetString("Reporting_ReportValue_Edit.ErrorCodeNameExist");
            }
        }

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

        if ((errorMessage == ""))
        {
            //new Value
            if (valueInfo == null)
            {
                valueInfo = new ReportValueInfo();
            }

            valueInfo.ValueDisplayName = txtDisplayName.Text.Trim();
            valueInfo.ValueName        = txtCodeName.Text.Trim();

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

            valueInfo.ValueQueryIsStoredProcedure = chkIsProcedure.Checked;
            valueInfo.ValueFormatString           = txtFormatString.Text.Trim();
            valueInfo.ValueReportID = reportInfo.ReportID;

            if (save)
            {
                ReportValueInfoProvider.SetReportValueInfo(valueInfo);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
            return(false);
        }
        return(true);
    }