c#中读水晶报表转为pdf的方法
2013-09-13 10:03
531 查看
private voidCreateRpt(string pMapPath, string pRptID, string pFlag, string pHospNo, string pUsrID)
{
ReportDocument ReportDoc = new ReportDocument();
string strData = System.DateTime.Now.ToString("yyyy/MM/dd").Replace("/", "-");
string strServerPath = Server.MapPath("~");
if (!strServerPath.EndsWith("\\"))
strServerPath += "\\";
string strReportName = strServerPath + "DISRPT\\" + "水晶报表的名字";// "Check.rpt";水晶报表的位置,即绝对路径
ReportDoc.Load(strReportName);
ReportDoc.SetParameterValue("UsrID", pUsrID);//向水晶报表传递的参数
ReportDoc.SetParameterValue("HospNo", pHospNo);
SetReportDBInf(ReportDoc.Database.Tables);
string strPdfPath = "";//生成的pdf的存放路径
if (!System.IO.Directory.Exists(strPdfPath))
{
System.IO.Directory.CreateDirectory(strPdfPath);
}
string PdfName = pRptID.ToUpper().Replace(".RPT", "") + ".pdf";
strPdfPath += "\\" + PdfName;
if (File.Exists(strPdfPath))
File.Delete(strPdfPath);
ReportDoc.ExportToDisk(ExportFormatType.PortableDocFormat, strPdfPath);
}
//设定水晶报表连接数据库
public void SetReportDBInf(CrystalDecisions.CrystalReports.Engine.Tables rptTables)
{
string strDBLink = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
string[] aryDB = strDBLink.Split(';');
try
{
string strServerName = "";
string strDatabaseName = "";
string strUserID = "";
string strPassword = "";
for (int i = 0; i < aryDB.Length; i++)
{
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "SERVER")
strServerName = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "DATABASE")
strDatabaseName = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "USER ID")
strUserID = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "PASSWORD")
strPassword = aryDB[i].Split('=')[1].ToString().Trim();
}
CrystalDecisions.Shared.TableLogOnInfo tLogOnInfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table cTable in rptTables)
{
tLogOnInfo = cTable.LogOnInfo;
tLogOnInfo.ConnectionInfo.ServerName = strServerName;
tLogOnInfo.ConnectionInfo.DatabaseName = strDatabaseName;
tLogOnInfo.ConnectionInfo.UserID = strUserID;
tLogOnInfo.ConnectionInfo.Password = strPassword;
cTable.ApplyLogOnInfo(tLogOnInfo);
}
}
catch (Exception ex)
{ }
}
{
ReportDocument ReportDoc = new ReportDocument();
string strData = System.DateTime.Now.ToString("yyyy/MM/dd").Replace("/", "-");
string strServerPath = Server.MapPath("~");
if (!strServerPath.EndsWith("\\"))
strServerPath += "\\";
string strReportName = strServerPath + "DISRPT\\" + "水晶报表的名字";// "Check.rpt";水晶报表的位置,即绝对路径
ReportDoc.Load(strReportName);
ReportDoc.SetParameterValue("UsrID", pUsrID);//向水晶报表传递的参数
ReportDoc.SetParameterValue("HospNo", pHospNo);
SetReportDBInf(ReportDoc.Database.Tables);
string strPdfPath = "";//生成的pdf的存放路径
if (!System.IO.Directory.Exists(strPdfPath))
{
System.IO.Directory.CreateDirectory(strPdfPath);
}
string PdfName = pRptID.ToUpper().Replace(".RPT", "") + ".pdf";
strPdfPath += "\\" + PdfName;
if (File.Exists(strPdfPath))
File.Delete(strPdfPath);
ReportDoc.ExportToDisk(ExportFormatType.PortableDocFormat, strPdfPath);
}
//设定水晶报表连接数据库
public void SetReportDBInf(CrystalDecisions.CrystalReports.Engine.Tables rptTables)
{
string strDBLink = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
string[] aryDB = strDBLink.Split(';');
try
{
string strServerName = "";
string strDatabaseName = "";
string strUserID = "";
string strPassword = "";
for (int i = 0; i < aryDB.Length; i++)
{
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "SERVER")
strServerName = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "DATABASE")
strDatabaseName = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "USER ID")
strUserID = aryDB[i].Split('=')[1].ToString().Trim();
if (aryDB[i].Split('=')[0].ToString().ToUpper() == "PASSWORD")
strPassword = aryDB[i].Split('=')[1].ToString().Trim();
}
CrystalDecisions.Shared.TableLogOnInfo tLogOnInfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table cTable in rptTables)
{
tLogOnInfo = cTable.LogOnInfo;
tLogOnInfo.ConnectionInfo.ServerName = strServerName;
tLogOnInfo.ConnectionInfo.DatabaseName = strDatabaseName;
tLogOnInfo.ConnectionInfo.UserID = strUserID;
tLogOnInfo.ConnectionInfo.Password = strPassword;
cTable.ApplyLogOnInfo(tLogOnInfo);
}
}
catch (Exception ex)
{ }
}
相关文章推荐
- C#使用VS2005制作水晶报表 提示注册 解决方法
- 水晶报表使用经验谈1--建立水晶报表第一步及编译最易出现错误的解决方法及报表转换成pdf文档进行打印方法
- 建立水晶报表登录及报表转换成pdf文档进行打印的方法
- C# PDF转为图片的方法
- C#使用doggleReport生成pdf报表的方法
- C#将PDF转为多种图像文件格式的方法(Png/Bmp/Emf/Tiff)
- C#中水晶报表实现动态传递参数的简单方法
- 水晶报表直接打印 不用转为PDF打印
- C#操作水晶报表跟转换成PDF格式
- ASP.NET下水晶报表的导出成pdf格式的方法
- 用C#实现生成PDF文档的方法
- C#实现利用泛型将DataSet转为Model的方法
- 有没有人知道怎么把很多Crystal Report(水晶报表)的报表封装成c#的一个DLL
- C#实现Office文档转Pdf的方法
- C#获取指定PDF文件页数的方法
- C#实现 word、pdf、ppt 转为图片
- C#中调用abobe reader打开PDF文件的方法
- VC++中使用,安装及部署水晶报表的方法
- 水晶报表打印直接弹出打印设置页面不通过PDF进行打印
- PDF文档转为图片的方法