2012-03-02 2 views
1

У меня есть страница отчета, которая использует динамические xtrachart s. Чтобы динамически создать xtrachart, я использовал событие BeforePrint. Но есть дубликат XtraChart сгенерирован. Из сценария ожидаемое количество диаграмм равно 2, но есть 24 сгенерированных диаграммы (создание 12 дубликатов ожидаемых графиков).Слишком много XtraChart Сгенерировано во время выполнения

Вот мой class для отчета

public class SystemReport : DevExpress.XtraReports.UI.XtraReport 
{ 
    private DevExpress.XtraReports.UI.DetailBand Detail; 
    private DevExpress.XtraReports.UI.PageFooterBand PageFooter; 
    private ReportHeaderBand ReportHeader; 
    ... 

    public SystemReport(List<SystemLog> logs) 
    { 
     InitializeComponent(); 
     Detail.Report.DataSource = logs 
    } 

    protected override void Dispose(bool disposing) 
    { 
     ... 
    } 

    #region Designer generated code 

    private void InitializeComponent() 
    { 
     this.Detail = new DevExpress.XtraReports.UI.DetailBand(); 
     this.PageFooter = new DevExpress.XtraReports.UI.PageFooterBand(); 
     this.xrPageInfo1 = new DevExpress.XtraReports.UI.XRPageInfo(); 
     this.ReportHeader = new DevExpress.XtraReports.UI.ReportHeaderBand(); 
     this.xrLblSystemReport = new DevExpress.XtraReports.UI.XRLabel(); 
     ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); 
     // 
     // Detail 
     // 
     this.Detail.Name = "Detail"; 
     this.Detail.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); 
     this.Detail.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; 
     // 
     // PageFooter 
     // 
     this.PageFooter.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { 
     this.xrPageInfo1}); 
     this.PageFooter.HeightF = 25.83332F; 
     this.PageFooter.Name = "PageFooter"; 
     this.PageFooter.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); 
     this.PageFooter.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; 
     // 
     // xrPageInfo1 
     // 
     this.xrPageInfo1.ForeColor = System.Drawing.Color.Gray; 
     this.xrPageInfo1.Format = "Page {0} of {1}"; 
     this.xrPageInfo1.LocationFloat = new DevExpress.Utils.PointFloat(388.7917F, 0F); 
     this.xrPageInfo1.Name = "xrPageInfo1"; 
     this.xrPageInfo1.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); 
     this.xrPageInfo1.SizeF = new System.Drawing.SizeF(120F, 25F); 
     this.xrPageInfo1.StylePriority.UseForeColor = false; 
     this.xrPageInfo1.StylePriority.UseTextAlignment = false; 
     this.xrPageInfo1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter; 
     // 
     // ReportHeader 
     // 
     this.ReportHeader.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { 
     this.xrLblSystemReport}); 
     this.ReportHeader.HeightF = 107.0417F; 
     this.ReportHeader.Name = "ReportHeader"; 
     this.ReportHeader.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); 
     this.ReportHeader.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; 
     // 
     // xrLblSystemReport 
     // 
     this.xrLblSystemReport.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold); 
     this.xrLblSystemReport.LocationFloat = new DevExpress.Utils.PointFloat(363.3333F, 10.00001F); 
     this.xrLblSystemReport.Name = "xrLblSystemReport"; 
     this.xrLblSystemReport.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); 
     this.xrLblSystemReport.SizeF = new System.Drawing.SizeF(175F, 25F); 
     this.xrLblSystemReport.Text = "System Report"; 
     this.xrLblSystemReport.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopCenter; 
     // 
     // SystemReport 
     // 
     this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { 
     this.Detail, 
     this.PageFooter, 
     this.ReportHeader}); 
     this.Font = new System.Drawing.Font("Arial", 9.75F); 
     this.ForeColor = System.Drawing.Color.Gray; 
     this.Landscape = true; 
     this.PageHeight = 850; 
     this.PageWidth = 1100; 
     this.Version = "11.2"; 
     this.BeforePrint += new System.Drawing.Printing.PrintEventHandler(Report_BeforePrint); 
     ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); 
    } 

    private void Report_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) 
    { 
     DetailBand detail = (DetailBand)((XtraReport)sender).Bands[BandKind.Detail]; 
     List<SystemLog> logs = (List<SystemLog>)detail.Report.DataSource; 
     int chartQuantity = GetChartQuantity(logs); 

     PopulateDetailWithCharts(detail, chartQuantity); 
     PopulateDetailWithValues(logs, detail, chartQuantity); 
    } 

    #endregion 

    private int GetChartQuantity(List<SystemLog> logs) 
    { 
     return logs.Count/15 + (logs.Count % 15 > decimal.Zero ? 1 : 0); 
    } 

    private void PopulateDetailWithCharts(DetailBand detail, int chartQuantity) 
    { 
     for (int i = 0; i < chartQuantity; i++) 
     { 
      if (detail.FindControl(string.Format("xrChart{0}", i), false) == null) 
      { 
       XRChart chart = GetChart(i); 
       detail.Controls.Add(chart); 
       chart.Location = new Point(0, 300 * (i)); 
      } 
     } 
    } 

    private XRChart GetChart(int i) 
    { 
     XRChart chart = new XRChart(); 

     chart.AppearanceNameSerializable = "Gray"; 
     chart.BackColor = System.Drawing.Color.Transparent; 
     chart.BorderColor = System.Drawing.SystemColors.ControlText; 
     chart.Borders = DevExpress.XtraPrinting.BorderSide.None; 
     chart.ImageType = DevExpress.XtraReports.UI.ChartImageType.Bitmap; 
     chart.Name = string.Format("xrChart{0}", i); 
     chart.PaletteBaseColorNumber = 11; 
     chart.PaletteName = "Nature Colors"; 
     chart.SizeF = new System.Drawing.SizeF(852.4167F, 300F); 
     chart.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; 
     chart.Legend.Visible = false; 

     return chart; 
    } 

    private void PopulateDetailWithValues(List<SystemLog> logs, DetailBand detail, int chartQuantity) 
    {    
     for (int i = 0; i < chartQuantity; i++) 
     { 
      XRChart chart = (XRChart)detail.FindControl(string.Format("xrChart{0}", i), false); 
      chart.DataSource = logs.SkipWhile((log, index) => index < i * 15).TakeWhile((log, index) => index < i + 15).ToList(); 
      InitializeChartValues(chart); 
     } 
    } 

    private void InitializeChartValues(XRChart chart) 
    { 
     Series salesSeries = new Series(); 
     salesSeries.ArgumentDataMember = "DateTime"; 
     salesSeries.ValueDataMembers.AddRange(new string[] { "Quantity" }); 
     salesSeries.Name = "System Log Quantity"; 

     chart.Series.AddRange(new Series[] { salesSeries }); 

     XYDiagram diagram = (XYDiagram)chart.Diagram; 
     diagram.AxisY.Title.Text = "Quantity of System Logs"; 
     diagram.AxisX.Title.Text = "Date of System Logs"; 
     diagram.AxisY.Title.Visible = true; 
     diagram.AxisX.Title.Visible = true; 
     diagram.AxisX.Label.Angle = -30; 
    } 
} 

Я не вижу никакой логической ошибки на моих кодов. Может быть, есть некоторые поведения, которые я не понимаю. Надеюсь, кто-нибудь может мне помочь. Большое спасибо.

ответ

2

Не устанавливайте DataSourceXtraReport. Он будет дублировать ваш график. Установите только DataSource вашего XtraChart.

+0

Я никогда не думал, что установка 'DataSource' 'XtraReport' приведет к этой проблеме. Работал как шарм! Большое спасибо принцу! :) – KaeL