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

📄 accounts_useradd.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 OI.DatabaseOper;

namespace OI.Manage
{
	/// <summary>
	/// Accounts_User 的摘要说明。
	/// </summary>
	public class Accounts_UserAdd : OI.PageBase
	{
		protected System.Web.UI.WebControls.TextBox TextBoxUserName;
		protected System.Web.UI.WebControls.DropDownList DropDownListSex;
		protected System.Web.UI.WebControls.TextBox TextBoxSchool;
		protected System.Web.UI.WebControls.TextBox TextBoxSpeciality;
		protected System.Web.UI.WebControls.DropDownList DropDownListIsMarried;
		protected System.Web.UI.WebControls.TextBox TextBoxNationality;
		protected System.Web.UI.WebControls.TextBox TextBoxNativePlace;
		protected System.Web.UI.WebControls.DropDownList DropDownListPoliticalFeature;
		protected System.Web.UI.WebControls.TextBox TextBoxIDCard;
		protected System.Web.UI.WebControls.TextBox TextBoxTelephone;
		protected System.Web.UI.WebControls.TextBox TextBoxMobile;
		protected System.Web.UI.WebControls.TextBox TextBoxEmail;
		protected System.Web.UI.WebControls.TextBox TextBoxZipCode;
		protected System.Web.UI.WebControls.TextBox TextBoxContent;
		protected System.Web.UI.WebControls.DropDownList DropDownListBirthdayY;
		protected System.Web.UI.WebControls.DropDownList DropDownListBirthdayM;
		protected System.Web.UI.WebControls.DropDownList DropDownListBirthdayD;
		private int[] daysCommon={31,28,31,30,31,30,31,31,30,31,30,31};
		private int[] daysLeap={31,29,31,30,31,30,31,31,30,31,30,31};

		protected System.Web.UI.WebControls.TextBox TextBoxAddress;
		protected System.Web.UI.WebControls.ImageButton ImageButtonCancel;
		protected System.Web.UI.WebControls.ImageButton ImageButtonSave;
		protected System.Web.UI.WebControls.TextBox UnitID;
		protected System.Web.UI.WebControls.DropDownList DropDownListJobLevelID;
		protected System.Web.UI.WebControls.DropDownList DropDownListState;
		protected System.Web.UI.WebControls.DropDownList DropDownListProfessionalLevelID;
		protected System.Web.UI.HtmlControls.HtmlInputHidden DeptID;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		private DatabaseOper.DatabaseConnect dc = new DatabaseOper.DatabaseConnect();
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if (Session["userid"]==null)
			{
				Response.Write ("<script>alert('超时,请重新登录');top.location.href='../userpass.aspx';</script>");
				return ;
			}
			ImageButtonSave.Attributes ["onclick"]="return check();";
			
			if (!IsPostBack)
			{
				this.Bind();
				this.initDate ();

			} 
		}
		/// <summary>
		/// 绑定部门、职务、职称下拉列表框,单位
		/// </summary>
		private void Bind()
		{
			//databaseConnect dc = new databaseConnect();
			string strCom1="select * from ProfessionalLevel";
			DataSet ds1=dc.getBinding(strCom1,"ProfessionalLevel");
			this.DropDownListProfessionalLevelID.DataSource =ds1.Tables ["ProfessionalLevel"];
			DropDownListProfessionalLevelID.DataTextField=ds1.Tables[0].Columns["ProfessionalLevelName"].ToString ();;
			DropDownListProfessionalLevelID.DataValueField= ds1.Tables[0].Columns["ProfessionalLevelID"].ToString ();;
			this.DropDownListProfessionalLevelID.DataBind ();
			string strCom2= "SELECT * FROM JobLevels";
			DataSet ds2=dc.getBinding(strCom2,"JobLevels");
			this.DropDownListJobLevelID.DataSource =ds2.Tables ["JobLevels"];
			DropDownListJobLevelID.DataTextField=ds2.Tables[0].Columns["Description"].ToString ();; 
			DropDownListJobLevelID.DataValueField= ds2.Tables[0].Columns["JobLevelID"].ToString ();;
			this.DropDownListJobLevelID.DataBind ();
			string strCom3= "SELECT * FROM departments";
			DataSet ds3=dc.getBinding(strCom3,"departments");
			//			this.DropDownListDepartmentID.DataSource =ds3.Tables ["departments"];
			//			DropDownListDepartmentID.DataTextField=ds3.Tables[0].Columns["DepartmentName"].ToString ();;
			//			DropDownListDepartmentID.DataValueField= ds3.Tables[0].Columns["DepartmentID"].ToString ();;
			//			this.DropDownListDepartmentID.DataBind ();

			//绑定单位 
			//			this.UnitID.Items.Clear();
			//			
			//			OI.NjObjCheck.DataClass.b_unit_infos obs =new OI.NjObjCheck.DataClass.b_unit_infos();
			//			obs.GetData();
			//			foreach(OI.NjObjCheck.DataClass.b_unit_infos.b_unit_info ob in obs )
			//			{
			//				this.UnitID.Items.Add(new System.Web.UI.WebControls.ListItem(ob.UnitName,ob.UnitID));
			//			}
			//			this.UnitID.SelectedIndex=0;
		}
		/// <summary>
		/// 清空各输入框,将各项的值设为默认值
		/// </summary>
		/// <param name="e"></param>
		private void CleanUp()
		{
			this.TextBoxUserName.Text="";
			this.TextBoxNationality.Text="";
			this.TextBoxZipCode.Text="";
			this.TextBoxTelephone.Text="";
			this.TextBoxSpeciality.Text="";
			this.TextBoxSchool.Text="";
			this.TextBoxNativePlace.Text="";
			this.TextBoxMobile.Text="";
			this.TextBoxIDCard.Text="";
			this.TextBoxEmail.Text="";
			this.TextBoxContent.Text="";
			this.TextBoxAddress.Text="";
			this.DropDownListSex.SelectedIndex=0;
			this.DropDownListIsMarried.SelectedIndex=0;
			this.DropDownListPoliticalFeature.SelectedIndex=0;
			this.DropDownListJobLevelID.SelectedIndex=0;
			this.DropDownListProfessionalLevelID.SelectedIndex=0;
			this.DropDownListState.SelectedIndex=0;
			//this.DropDownListDepartmentID.SelectedIndex=0;
		}
	
	
		/// <summary>
		/// 计算闰年
		/// </summary>
		/// <param name="year"></param>
		/// <param name="month"></param>
		/// <returns></returns>
		private ArrayList getDays(int year,int month)
		{
			ArrayList dayArray=new ArrayList ();
			if((year%4==0)&&(year%100!=0)||(year%400==0))
				for(int i=0;i<daysLeap[month-1];i++)
					dayArray.Add (i+1);
			else
				for(int i=0;i<daysCommon[month-1];i++)
					dayArray.Add (i+1);
			return dayArray;
		}
		/// <summary>
		/// 获取年份
		/// </summary>
		/// <param name="initYear"></param>
		/// <returns></returns>
		private ArrayList getYear(int initYear)
		{
			ArrayList years=new ArrayList ();
			DateTime tempYear=DateTime.Now ;
			for(int i=tempYear.Year-initYear;i<=tempYear.Year;i++)
				years.Add (i);
			return years;
		}
		/// <summary>
		/// 绑定出生日期,进公司日期,合同开始日期,合同结束日期列表框
		/// </summary>
		private void initDate()
		{
			this.DropDownListBirthdayY.DataSource=this.getYear(60);
			this.DropDownListBirthdayY.SelectedIndex=0;
			this.DropDownListBirthdayY.DataBind();
			this.DropDownListBirthdayM.SelectedIndex =0;
			this.DropDownListBirthdayD.DataSource =this.getDays (Convert.ToInt32 (this.DropDownListBirthdayY.SelectedItem .Value .Trim ()),
				Convert.ToInt32 (this.DropDownListBirthdayM.SelectedItem.Value .Trim ()));
			this.DropDownListBirthdayD.DataBind ();



			

		}

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

		}
		#endregion

	
			
		
		

		
		/// <summary>
		/// 清空文本框中的内容
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ImageButtonCancel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			this.CleanUp();
			
		}
		private bool Check()
		{
			dc=new DatabaseConnect();
			string sql="select count(*) as count from accounts_users";
			int count=Convert.ToInt32(dc.GetObjectBySql(sql));
			if(count>=200)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
        	
		/// <summary>
		/// 保存人员信息
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
	
		private void ImageButtonSave_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if(Page.IsValid)
			{
				if(Check())
				{
					dc=new DatabaseConnect ();
				    
					string texUserName=this.TextBoxUserName.Text.Trim().Replace ("'","''");
					checkUser cu=new checkUser ();
					if (cu.ExistUser(texUserName)) 
					{
						Page.RegisterStartupScript ("","<script>alert('"+texUserName+"己经存在!');Form1.TextBoxUserName.focus();</script>");
						return;
					}
					string texIDCard=this.TextBoxIDCard.Text.Trim().Replace ("'","''");
					string texNationality=this.TextBoxNationality.Text.Trim().Replace ("'","''");
					string texNativePlace=this.TextBoxNativePlace.Text.Trim().Replace ("'","''");
					string texSchool=this.TextBoxSchool.Text.Trim().Replace ("'","''");
					string texSpeciality=this.TextBoxSpeciality.Text.Trim().Replace ("'","''");
					string texTelephone=this.TextBoxTelephone.Text.Trim().Replace ("'","''");
					string texMobile=this.TextBoxMobile.Text.Trim().Replace ("'","''");
					string texEmail=this.TextBoxEmail.Text.Trim().Replace ("'","''");
					string texZipCode=this.TextBoxZipCode.Text.Trim().Replace ("'","''");
					string texAddress=this.TextBoxAddress.Text.Trim().Replace ("'","''");
					string texContent=this.TextBoxContent.Text.Trim().Replace ("'","''");
					string strBirthday=this.DropDownListBirthdayY.SelectedItem.Value+"-"+
						this.DropDownListBirthdayM.SelectedItem.Value+"-"+
						this.DropDownListBirthdayD.SelectedItem.Value;
		
					int intProfessionalLevelID=Convert.ToInt32(this.DropDownListProfessionalLevelID.SelectedItem.Value);
					int intJobLevelID=Convert.ToInt32(this.DropDownListJobLevelID.SelectedItem.Value);

					int intDepartmentID=Convert.ToInt32 (DeptID.Value .Trim ()) ;//Modifier: wu,Time:2004-1-31
					char charSex=Convert.ToChar(this.DropDownListSex.SelectedItem.Value);
					char charIsMarried=Convert.ToChar(this.DropDownListIsMarried.SelectedItem.Value);
					string  charPoliticalFeature=this.DropDownListPoliticalFeature.SelectedItem.Value;
					char charState=Convert.ToChar(this.DropDownListState.SelectedItem.Value);

					if (texUserName!="")//检查姓名项是否为空
					{
				       object o=dc.GetObjectBySql ("select max(DisplayOrder) from Accounts_Users");
						int DisplayOrder=int.Parse (o.ToString ())+1;
				
						string sql="insert into Accounts_Users(ProfessionalLevelID,JobLevelID,DepartmentID,UserName,Sex,School,Speciality,IsMarried,Nationality,NativePlace,PoliticalFeature,IDCard,Birthday,Telephone,Mobile,Email,ZipCode,Address,State,Content,IsPublic,Password,UnitID,DisplayOrder)"+
							"values('"+intProfessionalLevelID+"','"+intJobLevelID+"','"+intDepartmentID+"','"+texUserName+"','"+charSex+"','"+texSchool+"','"+texSpeciality+"','"+charIsMarried+"','"+texNationality+"','"+texNativePlace+"','"+charPoliticalFeature+"','"+texIDCard+"','"+strBirthday+"','"+texTelephone+"','"+texMobile+"','"+texEmail+"','"+texZipCode+"','"+texAddress+"','"+charState+"','"+texContent+"','1','1111','"+UnitID.Text +"',"+DisplayOrder.ToString ()+")"; 
						dc.addData (sql);

						sql ="select userid from accounts_users where username='"+texUserName+"'";
						o= dc.GetObjectBySql (sql);
						if (o!=null)
						{
							OI.cs.createDefaultPower cp=new OI.cs.createDefaultPower ();
							cp.createUserRole(o.ToString (),"个人管理") ;
						}
						Response.Redirect("Accounts_Users.aspx");
				
				
					}
				}
				else
				{
					Page.RegisterStartupScript("","<script>alert('用户不能超过200人');</script>");
					return;
				}
			}
			

		}

	}
	/// <summary>
	/// checkUser :检验用户。
	/// 
	/// </summary>
	public class checkUser:System.Web .UI .Page 
	{
		public checkUser()
		{
		}
		/// <summary>
		/// 检查当前用户在数据库中是否存在
		/// </summary>
		/// <param name="username">用户名</param>
		/// <returns></returns>
		public bool ExistUser(string username)
		{
			OI.DatabaseOper.DatabaseConnect  dc=new DatabaseConnect();
			string sql="select count(*)  from accounts_users where username='"+username+"'" ;
			int count=0;
			try
			{
				count =int.Parse (dc.GetValueBySql(sql));
			}
			catch(Exception er)
			{
				Response.Write (er.Message );
				Response.End ();
			}
			if (count>0)
			{
				return true;
			}
			return false;
		}
		/// <summary>
		/// 检查当前用户在数据库中是否存在,此方法用在用户修改模块
		/// </summary>
		/// <param name="username">用户名</param>
		/// <param name="userid">原用户ID</param>
		/// <returns></returns>
		public bool ExistUser(string username,int userid)
		{
			OI.DatabaseOper.DatabaseConnect  dc=new DatabaseConnect();
			string sql="select count(*)  from accounts_users where username='"+username+"' and userid !="+userid.ToString () ;
			int count=0;
			try
			{
				count =int.Parse (dc.GetValueBySql(sql));
			}
			catch(Exception er)
			{
				Response.Write (er.Message );
				Response.End ();
			}
			if (count>0)
			{
				return true;
			}
			return false;
		}
	}

}
		

⌨️ 快捷键说明

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