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

📄 person.cs

📁 网络人才招聘,系统全面很好,喜欢的朋友拿去
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;

namespace My.Hr
{
	/// <summary>
	/// User Class
	/// Manage users
	/// </summary>
	public class Person:DbBase.Base
	{
		private string m_Password;		
		private string m_Mail;


		/// <summary>
		/// Property:password
		/// </summary>
		public string Password
		{
			get
			{
				return m_Password;
			}
			set
			{
				m_Password = value;
			}
		}

		

		/// <summary>
		/// Property:Email
		/// </summary>
		public string Mail
		{
			get
			{
				return m_Mail;
			}
			set
			{
				m_Mail = value;
			}
		}		


		public Person()
		{

		}


		/// <summary>
		/// Add new user
		/// need Name、Password、Mail.
		/// </summary>		
		public void Add()
		{

			if(IsExist())
			{
				throw new Exception("This name was registered!");
			}
			else
			{
				strSQL = "Insert into person (Name,Password,Mail) Values("				
					+ "'" + this.Name + "',"
					+ "'" + Functions.Encrypt(this.Password,1) + "',"				
					+ "'" + this.Mail + "')";

				try
				{
					ExecuteSql(strSQL);				
				}
				catch
				{
					throw new Exception("Register FAILED!");
				}
					
				strSQL = "Select Max(personID) From person";
				int personId;
				
				try
				{
					personId = ExecuteSql4Value(strSQL);			
				}
				catch
				{
					throw new Exception("Register FAILED!");
				}
				
				
				strSQL = "Insert into getJobInfo (personID) Values("+"'"+ personId.ToString() +"')";
					
				try
				{
					ExecuteSql(strSQL);				
				}
				catch
				{
					throw new Exception("Register FAILED!");
				}
			}			
		}


		/// <summary>
		/// Add new user(register).
		/// </summary>		
		public static void Add(string name,string password,string mail)
		{
			if(IsExist(name))
			{
				throw new Exception("This name was registered!");
			}
			else
			{
				strSQL = "Insert into person (Name,Password,Mail) Values("				
					+ "'" + name + "',"
					+ "'" + Functions.Encrypt(password,1) + "',"				
					+ "'" + mail + "')";

				try
				{
					ExecuteSql(strSQL);				
				}
				catch
				{
					throw new Exception("Register FAILED!");
				}			
			}					
		}


		/// <summary>
		/// Change password
		/// need Name & Password
		/// </summary>
		/// <param name="newPassword">new password (string)</param>		

		public void ChangePassword(string newPassword)
		{
			strSQL = "Update person Set "
				+ "Password='" + Functions.Encrypt(newPassword,1) + "'"
				+ " Where Name='" + this.Name + "'"
				+ " And Password='" + Functions.Encrypt(this.Password,1) + "'"; 

			try
			{
				ExecuteSql(strSQL);				
			}
			catch
			{
				throw new Exception("Change password FAILED!");
			}
		}



		/// <summary>
		/// Change password
		/// </summary>
		/// <param name="name"></param>
		/// <param name="oldPassword">Old password(string)</param>
		/// <param name="newPassword">New password(string)</param>

		public static void ChangePassword(string name,string oldPassword,string newPassword)
		{
			strSQL = "Update person Set "
				+ "Password='" + Functions.Encrypt(newPassword,1) + "'"
				+ " Where Name='" + name + "'"
				+ " And Password='" + Functions.Encrypt(oldPassword,1) + "'"; 

			try
			{
				ExecuteSql(strSQL);				
			}
			catch
			{
				throw new Exception("Change password FAILED!");
			}
		}


		/// <summary>
		/// Check user(for getting lost password)
		/// </summary>
		/// <returns>return bool value</returns>
		public bool Check()
		{
			strSQL = "Select personID from person Where Name='"
				+ Name + "'"
				+ " And Mail='" + Mail +"'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}


		/// <summary>
		/// Check user(for getting lost password)
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="mail">Email</param>
		/// <returns>return bool value</returns>
		public static bool Check(string name,string mail)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'"
				+ " And Mail='" + mail +"'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}



		/// <summary>
		/// Delete user
		/// </summary>
		/// <param name="personID">User personID(int)</param>		
		public static void Delete(int id)
		{
			strSQL = "Delete From getJobInfo Where personID="+id;

			
			try
			{
				ExecuteSql(strSQL);
			}
			catch
			{
				throw new Exception("Delete user FAILED!");
			}
			strSQL = "Delete From person Where personID="+id;
			try
			{
				ExecuteSql(strSQL);
			}
			catch
			{
				throw new Exception("Delete user FAILED!");
			}
		}


		/// <summary>
		/// Delete user
		/// </summary>				
		public void Delete()
		{
			strSQL = "Delete From person Where Name="+Name;
			
			try
			{
				ExecuteSql(strSQL);				
			}
			catch
			{
				throw new Exception("Delete user FAILED!");
			}
		}


		/// <summary>
		/// Delete user
		/// </summary>
		/// <param name="Name">User name(string)</param>		
		public static void Delete(string name)
		{
			strSQL = "Delete From person Where Name="+name;
			
			try
			{
				ExecuteSql(strSQL);				
			}
			catch
			{
				throw new Exception("Delete user FAILED!");
			}
		}


		/// <summary>
		/// Delete a group user
		/// </summary>
		/// <param name="names">Users' names</param>		
		public static void DeleteGroup(string names)
		{
			strSQL = "Delete From person Where Name in ('" + names + "')";
			
			try
			{
				ExecuteSql(strSQL);				
			}
			catch
			{
				throw new Exception("Delete user FAILED!");
			}
		}


		/// <summary>
		/// Does this user exist?
		/// </summary>
		/// <returns>return bool value</returns>
		public bool IsExist()
		{
			strSQL = "Select personID from person Where Name='"
				+ this.Name + "'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}


		/// <summary>
		/// Does this user exist?
		/// </summary>
		/// <param name="name">user name(string)</param>
		/// <returns>return bool value</returns>			
		public static bool IsExist(string name)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}


		/// <summary>
		/// Is a supervisor
		/// </summary>
		/// <returns>return bool value</returns>
		public bool IsSupervisor()
		{
			string strManager = ConfigurationSettings.AppSettings["Manager"];			
			string [] names = strManager.Split(',');
			int i;

			for(i=0;i<names.Length;i++)
			{
				if(Name == names[i])
				{
					return true;
				}
			}

			return false;			
		}


		/// <summary>
		/// Is a supervisor
		/// </summary>
		/// <param name="name">User Name</param>
		/// <returns>return bool value</returns>
		public static bool IsSupervisor(string name)
		{
			string strManager = ConfigurationSettings.AppSettings["Manager"];
			string [] names = strManager.Split(',');
			int i;

			for(i=0;i<names.Length;i++)
			{
				if(name == names[i])
				{
					return true;
				}
			}

			return false;
		}


		/// <summary>
		/// Get password
		/// </summary>
		/// <returns>Password</returns>
		public string GetPassword()
		{
			Random rnd = new Random();
			StringBuilder sb = new StringBuilder();
			int i;
			for(i=0;i<32;i++)
			{
				sb.Append(rnd.Next(0,9).ToString());
			}
			string Password = sb.ToString();//ASCIIEncoding.ASCII.GetString(random);
			string EnPassword = Functions.Encrypt(Password,1);

			strSQL = "Update person Set Password = '"
				+ EnPassword + "'"
				+ " Where Name='" + Name + "'";

			try
			{
				ExecuteSql(strSQL);	
				return Password;
			}
			catch
			{
				throw new Exception("Get Password FAILED");
			}
		}


		/// <summary>
		///  Get password
		/// </summary>
		/// <param name="name">User name(string)</param>	
		/// <returns>password</returns>
		public static string GetPassword(string name)
		{
			Random rnd = new Random();
			StringBuilder sb = new StringBuilder();
			int i;
			for(i=0;i<32;i++)
			{
				sb.Append(rnd.Next(0,9).ToString());
			}
			string Password = sb.ToString();//ASCIIEncoding.ASCII.GetString(random);
			string EnPassword = Functions.Encrypt(Password,1);

			strSQL = "Update person Set Password = '"
				+ EnPassword + "'"
				+ " Where Name='" + name + "'";

			try
			{
				ExecuteSql(strSQL);	
				return Password;
			}
			catch
			{
				throw new Exception("Get Password FAILED");
			}
		}



		/// <summary>
		/// Login
		/// Need : Name、Password
		/// </summary>
		/// <returns>return bool</returns>
		public bool Login()
		{
			strSQL = "Select personID from person Where Name='"
				+ this.Name + "'"
				+ " And Password='" + Functions.Encrypt(this.Password,1) +"'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}			
		}


		/// <summary>
		/// Login
		/// </summary>
		/// <param name="name">User name</param>
		/// <param name="password">Password</param>
		/// <returns></returns>
		public static bool Login(string name,string password)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'"
				+ " And Password='" + Functions.Encrypt(password,1) +"'";

			try
			{
				ExecuteSql4Value(strSQL);
				return true;
			}
			catch
			{
				return false;
			}			
		}



		/// <summary>
		/// Update user information
		/// Need : Name、Mail、Password.
		/// </summary>
		/// <returns></returns>
		public bool Update()
		{
			strSQL = "Update person Set "				
				+ "Mail='" + this.Mail
				+"' Where Name='"+this.Name + "'"
				+ " And Password='" + Functions.Encrypt(this.Password,1) +"'";
			
			try
			{
				ExecuteSql(strSQL);
				return true;
			}
			catch
			{
				throw new Exception("Update failed!");
			}
		}



		/// <summary>
		/// Update user information.
		/// </summary>
		/// <param name="name">Email(string)</param>	
		/// <param name="mail">User name(string)</param>	
		/// <param name="password">Password(string)</param>	
		/// <returns></returns>
		public static bool Update(string mail,string name,string password)
		{
			strSQL = "Update person Set "				
				+ "Mail='" + mail
				+"' Where Name='"+name + "'"
				+ " And Password='" + Functions.Encrypt(password,1) +"'";
			
			try
			{
				ExecuteSql(strSQL);
				return true;
			}
			catch
			{
				throw new Exception("Update failed!");
			}
		}



		/// <summary>
		///  Get all the users
		/// </summary>
		/// <returns>return DataSet</returns>
		public static DataSet GetUsers()
		{
			strSQL = "SELECT * FROM person";

			try
			{
				return ExecuteSql4Ds(strSQL);				
			}
			catch
			{
				throw new Exception("Get all the Users Information failed!");
			}			
		}
		

		/// <summary>
		/// Get user info
		/// </summary>
		/// <returns></returns>
		public bool GetUserInfo()
		{
			strSQL = "Select * from person Where Name='"
				+ this.Name + "'";
			SqlConnection myCn = new SqlConnection(strConn);
			myCn.Open();
			SqlCommand myCmd = new SqlCommand(strSQL,myCn);
			try
			{
				myCmd.ExecuteNonQuery();
				SqlDataReader reader = myCmd.ExecuteReader();
				if(reader.Read())
				{
					this.ID = reader.GetInt32(0);
					this.Mail = reader.GetString(3);
					return true;
				}
				else
				{
					return false;
				}
			}
			catch(System.Data.SqlClient.SqlException e)
			{
				throw new Exception(e.Message);
			}
			finally
			{
				myCmd.Dispose();
				myCn.Close();
			}
		}
		
		public static DataSet GetPersonStore(int personId)
		{
			strSQL = "Select * from personStoreV Where personId=" + personId.ToString();
			try
			{
				return ExecuteSql4Ds(strSQL);				
			}
			catch
			{
				throw new Exception("Get person store failed!");
			}
		}
		
	}
}

⌨️ 快捷键说明

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