showempinfo.aspx.cs

来自「该管理系统的主要功能是管理员工资料、管理员工考勤、计算员工薪资和业绩评定等。大部」· CS 代码 · 共 179 行

CS
179
字号
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 DBUtils;

namespace BlueHill.EmployeeInfo
{
	/// <summary>
	/// ShowEmpInfo 的摘要说明。
	/// </summary>
	public class ShowEmpInfo : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Image image;
		protected System.Web.UI.WebControls.TextBox tbSelfintro;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Label lblEmpID;
		protected System.Web.UI.WebControls.Label lblEmail;
		protected System.Web.UI.WebControls.Label lblManage;
		protected System.Web.UI.WebControls.Label lblDept;
		protected System.Web.UI.WebControls.Label lblExt;
		protected System.Web.UI.WebControls.HyperLink HlinkMailtoEmp;
		protected System.Web.UI.WebControls.HyperLink HlinkMailtoManager;
		protected System.Web.UI.WebControls.Label lblMsg;
		protected System.Web.UI.WebControls.Label lblName;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!this.Page.IsPostBack)
			{
				int EmpID = 0;
				
				try
				{
					if(Request.QueryString["EmpID"] != null)
					{
						//记录登录者查询到的员工编号
						EmpID = Convert.ToInt32(Request.QueryString["EmpID"]);
						
						//将"修改"按钮设为不可用
						this.btnSubmit.Enabled = false;

						//将"自我介绍"文本框设为只读
						this.tbSelfintro.ReadOnly = true;

						//将"提示信息"标签设为不可见
						this.lblMsg.Visible = false;
					}
					else
					{
						//记录登录者的编号
						EmpID = Convert.ToInt32(Session["EmployeeID"]);
					}

					//显示员工的个人信息
					this.Search(EmpID);
				}
				catch(Exception ex)
				{
					Response.Write("<script>alert('没人此用户!')</script>");
				}
			}
		}

		/// <summary>
		/// 显示员工的个人信息
		/// </summary>
		/// <param name="iEmpID">员工编号</param>
		protected void Search(int iEmpID)
		{
			//定义一个员工对象,以获取员工个人信息,并显示在页面上
			Employee employee = new Employee();
			
			//获取员工个人信息,除照片外
			Employee.GetEmployeeInfo(iEmpID,ref employee);
			
			//部门名称
			this.lblDept.Text = employee.DeptName;
			
			//员工邮箱
			this.lblEmail.Text = employee.Email;
			
			//员工姓名
			this.lblName.Text = employee.Name;
			
			//经理姓名
			this.lblManage.Text = employee.ManagerName;
			
			//员工编号
			this.lblEmpID.Text = employee.EmployeeID.ToString();
			
			//员工分机
			this.lblExt.Text = employee.Telephone;

			//员工自我介绍
			this.tbSelfintro.Text = employee.SelfIntro.Trim();
			
			//超链接,可以发邮件给此员工
			this.HlinkMailtoEmp.NavigateUrl = "mailto:" + employee.Email;
			
			//超链接,可以发邮件给此经理
			this.HlinkMailtoManager.NavigateUrl = "mailto:" + employee.ManagerEmail;

			//下面的方法是将数据库中的照片存储到文件中,并在页面上显示
			//DBUtils.EmployeeInfo.CreatePhotoFile(int iEmpID, string strFilePath )

			//员工照片地址
			string strPhotoPath = @"../Common/EmployeePhoto/" + iEmpID.ToString() +".jpg";
			string strFilePath = Server.MapPath(strPhotoPath);

			//将员工照片保存到Common/EmployeePhot/+iEmpID.bmp文件中,
			//返回DBResult.Success 或 DBResult.Failed,表示操作成功与否,失败则使用默认的图片.
			int iSavePhoto = DBUtils.EmployeeInfo.CreatePhotoFile(iEmpID,strFilePath);

			//员工的照片保存到以员工号命名的文件中了
			if(iSavePhoto == (int)DBResult.Success)
			{
				this.image.ImageUrl= strPhotoPath;
			}

		}

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

		}
		#endregion

		//更新员工自我介绍
		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			string strSelfIntro = this.tbSelfintro.Text;
			//自我介绍在200字以内
			if(strSelfIntro.Length>200)
			{
				strSelfIntro = strSelfIntro.Substring(0,200);
			}

			//执行更新员工自我介绍
			//返回DBResult.Success 或 DBResult.Failed,表示操作成功与否
			int iResult = DBUtils.EmployeeInfo.ChangeSelfIntro(Convert.ToInt32(Session["EmployeeID"]),strSelfIntro);
		
			//更新成功
			if(iResult ==(int)DBResult.Success)
			{
				Response.Write("<script>alert('已成功更新自我介绍!')</script>");
			}
			else
			{
				Response.Write("<script>alert('自我介绍更新失败,请重试!')</script>");
			}
		}
	}
}

⌨️ 快捷键说明

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