Exemplo n.º 1
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);
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        if ((TableInfo == null) || ((GraphImageWidth != 0) && (ComputedWidth == 0)))
        {
            // Graph width is computed no need to create graph
            return;
        }

        Visible = true;

        EnsureChildControls();

        LoadTable();

        mReportInfo = ReportInfoProvider.GetReportInfo(TableInfo.TableReportID);
        if (mReportInfo == null)
        {
            return;
        }

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

        // Prepare query attributes
        QueryIsStoredProcedure = TableInfo.TableQueryIsStoredProcedure;
        QueryText = TableInfo.TableQuery;

        // Init parameters
        InitParameters(mReportInfo.ReportParameters);

        // Init macro resolver
        InitResolver();

        mErrorOccurred = false;
        DataSet ds = null;

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

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

        // If no data load, set empty dataset
        if (DataHelper.DataSourceIsEmpty(ds))
        {
            if (EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
                return;
            }

            string noRecordText = ValidationHelper.GetString(TableInfo.TableSettings["QueryNoRecordText"], String.Empty);
            if (!String.IsNullOrEmpty(noRecordText))
            {
                UIGridViewObject.Visible = false;
                lblInfo.Text             = ResolveMacros(noRecordText);
                lblInfo.Visible          = true;
                EnableExport             = false;
                return;
            }

            if (!EmailMode)
            {
                Visible = false;
                return;
            }
        }
        else
        {
            UIGridViewObject.Visible = true;
            // Resolve macros in column names
            int i = 0;
            foreach (DataColumn dc in ds.Tables[0].Columns)
            {
                if (dc.ColumnName == "Column" + (i + 1))
                {
                    dc.ColumnName = ResolveMacros(ds.Tables[0].Rows[0][i].ToString());
                }
                else
                {
                    dc.ColumnName = ResolveMacros(dc.ColumnName);
                }
                i++;
            }

            // Resolve macros in dataset
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    if (dc.DataType.FullName.Equals("system.string", StringComparison.CurrentCultureIgnoreCase))
                    {
                        dr[dc.ColumnName] = ResolveMacros(ValidationHelper.GetString(dr[dc.ColumnName], String.Empty));
                    }
                }
            }

            if (EmailMode)
            {
                // For some email formats, export data in csv format
                EmailFormatEnum format = EmailHelper.GetEmailFormat(ReportSubscriptionSiteID);

                if ((format == EmailFormatEnum.Both) || (format == EmailFormatEnum.PlainText))
                {
                    using (var ms = new SystemIO.MemoryStream())
                    {
                        DataExportHelper deh  = new DataExportHelper(ds);
                        byte[]           data = deh.ExportToCSV(ds, 0, ms, true);
                        ReportSubscriptionSender.AddToRequest(mReportInfo.ReportName, "t" + TableInfo.TableName, data);
                    }
                }

                // For plain text email show table only as attachment
                if (format == EmailFormatEnum.PlainText)
                {
                    menuCont.Visible = false;
                    ltlEmail.Visible = true;
                    ltlEmail.Text    = String.Format(GetString("reportsubscription.attachment"), TableInfo.TableName);
                    return;
                }

                GenerateTableForEmail(ds);
                menuCont.Visible = false;
                return;
            }
        }

        // Databind to gridview control
        UIGridViewObject.DataSource = ds;
        EnsurePageIndex();
        UIGridViewObject.DataBind();

        if ((TableFirstColumnWidth != Unit.Empty) && (UIGridViewObject.Rows.Count > 0))
        {
            UIGridViewObject.Rows[0].Cells[0].Width = TableFirstColumnWidth;
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        if ((GraphImageWidth != 0) && (ComputedWidth == 0))
        {
            // Graph width is computed no need to create graph
            return;
        }

        Visible = true;

        errorOccurred = false;

        try
        {
            ReportTableName = Parameter;

            EnsureTableInfo();
            EnsureChildControls();

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

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

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

                    ApplyTimeParameters();
                }
            }

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

            // Load data
            DataSet ds = LoadData();

            // If no data load, set empty dataset
            if (DataHelper.DataSourceIsEmpty(ds))
            {
                if (EmailMode && SendOnlyNonEmptyDataSource)
                {
                    Visible = false;
                    return;
                }

                string noRecordText = ValidationHelper.GetString(TableInfo.TableSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    GridViewObject.Visible = false;
                    lblInfo.Text           = CMSContext.ResolveMacros(noRecordText);
                    plcInfo.Visible        = true;
                    EnableExport           = false;
                    return;
                }

                if (!EmailMode)
                {
                    Visible = false;
                }
            }
            else
            {
                GridViewObject.Visible = true;
                // Resolve macros in column names
                int i = 0;
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    if (dc.ColumnName == "Column" + ((int)(i + 1)).ToString())
                    {
                        dc.ColumnName = ResolveMacros(ds.Tables[0].Rows[0][i].ToString());
                    }
                    else
                    {
                        dc.ColumnName = ResolveMacros(dc.ColumnName);
                    }
                    i++;
                }

                // Resolve macros in dataset
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foreach (DataColumn dc in ds.Tables[0].Columns)
                    {
                        if (dc.DataType.FullName.ToLowerCSafe() == "system.string")
                        {
                            dr[dc.ColumnName] = ResolveMacros(ValidationHelper.GetString(dr[dc.ColumnName], ""));
                        }
                    }
                }

                if (EmailMode)
                {
                    // For some email formats, export data in csv format
                    EmailFormatEnum format = EmailHelper.GetEmailFormat(ReportSubscriptionSiteID);

                    if ((format == EmailFormatEnum.Both) || (format == EmailFormatEnum.PlainText))
                    {
                        using (MemoryStream ms = MemoryStream.New())
                        {
                            DataExportHelper deh  = new DataExportHelper(ds);
                            byte[]           data = deh.ExportToCSV(ds, 0, ms, true);
                            ReportSubscriptionSender.AddToRequest(ri.ReportName, "t" + TableInfo.TableName, data);
                        }
                    }

                    // For plain text email show table only as attachment
                    if (format == EmailFormatEnum.PlainText)
                    {
                        menuCont.Visible = false;
                        ltlEmail.Visible = true;
                        ltlEmail.Text    = String.Format(GetString("reportsubscription.attachment"), TableInfo.TableName);
                        return;
                    }

                    GenerateTableForEmail(ds);
                    menuCont.Visible = false;
                    return;
                }
            }

            ApplyStyles();

            // Databind to gridview control
            GridViewObject.DataSource = ds;
            EnsurePageIndex();
            GridViewObject.DataBind();

            if ((TableFirstColumnWidth != Unit.Empty) && (GridViewObject.Rows.Count > 0))
            {
                GridViewObject.Rows[0].Cells[0].Width = TableFirstColumnWidth;
            }
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text    = "[ReportTable.ascx] Error loading the data: " + ex.Message;
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Report table", "E", ex);
            errorOccurred = true;
        }
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        pnlContent.Controls.Clear();
        mReportControls = null;

        // Report info must exists
        if (ReportInfo != null)
        {
            // Check permissions for report
            if (ReportInfo.ReportAccess != ReportAccessEnum.All)
            {
                if (!CMSContext.CurrentUser.IsAuthenticated())
                {
                    Visible = false;
                    return;
                }
            }

            // If ReloadData is called before Init, load parameters
            if (!wasInit || IgnoreWasInit)
            {
                LoadParameters();
            }

            // Set parameters only if it is allowed
            if (mLoadFormParameters)
            {
                ReportParameters = formElem.DataRow;
            }

            // Clear resolver because it can contains old parameters values
            ClearResolver();

            // Build report HTML
            mReportHTML = ReportInfo.ReportLayout;
            mReportHTML = ResolveMacros(mReportHTML);
            mReportHTML = HTMLHelper.ResolveUrls(mReportHTML, null);

            // For emails - resolve metafile images as inline attachments
            if (EmailMode)
            {
                // Find all inline images
                MatchCollection coll = InlineImageRegex.Matches(mReportHTML);
                foreach (Match m in coll)
                {
                    Guid guid = ValidationHelper.GetGuid(m.Groups[1], Guid.Empty);
                    if (guid != Guid.Empty)
                    {
                        // For all found images, find according metafile
                        MetaFileInfo mfi = MetaFileInfoProvider.GetMetaFileInfo(guid, null, true);
                        if (mfi != null)
                        {
                            // If metafile found add binary representation to inline attachments
                            ReportSubscriptionSender.AddToRequest(ReportName, "g" + guid, mfi.MetaFileBinary);
                            mReportHTML = mReportHTML.Replace(m.Value, "##InlineImage##" + guid + "##InlineImage##");
                        }
                    }
                }
            }

            // Add the content
            pnlContent.Controls.Clear();
            pnlContent.Controls.Add(new LiteralControl(mReportHTML));

            ControlsHelper.ResolveDynamicControls(pnlContent);

            // Null GraphImageWidh if no graph present to enable load alone tables,values,etc
            bool containsGraph = mReportHTML.Contains("%%control:ReportGraph?");
            if (!containsGraph)
            {
                GraphImageWidth = 0;
            }

            // Indicates if any item in the report is visible
            bool itemVisible = false;

            // Init the child controls
            foreach (AbstractReportControl ctrl in ReportControls)
            {
                if ((CheckInnerControls) && (!ctrl.IsValid(ReportInfo)))
                {
                    ctrl.Visible = false;
                    continue;
                }

                ctrl.RenderCssClasses           = RenderCssClasses;
                ctrl.ReportParameters           = ReportParameters;
                ctrl.ContextParameters          = ContextParameters;
                ctrl.AllParameters              = AllParameters;
                ctrl.SavedReportGuid            = Guid.Empty;
                ctrl.GraphImageWidth            = GraphImageWidth;
                ctrl.DynamicMacros              = DynamicMacros;
                ctrl.TableFirstColumnWidth      = TableFirstColumnWidth;
                ctrl.SelectedInterval           = SelectedInterval;
                ctrl.RenderCssClasses           = RenderCssClasses;
                ctrl.SendOnlyNonEmptyDataSource = SendOnlyNonEmptyDataSource;
                ctrl.EmailMode = EmailMode;
                ctrl.ReportSubscriptionSiteID = ReportSubscriptionSiteID;

                // Do no generate export context menu for saved graph
                ctrl.EnableExport = !isSave && EnableExport;

                if (AreaMaxWidth != 0)
                {
                    ctrl.ComputedWidth = AreaMaxWidth;
                }

                // In save mode must be defined new Guid for graph image and saved reeport id
                if (mSaveMode)
                {
                    ctrl.SavedReportGuid = Guid.NewGuid();
                    ctrl.SavedReportID   = mSavedReportId;
                }
                ctrl.ReloadData(forceLoad);

                if (ctrl.ComputedWidth != 0)
                {
                    AreaMaxWidth = ctrl.ComputedWidth;
                }

                itemVisible = itemVisible || ctrl.Visible;
            }

            if (!itemVisible && EmailMode)
            {
                Visible = false;
            }

            reportLoaded = true;

            // Display/hide the filtering form
            formElem.Visible = mDisplayFilterResult;
        }
    }
Exemplo n.º 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;
        }
    }