private void button1_Click(object sender, EventArgs e)
        {
            List<ReportGraph> reportGraphs = new List<ReportGraph>();
            ReportGraph reportGraph;

            reportGraph = new ReportGraph();
            reportGraph.ID = 1;
            reportGraph.CName="c1111";
            reportGraph.OrderDate = "17/08/2553";
            reportGraph.PName1 = "";
            reportGraph.Month1 = 50;
            reportGraph.Month2 = 30;

            reportGraphs.Add(reportGraph);

            ReportDocument rp = new ReportDocument();
            string path = Application.StartupPath + @"\report\ReportGraphList.rpt";
            rp.Load(path);
            rp.SetDataSource(reportGraphs);

            PV.ReportSource = rp;
        }
Beispiel #2
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);
            }
        }
    }
Beispiel #3
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;
                    }
                }
            }
        }
    }
Beispiel #4
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));
        }
    }
    /// <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));
        }
    }
    /// <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))
        {
            registerWidthScript = true;
            ucChart.Visible = false;
            RequestStockHelper.Add("CMSGraphAutoWidth", true);
            return;
        }

        RequestStockHelper.Add("CMSGraphAutoWidth", false);
        registerWidthScript = 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 ev = new EventLogProvider();
                    ev.LogEvent("Report graph", "E", new Exception("Report graph '" + ReportGraphName + "' not found."));
                }
            }
            else
            {
                if (rgi != null)
                {
                    int correctWidth = 0;
                    if (ComputedWidth != 0)
                    {
                        correctWidth = ModifyGraphInfo();
                    }

                    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();

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

                    string noRecordText = 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 ev = new EventLogProvider();
                        ev.LogEvent("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>
    /// 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;
        }
    }
        private List<ReportGraph> graphSale(string _year)
        {
            List<ReportGraph> reportGraphs = new List<ReportGraph>();
            ReportGraph reportGraph;

            List<SaleCountGraph> reportGraphstmp = new List<SaleCountGraph>();
            reportGraphstmp = serviceSale.getCountGraph();

            foreach (SaleCountGraph r in reportGraphstmp)
            {
                string[] year = r.DateSale.Split('/');

                if (year[2].Equals(_year))
                {
                    reportGraph = new ReportGraph();
                    reportGraph.Month1 = this.countByMonthSale(reportGraphstmp, "01");
                    reportGraph.Month2 = this.countByMonthSale(reportGraphstmp, "02");
                    reportGraph.Month3 = this.countByMonthSale(reportGraphstmp, "03");
                    reportGraph.Month4 = this.countByMonthSale(reportGraphstmp, "04");
                    reportGraph.Month5 = this.countByMonthSale(reportGraphstmp, "05");
                    reportGraph.Month6 = this.countByMonthSale(reportGraphstmp, "06");
                    reportGraph.Month7 = this.countByMonthSale(reportGraphstmp, "07");
                    reportGraph.Month8 = this.countByMonthSale(reportGraphstmp, "08");
                    reportGraph.Month9 = this.countByMonthSale(reportGraphstmp, "09");
                    reportGraph.Month10 = this.countByMonthSale(reportGraphstmp, "10");
                    reportGraph.Month11 = this.countByMonthSale(reportGraphstmp, "11");
                    reportGraph.Month12 = this.countByMonthSale(reportGraphstmp, "12");
                    reportGraphs.Add(reportGraph);
                    break;

                }

            }
            return reportGraphs;
        }
    /// <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);
            }
        }
    }
Beispiel #10
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;
        }
    }