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

📄 printsalary.aspx.cs

📁 该管理系统的主要功能是管理员工资料、管理员工考勤、计算员工薪资和业绩评定等。大部分涉及对敏感数据修改的工作都仅由人事部完成
💻 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;

using DBUtils;

namespace BlueHill.Salary
{
	/// <summary>
	/// PrintSalary 的摘要说明。
	/// </summary>
	public class PrintSalary : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Panel pnlSalary;
		protected System.Web.UI.WebControls.DropDownList cmbYear;
		protected System.Web.UI.WebControls.DropDownList cmbMonth;
		protected System.Web.UI.WebControls.Button btnSearch;
		protected System.Web.UI.WebControls.Button btnPrint;
		protected System.Web.UI.WebControls.Label lblBase;
		protected System.Web.UI.WebControls.Label lblOvertime;
		protected System.Web.UI.WebControls.Label lblAttendance;
		protected System.Web.UI.WebControls.Label lblOther;
		protected System.Web.UI.WebControls.Label lblFinally;
		protected System.Web.UI.WebControls.Label lblSalaryID;
		protected System.Web.UI.WebControls.Label lblMessage;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!this.Page.IsPostBack)
			{
				//绑定可选择的年份
				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();

				//设置默认选中月为当前月
				this.cmbMonth.SelectedValue = System.DateTime.Now.Month.ToString();
			}
		}

		#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.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			//设置要查询的年份
			int iYear =2000;

			//设置要查询月份的界线,在上个月的最后一天和下个月的第一天之间

			//获取要查询的上个月的最后一天
			int iPreMonth = Convert.ToInt32(this.cmbMonth.SelectedValue) - 1;
			int iDay = 31;
			if(iPreMonth <1)
			{
				//当前月份为1月,前一个月为上一年的12月
				iYear = Convert.ToInt32(this.cmbYear.SelectedValue) - 1;
				iPreMonth = 12;
			}
			else
			{
				iYear = Convert.ToInt32(this.cmbYear.SelectedValue);
			}
			if(iPreMonth == 4||iPreMonth == 6||iPreMonth == 9||iPreMonth == 12)
			{
				//月份为小月只有30天
				iDay = 30;
			}
			if(iPreMonth == 2 ||((iYear%4 == 0 && iYear%100 != 0)||iYear%400 == 0))
			{
				//润年的2月
				iDay = 28;
			}
			else 
			{
				if(iPreMonth == 2)
				{
					iDay = 29;
				}
			}

			string strStartTime = iYear + "-" + iPreMonth + "-" + iDay ;

			//获取要查询的下一个月的第一天
			int iNextMonth = Convert.ToInt32(this.cmbMonth.SelectedValue) +1;
			if(iNextMonth > 12)
			{
				//当前月份是12月,下个月为下一年的1月
				iYear = Convert.ToInt32(this.cmbYear.SelectedValue) + 1;
				iNextMonth = 1;
			}
			else
			{
				iYear = Convert.ToInt32(this.cmbYear.SelectedValue);
			}
			string strEndTime = iYear + "-" + iNextMonth + "-01";

			//获取员工编号
			int iEmpID = Convert.ToInt32(Session["EmployeeID"]);

			//设置时间格式是否正确的标志,默认为真,将字符串转化为时间类型时出错则为 false
			bool isTime = true;

			//设置一个时间类型变量用于判断时间格式是否正确
			DateTime dt = System.DateTime.Now;

			try
			{
				//验证开始时间的格式是否正确
				dt = Convert.ToDateTime(strStartTime);
			}
			catch(Exception ex)
			{
				//开始时间格式不正确
				isTime = false;
			}

			try
			{
				//验证结束时间的格式是否正确
				dt = Convert.ToDateTime(strEndTime);
			}
			catch(Exception ex)
			{
				//结束时间格式不正确
				isTime = false;
			}

			if(isTime)
			{
				//用户输入的时间格式正确

				//创建 DataSet 对象保存查询返回的结果集
				DataSet dsResult = new DataSet();

				//查询员工工资信息,返回数据库操作是否成功的标志
				int iSuccess = DBUtils.SalaryInfo.QueryHistorySalary(iEmpID,strStartTime,strEndTime,ref dsResult);

				if(iSuccess == (int)DBResult.Success)
				{
					//数据库操作成功
					if(dsResult.Tables[0].Rows.Count >0 )
					{
						//数据库中有查询的记录
						//将工资信息绑定到 DataGrid 控件上
						//工资信息编号
						this.lblSalaryID.Text = dsResult.Tables[0].Rows[0]["SalaryID"].ToString();
						this.lblSalaryID.Visible = false;

						//基本工资
                        this.lblBase.Text = dsResult.Tables[0].Rows[0]["BasicSalary"].ToString();
						this.lblBase.Visible = true;

						//加班工资
						this.lblOvertime.Text = dsResult.Tables[0].Rows[0]["OvertimeSalary"].ToString();
						this.lblOvertime.Visible = true;

						//考勤扣除
						this.lblAttendance.Text = dsResult.Tables[0].Rows[0]["AbsenceSalary"].ToString();
						this.lblAttendance.Visible = true;

						//其他增减
						this.lblOther.Text = dsResult.Tables[0].Rows[0]["OtherSalary"].ToString();
						this.lblOther.Visible = true;

						//最终所得
						this.lblFinally.Text = dsResult.Tables[0].Rows[0]["ActualSalary"].ToString();
						this.lblFinally.Visible = true;

						//将工资信息显示出来
						this.pnlSalary.Visible = true;
						this.lblMessage.Visible = false;
						this.btnPrint.Visible = true;
						this.lblSalaryID.Visible = false;
					}
					else
					{
						//数据库中没有要查询的记录
						this.lblMessage.Text = "没有任何工资信息记录";
						this.lblMessage.Visible = true;
						this.btnPrint.Visible = false;
						this.pnlSalary.Visible = false;
						this.lblSalaryID.Visible = false;
					}
				}
				else
				{
					//数据库操作失败
					this.lblMessage.Text = "数据库操作失败,请重试";
					this.lblMessage.Visible = true;
					this.btnPrint.Visible = false;
					this.pnlSalary.Visible = false;
					this.lblSalaryID.Visible = false;
				}
			}
			else
			{
				//用户输入的时间格式不正确
				this.lblMessage.Text = "时间格式不正确,请重新输入";
				this.lblMessage.Visible = true;
				this.btnPrint.Visible = false;
				this.pnlSalary.Visible = false;
				this.lblSalaryID.Visible = false;
			}
		}

		private void btnPrint_Click(object sender, System.EventArgs e)
		{
			//获取工资编号
			string strSalaryID = this.lblSalaryID.Text.Trim();

			//转向打印页面
//			Response.Write("<script language=javascript>window.open('SalaryMenu.aspx?SalaryID=" + strSalaryID + "','', 'alwaysRaised=1,dependent=1,resizable=0,scrollbars,width=450,height=550');</script>");
//			Response.Write("<script language=javascript> window.open('SalaryMenu.aspx?SalaryID=" + strSalaryID + "','')</script>");
			Response.Redirect("SalaryMenu.aspx?SalaryID=" + strSalaryID);
		}
	}
}

⌨️ 快捷键说明

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