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

📄 signtrainmanage.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 System.Data.SqlClient;
using MisOfficeAffair.Components;
using SQLHelper;

namespace MisOfficeAffair.DesktopModules.SignTrain
{
	/// <summary>
	/// SignTrainManage 的摘要说明。
	/// </summary>
	public class SignTrainManage : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button SelectBtn;
		protected System.Web.UI.WebControls.ListBox TrainList;
		protected System.Web.UI.WebControls.Label TrainName;
		protected System.Web.UI.WebControls.DataGrid SignTrainList;
		protected System.Web.UI.WebControls.Button AddBtn;
	
		public int nTrainID    = -1;
		private static string CurrentTrainName = "";
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			///判断用户是否登陆
			if(Session["UserID"] == null)
			{
				Response.Redirect("~/Default.aspx");
			}
			///判断用户是否是超级管理员
			if(Components.User.IsAuthorityAdmin(Session["UserID"].ToString()) >= Components.User.USERTYPENORMAL)
			{
				Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
				Response.Write("<script>history.back();</script>");
			}			
			if(Request.Params["TrainID"] != null)
			{
				nTrainID = Int32.Parse(Request.Params["TrainID"].ToString());			
			}
			if(!Page.IsPostBack)
			{
				///绑定控件的数据
				BindTrainData();

				///设置员工的选择项
				MisSystem.SetListBoxItem(TrainList,nTrainID.ToString());

				if(nTrainID > -1)
				{   ///显示操作前的信息
					BindSignTrainData(nTrainID);
					TrainName.Text = CurrentTrainName;
				}
				else
				{   ///显示当前选择项的信息
					if(TrainList.SelectedIndex > -1)
					{
						BindSignTrainData(Int32.Parse(TrainList.SelectedValue));
						TrainName.Text = TrainList.SelectedItem.Text;
					}
					else
					{   ///显示第一项的信息
						if(TrainList.Items.Count > 0)
						{
							BindSignTrainData(Int32.Parse(TrainList.Items[0].Value));
							TrainName.Text = TrainList.Items[0].Text;
							TrainList.SelectedIndex = 0;
						}
					}
				}
			}

			///设置添加按钮的可用性
			AddBtn.Enabled = (TrainList.Items.Count <= 0) ? false : true;			
		}

		private void BindTrainData()
		{
			///定义获取数据的类
			MisOfficeAffair.Components.Train train = new MisOfficeAffair.Components.Train();
			SqlDataReader rect = train.GetTrains();

			///设定控件的数据源
			TrainList.DataSource = rect;
			
			///设定控件的Text属性和Value属性
			TrainList.DataTextField = "Subject";
			TrainList.DataValueField = "TrainID";

			///绑定控件的数据
			TrainList.DataBind();

			///关闭数据读取器和数据库的连接
			rect.Close();
		}

		private void BindSignTrainData(int nTrainID)
		{
			///定义获取数据的类
			MisOfficeAffair.Components.SignTrain sign = new MisOfficeAffair.Components.SignTrain();
			SqlDataReader recs = sign.GetSignByTrain(nTrainID);

			///创建DataSet数据源
			DataTable dataTable = SystemTools.ConvertDataReaderToDataTable(recs);
			DataSet dataSet = new DataSet("SignTrain");
			dataSet.Tables.Add(dataTable);

			///设定控件的数据源
			SignTrainList.DataSource = dataSet;
			///绑定控件的数据
			SignTrainList.DataBind();
		}

		public string FormatStatus(string statusString)
		{
			switch(statusString)
			{
				case "0":
					return("申请");
				case "1":
					return("提交");
				case "2":
					return("确认");				
				default:
					return("状态错误");
			}
		}		

		public string FormatDate(string dateString)
		{
			return(Convert.ToDateTime(dateString).ToShortDateString());
		}

		public string FormatString(string oldString)
		{
			return(oldString.Length > 50 ? oldString.Substring(0,50) + "..." : oldString);
		}

		private void SelectBtn_Click(object sender, System.EventArgs e)
		{
			///显示选择的信息
			if(TrainList.SelectedIndex > -1)
			{
				///显示信息,并显示名称
				BindSignTrainData(Int32.Parse(TrainList.SelectedValue));
				TrainName.Text = TrainList.SelectedItem.Text;
				CurrentTrainName = TrainList.SelectedItem.Text;
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + MisSystem.OPERATIONNOSELECTMESSAGE + "')</script>");
			}				
		}

		private void SignTrainList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{			
			///显示选择员工的考评信息
			if(TrainList.SelectedIndex > -1)
			{
				///设置新的页码,并重新绑定数据
				SignTrainList.CurrentPageIndex = e.NewPageIndex;

				///显示信息,并显示员工的名称
				BindSignTrainData(Int32.Parse(TrainList.SelectedValue));
				TrainName.Text = TrainList.SelectedItem.Text;
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + MisSystem.OPERATIONNOSELECTMESSAGE + "')</script>");
			}		
		}

		private void AddBtn_Click(object sender, System.EventArgs e)
		{
			if(TrainList.SelectedIndex > -1)
			{
				///跳转到添加页面
				Response.Redirect("~/DesktopModules/SignTrain/AddSignTrain.aspx?TrainID="
					+ (TrainList.SelectedIndex > -1 ? TrainList.SelectedValue : "-1"));
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + MisSystem.OPERATIONNOSELECTMESSAGE + "')</script>");
			}		
		}

		private void TrainList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			SelectBtn_Click(sender,e);
		}

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

		}
		#endregion
	}
}

⌨️ 快捷键说明

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