📄 pdffrm.aspx.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;
namespace WebApplication1
{
/// <summary>
/// PdfFrm 的摘要说明。
/// </summary>
public class PdfFrm : System.Web.UI.Page
{
protected System.Data.Odbc.OdbcConnection odbcConnection1;
protected System.Data.Odbc.OdbcCommand odbcSelectCommand1;
protected System.Data.Odbc.OdbcCommand odbcInsertCommand1;
protected System.Data.Odbc.OdbcCommand odbcUpdateCommand1;
protected System.Data.Odbc.OdbcCommand odbcDeleteCommand1;
protected System.Data.Odbc.OdbcDataAdapter odbcDataAdapter1;
protected System.Data.DataSet dataSet1;
protected CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strCommand;
string strReport,StartDate,EndDate;
string strKind;
int PageSize;
//传递参数
//strConnect = (string)Session["strConnect"];
strCommand = (string)Session["strCommand"];
strReport = (string)Session["strReport"];
StartDate = (string)Session["StartDate"];
EndDate = (string)Session["EndDate"];
strKind = (string)Session["strKind"];
//2006-05-07
PageSize = (int)Session["PageSize"];
if(!Global.CheckUserValidation((string)Session["strRole"], Global.MENU_VIEWRPT))
{
Response.Redirect("err_session.htm", true);
}
//连接DB
connectionDB();
odbcDataAdapter1.SelectCommand.CommandText = strCommand;
odbcDataAdapter1.SelectCommand.Connection = odbcConnection1;
reportDocument1 = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
switch(strReport)
{
case "t_order":
odbcDataAdapter1.Fill(dataSet1,"T_ORDER");
//传递参数给CrystalReports
reportDocument1.Load(Server.MapPath("Order_Rpt.rpt"));
reportDocument1.SetParameterValue("strKind",strKind);
break;
case "t_batch_order":
odbcDataAdapter1.Fill(dataSet1,"T_BATCH_ORDER");
//传递参数给CrystalReports
reportDocument1.Load(Server.MapPath("Batch_order_rpt.rpt"));
reportDocument1.SetParameterValue("strKind",strKind);
break;
case "Batch_Date_rpt":
odbcDataAdapter1.Fill(dataSet1,"Batch_Date_Total");
//传递参数给CrystalReports
reportDocument1.Load(Server.MapPath("Batch_Date_rpt.rpt"));
reportDocument1.SetParameterValue("StartDate",StartDate);
reportDocument1.SetParameterValue("EndDate",EndDate);
break;
case "Order_Date_rpt":
odbcDataAdapter1.Fill(dataSet1,"Order_Date_Total");
//传递参数给CrystalReports
reportDocument1.Load(Server.MapPath("Order_Date_rpt.rpt"));
reportDocument1.SetParameterValue("StartDate",StartDate);
reportDocument1.SetParameterValue("EndDate",EndDate);
break;
}
//2006-05-07
switch(PageSize)
{
case 0:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
break;
case 1:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperA4;
break;
case 2:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperA5;
break;
case 3:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperB4;
break;
case 4:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperB5;
break;
case 5:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperA3;
break;
case 6:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperLetter;
break;
case 7:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.Paper10x14;
break;
case 8:
reportDocument1.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.Paper11x17;
break;
}
CrystalDecisions.Shared.PageMargins margins;
margins = new CrystalDecisions.Shared.PageMargins();
margins = reportDocument1.PrintOptions.PageMargins;
margins.bottomMargin = 250;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 250;
reportDocument1.PrintOptions.ApplyPageMargins(margins);
reportDocument1.SetDataSource(dataSet1);
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
reportDocument1.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
reportDocument1.ExportOptions.ExportFormatType =CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
DiskOpts.DiskFileName = Server.MapPath("Crystal_Pdf_Rpt.pdf");
reportDocument1.ExportOptions.DestinationOptions = DiskOpts;
reportDocument1.Export();
Response.ContentType = "Application/pdf";
Response.WriteFile(Server.MapPath("Crystal_Pdf_Rpt.pdf"));
Response.End();
// Global.WriteLog(ref odbcConnection1, strUser,Global.MENU_PRINT,Global.ACTION_OTHER,"打印"); //+strDate+DListIndex+RptDList.SelectedItem.Text
closeDB();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.odbcConnection1 = new System.Data.Odbc.OdbcConnection();
this.odbcSelectCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcInsertCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcUpdateCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcDeleteCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter();
this.dataSet1 = new System.Data.DataSet();
this.reportDocument1 = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
//
// odbcDataAdapter1
//
this.odbcDataAdapter1.DeleteCommand = this.odbcDeleteCommand1;
this.odbcDataAdapter1.InsertCommand = this.odbcInsertCommand1;
this.odbcDataAdapter1.SelectCommand = this.odbcSelectCommand1;
this.odbcDataAdapter1.UpdateCommand = this.odbcUpdateCommand1;
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// reportDocument1
//
this.reportDocument1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
this.reportDocument1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
this.reportDocument1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
this.reportDocument1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
}
#endregion
private void connectionDB()
{
Global.OpenConnection(ref odbcConnection1);
}
private void closeDB()
{
odbcConnection1.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -