c#endread怎么打印出来_C#实现打印

C#实现导出pdf文件,打印

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingBusinessFacade;usingSystem.IO;usingCommon.Table;usingCrystalDecisions.Shared;usingCrystalDecisions.CrystalReports.Engine;public partial classPages_ReportFile_BhXjspf_XjspfCheckList : PageBase

{

ReportDocument myReportDoc= newReportDocument();private void SetParameterValue(string strColumn, stringstrValue)

{

myReportDoc.SetParameterValue(strColumn, strValue);

}protected void Page_Load(objectsender, EventArgs e)

{if (!Page.IsPostBack)

{string strResult0 = "";string strResult1 = "";string strResult2 = "";string strBuildArea = string.Empty;string strHouseCount = string.Empty;string strPerBuild = string.Empty;string strPage = string.Empty;string strCount = string.Empty;this.CheckPageParameter();string strError = string.Empty;

PrintSystem mySystem= new PrintSystem(base.UserSessionID);

DataSet myData= newDataSet();

myData= mySystem.mothed(this.GetSessionParameterValue("FILE_ID"), outstrError);if (!string.IsNullOrEmpty(strError))

{

webTools.InsertAlert(this.Page, webTools.FilterInvalidString(strError));

webTools.closewin(this.Page);return;

}

myData.Tables[LY_ZG_XJSPF_TABLE.LY_ZG_XJSPF_TABLENAME].Columns.Add("QRCODE", typeof(System.Byte[]));

myData.Tables[LY_ZG_XJSPF_TABLE.LY_ZG_XJSPF_TABLENAME].Rows[0]["QRCODE"] =ProductQR(myData);

myData.AcceptChanges();if (!string.IsNullOrEmpty(myData.Tables[0].Rows[0]["GZ_RESULT"].ToString()))

{switch (myData.Tables[0].Rows[0]["GZ_RESULT"].ToString())

{case "0":

strResult0= "√";

strResult1= "×";

strResult2= "×";break;case "1":

strResult1= "√";

strResult0= "×";

strResult2= "×";break;case "2":

strResult2= "√";

strResult0= "×";

strResult1= "×";break;

}

}for (int i = 0; i < myData.Tables[LY_FAMILYHOUSEINFORMATION_TABLE.LY_FAMILYHOUSEINFORMATION_TABLENAME].Rows.Count; i++)

{

strHouseCount= myData.Tables[2].Rows[i]["HouseCount"].ToString();if (!string.IsNullOrEmpty(myData.Tables[2].Rows[i]["SumIDENTIFIEDAREA"].ToString()))

{

strPerBuild= Convert.ToString(Math.Round((Convert.ToDouble(myData.Tables[2].Rows[i]["SumIDENTIFIEDAREA"].ToString()) / Convert.ToDouble(myData.Tables[0].Rows[0]["PersonCount"].ToString())), 2));

strBuildArea= myData.Tables[2].Rows[i]["SumIDENTIFIEDAREA"].ToString();

}

}for (int i = 0; i < myData.Tables[LY_H_RECEIVE_TABLE.LY_H_RECEIVE_TABLENAME].Rows.Count; i++)

{

strCount= myData.Tables[3].Rows[i]["counts"].ToString();

strPage= myData.Tables[3].Rows[i]["pages"].ToString();

}

myReportDoc.Load(Server.MapPath(@"rptxjspfChecklist.rpt"));

myReportDoc.SetDataSource(myData);//这里必须先设置数据源,然后再设置参数,否则报‘找不到参数’的错误

myReportDoc.SetParameterValue("Result0", strResult0);

myReportDoc.SetParameterValue("Result1", strResult1);

myReportDoc.SetParameterValue("Result2", strResult2);

myReportDoc.SetParameterValue("BuildArea", strBuildArea);

myReportDoc.SetParameterValue("HouseCount", strHouseCount);

myReportDoc.SetParameterValue("PerBuild", strPerBuild);

myReportDoc.SetParameterValue("page", strPage);

myReportDoc.SetParameterValue("count", strCount);try{

DiskFileDestinationOptions myDestinationFile= newDiskFileDestinationOptions();string filename = "";

filename= System.DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".pdf";

Stream stream=myReportDoc.ExportToStream(ExportFormatType.PortableDocFormat);byte[] bytes = new byte[stream.Length];

stream.Read(bytes,0, bytes.Length);

stream.Close();

String contentType= "application/octet-stream";

Response.Clear();

Response.ClearContent();

Response.ClearHeaders();

Response.Buffer= false;

Response.AddHeader("Content-Disposition", "attachment; filename=" +filename);

Response.AddHeader("Content-Length", bytes.Length.ToString());

Response.Charset= "GB2312";

Response.ContentType=contentType;

Response.BinaryWrite(bytes);

Response.Flush();

Response.End();

}catch(System.Exception exp)

{throwexp;

}

}

}private byte[] ProductQR(DataSet myData)

{

DataTable mytable= myData.Tables[0];string strFILE_ID = mytable.Rows[0][LY_ZG_XJSPF_TABLE.FILE_ID_FIELD].ToString().Trim();string strRegister_num = mytable.Rows[0][LY_ZG_XJSPF_TABLE.REGISTER_NUM_FIELD].ToString().Trim();#region 设置QR码

string strCode = strRegister_num + "\r\n";//"审核表编号:" +

strCode += strFILE_ID + "\r\n";//"收件号:" +

QRCode.Service1 QrCode = newQRCode.Service1();returnQrCode.GetQrCode(strCode);#endregion}private void Page_UnLoad(objectsender, System.EventArgs e)

{if (myReportDoc != null)

{

myReportDoc.Close();

myReportDoc.Dispose();

}

}

}

1.注意rpt中的数据库专家中的xsd文件的类名必须和访问数据库返回的表名必须相同,否则会报登录数据库失败的错误

见了他,她变得很低很低,低到尘埃里。但她心里是欢喜的,从尘埃里开出花来。魂牵梦绕,辗转反侧,可越是这样执着的爱,越是让我束手无策,无法表达,成就一段烽火佳话,迎接她包含深情炙热的眼光吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值