performsummary.aspx.cs

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

CS
238 行
字号
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.Performance
{
	/// <summary>
	/// PerformSummary 的摘要说明。
	/// </summary>
	public class PerformSummary : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblDept;
		protected System.Web.UI.WebControls.DropDownList cmbYear;
		protected System.Web.UI.WebControls.DataGrid grdResult;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.Panel pnlSearch;
		protected System.Web.UI.WebControls.Label lblYear;
		protected System.Web.UI.WebControls.Label lblDeptID;
		protected System.Web.UI.WebControls.Button btnSearch;
		protected System.Web.UI.WebControls.DropDownList cmbDeptList;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			#region// 在此处放置用户代码以初始化页面
			if(!this.Page.IsPostBack)
			{
				//获取员工编号信息和员工其他信息
				int iEmpID = Convert.ToInt32(Session["EmployeeID"]);
				Employee employee = new Employee();
				//查询员工信息,并返回查询是否成功
				int iSuccess = Employee.GetEmployeeInfo(iEmpID,ref employee);

				if(iSuccess == (int)DBResult.Success)
				{
					//查询员工信息操作成功
					//判断当前登录员工的权限
					if(!employee.IsManager)
					{
						//普通员工,没有权限查看此页
						this.lblMessage .Text = "对不起,该网页属经理专用,请退出!";
						this.lblMessage.Visible = true;
						this.pnlSearch.Visible = false;
					}
					else
					{
						//当前员工是部门经理或总经理
						this.pnlSearch.Visible = true;
						this.lblDeptID.Visible = false;

						//绑定"设定年份"
						int iYear = 2000;

						for(iYear = 2000;iYear <2100;iYear++)
						{
							//创建一个年份元素
							System.Web.UI.WebControls.ListItem YearItem = new ListItem(iYear.ToString(),iYear.ToString());

							//增加到下拉框中
							this.cmbYear.Items.Add(YearItem);
						}
						//设置默认选中年为当前年份
						this.cmbYear.SelectedValue = System.DateTime.Now.Year.ToString();


						//判断当前员工是否为总经理
						int iCEOID = 0;
						iSuccess = Employee.GetCEOInfo(ref iCEOID);
						if(iSuccess ==(int)DBResult.Success)
						{
							//查询是否为总经理操作成功
							if(employee.EmployeeID == iCEOID)
							{
								//当前登录的员工是总经理,要显示"要查询的部门"
								this.lblDept.Visible = true;
								this.cmbDeptList.Visible = true;

								this.lblMessage.Visible = false;


								//绑定部门列表,以供查询选择的部门
								//创建 DataSet 对象,用来保存部门列表
								DataSet dsDept = new DataSet();

								//查询部门列表,并判断是否查询成功
								iSuccess = DBUtils.CheckLvReq.GetDeptList(ref dsDept);

								if(iSuccess == (int)DBResult.Success)
								{
									//查询部门列表操作成功
									//绑定部门列表到下拉列表框
									this.cmbDeptList.DataSource = dsDept.Tables[0].DefaultView;
									this.cmbDeptList.DataTextField = "DeptName";
									this.cmbDeptList.DataValueField = "DeptID";
									this.cmbDeptList.DataBind();

									//默认选中第一项
									this.cmbDeptList.SelectedIndex = 0;
								}
								else
								{
									//查询部门列表操作失败
									this.lblMessage.Text = "数据库操作失败,请重试";
									this.lblMessage.Visible = true;
									this.pnlSearch.Visible = false;
								}

							}
							else
							{
								//当前员工是部门经理,没有权限查看其他部门的信息
								this.lblDept.Visible = false;
								this.cmbDeptList.Visible = false;
								this.grdResult.Visible = false;

								//获取部门经理所在的部门编号
								this.lblDeptID.Text = employee.DeptID.ToString();
								this.lblDeptID.Visible = false;
								this.lblMessage.Visible = false;
							}
						}
						else
						{
							//查询是否为总经理操作失败
							this.lblMessage.Text = "数据库操作失败,请重试";
							this.lblMessage.Visible = true;
							this.pnlSearch.Visible = false;
						}
					}
				}
				else
				{
					//查询员工信息操作失败
					this.lblMessage.Text = "数据库操作失败,请重试";
					this.lblMessage.Visible = true;
					this.pnlSearch.Visible = false;
				}
			}

			#endregion
		}

		/// <summary>
		/// 当前年份和部门编号,从数据库中检索部门业绩汇总信息
		/// </summary>
		private void RefreshPage()
		{
			//调用 Performance.DeptSummary(iDeptID, iyear, dsResult) 函数
			//获取部门编号
			int iDeptID = 0;
			if(this.lblDeptID.Text.Trim() != "")
			{
				//当前是部门经理登录
				iDeptID = Convert.ToInt32(this.lblDeptID.Text.Trim());
			}
			else
			{
				iDeptID = Convert.ToInt32(this.cmbDeptList.SelectedValue);
			}

			//获取当前年份
			int iYear = Convert.ToInt32(this.cmbYear.SelectedValue);

			//创建 DataSet 对象保存部门业绩汇总信息
			DataSet dsResult = new DataSet();

			//从数据库中检索部门业绩汇总信息,返回数据库操作是否成功的标志
			int iSuccess = DBUtils.Performance.DeptSummary(iDeptID,iYear,ref dsResult);
			if(iSuccess == (int)DBResult.Success )
			{
				//数据库操作成功
				if(dsResult.Tables[0].Rows.Count > 0)
				{
					//绑定汇总信息到 DataGrid 控件上
					this.grdResult.DataSource = dsResult.Tables[0].DefaultView;
					this.grdResult.DataBind();

					//将汇总信息显示出来
					this.grdResult.Visible = true;
					this.lblMessage.Visible = false;
				}
				else
				{
					//数据库中没有任何记录
					this.lblMessage.Visible = true;
					this.lblMessage.Text = "数据库中没有任何记录";
					this.grdResult.Visible = false;
				}
			}
			else
			{
				//数据库操作失败
				this.lblMessage.Visible = true;
				this.lblMessage.Text = "对不起,数据库操作失败,请重试!";
				this.grdResult.Visible = false;
			}
		}
		
		
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			this.RefreshPage();
		}

	
	}
}

⌨️ 快捷键说明

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