Example #1
0
    /// <summary>
    /// Ensires teble info object.
    /// </summary>
    private void EnsureTableInfo()
    {
        ReportTableInfo rti = TableInfo;

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

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

            QueryText = ResolveMacros(rti.TableQuery);
            TableInfo = rti;
        }
    }
    /// <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;
        }
    }
Example #3
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));
        }
    }
Example #4
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        try
        {
            // Load value info object
            ReportValueInfo rvi = ValueInfo;

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

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

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

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

                //Set default parametrs directly if not set
                if (ReportParameters == null)
                {
                    if (ri != null)
                    {
                        FormInfo fi = new FormInfo(ri.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);
            }

            // Load data
            DataSet ds = LoadData();

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

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