#region 变量
private string stype;
private string swhere;
private ReportDocument rpt = new ReportDocument();
cashier.business.bi.ConsumerBI cbi = cashier.business.ABusinessFactory.BusinessFactory.CreateConsumerBI();
#endregion
//设置体检报告数据源
private void SetTJBGDataSource(string swhere)
{
try
{
//主报表数据
DataView dv = cbi.GetTJDataSource(swhere);
DataView dv1= cbi.GetTJDataSource(swhere);
DataView dv2 = cbi.GetTJDataSource(swhere);
string tjbh = string.Empty;
if (dv != null && dv.Count > 0)
{
tjbh = dv[0]["tjbh"].ToString();
}
DataView dvjg = cbi.GetTJJGDataSource("tjbh='" + tjbh + "'");
TableLogOnInfo logOnInfo = new TableLogOnInfo();
//这里必须事先申明一个ReportDocument对象 Report,同时加载数据报表
//建立安全信息
//受密码保护的 Microsoft Access 和 Paradox 等 PC 数据库也使用该方法,但 LogOnInfo.ServerName //和 LogOnInfo.DatabaseName 要保留为空
logOnInfo.ConnectionInfo.ServerName = @"URSN3B65HP9TWOC\SQLEXPRESS";
logOnInfo.ConnectionInfo.DatabaseName = "LIS";
logOnInfo.ConnectionInfo.UserID = "sa";
logOnInfo.ConnectionInfo.Password = "sc1234";
//logOnInfo.ConnectionInfo.ServerName = @"192.168.100.3";
//logOnInfo.ConnectionInfo.DatabaseName = "LIS";
//logOnInfo.ConnectionInfo.UserID = "sa";
//logOnInfo.ConnectionInfo.Password = "123.com";
string path = Server.MapPath(@"\CrystalReport3.rpt");
rpt.Load(path);
for (int i = 0; i < rpt.Database.Tables.Count; i++)
{
rpt.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
}
//rpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
//obj.SetDataSource(this.ds.Tables["tablename"]
rpt.SetDataSource(dv.Table);
rpt.OpenSubreport("GRWord").SetDataSource(dv1.Table);
rpt.OpenSubreport("JYZ").SetDataSource(dv2.Table);
rpt.OpenSubreport("JYJGRPT").SetDataSource(dvjg.Table);
//建立.rpt文件与CryStalReportviewer文件之间的连接
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.DataBind();
CrystalReportViewer1.Visible = true;
rpt.Refresh();
}
catch (Exception ex)
{
lblmsg.Text = ex.Message;
}
}
protected override void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
if (!IsPostBack)
{
//swhere = Session["stwhere"].ToString();
//stype = Session["stype"].ToString();
SetTJBGDataSource(" where [XM]='李俊'");
}
}