如何在 Crystal 报表中创建销售发票报表(在两个 Table 中绑定数据)
How to Create a Sales Invoice Report in Crystal Report(Bind data in Two Table)
我需要创建一个 crystal 报告以在两个 table 中显示数据(即,Sales_Invoice 和 Sales_Invoice_Items)。Sales_Invoice_Items有来自Sales_Invoice.I的外国人需要这样显示报告,
我创建了一个 Crystal 报告来显示这样的数据。 Sales_Invoice table 中的数据根据 invoice_no 正确分组。但是它显示 Sales_Invoice_Items 中的所有数据 每个 Sales_Invoice row.I 中的表需要显示 Sales_Invoice_Items 数据相对于 Sales_Invoice 中的外来数据 Sales_Invoice_项
然后我用下面的代码绑定它。
private DataSet getData()
{
DataSetSalesReport ds = new DataSetSalesReport();
try
{
using (SqlConnection con = new SqlConnection(DBCon.conStr))
{
con.Open();
SqlCommand cmd = new SqlCommand(AppConstraints.GET_SALES_REPORT);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rd = cmd.ExecuteReader();
decimal slno = 1;
while (rd.Read())
{
DataRow dr = ds.Tables["DataTable1"].NewRow();
dr["Id"] = rd["Id"].ToString();
dr["invoiceno"] = rd["invoiceno"].ToString();
dr["invoice_date"] = rd["invoice_date"].ToString();
dr["delivery_date"] = rd["delivery_date"].ToString();
dr["account"] = rd["account"].ToString();
dr["customer"] = rd["customer"].ToString();
dr["gross_amount"] = rd["gross_amount"].ToString();
dr["discount"] = rd["discount"].ToString();
dr["total_tax"] = rd["total_tax"].ToString();
dr["net_amount"] = rd["net_amount"].ToString();
dr["cash_discount"] = rd["cash_discount"].ToString();
dr["freight_charge"] = rd["freight_charge"].ToString();
dr["additional"] = rd["additional"].ToString();
dr["paid"] = rd["paid"].ToString();
dr["balance"] = rd["balance"].ToString();
dr["balancepaid_date"] = rd["balancepaid_date"].ToString();
dr["note"] = rd["note"].ToString();
dr["total_amount"] = rd["total_amount"].ToString();
dr["payment_mode"] = rd["payment_mode"].ToString();
dr["ac"] = rd["ac"].ToString();
dr["reg_date"] = rd["reg_date"].ToString();
dr["last_update"] = rd["last_update"].ToString();
dr["invoice_note"] = rd["invoice_note"].ToString();
dr["slno"] = slno++.ToString();
ds.Tables["DataTable1"].Rows.Add(dr);
using (SqlConnection con1 = new SqlConnection(DBCon.conStr))
{
con1.Open();
SqlCommand cmd1 = new SqlCommand(AppConstraints.GET_SALES_ITEMS_REPORT);
cmd1.Connection = con1;
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@Id", rd["Id"].ToString());
SqlDataReader rd1 = cmd1.ExecuteReader();
decimal j = 1;
while(rd1.Read())
{
DataRow dr1 = ds.Tables["DataTable2"].NewRow();
dr1["Id"] = rd1["Id"].ToString();
dr1["invoice_id"] = rd["Id"].ToString();
dr1["item_name"] = rd1["item_name"].ToString();
dr1["barcode"] = rd1["barcode"].ToString();
dr1["rate"] = rd1["rate"].ToString();
dr1["discount"] = rd1["discount"].ToString();
dr1["qty"] = rd1["qty"].ToString();
dr1["unit"] = rd1["unit"].ToString();
dr1["tax"] = rd1["tax"].ToString();
dr1["net"] = rd1["net"].ToString();
dr1["mrp"] = rd1["mrp"].ToString();
dr1["slno"] = j++.ToString();
ds.Tables["DataTable2"].Rows.Add(dr1);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return ds;
}
我在 WPF Window_Loaded 事件中调用了上面的方法 Window
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ReportDocument report = new ReportDocument();
report.Load("rptSalesReport.rpt");
report.SetDataSource(getData());
PrintSalesReport.ViewerCore.ReportSource = report;
PrintSalesReport.ToggleSidePanel = SAPBusinessObjects.WPF.Viewer.Constants.SidePanelKind.None;
}
我的数据集如下所示
在运行之后我得到了以下结果
在上面的结果中;它在下面的每个 Sales_Invoice 数据中显示所有 Sales_invoice_Items 数据。
我需要显示 Sales_Invoice 数据及其 Sales_Invoice_Items 数据(Sales_Invoice_Items 包含 Sales_Invoice 的外键)。我需要你的帮助这个。
谢谢
使用子报表解决这个问题
我需要创建一个 crystal 报告以在两个 table 中显示数据(即,Sales_Invoice 和 Sales_Invoice_Items)。Sales_Invoice_Items有来自Sales_Invoice.I的外国人需要这样显示报告,
我创建了一个 Crystal 报告来显示这样的数据。 Sales_Invoice table 中的数据根据 invoice_no 正确分组。但是它显示 Sales_Invoice_Items 中的所有数据 每个 Sales_Invoice row.I 中的表需要显示 Sales_Invoice_Items 数据相对于 Sales_Invoice 中的外来数据 Sales_Invoice_项
然后我用下面的代码绑定它。
private DataSet getData()
{
DataSetSalesReport ds = new DataSetSalesReport();
try
{
using (SqlConnection con = new SqlConnection(DBCon.conStr))
{
con.Open();
SqlCommand cmd = new SqlCommand(AppConstraints.GET_SALES_REPORT);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rd = cmd.ExecuteReader();
decimal slno = 1;
while (rd.Read())
{
DataRow dr = ds.Tables["DataTable1"].NewRow();
dr["Id"] = rd["Id"].ToString();
dr["invoiceno"] = rd["invoiceno"].ToString();
dr["invoice_date"] = rd["invoice_date"].ToString();
dr["delivery_date"] = rd["delivery_date"].ToString();
dr["account"] = rd["account"].ToString();
dr["customer"] = rd["customer"].ToString();
dr["gross_amount"] = rd["gross_amount"].ToString();
dr["discount"] = rd["discount"].ToString();
dr["total_tax"] = rd["total_tax"].ToString();
dr["net_amount"] = rd["net_amount"].ToString();
dr["cash_discount"] = rd["cash_discount"].ToString();
dr["freight_charge"] = rd["freight_charge"].ToString();
dr["additional"] = rd["additional"].ToString();
dr["paid"] = rd["paid"].ToString();
dr["balance"] = rd["balance"].ToString();
dr["balancepaid_date"] = rd["balancepaid_date"].ToString();
dr["note"] = rd["note"].ToString();
dr["total_amount"] = rd["total_amount"].ToString();
dr["payment_mode"] = rd["payment_mode"].ToString();
dr["ac"] = rd["ac"].ToString();
dr["reg_date"] = rd["reg_date"].ToString();
dr["last_update"] = rd["last_update"].ToString();
dr["invoice_note"] = rd["invoice_note"].ToString();
dr["slno"] = slno++.ToString();
ds.Tables["DataTable1"].Rows.Add(dr);
using (SqlConnection con1 = new SqlConnection(DBCon.conStr))
{
con1.Open();
SqlCommand cmd1 = new SqlCommand(AppConstraints.GET_SALES_ITEMS_REPORT);
cmd1.Connection = con1;
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@Id", rd["Id"].ToString());
SqlDataReader rd1 = cmd1.ExecuteReader();
decimal j = 1;
while(rd1.Read())
{
DataRow dr1 = ds.Tables["DataTable2"].NewRow();
dr1["Id"] = rd1["Id"].ToString();
dr1["invoice_id"] = rd["Id"].ToString();
dr1["item_name"] = rd1["item_name"].ToString();
dr1["barcode"] = rd1["barcode"].ToString();
dr1["rate"] = rd1["rate"].ToString();
dr1["discount"] = rd1["discount"].ToString();
dr1["qty"] = rd1["qty"].ToString();
dr1["unit"] = rd1["unit"].ToString();
dr1["tax"] = rd1["tax"].ToString();
dr1["net"] = rd1["net"].ToString();
dr1["mrp"] = rd1["mrp"].ToString();
dr1["slno"] = j++.ToString();
ds.Tables["DataTable2"].Rows.Add(dr1);
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return ds;
}
我在 WPF Window_Loaded 事件中调用了上面的方法 Window
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ReportDocument report = new ReportDocument();
report.Load("rptSalesReport.rpt");
report.SetDataSource(getData());
PrintSalesReport.ViewerCore.ReportSource = report;
PrintSalesReport.ToggleSidePanel = SAPBusinessObjects.WPF.Viewer.Constants.SidePanelKind.None;
}
我的数据集如下所示
在运行之后我得到了以下结果
在上面的结果中;它在下面的每个 Sales_Invoice 数据中显示所有 Sales_invoice_Items 数据。
我需要显示 Sales_Invoice 数据及其 Sales_Invoice_Items 数据(Sales_Invoice_Items 包含 Sales_Invoice 的外键)。我需要你的帮助这个。
谢谢
使用子报表解决这个问题