⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staffreport.aspx.cs

📁 除了具有传统OA的邮件、工作流、文档等功能外
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 UDS.SubModule.Staff.Report
{
	/// <summary>
	/// StaffReport 的摘要说明。
	/// </summary>
	public partial class StaffReport : System.Web.UI.Page
	{
	
		private StaffDataSet ds;
		private StaffList stafflistreport;

		private string staffname,mobile,gender,email,bound;
		private int positionid;
		private string[] displayfields;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			ds = new StaffDataSet();
			DataTable dt =(DataTable)Cache["StaffList"];
			if(!Page.IsPostBack)
			{
				staffname = Session["staffname"].ToString();
				positionid = Int32.Parse(Session["positionid"].ToString());
				mobile = Session["mobile"].ToString();
				email = Session["email"].ToString();
				gender = Session["gender"].ToString();
				bound = Session["bound"].ToString();
				displayfields = (string[])Session["displayfieldsname"];

				ViewState["staffname"] = staffname;
				ViewState["positionid"] = positionid.ToString();
				ViewState["mobile"] = mobile.ToString();
				ViewState["email"] = email.ToString();
				ViewState["gender"] = gender.ToString();
				ViewState["bound"] = bound.ToString();
				ViewState["displayfields"] = displayfields;

				Session["staffname"] = null;
				Session["positionid"] = null;
				Session["mobile"] = null;
				Session["gender"] = null;
				Session["displayfieldsname"] = null;
				Session["bound"] = null;
			}
			else
			{
				staffname = ViewState["staffname"].ToString();
				positionid = Int32.Parse(ViewState["positionid"].ToString());
				mobile = ViewState["mobile"].ToString();
				email = ViewState["email"].ToString();
				gender = ViewState["gender"].ToString();
				bound = ViewState["bound"].ToString();
				displayfields = (string[])ViewState["displayfields"];
			}

			if(dt==null)
			{
				//得不到缓存的内容,重新获取
				SqlDataReader dr;
				UDS.Components.Staff staff = new UDS.Components.Staff();
				dr = staff.Find(staffname,positionid,mobile,email,gender,bound);
				dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr);

				Cache["StaffList"] = dt;
				
			}

			//添加datatable中的数据
			foreach(DataRow row in dt.Rows)
			{
				DataRow staffviewrow = ds.StaffView.NewRow();
				staffviewrow["Staff_Name"] = row["Staff_Name"].ToString();
				staffviewrow["RealName"] = row["RealName"].ToString();
				staffviewrow["Mobile"] = row["Mobile"].ToString();
				staffviewrow["SexName"] = row["SexName"].ToString();
				staffviewrow["Email"] = row["Email"].ToString();
				staffviewrow["Position_Name"] = row["Position_Name"].ToString();
				ds.StaffView.AddStaffViewRow((StaffDataSet.StaffViewRow)staffviewrow);
			}

			stafflistreport = new StaffList();
			stafflistreport.SetDataSource(ds);
			crv_StaffList.ReportSource = stafflistreport;
			//根据用户选择隐藏字段
			foreach(string fieldname in displayfields)
			{
				stafflistreport.ReportDefinition.ReportObjects["ttl"+fieldname].ObjectFormat.EnableSuppress = false;
				stafflistreport.ReportDefinition.ReportObjects[fieldname].ObjectFormat.EnableSuppress = false;
			}
			
			crv_StaffList.DataBind();
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btn_Change_Click(object sender, System.EventArgs e)
		{
			string filetype = "";
			filetype = ddl_FileFormat.SelectedValue;
			string contenttype = "";
			

			string myfilename = Request.MapPath(".")+"\\ReportExportFile\\"+Session.SessionID+"."+filetype;
			CrystalDecisions.Shared.DiskFileDestinationOptions mydiskfiledestinationoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
			mydiskfiledestinationoptions.DiskFileName = myfilename;
			CrystalDecisions.Shared.ExportOptions myExportOptions = stafflistreport.ExportOptions;
			myExportOptions.DestinationOptions = mydiskfiledestinationoptions;
			myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

			switch(ddl_FileFormat.SelectedItem.Value)
			{
				case "pdf":
					contenttype = "application/pdf";
					myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
					break;
				case "doc":
					contenttype = "application/msword";
					myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
					break;
			}
			
			
			stafflistreport.Export();

			Response.ClearContent();
			Response.ClearHeaders();
			Response.ContentType = contenttype;
			Response.WriteFile(myfilename);
			Response.Flush();
			Response.Close();

			System.IO.File.Delete(myfilename);
		}

		protected void lbtn_IEPrint_Click(object sender, System.EventArgs e)
		{
			if(lbtn_IEPrint.Text == "IE打印预览")
			{
				crv_StaffList.SeparatePages = false;
				crv_StaffList.DisplayToolbar = false;
				lbtn_IEPrint.Text = "取消IE打印预览";
			}
			else
			{
				crv_StaffList.SeparatePages = true;
				crv_StaffList.DisplayToolbar = true;
				lbtn_IEPrint.Text = "IE打印预览";
			}
		}

		protected void ddl_FileFormat_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -