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

📄 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 Hr.component
{

	public class Person:Hr.component.DatabaseOperation
	{
		private string m_Password;		
		private string m_Mail;

		public string Password
		{
			get
			{
				return m_Password;
			}
			set
			{
				m_Password = value;
			}
		}

		public string Mail
		{
			get
			{
				return m_Mail;
			}
			set
			{
				m_Mail = value;
			}
		}		


		public Person()
		{

		}


		public void Add()
		{

			if(IsExist())
			{
				throw new Exception("该用户名已经被注册了!");
			}
			else
			{
				strSQL = "Insert into person (Name,Password,Mail) Values("				
					+ "'" + this.Name + "',"
					+ "'" + publicfunc.Encrypt(this.Password,1) + "',"				
					+ "'" + this.Mail + "')";

				try
				{
					ExecuteNonQuery(strSQL);				
				}
				catch
				{
					throw new Exception("注册失败!");
				}
					
				strSQL = "Select Max(personID) From person";
				int personId;
				
				try
				{
					personId = ExecuteReturnValue(strSQL);			
				}
				catch
				{
					throw new Exception("注册失败!");
				}
				
				
				strSQL = "Insert into PersonApply (personID) Values("+"'"+ personId.ToString() +"')";
				try
				{
					ExecuteNonQuery(strSQL);				
				}
				catch
				{
					throw new Exception("注册失败!");
				}
			}			
		}
	
		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 + "',"
					+ "'" + publicfunc.Encrypt(password,1) + "',"				
					+ "'" + mail + "')";

				try
				{
					ExecuteNonQuery(strSQL);				
				}
				catch
				{
					throw new Exception("注册失败!");
				}			
			}					
		}

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

			try
			{
				ExecuteNonQuery(strSQL);				
			}
			catch
			{
				throw new Exception("更改密码失败!");
			}
		}

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

			try
			{
				ExecuteNonQuery(strSQL);				
			}
			catch
			{
				throw new Exception("更改密码失败!");
			}
		}

		public bool Check()
		{
			strSQL = "Select personID from person Where Name='"
				+ Name + "'"
				+ " And Mail='" + Mail +"'";

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

		}

		public static bool Check(string name,string mail)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'"
				+ " And Mail='" + mail +"'";

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

		}

		public static void Delete(int id)
		{
			strSQL = "Delete From PersonApply Where personID="+id;

			
			try
			{
				ExecuteNonQuery(strSQL);
			}
			catch
			{
				throw new Exception("删除用户失败!");
			}
			strSQL = "Delete From person Where personID="+id;
			try
			{
				ExecuteNonQuery(strSQL);
			}
			catch
			{
				throw new Exception("删除用户失败!");
			}
		}

	
		public void Delete()
		{
			strSQL = "Delete From person Where Name="+Name;
			
			try
			{
				ExecuteNonQuery(strSQL);				
			}
			catch
			{
				throw new Exception("删除用户失败!");
			}
		}

		public static void Delete(string name)
		{
			strSQL = "Delete From person Where Name="+name;
			
			try
			{
				ExecuteNonQuery(strSQL);				
			}
			catch
			{
				throw new Exception("删除用户失败!");
			}
		}
	
		public static void DeleteGroup(string names)
		{
			strSQL = "Delete From person Where Name in ('" + names + "')";
			
			try
			{
				ExecuteNonQuery(strSQL);				
			}
			catch
			{
				throw new Exception("删除用户失败!");
			}
		}

		public bool IsExist()
		{
			strSQL = "Select personID from person Where Name='"
				+ this.Name + "'";
			try
			{
				ExecuteReturnValue(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}
		
		public static bool IsExist(string name)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'";
			try
			{
				ExecuteReturnValue(strSQL);
				return true;
			}
			catch
			{
				return false;
			}

		}

		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();
			string EnPassword = publicfunc.Encrypt(Password,1);

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

			try
			{
				ExecuteNonQuery(strSQL);	
				return Password;
			}
			catch
			{
				throw new Exception("读取密码失败");
			}
		}

		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();
			string EnPassword = publicfunc.Encrypt(Password,1);

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

			try
			{
				ExecuteNonQuery(strSQL);	
				return Password;
			}
			catch
			{
				throw new Exception("读取密码失败");
			}
		}

		public bool Login()
		{
			strSQL = "Select personID from person Where Name='"+ this.Name + "'"
				+ " And Password='" + publicfunc.Encrypt(this.Password,1) +"'";

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

		public static bool Login(string name,string password)
		{
			strSQL = "Select personID from person Where Name='"
				+ name + "'"
				+ " And Password='" + publicfunc.Encrypt(password,1) +"'";

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

		public bool Update()
		{
			strSQL = "Update person Set "				
				+ "Mail='" + this.Mail
				+"' Where Name='"+this.Name + "'"
				+ " And Password='" + publicfunc.Encrypt(this.Password,1) +"'";
			
			try
			{
				ExecuteNonQuery(strSQL);
				return true;
			}
			catch
			{
				throw new Exception("Update failed!");
			}
		}

		public static bool Update(string mail,string name,string password)
		{
			strSQL = "Update person Set "				
				+ "Mail='" + mail
				+"' Where Name='"+name + "'"
				+ " And Password='" + publicfunc.Encrypt(password,1) +"'";
			
			try
			{
				ExecuteNonQuery(strSQL);
				return true;
			}
			catch
			{
				throw new Exception("Update failed!");
			}
		}

		public static DataSet GetUsers()
		{
			strSQL = "SELECT * FROM person";

			try
			{
				return ExecuteReturnDS(strSQL);				
			}
			catch
			{
				throw new Exception("读取所有用户信息失败!");
			}			
		}

		public bool GetUserInfo()
		{
			strSQL = "Select * from person Where Name='"
				+ this.Name + "'";
			SqlConnection myConn = new SqlConnection(strConn);
			myConn.Open();
			SqlCommand myCmd = new SqlCommand(strSQL,myConn);
			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();
				myConn.Close();
			}
		}
		
		public static DataSet GetPersonStore(int personId)
		{
			strSQL = "Select * from personStoreV Where personId=" + personId.ToString();
			try
			{
				return ExecuteReturnDS(strSQL);				
			}
			catch
			{
				throw new Exception("Get person store failed!");
			}
		}
		
	}
}

⌨️ 快捷键说明

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