protected void Page_Load(object sender, EventArgs e) { DataBase.Clear(); //clear the first-level cache in NHibernaet var EntityOneRaw = DataBase.EntityOne.ToList(); var EntityOneObjects = EntityOneRaw.Select(q => AutoMapper.Mapper.Map <NHibernateClassLibrary.Entities.EntityOne, EntityOnePoco>(q)).ToList(); GridViewObject.DataSource = new BindingList <EntityOnePoco>(EntityOneObjects); GridViewObject.DataBind(); }
/// <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) { 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)); } }