/// <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, 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> /// 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) { try { // Load value info object ReportValueInfo rvi = ValueInfo; if (rvi != null) { //Test security ReportInfo ri = ReportInfoProvider.GetReportInfo(rvi.ValueReportID); if (ri.ReportAccess != ReportAccessEnum.All) { if (!CMSContext.CurrentUser.IsAuthenticated()) { this.Visible = false; return; } } ContextResolver resolver = CMSContext.CurrentResolver; // Resolve dynamic data macros if (DynamicMacros != null) { for (int i = 0; i <= this.DynamicMacros.GetUpperBound(0); i++) { resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]); } } this.QueryIsStoredProcedure = rvi.ValueQueryIsStoredProcedure; this.QueryText = resolver.ResolveMacros(rvi.ValueQuery); //Set default parametrs directly if not set if (this.ReportParameters == null) { if (ri != null) { FormInfo fi = new FormInfo(ri.ReportParameters); // Get datarow with required columns this.ReportParameters = fi.GetDataRow(); fi.LoadDefaultValues(this.ReportParameters, true); } } } // Only use base parameters in case of stored procedure if (this.QueryIsStoredProcedure) { this.AllParameters = SpecialFunctions.ConvertDataRowToParams(this.ReportParameters, null); } // Load data DataSet ds = this.LoadData(); // If datasource is emptry, create empty dataset if (!DataHelper.DataSourceIsEmpty(ds)) { // Set literal text string value = rvi.ValueFormatString; if ((value == null) || (value == "")) { value = ValidationHelper.GetString(ds.Tables[0].Rows[0][0], ""); } else { value = string.Format(value, ds.Tables[0].Rows[0].ItemArray); } lblValue.Text = HTMLHelper.HTMLEncode(ResolveMacros(value)); } } catch (Exception ex) { // Display error message, if data load fail lblError.Visible = true; lblError.Text = "[ReportValue.ascx] Error loading the data: " + ex.Message; EventLogProvider ev = new EventLogProvider(); ev.LogEvent("Report value", "E", ex); } }
/// <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; } this.Visible = true; // Indicaates whether exception was throw during data loading bool errorOccurred = false; ReportInfo ri = null; try { this.ReportTableName = this.Parameter; this.EnsureTableInfo(); this.EnsureChildControls(); //Test security if (TableInfo != null) { ri = ReportInfoProvider.GetReportInfo(TableInfo.TableReportID); if (ri != null) { if (ri.ReportAccess != ReportAccessEnum.All) { if (!CMSContext.CurrentUser.IsAuthenticated()) { this.Visible = false; return; } } //Set default parametrs directly if not set if (this.ReportParameters == null) { FormInfo fi = new FormInfo(ri.ReportParameters); // Get datarow with required columns this.ReportParameters = fi.GetDataRow(); fi.LoadDefaultValues(this.ReportParameters, true); } ApplyTimeParameters(); } } // Only use base parameters in case of stored procedure if (this.QueryIsStoredProcedure) { this.AllParameters = SpecialFunctions.ConvertDataRowToParams(this.ReportParameters, null); } // Load data DataSet ds = this.LoadData(); // If no data load, set empty dataset if (DataHelper.DataSourceIsEmpty(ds)) { string noRecordText = ValidationHelper.GetString(TableInfo.TableSettings["QueryNoRecordText"], String.Empty); if (noRecordText != String.Empty) { GridViewObject.Visible = false; lblInfo.Text = noRecordText; lblInfo.Visible = true; return; } this.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.ToLower() == "system.string") { dr[dc.ColumnName] = ResolveMacros(ValidationHelper.GetString(dr[dc.ColumnName], "")); } } } } ApplyStyles(); // Databind to gridview control GridViewObject.DataSource = ds; this.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; } // Export data if ((ri != null) && (!errorOccurred)) { ProcessExport(ValidationHelper.GetCodeName(ri.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; 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; } }