我正在使用VS社区2017和CrystalReports的sp25。
我制作了一个程序,该程序应该将List对象中的数据显示到CrystalReport窗口中。这是列表类:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AgricoveBilling
{
public class reporter : IEnumerable<reporter>
{
public string InvoiceNo { get; set; }
public string InvoiceDt { get; set; }
public string DueDt { get; set; }
public string BillToName { get; set; }
public string BillToAdd { get; set; }
public string ItemID1Name { get; set; }
public decimal ItemID1Price { get; set; }
public decimal ItemID1Qty { get; set; }
public decimal ItemID1Total { get; set; }
public string ItemID2Name { get; set; }
public decimal ItemID2Price { get; set; }
public decimal ItemID2Qty { get; set; }
public decimal ItemID2Total { get; set; }
public string ItemID3Name { get; set; }
public decimal ItemID3Price { get; set; }
public decimal ItemID3Qty { get; set; }
public decimal ItemID3Total { get; set; }
public string ItemID4Name { get; set; }
public decimal ItemID4Price { get; set; }
public decimal ItemID4Qty { get; set; }
public decimal ItemID4Total { get; set; }
public string ItemID5Name { get; set; }
public decimal ItemID5Price { get; set; }
public decimal ItemID5Qty { get; set; }
public decimal ItemID5Total { get; set; }
public string ItemID6Name { get; set; }
public decimal ItemID6Price { get; set; }
public decimal ItemID6Qty { get; set; }
public decimal ItemID6Total { get; set; }
public string ItemID7Name { get; set; }
public decimal ItemID7Price { get; set; }
public decimal ItemID7Qty { get; set; }
public decimal ItemID7Total { get; set; }
public string ItemID8Name { get; set; }
public decimal ItemID8Price { get; set; }
public decimal ItemID8Qty { get; set; }
public decimal ItemID8Total { get; set; }
public string ItemID9Name { get; set; }
public decimal ItemID9Price { get; set; }
public decimal ItemID9Qty { get; set; }
public decimal ItemID9Total { get; set; }
public string ItemID10Name { get; set; }
public decimal ItemID10Price { get; set; }
public decimal ItemID10Qty { get; set; }
public decimal ItemID10Total { get; set; }
public string ItemID11Name { get; set; }
public decimal ItemID11Price { get; set; }
public decimal ItemID11Qty { get; set; }
public decimal ItemID11Total { get; set; }
public decimal Subtotal { get; set; }
public string DiscountType { get; set; }
public decimal DiscountValue { get; set; }
public decimal SubtotalLessDiscount { get; set; }
public decimal TaxRate { get; set; }
public decimal Totaltax { get; set; }
public decimal GrossTotal { get; set; }
public decimal Paid { get; set; }
public decimal Due { get; set; }
public IEnumerator<reporter> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
}
我已将报告程序类设置为数据源
CrystalReportViewer嵌入的窗体具有以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
namespace AgricoveBilling
{
public partial class Printpreview : Form
{
List<reporter> rep;
public Printpreview(List<reporter> r)
{
InitializeComponent();
rep = r;
}
private void Printpreview_Load(object sender, EventArgs e)
{
ReportDocument rpt = new ReportDocument();
rpt.Load(@"..\printform.rpt");
rpt.SetDataSource(rep);
print_crystalreport.ReportSource = rpt;
print_crystalreport.Zoom(55);
print_crystalreport.Refresh();
}
}
}
没有错误。使用QuickWatch,我检查了所有C#对象是否正确加载。我知道正在加载正确的rpt文件,因为报表上的Text对象是正确的。
但是报告上绝对没有数据。
说实话:我不知道CrystalReports如何将正确的字段与正确的数据绑定在一起。我是否应该在某个地方写一些代码来做到这一点?
我尝试将iEnumerable更改为常规类,但是随后在SetDataSoruce期间被告知该对象是无效的数据源。我尝试手动使用SetParamerterValue,但是那样会出现Badindex错误。我确保参数名称正确。