尝试将数据(主要详细信息)绑定到XtraReport程序化。如果 Master 是单个数据/值意味着 XtraReport 正常工作。但在我的情况下, Master 是多个数据/值,此处所有详细信息数据都会打印在所有 Masters 上。
例如。 (车辆报告) - 这里1)汽车& 2)自行车是大师,汽车大师的详细信息宝马,达特森,现代。 Bike Master的详细信息是 Honda,Moto,Yamaha 。现在我想像这样打印
Report
Cars
BMW
Datsun
Hyundai
Bikes
Honda
Moto
Yamaha
但它会像这样打印
Report
Cars
BMW
Datsun
Hyundai
Honda
Moto
Yamaha
Bikes
BMW
Datsun
Hyundai
Honda
Moto
Yamaha
我已经在设计师XtraReports中放置了标签。这是我在XtraReports programmatic
上打印数据的代码private void Report1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
try
{
StrConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Properties.Settings.Default.DataPath + @"CMDB\database.mdb";
string qry2 = "SELECT chequeid AS ChqBukId, chdescri AS ChqBukDesc, (SELECT bankname FROM tblBankMaster WHERE bank_id=tbchequebook.bankID) AS BankName FROM tbchequebook";
OleDbDataAdapter adapter1 = new OleDbDataAdapter(qry2, StrConnection);
DataSet ds1 = new DataSet();
adapter1.Fill(ds1, "Detail");
ds1.Tables[0].TableName = "QryBank";
DetailReport.DataSource = ds1;
XRBinding bindingBankName = new XRBinding("Text", ds1, "QryBank.BankName");
TXE_BankName.DataBindings.Add(bindingBankName);
XRBinding bindingchqbukame = new XRBinding("Text", ds1, "QryBank.ChqBukDesc");
TXE_ChequeBookDesc.DataBindings.Add(bindingchqbukame);
string qry4 = "SELECT chq_no, chq_date, party_name, chq_amount FROM tblchequeleafnew WHERE Status='P' ";
OleDbDataAdapter adapter3 = new OleDbDataAdapter(qry4, StrConnection);
DataSet ds3 = new DataSet();
adapter3.Fill(ds3, "Detail2");
ds3.Tables[0].TableName = "QryCheque";
DetailReport1.DataSource = ds3;
XRBinding bindingChqNo = new XRBinding("Text", ds3, "QryCheque.chq_no");
TXE_ChequeNo.DataBindings.Add(bindingChqNo);
XRBinding bindingChqDate = new XRBinding("Text", ds3, "QryCheque.chq_date", "{0:MM/dd/yyyy}");
TXE_ChequeDate.DataBindings.Add(bindingChqDate);
XRBinding bindingPartyName = new XRBinding("Text", ds3, "QryCheque.party_name");
TXE_PartyName.DataBindings.Add(bindingPartyName);
XRBinding bindingChqAmt = new XRBinding("Text", ds3, "QryCheque.chq_amount", "{0:N2}");
TXE_ChequeAmount.DataBindings.Add(bindingChqAmt);
}
catch (Exception ex)
{
XtraMessagebox.Show(ex.message.tostring());
}
}
这是我的XtraReport
如何解决这个问题才能获得精确的Master&它的细节。使用上面的代码我正好得到了Master,但它显示了所有主人的所有细节。
答案 0 :(得分:0)
您需要在主要级别和详细级别之间建立关系
如果您使用的是DataSet
,那么您需要为所有DataSet
成员和DataSource
集合使用一个DataSet.Relations
对象来创建表格之间的关系。您还需要将关系名称用作DetailReport.DataMember
属性,并在绑定中使用相同的关系名称
这是一个例子:
private void XtraReport1_BeforePrint(object sender, PrintEventArgs e)
{
var vehicleTypes = new DataTable("VehicleTypes");
vehicleTypes.Columns.Add("Type", typeof(string));
vehicleTypes.Rows.Add("Cars");
vehicleTypes.Rows.Add("Bikes");
var vehicles = new DataTable("Vehicles");
vehicles.Columns.Add("Type", typeof(string));
vehicles.Columns.Add("Name", typeof(string));
vehicles.Rows.Add("Cars", "BMW");
vehicles.Rows.Add("Cars", "Datsun");
vehicles.Rows.Add("Cars", "Hyundai");
vehicles.Rows.Add("Bikes", "Honda");
vehicles.Rows.Add("Bikes", "Moto");
vehicles.Rows.Add("Bikes", "Yamaha");
var dataSet = new DataSet("Data");
dataSet.Tables.Add(vehicleTypes);
dataSet.Tables.Add(vehicles);
dataSet.Relations.Add("VehiclesRelation", vehicleTypes.Columns["Type"], vehicles.Columns["Type"]);
DataSource = dataSet;
vehicleTypeLabel.DataBindings.Add("Text", dataSet, "Type");
VehicleDetailReport.DataMember = "VehiclesRelation";
vehicleLabel.DataBindings.Add("Text", dataSet, "VehiclesRelation.Name");
}