2012-03-02 7 views
1

동적 인 xtrachart을 사용하는 보고서 페이지가 있습니다. xtrachart을 동적으로 생성하려면 XtraReportBeforePrint 이벤트를 사용했습니다. 그러나 중복 된 XtraChart가 생성되었습니다. 시나리오에서 예상되는 차트 수는 2이지만 24 개의 차트가 생성됩니다 (예상 차트 12 복제본 생성).런타임시 생성 된 XtraChart가 너무 많습니다.

다음은 보고서

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; 
    } 
} 

내 코드에 대한 논리적 오류가 표시되지 않는 내 class입니다. 어쩌면 내가 이해하지 못하는 행동이있을 수 있습니다. 누구든지 이걸 도와 줄 수 있기를 바랍니다. 고마워.

답변

2

XtraReportDataSource을 설정하지 마십시오. 차트가 복제됩니다. XtraChartDataSource 만 설정하십시오.

+0

'XtraReport'의'DataSource' 설정이이 문제를 일으킨다 고 생각한 적은 한 번도 없었습니다. 매력처럼 일했습니다! 고마워요 왕자님! :) – KaeL