示例#1
0
    /// <summary>
    /// Returns true if graph belongs to report.
    /// </summary>
    /// <param name="report">Report to validate</param>
    public override bool IsValid(ReportInfo report)
    {
        ReportGraphInfo rgi = ReportGraphInfo;

        // Test validity
        if ((report != null) && (rgi != null) && (report.ReportID == rgi.GraphReportID))
        {
            return(true);
        }

        return(false);
    }
示例#2
0
    /// <summary>
    /// Gets and updates report graph. Called when the "Get and update graph" button is pressed.
    /// Expects the CreateReportGraph method to be run first.
    /// </summary>
    private bool GetAndUpdateReportGraph()
    {
        // Get the report graph
        ReportGraphInfo updateGraph = ReportGraphInfoProvider.GetReportGraphInfo("MyNewGraph");

        if (updateGraph != null)
        {
            // Update the properties
            updateGraph.GraphDisplayName = updateGraph.GraphDisplayName.ToLower();

            // Save the changes
            ReportGraphInfoProvider.SetReportGraphInfo(updateGraph);

            return(true);
        }

        return(false);
    }
示例#3
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 the changes to DB
    /// </summary>
    /// <param name="saveToDatabase">If true, data are saved into database</param>
    private bool SetData(bool saveToDatabase = false)
    {
        string errorMessage = String.Empty;
        if (saveToDatabase)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            errorMessage = new Validator()
                .NotEmpty(txtDefaultName.Text, rfvDisplayName.ErrorMessage)
                .NotEmpty(txtDefaultCodeName.Text, rfvCodeName.ErrorMessage)
                .NotEmpty(txtQueryQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

            if ((errorMessage == String.Empty) && (!ValidationHelper.IsIdentifier(txtDefaultCodeName.Text.Trim())))
            {
                errorMessage = GetString("general.erroridentifierformat");
            }

            string fullName = mReportInfo.ReportName + "." + txtDefaultCodeName.Text.Trim();
            ReportGraphInfo codeNameCheck = ReportGraphInfoProvider.GetReportGraphInfo(fullName);
            if ((errorMessage == String.Empty) && (codeNameCheck != null) && (codeNameCheck.GraphID != mGraphId))
            {
                errorMessage = GetString("Reporting_ReportGraph_Edit.ErrorCodeNameExist");
            }
        }

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

        if (errorMessage == String.Empty)
        {
            // New graph
            if (mReportGraphInfo == null)
            {
                mReportGraphInfo = new ReportGraphInfo();
            }

            mReportGraphInfo.GraphDisplayName = txtDefaultName.Text.Trim();
            mReportGraphInfo.GraphName = txtDefaultCodeName.Text.Trim();

            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                mReportGraphInfo.GraphQuery = txtQueryQuery.Text;
            }

            mReportGraphInfo.GraphQueryIsStoredProcedure = chkIsStoredProcedure.Checked;
            mReportGraphInfo.GraphReportID = mReportInfo.ReportID;
            mReportGraphInfo.GraphTitle = txtGraphTitle.Text;
            mReportGraphInfo.GraphIsHtml = true;
            mReportGraphInfo.GraphType = String.Empty;
            mReportGraphInfo.GraphConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty);

            ReportCustomData settings = mReportGraphInfo.GraphSettings;
            settings["QueryNoRecordText"] = txtQueryNoRecordText.Text;
            settings["LegendTitle"] = txtLegendTitle.Text;
            settings["DisplayLegend"] = chkDisplayLegend.Checked.ToString();
            settings["SeriesItemToolTip"] = txtSeriesItemTooltip.Text;
            settings["SeriesItemLink"] = txtSeriesItemLink.Text;
            settings["ItemValueFormat"] = txtItemValueFormat.Text;
            settings["SeriesItemNameFormat"] = txtItemNameFormat.Text;
            settings["ExportEnabled"] = chkExportEnable.Checked.ToString();
            settings["SubscriptionEnabled"] = chkSubscription.Checked.ToString();

            if (saveToDatabase)
            {
                ReportGraphInfoProvider.SetReportGraphInfo(mReportGraphInfo);
            }

            return true;
        }

        ShowError(errorMessage);
        return false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQueryQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

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

        versionList.OnAfterRollback += versionList_onAfterRollback;

        // Register script for resize and rollback
        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;

        Title = "ReportGraph Edit";
        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        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 isPreview = QueryHelper.GetBoolean("preview", false);

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

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

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

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

                if (id > 0)
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(id);
                    mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
        }

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

        if (mReportGraphInfo != null)
        {
            PageTitle.TitleText = GetString("Reporting_ReportGraph_EditHTML.TitleText");
            mGraphId = mReportGraphInfo.GraphID;

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

                versionList.Object = mReportGraphInfo;
                versionList.IsLiveSite = false;
            }
        }
        else
        {
            PageTitle.TitleText = GetString("Reporting_ReportGraph_EditHTML.NewItemTitleText");
            mNewReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Load default data for new report
            if (mNewReport)
            {
                ucSelectString.Value = String.Empty;
                txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                txtItemValueFormat.Text = "{%yval%}";
                txtSeriesItemTooltip.Text = "{%ser%}";
                chkExportEnable.Checked = true;
                chkSubscription.Checked = true;
            }
            // Otherwise load saved data
            else
            {
                LoadData();
            }
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
        CurrentMaster.PanelContent.RemoveCssClass("ModalDialogContent");
    }
示例#7
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>";
    }
示例#8
0
    /// <summary>
    /// Gets and bulk updates report graphs. Called when the "Get and bulk update graphs" button is pressed.
    /// Expects the CreateReportGraph method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateReportGraphs()
    {
        // Prepare the parameters
        string where = "GraphName LIKE N'MyNewGraph%'";

        // Get the data
        DataSet graphs = ReportGraphInfoProvider.GetGraphs(where, null);
        if (!DataHelper.DataSourceIsEmpty(graphs))
        {
            // Loop through the individual items
            foreach (DataRow graphDr in graphs.Tables[0].Rows)
            {
                // Create object from DataRow
                ReportGraphInfo modifyGraph = new ReportGraphInfo(graphDr);

                // Update the properties
                modifyGraph.GraphDisplayName = modifyGraph.GraphDisplayName.ToUpper();

                // Save the changes
                ReportGraphInfoProvider.SetReportGraphInfo(modifyGraph);
            }

            return true;

        }
        return false;
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        // Check whether report graph is defined
        if (reportGraph == null)
        {
            return;
        }

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (!(CheckReportAccess(report) && CheckEmailModeSubscription(report, ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true))))
        {
            Visible = false;
            return;
        }

        // Prepare query attributes
        QueryText = reportGraph.GraphQuery;
        QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

        // Init parameters
        InitParameters(report.ReportParameters);

        // Init macro resolver
        InitResolver();

        // Indicaates whether exception was throw during data loading
        errorOccurred = false;

        // Create graph data
        try
        {
            // Load data
            DataSource = LoadData();
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Get report graph", "E", ex);
            lblError.Text = ex.Message;
            lblError.Visible = true;
            errorOccurred = true;
        }

        if (DataHelper.DataSourceIsEmpty(DataSource) && EmailMode && SendOnlyNonEmptyDataSource)
        {
            Visible = false;
            return;
        }
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible = true;
        ucChart.Visible = true;

        int correctWidth = 0;
        if (ComputedWidth != 0)
        {
            correctWidth = GetGraphWidth();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph() { Colors = Colors };
        graph.ChartControl = ucChart;

        mReport = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (mReport == null)
        {
            return;
        }

        // Check graph security settings
        if (!(CheckReportAccess(mReport) && CheckEmailModeSubscription(mReport, ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true))))
        {
            Visible = false;
            return;
        }

        // Prepare query attributes
        QueryText = reportGraph.GraphQuery;
        QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

        // Init parameters
        InitParameters(mReport.ReportParameters);

        // Init macro resolver
        InitResolver();

        mErrorOccurred = false;
        DataSet dsGraphData = null;

        // Create graph image
        try
        {
            // LoadData
            dsGraphData = LoadData();
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            mErrorOccurred = true;
        }

        // Test if dataset is empty
        if (DataHelper.DataSourceIsEmpty(dsGraphData))
        {
            if (EmailMode && SendOnlyNonEmptyDataSource)
            {
                // Empty dataset, and flag not send empty dataset is set
                Visible = false;
                return;
            }

            string noRecordText = ResolveMacros(ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty));
            if (noRecordText != String.Empty)
            {
                ltlEmail.Text = noRecordText;
                lblInfo.Text = noRecordText;
                ucChart.Visible = false;
                menuCont.MenuID = String.Empty;
                EnableExport = false;
                lblInfo.Visible = true;
            }
            else
            {
                Visible = false;
            }
        }
        else
        {
            // Create chart
            graph.CorrectWidth = correctWidth;
            if (EmailMode)
            {
                byte[] data = graph.CreateChart(reportGraph, dsGraphData, ContextResolver, true);
                ltlEmail.Text = "##InlineImage##" + reportGraph.GraphName + "##InlineImage##";
                ReportSubscriptionSender.AddToRequest(mReport.ReportName, "g" + reportGraph.GraphName, data);
            }
            else
            {
                graph.CreateChart(reportGraph, dsGraphData, ContextResolver);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQueryQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

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

        versionList.OnAfterRollback += versionList_onAfterRollback;

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

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

        tabControlElem.UsePostback = true;

        Title = "ReportGraph Edit";
        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        RegisterClientScript();

        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 isPreview = QueryHelper.GetBoolean("preview", false);

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

        if (reportId > 0)
        {
            // Get report info
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

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

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

                if (id > 0)
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(id);
                    mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
        }

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

        if (mReportGraphInfo != null)
        {
            // Set title text and image
            PageTitle.TitleText = GetString("Reporting_ReportGraph_Edit.TitleText");
            mGraphId = mReportGraphInfo.GraphID;

            // Show versions tab
            if (ObjectVersionManager.DisplayVersionsTab(mReportGraphInfo))
            {
                tabControlElem.TabItems.Add(new UITabItem
                {
                    Text = GetString("objectversioning.tabtitle")
                });

                versionList.Object = mReportGraphInfo;
                versionList.IsLiveSite = false;
            }
        }
        else
        {
            // Current report graph is new object
            PageTitle.TitleText = GetString("Reporting_ReportGraph_Edit.NewItemTitleText");
            mNewReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Fill border styles
            FillBorderStyle(drpLegendBorderStyle);
            FillBorderStyle(drpChartAreaBorderStyle);
            FillBorderStyle(drpPlotAreaBorderStyle);
            FillBorderStyle(drpSeriesBorderStyle);
            FillBorderStyle(drpSeriesLineBorderStyle);

            // Fill gradient styles
            FillGradientStyle(drpChartAreaGradient);
            FillGradientStyle(drpPlotAreaGradient);
            FillGradientStyle(drpSeriesGradient);

            // Fill axis's position
            FillPosition(drpYAxisTitlePosition);
            FillPosition(drpXAxisTitlePosition);
            FillTitlePosition(drpTitlePosition);

            // Fill legend's position
            FillLegendPosition(drpLegendPosition);

            // Fill font type
            FillChartType(drpChartType);

            // Fill Chart type controls
            FillBarType(drpBarDrawingStyle);
            FillStackedBarType(drpStackedBarDrawingStyle);
            FillPieType(drpPieDrawingStyle);
            FillDrawingDesign(drpPieDrawingDesign);
            FillLabelStyle(drpPieLabelStyle);
            FillPieRadius(drpPieDoughnutRadius);
            FillLineDrawingStyle(drpLineDrawingStyle);
            FillOrientation(drpBarOrientation);
            FillOrientation(drpBarStackedOrientation);
            FillBorderSkinStyle();

            // FillSymbos
            FillSymbols(drpSeriesSymbols);
            if (!mNewReport)
            {
                LoadData();
            }
            // Load default data
            else
            {
                chkExportEnable.Checked = ReportGraphDefaults.ExportEnable;
                chkSubscription.Checked = ReportGraphDefaults.Subscription;

                ucSelectString.Value = ReportGraphDefaults.SelectConnectionString;

                // Set default values for some controls
                txtQueryNoRecordText.Text = ResHelper.GetString("attachmentswebpart.nodatafound");
                drpPieLabelStyle.SelectedValue = ReportGraphDefaults.PieLabelStyle;
                drpPieDoughnutRadius.SelectedValue = ReportGraphDefaults.PieDoughnutRadius;
                drpSeriesBorderStyle.SelectedValue = ReportGraphDefaults.SeriesBorderStyle;
                drpSeriesLineBorderStyle.SelectedValue = ReportGraphDefaults.SeriesLineBorderStyle;
                drpLegendBorderStyle.SelectedValue = ReportGraphDefaults.LegendBorderStyle;
                drpChartAreaBorderStyle.SelectedValue = ReportGraphDefaults.ChartAreaBorderStyle;
                drpPlotAreaBorderStyle.SelectedValue = ReportGraphDefaults.PlotAreaBorderStyle;

                // Border size
                txtSeriesLineBorderSize.Text = ReportGraphDefaults.SeriesLineBorderSize.ToString();
                txtSeriesBorderSize.Text = ReportGraphDefaults.SeriesBorderSize.ToString();
                txtChartAreaBorderSize.Text = ReportGraphDefaults.ChartAreaBorderSize.ToString();
                txtPlotAreaBorderSize.Text = ReportGraphDefaults.PlotAreaBorderSize.ToString();
                txtLegendBorderSize.Text = ReportGraphDefaults.LegendBorderSize.ToString();

                // Border color
                ucPlotAreaBorderColor.SelectedColor = ReportGraphDefaults.PlotAreaBorderColor;
                ucChartAreaBorderColor.SelectedColor = ReportGraphDefaults.ChartAreaBorderColor;
                ucLegendBorderColor.SelectedColor = ReportGraphDefaults.LegendBorderColor;
                ucSeriesBorderColor.SelectedColor = ReportGraphDefaults.SeriesBorderColor;

                // Other values
                ucChartAreaPrBgColor.SelectedColor = ReportGraphDefaults.ChartAreaPrBgColor;
                ucChartAreaSecBgColor.SelectedColor = ReportGraphDefaults.ChartAreaSecBgColor;
                drpChartAreaGradient.SelectedValue = ReportGraphDefaults.ChartAreaGradient;
                ucTitleColor.SelectedColor = ReportGraphDefaults.TitleColor;
                drpBorderSkinStyle.SelectedValue = ReportGraphDefaults.BorderSkinStyle;
                txtChartWidth.Text = ReportGraphDefaults.ChartWidth.ToString();
                txtChartHeight.Text = ReportGraphDefaults.ChartHeight.ToString();
                chkShowGrid.Checked = ReportGraphDefaults.ShowGrid;
                chkYAxisUseXSettings.Checked = ReportGraphDefaults.YAxisUseXSettings;
                ucXAxisTitleColor.SelectedColor = ReportGraphDefaults.XAxisTitleColor;
                ucYAxisTitleColor.SelectedColor = ReportGraphDefaults.YAxisTitleColor;
                drpSeriesSymbols.SelectedValue = ReportGraphDefaults.SeriesSymbols;

                drpBarDrawingStyle.SelectedValue = ReportGraphDefaults.BarDrawingStyle;
                chkSeriesDisplayItemValue.Checked = ReportGraphDefaults.SeriesDisplayItemValue;
                txtXAxisInterval.Text = ReportGraphDefaults.XAxisInterval.ToString();
                chkXAxisSort.Checked = ReportGraphDefaults.XAxisSort;
                drpPieDrawingStyle.SelectedValue = ReportGraphDefaults.PieDrawingStyle;
                drpPieDrawingDesign.SelectedValue = ReportGraphDefaults.PieDrawingDesign;
                drpStackedBarDrawingStyle.SelectedValue = ReportGraphDefaults.StackedBarDrawingStyle;
            }
        }

        HideChartTypeControls(drpChartType.SelectedIndex);
        ucXAxisTitleFont.SetOnChangeAttribute("xAxixTitleFontChanged ()");

        // Font settings
        ucTitleFont.DefaultSize = 14;
        ucTitleFont.DefaultStyle = "bold";
        ucXAxisTitleFont.DefaultSize = 11;
        ucXAxisTitleFont.DefaultStyle = "bold";
        ucYAxisTitleFont.DefaultSize = 11;
        ucYAxisTitleFont.DefaultStyle = "bold";

        txtRotateX.Enabled = chkShowAs3D.Checked;
        txtRotateY.Enabled = chkShowAs3D.Checked;
        chkBarOverlay.Enabled = chkShowAs3D.Checked;

        // Doughnut settings
        drpPieDoughnutRadius.Enabled = drpPieDrawingStyle.SelectedValue == "Doughnut";

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
    }
示例#12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQueryQuery.Enabled = false;
        }
        else
        {
            txtQueryQuery.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 script for resize and rolback
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

        tabControlElem.Tabs        = tabs;
        tabControlElem.UsePostback = true;

        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";
        CurrentMaster.Title.HelpTopicName = "report_htmlgraph_properties";
        CurrentMaster.Title.HelpName      = "helpTopic";
        Title = "ReportGraph Edit";

        btnOk.Text     = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text  = GetString("General.apply");

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

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

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

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

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) //must be valid reportid parameter
            {
                string graphName = QueryHelper.GetString("itemname", "");

                // try to load graphname from hidden field (adding new graph & preview)
                if (graphName == String.Empty)
                {
                    graphName = txtNewGraphHidden.Value;
                }

                if (ValidationHelper.IsIdentifier(graphName))
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(reportInfo.ReportName + "." + graphName);
                    graphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            graphInfo = PersistentEditedObject as ReportGraphInfo;
        }


        if (graphInfo != null)
        {
            CurrentMaster.Title.TitleText  = GetString("Reporting_ReportGraph_EditHTML.TitleText");
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportGraph/object.png");

            graphId = graphInfo.GraphID;

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

            newReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Load default data for new report
            if (newReport)
            {
                txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                txtItemValueFormat.Text   = "{%yval%}";
                txtSeriesItemTooltip.Text = "{%ser%}";
                chkExportEnable.Checked   = true;
            }
            // Otherwise load saved data
            else
            {
                LoadData();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQueryQuery.Enabled = false;
        }
        else
        {
            txtQueryQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

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

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

        tabControlElem.Tabs = tabs;
        tabControlElem.UsePostback = true;

        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";
        CurrentMaster.Title.HelpName = "helpTopic";
        CurrentMaster.Title.HelpTopicName = "report_graph_properties";
        Title = "ReportGraph Edit";

        RegisterClientScript();

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

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

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

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

        // Must be valid reportid parameter
        if (PersistentEditedObject == null)
        {
            if (reportInfo != null)
            {
                string graphName = QueryHelper.GetString("itemname", "");

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

                if (ValidationHelper.IsIdentifier(graphName))
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(reportInfo.ReportName + "." + graphName);
                    graphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            graphInfo = PersistentEditedObject as ReportGraphInfo;
        }

        if (graphInfo != null)
        {
            CurrentMaster.Title.TitleText = GetString("Reporting_ReportGraph_Edit.TitleText");
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportGraph/object.png");

            graphId = graphInfo.GraphID;

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

            newReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Fill border styles
            FillBorderStyle(drpLegendBorderStyle);
            FillBorderStyle(drpChartAreaBorderStyle);
            FillBorderStyle(drpPlotAreaBorderStyle);
            FillBorderStyle(drpSeriesBorderStyle);
            FillBorderStyle(drpSeriesLineBorderStyle);

            // Fill gradient styles
            FillGradientStyle(drpChartAreaGradient);
            FillGradientStyle(drpPlotAreaGradient);
            FillGradientStyle(drpSeriesGradient);

            // Fill axis's position
            FillPosition(drpYAxisTitlePosition);
            FillPosition(drpXAxisTitlePosition);
            FillTitlePosition(drpTitlePosition);

            // Fill legend's position
            FillLegendPosition(drpLegendPosition);

            // Fill font type
            FillChartType(drpChartType);

            // Fill Chart type controls
            FillBarType(drpBarDrawingStyle);
            FillStackedBarType(drpStackedBarDrawingStyle);
            FillPieType(drpPieDrawingStyle);
            FillDrawingDesign(drpPieDrawingDesign);
            FillLabelStyle(drpPieLabelStyle);
            FillPieRadius(drpPieDoughnutRadius);
            FillLineDrawingStyle(drpLineDrawingStyle);
            FillOrientation(drpBarOrientation);
            FillOrientation(drpBarStackedOrientation);
            FillBorderSkinStyle();

            // FillSymbos
            FillSymbols(drpSeriesSymbols);
            if (!newReport)
            {
                LoadData();
            }
            // Load default data
            else
            {
                chkExportEnable.Checked = true;

                // Set default values for some controls
                txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                drpPieLabelStyle.SelectedValue = "Outside";
                drpPieDoughnutRadius.SelectedValue = "60";
                drpSeriesBorderStyle.SelectedValue = "Solid";
                drpSeriesLineBorderStyle.SelectedValue = "Solid";
                drpLegendBorderStyle.SelectedValue = "Solid";
                drpChartAreaBorderStyle.SelectedValue = "Solid";
                drpPlotAreaBorderStyle.SelectedValue = "None";

                txtSeriesLineBorderSize.Text = "2";
                txtSeriesBorderSize.Text = "1";
                txtChartAreaBorderSize.Text = "1";
                txtPlotAreaBorderSize.Text = "";
                txtLegendBorderSize.Text = "1";

                ucPlotAreaBorderColor.SelectedColor = "#bbbbbb";
                ucChartAreaBorderColor.SelectedColor = "#bbbbbb";
                ucLegendBorderColor.SelectedColor = "#000000";
                ucSeriesBorderColor.SelectedColor = "#000000";

                ucChartAreaPrBgColor.SelectedColor = "#FFFFFF";
                ucChartAreaSecBgColor.SelectedColor = "#d3dde7";
                drpChartAreaGradient.SelectedValue = "BottomTop";
                ucTitleColor.SelectedColor = "#000000";
                drpBorderSkinStyle.SelectedValue = "None";
                txtChartWidth.Text = "600";
                txtChartHeight.Text = "400";
                chkShowGrid.Checked = true;
                chkYAxisUseXSettings.Checked = true;
                ucXAxisTitleColor.SelectedColor = "#000000";
                ucYAxisTitleColor.SelectedColor = "#000000";
                drpSeriesSymbols.SelectedValue = "Circle";

                drpBarDrawingStyle.SelectedValue = "Cylinder";
                chkSeriesDisplayItemValue.Checked = true;
                txtXAxisInterval.Text = "1";
                chkXAxisSort.Checked = true;
                drpPieDrawingDesign.SelectedValue = "SoftEdge";
                drpStackedBarDrawingStyle.SelectedValue = "Cylinder";
            }
        }

        HideChartTypeControls(drpChartType.SelectedIndex);
        ucXAxisTitleFont.SetOnChangeAttribute("xAxixTitleFontChanged ()");

        ucLegendBgColor.SupportFolder = colorPickerPath;
        ucLegendBorderColor.SupportFolder = colorPickerPath;
        ucChartAreaPrBgColor.SupportFolder = colorPickerPath;
        ucChartAreaSecBgColor.SupportFolder = colorPickerPath;
        ucChartAreaBorderColor.SupportFolder = colorPickerPath;
        ucPlotAreSecBgColor.SupportFolder = colorPickerPath;
        ucSeriesPrBgColor.SupportFolder = colorPickerPath;
        ucSeriesLineColor.SupportFolder = colorPickerPath;
        ucSeriesSecBgColor.SupportFolder = colorPickerPath;
        ucPlotAreaPrBgColor.SupportFolder = colorPickerPath;
        ucPlotAreaBorderColor.SupportFolder = colorPickerPath;
        ucSeriesBorderColor.SupportFolder = colorPickerPath;
        ucTitleColor.SupportFolder = colorPickerPath;
        ucXAxisTitleColor.SupportFolder = colorPickerPath;
        ucYAxisTitleColor.SupportFolder = colorPickerPath;

        ucTitleFont.DefaultSize = 14;
        ucTitleFont.DefaultStyle = "bold";
        ucXAxisTitleFont.DefaultSize = 11;
        ucXAxisTitleFont.DefaultStyle = "bold";
        ucYAxisTitleFont.DefaultSize = 11;
        ucYAxisTitleFont.DefaultStyle = "bold";

        txtRotateX.Enabled = chkShowAs3D.Checked;
        txtRotateY.Enabled = chkShowAs3D.Checked;
        chkBarOverlay.Enabled = chkShowAs3D.Checked;

        if (drpPieDrawingStyle.SelectedValue != "Doughnut")
        {
            drpPieDoughnutRadius.Enabled = false;
        }
        else
        {
            drpPieDoughnutRadius.Enabled = true;
        }
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible = true;
        ucChart.Visible = true;

        int correctWidth = 0;
        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();
        graph.ChartControl = ucChart;

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        // Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            // Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);

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

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

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

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Empty dataset, and flag not send empty dataset is set
            if (SendOnlyNonEmptyDataSource && EmailMode && DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                Visible = false;
                return;
            }

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = CMSContext.ResolveMacros(ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty));
                if (noRecordText != String.Empty)
                {
                    ltlEmail.Text = noRecordText;
                    lblInfo.Text = noRecordText;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    EnableExport = false;
                    plcInfo.Visible = true;
                }
                else
                {
                    Visible = false;
                }
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                if (EmailMode)
                {
                    byte[] data = graph.CreateChart(reportGraph, dsGraphData, resolver, true);
                    ltlEmail.Text = "##InlineImage##" + reportGraph.GraphName + "##InlineImage##";
                    ReportSubscriptionSender.AddToRequest(report.ReportName, "g" + reportGraph.GraphName, data);
                }
                else
                {
                    graph.CreateChart(reportGraph, dsGraphData, resolver);
                }
            }

            // Check if subscription is allowed
            EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
            if (EmailMode && !EnableSubscription)
            {
                this.Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope                    = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible             = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQueryQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

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

        versionList.OnAfterRollback += versionList_onAfterRollback;

        // Register script for resize and rollback
        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;

        Title = "ReportGraph Edit";
        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        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 isPreview = QueryHelper.GetBoolean("preview", false);

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

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

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

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

                if (id > 0)
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(id);
                    mReportGraphInfo       = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
        }

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

        if (mReportGraphInfo != null)
        {
            PageTitle.TitleText = GetString("Reporting_ReportGraph_EditHTML.TitleText");
            mGraphId            = mReportGraphInfo.GraphID;

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

                versionList.Object     = mReportGraphInfo;
                versionList.IsLiveSite = false;
            }
        }
        else
        {
            PageTitle.TitleText = GetString("Reporting_ReportGraph_EditHTML.NewItemTitleText");
            mNewReport          = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Load default data for new report
            if (mNewReport)
            {
                ucSelectString.Value      = String.Empty;
                txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                txtItemValueFormat.Text   = "{%yval%}";
                txtSeriesItemTooltip.Text = "{%ser%}";
                chkExportEnable.Checked   = true;
                chkSubscription.Checked   = true;
            }
            // Otherwise load saved data
            else
            {
                LoadData();
            }
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
        CurrentMaster.PanelContent.RemoveCssClass("ModalDialogContent");
    }
    /// <summary>
    /// Save the changes to DB
    /// </summary>
    /// <param name="saveToDatabase">If true, data are saved into database</param>
    private bool SetData(bool saveToDatabase = false)
    {
        string errorMessage = String.Empty;

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

            errorMessage = new Validator()
                           .NotEmpty(txtDefaultName.Text, rfvDisplayName.ErrorMessage)
                           .NotEmpty(txtDefaultCodeName.Text, rfvCodeName.ErrorMessage)
                           .NotEmpty(txtQueryQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

            if ((errorMessage == String.Empty) && (!ValidationHelper.IsIdentifier(txtDefaultCodeName.Text.Trim())))
            {
                errorMessage = GetString("general.erroridentifierformat");
            }

            string          fullName      = mReportInfo.ReportName + "." + txtDefaultCodeName.Text.Trim();
            ReportGraphInfo codeNameCheck = ReportGraphInfoProvider.GetReportGraphInfo(fullName);
            if ((errorMessage == String.Empty) && (codeNameCheck != null) && (codeNameCheck.GraphID != mGraphId))
            {
                errorMessage = GetString("Reporting_ReportGraph_Edit.ErrorCodeNameExist");
            }
        }

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

        if (errorMessage == String.Empty)
        {
            // New graph
            if (mReportGraphInfo == null)
            {
                mReportGraphInfo = new ReportGraphInfo();
            }

            mReportGraphInfo.GraphDisplayName = txtDefaultName.Text.Trim();
            mReportGraphInfo.GraphName        = txtDefaultCodeName.Text.Trim();

            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                mReportGraphInfo.GraphQuery = txtQueryQuery.Text;
            }

            mReportGraphInfo.GraphQueryIsStoredProcedure = chkIsStoredProcedure.Checked;
            mReportGraphInfo.GraphReportID         = mReportInfo.ReportID;
            mReportGraphInfo.GraphTitle            = txtGraphTitle.Text;
            mReportGraphInfo.GraphIsHtml           = true;
            mReportGraphInfo.GraphType             = String.Empty;
            mReportGraphInfo.GraphConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty);

            ReportCustomData settings = mReportGraphInfo.GraphSettings;
            settings["QueryNoRecordText"]    = txtQueryNoRecordText.Text;
            settings["LegendTitle"]          = txtLegendTitle.Text;
            settings["DisplayLegend"]        = chkDisplayLegend.Checked.ToString();
            settings["SeriesItemToolTip"]    = txtSeriesItemTooltip.Text;
            settings["SeriesItemLink"]       = txtSeriesItemLink.Text;
            settings["ItemValueFormat"]      = txtItemValueFormat.Text;
            settings["SeriesItemNameFormat"] = txtItemNameFormat.Text;
            settings["ExportEnabled"]        = chkExportEnable.Checked.ToString();
            settings["SubscriptionEnabled"]  = chkSubscription.Checked.ToString();

            if (saveToDatabase)
            {
                ReportGraphInfoProvider.SetReportGraphInfo(mReportGraphInfo);
            }

            return(true);
        }

        ShowError(errorMessage);
        return(false);
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        // Check whether report graph is defined
        if (reportGraph == null)
        {
            return;
        }

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        //check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
        if (EmailMode && !EnableSubscription)
        {
            this.Visible = false;
            return;
        }

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

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

        // Indicaates whether exception was throw during data loading
        errorOccurred = false;

        // Create graph data
        try
        {
            ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
            //Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            //Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // Load data
            DataSource = LoadData();

            if (DataHelper.DataSourceIsEmpty(DataSource) && EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            lblError.Text = ex.Message;
            lblError.Visible = true;
            errorOccurred = true;
        }
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible = true;
        ucChart.Visible = true;

        int correctWidth = 0;
        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();
        graph.ChartControl = ucChart;

        ReportInfo report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

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

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

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

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        // Indicaates whether exception was throw during data loading
        bool errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    lblInfo.Text = noRecordText;
                    lblInfo.Visible = true;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    return;
                }
                Visible = false;
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                graph.CreateChart(reportGraph, dsGraphData, resolver);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }

        // Export data
        if ((report != null) && (!errorOccurred))
        {
            ProcessExport(ValidationHelper.GetCodeName(report.ReportDisplayName));
        }
    }
示例#19
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        // If percent Width is Set and reloadonPrerender == false  - it means first run .. ad postback scripts and exit
        if ((GraphImageWidth != 0) && (ComputedWidth == 0))
        {
            string argument = Request.Params[Page.postEventArgumentID];
            string target   = Request.Params[Page.postEventSourceID];

            // Check for empty (invisible) div to prevent neverending loop
            // If refresh postback and still no computedwidth - display graph with default width
            if (!((target == btnRefresh.UniqueID) && (argument == "refresh")))
            {
                mRegisterWidthScript = true;
                ucChart.Visible      = false;
                RequestStockHelper.Add("CMSGraphAutoWidth", true);
                return;
            }
        }

        RequestStockHelper.Add("CMSGraphAutoWidth", false);
        mRegisterWidthScript = false;

        // ReportGraphName is set from AbstractReportControl parameter
        ReportGraphName = Parameter;

        // Preview
        if (GraphInfo != null)
        {
            GetReportGraph(GraphInfo);
        }
        else
        {
            ReportGraphInfo rgi = ReportGraphInfo;
            // If saved report guid is empty ==> create "live" graph, else load saved graph
            if (SavedReportGuid == Guid.Empty)
            {
                // Get graph info object
                if (rgi != null)
                {
                    GetReportGraph(rgi);
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = "[ReportGraph.ascx] Report graph '" + ReportGraphName + "' not found.";
                    EventLogProvider.LogException("Report graph", "E", new Exception("Report graph '" + ReportGraphName + "' not found."));
                }
            }
            else
            {
                if (rgi != null)
                {
                    int correctWidth = 0;
                    if (ComputedWidth != 0)
                    {
                        correctWidth = GetGraphWidth();
                    }

                    rgi.GraphTitle      = ResHelper.LocalizeString(rgi.GraphTitle);
                    rgi.GraphXAxisTitle = ResHelper.LocalizeString(rgi.GraphXAxisTitle);
                    rgi.GraphYAxisTitle = ResHelper.LocalizeString(rgi.GraphYAxisTitle);

                    QueryIsStoredProcedure = rgi.GraphQueryIsStoredProcedure;
                    QueryText = ResolveMacros(rgi.GraphQuery);

                    // Load data, generate image
                    ReportGraph rg = new ReportGraph()
                    {
                        Colors = Colors
                    };

                    // Save image
                    SavedGraphInfo sgi = new SavedGraphInfo();

                    string noRecordText = ResolveMacros(ValidationHelper.GetString(rgi.GraphSettings["QueryNoRecordText"], String.Empty));

                    try
                    {
                        rg.CorrectWidth = correctWidth;
                        DataSet ds = LoadData();
                        if (!DataHelper.DataSourceIsEmpty(ds) || !String.IsNullOrEmpty(noRecordText))
                        {
                            sgi.SavedGraphBinary = rg.CreateChart(rgi, LoadData(), ContextResolver, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        EventLogProvider.LogException("Report graph", "E", ex);

                        byte[] invalidGraph = rg.CreateChart(rgi, null, ContextResolver, true);
                        sgi.SavedGraphBinary = invalidGraph;
                    }

                    if (sgi.SavedGraphBinary != null)
                    {
                        sgi.SavedGraphGUID          = SavedReportGuid;
                        sgi.SavedGraphMimeType      = "image/png";
                        sgi.SavedGraphSavedReportID = SavedReportID;

                        SavedGraphInfoProvider.SetSavedGraphInfo(sgi);

                        // Create graph image
                        imgGraph.Visible  = true;
                        ucChart.Visible   = false;
                        imgGraph.ImageUrl = ResolveUrl("~/CMSModules/Reporting/CMSPages/GetReportGraph.aspx") + "?graphguid=" + SavedReportGuid.ToString();
                    }
                    else
                    {
                        Visible = false;
                    }
                }
            }
        }
    }
    /// <summary>
    /// Save the changes to DB
    /// </summary>
    /// <param name="saveToDatabase">If false, data is not stored to DB, only info object is filled</param>
    private bool SetData(bool saveToDatabase = false)
    {
        string errorMessage = String.Empty;
        if (saveToDatabase)
        {
            // Check permissions
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            // Validate inputs
            errorMessage = new Validator()
                .NotEmpty(txtDefaultName.Text, rfvDisplayName.ErrorMessage)
                .NotEmpty(txtDefaultCodeName.Text, rfvCodeName.ErrorMessage)
                .NotEmpty(txtQueryQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

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

            string fullName = mReportInfo.ReportName + "." + txtDefaultCodeName.Text.Trim();

            // Get graph info
            ReportGraphInfo codeNameCheck = ReportGraphInfoProvider.GetReportGraphInfo(fullName);
            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.GraphID != mGraphId))
            {
                errorMessage = GetString("Reporting_ReportGraph_Edit.ErrorCodeNameExist");
            }
        }

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

            // Test valid integers
            errorMessage = ValidateNonNegativeIntegerValue(txtChartWidth, errorMessage, ChartWidthRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtChartHeight, errorMessage, ChartHeightRow);

            errorMessage = ValidateIntegerValue(txtRotateX, errorMessage, RotateXRow);
            errorMessage = ValidateIntegerValue(txtRotateY, errorMessage, RotateYRow);

            errorMessage = ValidateIntegerValue(txtXAxisAngle, errorMessage, XAxisAngleRow);
            errorMessage = ValidateIntegerValue(txtYAxisAngle, errorMessage, YAxisAngleRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtXAxisInterval, errorMessage, XAxisInterval);

            errorMessage = ValidateIntegerValue(txtScaleMin, errorMessage, ChartAreaScaleMin);
            errorMessage = ValidateIntegerValue(txtScaleMax, errorMessage, ChartAreaScaleMax);

            errorMessage = ValidateNonNegativeIntegerValue(txtChartAreaBorderSize, errorMessage, ChartAreaBorderSizeRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtSeriesBorderSize, errorMessage, SeriesBorderSizeRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtLegendBorderSize, errorMessage, LegendBorderSizeRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtPlotAreaBorderSize, errorMessage, PlotAreaBorderSizeRow);
            errorMessage = ValidateNonNegativeIntegerValue(txtSeriesLineBorderSize, errorMessage, SeriesLineBorderSizeRow);
        }

        if (errorMessage == String.Empty)
        {
            // New graph
            if (mReportGraphInfo == null)
            {
                mReportGraphInfo = new ReportGraphInfo();
            }

            mReportGraphInfo.GraphDisplayName = txtDefaultName.Text.Trim();
            mReportGraphInfo.GraphName = txtDefaultCodeName.Text.Trim();

            // Check authorization
            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                mReportGraphInfo.GraphQuery = txtQueryQuery.Text;
            }

            mReportGraphInfo.GraphQueryIsStoredProcedure = chkIsStoredProcedure.Checked;

            mReportGraphInfo.GraphType = drpChartType.SelectedValue;
            mReportGraphInfo.GraphReportID = mReportInfo.ReportID;
            mReportGraphInfo.GraphWidth = ValidationHelper.GetInteger(txtChartWidth.Text, 0);
            mReportGraphInfo.GraphHeight = ValidationHelper.GetInteger(txtChartHeight.Text, 0);
            mReportGraphInfo.GraphTitle = txtGraphTitle.Text;

            mReportGraphInfo.GraphXAxisTitle = txtXAxisTitle.Text;
            mReportGraphInfo.GraphYAxisTitle = txtYAxisTitle.Text;
            mReportGraphInfo.GraphConnectionString = ValidationHelper.GetString(ucSelectString.Value, String.Empty);

            ReportCustomData settings = mReportGraphInfo.GraphSettings;

            // Export
            settings["ExportEnabled"] = chkExportEnable.Checked.ToString();

            // Subscription
            settings["SubscriptionEnabled"] = chkSubscription.Checked.ToString();

            // ChartType
            settings["BarDrawingStyle"] = drpBarDrawingStyle.SelectedValue;
            settings["BarOverlay"] = chkBarOverlay.Checked.ToString();
            settings["BarOrientation"] = drpChartType.SelectedValue.ToLowerCSafe() == "bar" ? drpBarOrientation.SelectedValue : drpBarStackedOrientation.SelectedValue;

            settings["StackedBarDrawingStyle"] = drpStackedBarDrawingStyle.SelectedValue;
            settings["StackedBarMaxStacked"] = chkStacked.Checked.ToString();

            // Pie settings
            settings["PieDrawingStyle"] = drpPieDrawingStyle.SelectedValue;
            settings["PieDrawingDesign"] = drpPieDrawingDesign.SelectedValue;
            settings["PieLabelStyle"] = drpPieLabelStyle.SelectedValue;
            settings["PieDoughnutRadius"] = drpPieDoughnutRadius.SelectedValue;
            settings["PieOtherValue"] = txtPieOtherValue.Text;

            settings["LineDrawinStyle"] = drpLineDrawingStyle.SelectedValue;

            settings["ShowAs3D"] = chkShowAs3D.Checked.ToString();
            settings["RotateX"] = txtRotateX.Text;
            settings["RotateY"] = txtRotateY.Text;

            // Title
            settings["ShowMajorGrid"] = chkShowGrid.Checked.ToString();
            settings["TitleFontNew"] = (string)ucTitleFont.Value;
            settings["TitlePosition"] = drpTitlePosition.SelectedValue;
            settings["TitleColor"] = ucTitleColor.SelectedColor;

            // Legend
            settings["LegendBgColor"] = ucLegendBgColor.SelectedColor;
            settings["LegendBorderColor"] = ucLegendBorderColor.SelectedColor;
            settings["LegendBorderSize"] = txtLegendBorderSize.Text;
            settings["LegendBorderStyle"] = drpLegendBorderStyle.SelectedValue;
            settings["LegendPosition"] = drpLegendPosition.SelectedValue;
            settings["LegendInside"] = chkLegendInside.Checked.ToString();
            settings["LegendTitle"] = txtLegendTitle.Text;

            // XAxis
            settings["XAxisFont"] = (string)ucXAxisTitleFont.Value;
            settings["XAxisTitlePosition"] = drpXAxisTitlePosition.SelectedValue;
            settings["XAxisAngle"] = txtXAxisAngle.Text;
            settings["XAxisInterval"] = txtXAxisInterval.Text;
            settings["XAxisSort"] = chkXAxisSort.Checked.ToString();
            settings["XAxisLabelFont"] = (string)ucXAxisLabelFont.Value;
            settings["XAxisTitleColor"] = ucXAxisTitleColor.SelectedColor;
            settings["XAxisFormat"] = txtXAxisFormat.Text;

            // YAxis
            settings["YAxisUseXAxisSettings"] = chkYAxisUseXSettings.Checked.ToString();
            settings["YAxisAngle"] = txtYAxisAngle.Text;
            settings["YAxisTitleColor"] = ucYAxisTitleColor.SelectedColor;
            settings["YAxisFormat"] = txtYAxisFormat.Text;

            if (chkYAxisUseXSettings.Checked)
            {
                settings["YAxisFont"] = (string)ucXAxisTitleFont.Value;
                settings["YAxisTitlePosition"] = drpXAxisTitlePosition.SelectedValue;
                settings["YAxisLabelFont"] = (string)ucXAxisLabelFont.Value;
            }
            else
            {
                settings["YAxisFont"] = (string)ucYAxisTitleFont.Value;
                settings["YAxisLabelFont"] = (string)ucYAxisLabelFont.Value;
                settings["YAxisTitlePosition"] = drpYAxisTitlePosition.SelectedValue;
            }

            // Chart Area
            settings["ChartAreaPrBgColor"] = ucChartAreaPrBgColor.SelectedColor;
            settings["ChartAreaSecBgColor"] = ucChartAreaSecBgColor.SelectedColor;
            settings["ChartAreaBorderColor"] = ucChartAreaBorderColor.SelectedColor;
            settings["ChartAreaGradient"] = drpChartAreaGradient.SelectedValue;
            settings["ChartAreaBorderSize"] = txtChartAreaBorderSize.Text;
            settings["ChartAreaBorderStyle"] = drpChartAreaBorderStyle.SelectedValue;
            settings["ScaleMin"] = txtScaleMin.Text;
            settings["ScaleMax"] = txtScaleMax.Text;
            settings["TenPowers"] = chkTenPowers.Checked.ToString();
            settings["ReverseYAxis"] = chkReverseY.Checked.ToString();
            settings["BorderSkinStyle"] = drpBorderSkinStyle.SelectedValue;
            settings["QueryNoRecordText"] = txtQueryNoRecordText.Text;

            // Plot Area
            settings["PlotAreaPrBgColor"] = ucPlotAreaPrBgColor.SelectedColor;
            settings["PlotAreaSecBgColor"] = ucPlotAreSecBgColor.SelectedColor;
            settings["PlotAreaBorderColor"] = ucPlotAreaBorderColor.SelectedColor;
            settings["PlotAreaGradient"] = drpPlotAreaGradient.SelectedValue;
            settings["PlotAreaBorderSize"] = txtPlotAreaBorderSize.Text;
            settings["PlotAreaBorderStyle"] = drpPlotAreaBorderStyle.SelectedValue;

            // Series
            settings["SeriesPrBgColor"] = ucSeriesPrBgColor.SelectedColor;
            settings["SeriesSecBgColor"] = ucSeriesSecBgColor.SelectedColor;
            settings["SeriesBorderColor"] = ucSeriesBorderColor.SelectedColor;
            settings["SeriesGradient"] = drpSeriesGradient.SelectedValue;
            settings["SeriesBorderSize"] = txtSeriesBorderSize.Text;
            settings["SeriesBorderStyle"] = drpSeriesBorderStyle.SelectedValue;
            settings["SeriesSymbols"] = drpSeriesSymbols.SelectedValue;
            settings["DisplayItemValue"] = chkSeriesDisplayItemValue.Checked.ToString();
            settings["SeriesItemToolTip"] = txtSeriesItemTooltip.Text;
            settings["SeriesItemLink"] = txtSeriesItemLink.Text;
            settings["ItemValueFormat"] = txtItemValueFormat.Text;
            settings["ValuesAsPercent"] = chkValuesAsPercent.Checked.ToString();

            if (drpChartType.SelectedValue.ToLowerCSafe() == "line")
            {
                settings["SeriesBorderSize"] = txtSeriesLineBorderSize.Text;
                settings["SeriesBorderStyle"] = drpSeriesLineBorderStyle.SelectedValue;
                settings["SeriesPrBgColor"] = ucSeriesLineColor.SelectedColor;
            }

            // Delete old settings
            settings["axisFont"] = null;
            settings["colors"] = null;
            settings["graphGradient"] = null;
            settings["chartGradient"] = null;
            settings["itemGradient"] = null;
            settings["symbols"] = null;
            settings["titleFont"] = null;
            settings["VerticalBars"] = null;
            settings["FillCurves"] = null;
            settings["SmoothCurves"] = null;
            mReportGraphInfo.GraphLegendPosition = ReportGraphDefaults.GraphLegendPosition;
            if (saveToDatabase)
            {
                ReportGraphInfoProvider.SetReportGraphInfo(mReportGraphInfo);
            }
            else
            {
                PersistentEditedObject = mReportGraphInfo;
            }

            return true;
        }

        ShowError(errorMessage);
        return false;
    }
示例#21
0
    /// <summary>
    /// Save the changes to DB
    /// </summary>
    private bool Save(bool save)
    {
        string errorMessage = String.Empty;

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

            errorMessage = new Validator()
                           .NotEmpty(txtDefaultName.Text, rfvDisplayName.ErrorMessage)
                           .NotEmpty(txtDefaultCodeName.Text, rfvCodeName.ErrorMessage)
                           .NotEmpty(txtQueryQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

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

            string          fullName      = reportInfo.ReportName + "." + txtDefaultCodeName.Text.Trim();
            ReportGraphInfo codeNameCheck = ReportGraphInfoProvider.GetReportGraphInfo(fullName);
            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.GraphID != graphId))
            {
                errorMessage = GetString("Reporting_ReportGraph_Edit.ErrorCodeNameExist");
            }
        }

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

        if (errorMessage == String.Empty)
        {
            // New graph
            if (graphInfo == null)
            {
                graphInfo = new ReportGraphInfo();
            }

            graphInfo.GraphDisplayName = txtDefaultName.Text.Trim();
            graphInfo.GraphName        = txtDefaultCodeName.Text.Trim();

            if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                graphInfo.GraphQuery = txtQueryQuery.Text;
            }

            graphInfo.GraphQueryIsStoredProcedure = chkIsStoredProcedure.Checked;
            graphInfo.GraphReportID = reportInfo.ReportID;
            graphInfo.GraphTitle    = txtGraphTitle.Text;
            graphInfo.GraphIsHtml   = true;
            graphInfo.GraphType     = String.Empty;

            ReportCustomData settings = (ReportCustomData)graphInfo.GraphSettings;
            settings["QueryNoRecordText"]    = txtQueryNoRecordText.Text;
            settings["LegendTitle"]          = txtLegendTitle.Text;
            settings["DisplayLegend"]        = chkDisplayLegend.Checked.ToString();
            settings["SeriesItemToolTip"]    = txtSeriesItemTooltip.Text;
            settings["SeriesItemLink"]       = txtSeriesItemLink.Text;
            settings["ItemValueFormat"]      = txtItemValueFormat.Text;
            settings["SeriesItemNameFormat"] = txtItemNameFormat.Text;
            settings["ExportEnabled"]        = chkExportEnable.Checked.ToString();

            if (save)
            {
                ReportGraphInfoProvider.SetReportGraphInfo(graphInfo);
            }

            return(true);
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
            return(false);
        }
    }
示例#22
0
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible         = true;
        ucChart.Visible = true;

        int correctWidth = 0;

        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();

        graph.ChartControl = ucChart;

        ReportInfo report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);

        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

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

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

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

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        // Indicaates whether exception was throw during data loading
        bool errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    lblInfo.Text    = noRecordText;
                    lblInfo.Visible = true;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    return;
                }
                Visible = false;
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                graph.CreateChart(reportGraph, dsGraphData, resolver);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }

        // Export data
        if ((report != null) && (!errorOccurred))
        {
            ProcessExport(ValidationHelper.GetCodeName(report.ReportDisplayName));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int reportId = QueryHelper.GetInteger("reportid", 0);
        bool isPreview = QueryHelper.GetBoolean("preview", false);

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

        if (reportId > 0)
        {
            // Get report info
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

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

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

                if (id > 0)
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(id);
                    mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            mReportGraphInfo = PersistentEditedObject as ReportGraphInfo;
        }

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

        if (mReportGraphInfo != null)
        {
            // Set title text and image
            PageTitle.TitleText = GetString("Reporting_ReportGraph_Edit.TitleText");
            mGraphId = mReportGraphInfo.GraphID;

            // Show versions tab
            if (ObjectVersionManager.DisplayVersionsTab(mReportGraphInfo))
            {
                tabControlElem.TabItems.Add(new UITabItem
                {
                    Text = GetString("objectversioning.tabtitle")
                });

                versionList.Object = mReportGraphInfo;
                versionList.IsLiveSite = false;
            }
        }
        else
        {
            // Current report graph is new object
            PageTitle.TitleText = GetString("Reporting_ReportGraph_Edit.NewItemTitleText");
            mNewReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            if (!mNewReport)
            {
                LoadData();
            }
            // Load default data
            else
            {
                LoadDefaultData();
            }
        }

        HideChartTypeControls(drpChartType.SelectedIndex);
        ucXAxisTitleFont.SetOnChangeAttribute("xAxisTitleFontChanged()");

        // Font settings
        ucTitleFont.DefaultSize = 14;
        ucTitleFont.DefaultStyle = "bold";
        ucXAxisTitleFont.DefaultSize = 11;
        ucXAxisTitleFont.DefaultStyle = "bold";
        ucYAxisTitleFont.DefaultSize = 11;
        ucYAxisTitleFont.DefaultStyle = "bold";

        txtRotateX.Enabled = chkShowAs3D.Checked;
        txtRotateY.Enabled = chkShowAs3D.Checked;
        chkBarOverlay.Enabled = chkShowAs3D.Checked;

        drpBarStackedOrientation.Enabled = !(drpStackedBarDrawingStyle.SelectedValue.EqualsCSafe("Area", true));
        drpPieDoughnutRadius.Enabled = drpPieDrawingStyle.SelectedValue.EqualsCSafe("Doughnut", true);
    }
示例#24
0
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible         = true;
        ucChart.Visible = true;

        int correctWidth = 0;

        if (ComputedWidth != 0)
        {
            correctWidth = GetGraphWidth();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph()
        {
            Colors = Colors
        };

        graph.ChartControl = ucChart;

        mReport = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (mReport == null)
        {
            return;
        }

        // Check graph security settings
        if (!(CheckReportAccess(mReport) && CheckEmailModeSubscription(mReport, ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true))))
        {
            Visible = false;
            return;
        }

        // Prepare query attributes
        QueryText = reportGraph.GraphQuery;
        QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

        // Init parameters
        InitParameters(mReport.ReportParameters);

        // Init macro resolver
        InitResolver();

        mErrorOccurred = false;
        DataSet dsGraphData = null;

        // Create graph image
        try
        {
            // LoadData
            dsGraphData = LoadData();
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            mErrorOccurred = true;
        }

        // Test if dataset is empty
        if (DataHelper.DataSourceIsEmpty(dsGraphData))
        {
            if (EmailMode && SendOnlyNonEmptyDataSource)
            {
                // Empty dataset, and flag not send empty dataset is set
                Visible = false;
                return;
            }

            string noRecordText = ResolveMacros(ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty));
            if (noRecordText != String.Empty)
            {
                ltlEmail.Text   = noRecordText;
                lblInfo.Text    = noRecordText;
                ucChart.Visible = false;
                menuCont.MenuID = String.Empty;
                EnableExport    = false;
                lblInfo.Visible = true;
            }
            else
            {
                Visible = false;
            }
        }
        else
        {
            // Create chart
            graph.CorrectWidth = correctWidth;
            if (EmailMode)
            {
                byte[] data = graph.CreateChart(reportGraph, dsGraphData, ContextResolver, true);
                ltlEmail.Text = "##InlineImage##" + reportGraph.GraphName + "##InlineImage##";
                ReportSubscriptionSender.AddToRequest(mReport.ReportName, "g" + reportGraph.GraphName, data);
            }
            else
            {
                graph.CreateChart(reportGraph, dsGraphData, ContextResolver);
            }
        }
    }
 /// <summary>
 /// Get info from PersistentEditedObject and reload data
 /// </summary>
 private void ReloadDataAfrterRollback()
 {
     // Load rollbacked info
     GeneralizedInfo gi = PersistentEditedObject as GeneralizedInfo;
     if (gi != null)
     {
         graphInfo = gi.MainObject as ReportGraphInfo;
     }
     LoadData();
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQueryQuery.Enabled = false;
        }
        else
        {
            txtQueryQuery.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 script for resize and rolback
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

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

        tabControlElem.Tabs = tabs;
        tabControlElem.UsePostback = true;

        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";
        CurrentMaster.Title.HelpTopicName = "report_htmlgraph_properties";
        CurrentMaster.Title.HelpName = "helpTopic";
        Title = "ReportGraph Edit";

        btnOk.Text = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");
        btnApply.Text = GetString("General.apply");

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

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

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

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

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) //must be valid reportid parameter
            {
                string graphName = QueryHelper.GetString("itemname", "");

                // try to load graphname from hidden field (adding new graph & preview)
                if (graphName == String.Empty)
                {
                    graphName = txtNewGraphHidden.Value;
                }

                if (ValidationHelper.IsCodeName(graphName))
                {
                    PersistentEditedObject = ReportGraphInfoProvider.GetReportGraphInfo(reportInfo.ReportName + "." + graphName);
                    graphInfo = PersistentEditedObject as ReportGraphInfo;
                }
            }
        }
        else
        {
            graphInfo = PersistentEditedObject as ReportGraphInfo;
        }

        if (graphInfo != null)
        {
            CurrentMaster.Title.TitleText = GetString("Reporting_ReportGraph_EditHTML.TitleText");
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportGraph/object.png");

            graphId = graphInfo.GraphID;

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

            newReport = true;
        }

        if (!RequestHelper.IsPostBack())
        {
            // Load default data for new report
            if (newReport)
            {
                txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                txtItemValueFormat.Text = "{%yval%}";
                txtSeriesItemTooltip.Text = "{%ser%}";
                chkExportEnable.Checked = true;
            }
            // Otherwise load saved data
            else
            {
                LoadData();
            }
        }
    }
示例#27
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>";
    }
    /// <summary>
    /// Save the changes to DB
    /// </summary>
    private bool Save(bool save)
    {
        string errorMessage = String.Empty;
        if (save)
        {
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            errorMessage = new Validator()
                .NotEmpty(txtDefaultName.Text, rfvDisplayName.ErrorMessage)
                .NotEmpty(txtDefaultCodeName.Text, rfvCodeName.ErrorMessage)
                .NotEmpty(txtQueryQuery.Text, GetString("Reporting_ReportGraph_Edit.ErrorQuery")).Result;

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

            string fullName = reportInfo.ReportName + "." + txtDefaultCodeName.Text.Trim();
            ReportGraphInfo codeNameCheck = ReportGraphInfoProvider.GetReportGraphInfo(fullName);
            if ((errorMessage == "") && (codeNameCheck != null) && (codeNameCheck.GraphID != graphId))
            {
                errorMessage = GetString("Reporting_ReportGraph_Edit.ErrorCodeNameExist");
            }
        }

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

        if (errorMessage == String.Empty)
        {
            // New graph
            if (graphInfo == null)
            {
                graphInfo = new ReportGraphInfo();
            }

            graphInfo.GraphDisplayName = txtDefaultName.Text.Trim();
            graphInfo.GraphName = txtDefaultCodeName.Text.Trim();

            if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
            {
                graphInfo.GraphQuery = txtQueryQuery.Text;
            }

            graphInfo.GraphQueryIsStoredProcedure = chkIsStoredProcedure.Checked;
            graphInfo.GraphReportID = reportInfo.ReportID;
            graphInfo.GraphTitle = txtGraphTitle.Text;
            graphInfo.GraphIsHtml = true;
            graphInfo.GraphType = String.Empty;

            ReportCustomData settings = (ReportCustomData)graphInfo.GraphSettings;
            settings["QueryNoRecordText"] = txtQueryNoRecordText.Text;
            settings["LegendTitle"] = txtLegendTitle.Text;
            settings["DisplayLegend"] = chkDisplayLegend.Checked.ToString();
            settings["SeriesItemToolTip"] = txtSeriesItemTooltip.Text;
            settings["SeriesItemLink"] = txtSeriesItemLink.Text;
            settings["ItemValueFormat"] = txtItemValueFormat.Text;
            settings["SeriesItemNameFormat"] = txtItemNameFormat.Text;
            settings["ExportEnabled"] = chkExportEnable.Checked.ToString();

            if (save)
            {
                ReportGraphInfoProvider.SetReportGraphInfo(graphInfo);
            }

            return true;
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = errorMessage;
            return false;
        }
    }
示例#29
0
    /// <summary>
    /// Creates report graph. Called when the "Create graph" button is pressed.
    /// </summary>
    private bool CreateReportGraph()
    {
        // Get report object by report code name
        ReportInfo report = ReportInfoProvider.GetReportInfo("MyNewReport");

        // If report exists
        if (report != null)
        {
            // Create new report graph object
            ReportGraphInfo newGraph = new ReportGraphInfo();

            // Set the properties
            newGraph.GraphDisplayName = "My new graph";
            newGraph.GraphName = "MyNewGraph";
            newGraph.GraphQuery = "SELECT TOP 10 DocumentName, DocumentID FROM CMS_Document";
            newGraph.GraphReportID = report.ReportID;
            newGraph.GraphQueryIsStoredProcedure = false;
            newGraph.GraphType = "bar";

            // Save the report graph
            ReportGraphInfoProvider.SetReportGraphInfo(newGraph);

            return true;
        }

        return false;
    }
示例#30
0
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        // Check whether report graph is defined
        if (reportGraph == null)
        {
            return;
        }

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        //check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
        if (EmailMode && !EnableSubscription)
        {
            this.Visible = false;
            return;
        }

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

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

        // Indicaates whether exception was throw during data loading
        errorOccurred = false;

        // Create graph data
        try
        {
            ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
            //Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            //Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // Load data
            DataSource = LoadData();

            if (DataHelper.DataSourceIsEmpty(DataSource) && EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            errorOccurred    = true;
        }
    }
示例#31
0
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible         = true;
        ucChart.Visible = true;

        int correctWidth = 0;

        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();

        graph.ChartControl = ucChart;

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        // Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            // Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);

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

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

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

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

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

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Empty dataset, and flag not send empty dataset is set
            if (SendOnlyNonEmptyDataSource && EmailMode && DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                Visible = false;
                return;
            }

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = CMSContext.ResolveMacros(ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty));
                if (noRecordText != String.Empty)
                {
                    ltlEmail.Text   = noRecordText;
                    lblInfo.Text    = noRecordText;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    EnableExport    = false;
                    plcInfo.Visible = true;
                }
                else
                {
                    Visible = false;
                }
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                if (EmailMode)
                {
                    byte[] data = graph.CreateChart(reportGraph, dsGraphData, resolver, true);
                    ltlEmail.Text = "##InlineImage##" + reportGraph.GraphName + "##InlineImage##";
                    ReportSubscriptionSender.AddToRequest(report.ReportName, "g" + reportGraph.GraphName, data);
                }
                else
                {
                    graph.CreateChart(reportGraph, dsGraphData, resolver);
                }
            }

            // Check if subscription is allowed
            EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
            if (EmailMode && !EnableSubscription)
            {
                this.Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }
    }