本文介绍了链接参数值上的子报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public DataTable LINQToDataTable<t>(IEnumerable<t> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null; //using System.Reflection;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
protected void btnPreview_Click(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
DataTable dtable = new DataTable();
RLMemberDBEntities db = new RLMemberDBEntities();
String fromid, toid;
fromid = Convert.ToString(cboFromCustomer.SelectedValue);
Session["customer"] = fromid;
toid = Convert.ToString(cboToCustomer.SelectedValue);
var customer = from customertable in db.CSR_CU_ACNT
where (customertable.CU_ACNT_NUM == fromid )
//orderby
select new { customertable.CU_ACNT_NUM, customertable.CUST_FRST_NM, customertable.ENC_CTZ_CORP_NUM, customertable.CUST_TYP_CD, customertable.BIRTH_DT};
DataTable dt = new DataTable();
dt = LINQToDataTable(customer);
var service = from servicetable in db.CUS_SERVICE
where (servicetable.CU_ACNT_NUM == fromid)
select new {servicetable.CUS_SRV_ACNT,servicetable.SVR_PLAN,servicetable.ATV_DATE };
DataTable dtsub = new DataTable();
dtsub = LINQToDataTable(service);
rptDoc.Load(Server.MapPath("~\\Reports\\CustomerReportNService - Copy.rpt"));//show
rptDoc.SetDataSource(dt);
rptDoc.SetParameterValue("ReportTitle", "Customer Report");
rptDoc.SetParameterValue("From", Session["customer"]);
Session["Report"] = rptDoc;
CrystalReportViewer1.ReportSource = rptDoc;
//
}
推荐答案
这篇关于链接参数值上的子报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!