CrystalReport

1.引用 版本-10.0.3300.0 路径-C:/Program Files/Common Files/Crystal Decisions/2.5/managed/ +CrystalDecisions.CrystalReports.Engine +CrystalDecisions.ReportSource +CrystalDecisions.Shared +CrystalDecisions.Web 2.web.config 添加程序集引用如下(只要在工具箱添加10.0.3300.0版本的CrystalReportViewer控件便会自动生成以下引用) 3.添加CrystalReportViewer控件 命名空间-CrystalDecisions.Web 程序集-CrystalDecisions.Web(10.0.3300.0) 4.控件属性设置(aspx) <%@ Page language="c#" Codebehind="liaodan_report.aspx.cs" AutoEventWireup="false" Inherits="UTStudy.Report.liaodan_report" %> <%@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %> Report_Title
说明 DisplayGroupTree--不显示左边组树 PrintMode--打印模式(ActiveX-使用客户端打印 | Pdf-导出Pdf再打印) 注意:在webform下横向打印会失效 HasToggleGroupTreeButton--不显示组树按钮 HasCrystalLogo--不显示水晶报表Logo EnableDrillDown--不能查看子报表详细内容(即不能点击入去) 5.后台代码(cs) using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; //引用命名空间 using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Web; //用IO实现将图片转成二进制方式导入报表中显示(通过blob字段接收) using System.IO; namespace UTStudy.Report { /// /// liaodan_report 的摘要说明。 /// public class liaodan_report : System.Web.UI.Page { protected CrystalDecisions.Web.CrystalReportViewer CRViewer; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(Request.QueryString["id"]!=null) { BindReport(); } } private void BindReport() { ReportDocument oRpt=new ReportDocument(); oRpt.Load(Server.MapPath("liaodan.rpt"));//加载报表 string strCon = new UTData().OleDbConn; string strSqlMain=""; string strSqlDetail=""; string strSqlHistory=""; string strSqlSubRptLink=""; string strSqlPdDetail=""; string strequno=""; string strprospec=""; string strfilever=""; string strStatus=""; string strPath=""; //Get SubReport Link strSqlSubRptLink =" select "; strSqlSubRptLink+=" equno=gch "; strSqlSubRptLink+=" ,prospec=gcxh "; strSqlSubRptLink+=" ,filever=文件版本 "; strSqlSubRptLink+=" ,status=case rtrim(受控状态) when '已受控' then '1' when '已过期' then '2' else '0' end "; strSqlSubRptLink+=" from utmis.dbo.jdhtk main where id="+Request.QueryString["id"].ToString(); SqlDataReader dr; UTData utd=new UTData(); utd.ExecuteSql(strSqlSubRptLink,out dr); if(dr.Read()) { strequno=dr["equno"].ToString().Trim().Replace("'","''"); strprospec=dr["prospec"].ToString().Trim().Replace("'","''"); strfilever=dr["filever"].ToString().Trim().Replace("'","''"); strStatus=dr["status"].ToString(); } dr.Close(); dr=null; //Main strSqlMain =" select "; strSqlMain+=" equno=gch "; strSqlMain+=" ,proname=gcmc "; strSqlMain+=" ,prospec=gcxh "; strSqlMain+=" ,modal=型别 "; strSqlMain+=" ,fileno=文件编号 "; strSqlMain+=" ,filever=文件版本 "; strSqlMain+=" ,ctrldate=convert(varchar(10),文件日期,120) "; strSqlMain+=" ,seclevel='S' "; strSqlMain+=" ,admindes=主管设计 "; strSqlMain+=" ,[check]=审核 "; strSqlMain+=" ,chkconf=审定 "; strSqlMain+=" ,sign=会签 "; strSqlMain+=" ,pass=批准 "; strSqlMain+=" ,[desc]=组件说明"; strSqlMain+=" from utmis.dbo.jdhtk main where id="+Request.QueryString["id"].ToString(); //Detail strSqlDetail =" set nocount on; "; strSqlDetail+=" if (select object_id('tempdb..#t')) is not null drop table #t "; strSqlDetail+=" create table #t( "; strSqlDetail+=" equno char(18) "; strSqlDetail+=" ,id int identity(1,1) "; strSqlDetail+=" ,modal char(100) "; strSqlDetail+=" ,spec char(100) "; strSqlDetail+=" ,matname char(100) "; strSqlDetail+=" ,repmodal varchar(210) "; strSqlDetail+=" ,amount numeric(8,3) "; strSqlDetail+=" ,unit char(4) "; strSqlDetail+=" ,elemmark varchar(250) "; strSqlDetail+=" ,param varchar(40) "; strSqlDetail+=" ,pdvalue varchar(10) "; strSqlDetail+=" ,pdnote varchar(50) "; strSqlDetail+=" ,brand char(15) "; strSqlDetail+=" ,[desc] char(40) "; strSqlDetail+=" ,buymodal char(40) "; strSqlDetail+=" ,link varchar(50) "; strSqlDetail+=" ) "; strSqlDetail+=" insert #t "; strSqlDetail+=" select "; strSqlDetail+=" equno=gch "; strSqlDetail+=" ,modal=xh04 "; strSqlDetail+=" ,spec=guige04 "; strSqlDetail+=" ,matname=pm "; strSqlDetail+=" ,repmodal=dyxh "; strSqlDetail+=" ,amount=slk "; strSqlDetail+=" ,unit=dw "; strSqlDetail+=" ,elemmark=yjbh "; strSqlDetail+=" ,param=pd "; strSqlDetail+=" ,pdvalue "; strSqlDetail+=" ,pdnote "; strSqlDetail+=" ,brand=品牌 "; strSqlDetail+=" ,[desc]=note "; strSqlDetail+=" ,buymodal=cgzjxh "; strSqlDetail+=" ,link=case when rtrim(zj_gch)!='' "; strSqlDetail+=" then "; strSqlDetail+=" case when (select count(*) from utmis.dbo.jdhtk where gch=rtrim(zj_gch) and 受控状态='已受控')>0 "; strSqlDetail+=" then 'liaodanzj.aspx?sb='+rtrim(zj_gch)+'|查看(已受控)'+rtrim(zj_gch) "; strSqlDetail+=" else "; strSqlDetail+=" case when (select count(*) from utmis.dbo.jdhtk where gch=zj_gch and (受控状态='未受控' or 受控状态='已过期'))>0 "; strSqlDetail+=" then 'liaodanzj.aspx?sb='+rtrim(zj_gch)+'|查看'+rtrim(zj_gch) "; strSqlDetail+=" else '' "; strSqlDetail+=" end "; strSqlDetail+=" end "; strSqlDetail+=" else '' "; strSqlDetail+=" end "; strSqlDetail+=" from utmis.dbo.jdcpcl detail "; strSqlDetail+=" where gch='"+strequno+"'"; strSqlDetail+=" order by xh04,guige04 "; strSqlDetail+=" select * from #t "; strSqlDetail+=" set nocount off; "; //History strSqlHistory =" select "; strSqlHistory+=" prospec=gcxh "; strSqlHistory+=" ,equno=gch "; strSqlHistory+=" ,version=文件版本 "; strSqlHistory+=" ,reason=修改理由 "; strSqlHistory+=" ,content=修改内容 "; strSqlHistory+=" ,modifyby=编制 "; strSqlHistory+=" ,admit=批准 "; strSqlHistory+=" ,date=convert(varchar(10),文件日期,120) "; strSqlHistory+=" from utmis.dbo.jdhtk history where gcxh='"+strprospec+"'"; strSqlHistory+=" and (受控状态='已受控' or 受控状态='已过期' or 受控状态='已批准' ) "; strSqlHistory+=" and 修改内容 is not null and 修改内容<>'' "; strSqlHistory+=" and 文件版本<='"+strfilever+"' order by 文件版本 desc "; //PdDetail new liaodan().pdtable(strequno,"1"); utd.ExecuteSql("if not exists(select * from ##TempPd) insert into ##TempPd values('"+strequno+"',N'无',N'无')"); utd.Dispose(); strSqlPdDetail="select gch,pd,pdnote=replace(pdnote,'  ',' ') from ##TempPd pddetail"; //用推模式(push)将数据源(ds)传入报表 SqlDataAdapter da_Main = new SqlDataAdapter(strSqlMain,strCon); SqlDataAdapter da_Detail = new SqlDataAdapter(strSqlDetail,strCon); SqlDataAdapter da_History = new SqlDataAdapter(strSqlHistory,strCon); SqlDataAdapter da_PdDetail=new SqlDataAdapter(strSqlPdDetail,strCon); DataSet ds=new DataSet(); da_Main.Fill(ds,"main");//ds中表的名称必须与查询中的数据集名称(或别名)相同 da_Detail.Fill(ds,"detail"); da_History.Fill(ds,"history"); da_PdDetail.Fill(ds,"pddetail"); if(ds.Tables["main"].Rows.Count>0) { ds.Tables["main"].Columns.Add("pic",System.Type.GetType("System.Byte[]"));//增加Binary字段 if(strStatus!="0") { if(strStatus=="1") { strPath=Server.MapPath(".")+"//shoukong.jpg"; } else { strPath=Server.MapPath(".")+"//zuofei.jpg"; } FileStream fs = new FileStream(strPath, FileMode.Open); // 获取文本流; BinaryReader br = new BinaryReader(fs); // 创建Binary Reader //赋值 ds.Tables["main"].Rows[0]["pic"]=br.ReadBytes((int)br.BaseStream.Length); //释放 fs.Close(); br.Close(); br = null; fs = null; } } ReportDocument oSubRpt1=oRpt.Subreports["detail"];//创建子报表对象 oSubRpt1.SetDataSource(ds);//设置子报表数据源 oRpt.OpenSubreport("detail");//打开子报表 ReportDocument oSubRpt2=oRpt.Subreports["history"]; oSubRpt2.SetDataSource(ds); oRpt.OpenSubreport("history"); ReportDocument oSubRpt3=oRpt.Subreports["pddetail"]; oSubRpt3.SetDataSource(ds); oRpt.OpenSubreport("pddetail"); oRpt.SetDataSource(ds); CRViewer.ReportSource = oRpt; UTStudy.liaodPZ1List liaod=new liaodPZ1List(); decimal sum=liaod.slzongj("2"," from utmis.dbo.jdcpcl where ltrim(rtrim(gch))='"+strequno+"'"); //创建参数,注意--必须在CRViewer.ReportSource = oRpt之后 //price ParameterFields paramFields=CRViewer.ParameterFieldInfo; ParameterField paramField=paramFields["price"]; ParameterValues curValues=paramField.CurrentValues; ParameterDiscreteValue discreteValue=new ParameterDiscreteValue(); discreteValue.Value=sum; curValues.Add(discreteValue); //image if(ds.Tables["main"].Rows.Count>0) { ParameterField paramField_img=paramFields["status"]; ParameterValues curValues_img=paramField_img.CurrentValues; ParameterDiscreteValue discreteValue_img=new ParameterDiscreteValue(); discreteValue_img.Value=strStatus; curValues_img.Add(discreteValue_img); } CRViewer.ParameterFieldInfo=paramFields; } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } 6.报表字段定义文件(ttx) --图片字段 pic Blog 7.报表功能按钮用到的图片和CSS 报表用到的UI,CSS,Script都放在 --C:/Program Files/Common Files/Crystal Decisions/2.5/crystalreportviewers10 这个目录下(这个目录必须为虚拟目录,否则找不到图片路径) 8.web服务器安装包 http://support.businessobjects.com/communityCS/FilesAndUpdates/cr10_net_server_install_chs.zip.asp 9.报表技术例子相关网站 水晶报表官方网站 http://support.businessobjects.com 中国软件--haibodotnet的文档中心 http://www.csdn.net/develop/MY_article.asp?author=haibodotnet 最新官方水晶报表实例 - 报表,应用程序 选择自 haibodotnet 的 Blog http://dev.csdn.net/develop/article/26/26239.shtm 水晶报表 Crystal Reports Crystalreports 技术论坛 http://61.145.126.29:9000/bbs.crystal/index.php 博客园 - 阿泰的软件实用主义 - 水晶报表网络资源(不断更新) http://www.cnblogs.com/babyt/articles/139165.html 阿泰的软件实用主义 - 水晶报表及OWC http://blog.csdn.net/babyt/category/39074.aspx haibodotnet的专栏 http://blog.csdn.net/haibodotnet/
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值