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

📄 user.cs

📁 大话设计大话设计模式所有源代码模式所有源代码大话设计模式所有源代码
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;

namespace TBLibrary.Shop.Users
{
	/// <summary>
	/// User 的摘要说明。
	/// </summary>
	public class User:TBLibrary.Shop.DbBase.Base
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
		public static void Add(string userName,string password,string email,string question,string answer)
		{
			string strSQL = "Insert into UserInfo(UserName,EMail,UPassword,Question,Answer) values('"+userName+"','"+email+"','"+TBLibrary.Shop.Functions.Functions.Encrypt(password,1)+"','"+question+"','"+answer+"')";
			//strSQL[1] = "Insert into UserInfo2()";
			//User.Add(Bt_UserName.Text,Bt_Password.Text,Bt_EMails.Text,Bt_PQuestion.Text,Bt_Answer.Text);
			//string strSQL = "INSERT INTO fdfdfd(sa,sb)values('"+userName+"','"+email+"')";
			if(IsExist(userName))
			{
				throw new Exception("This name was registered!");
			}
			else
			{
				try
				{
					ExecuteSql(strSQL);
				}
				catch(Exception ex)
				{
					throw new Exception(ex.Message);
					//throw new Exception("Register is failed");				
					
				}
			}
		}
		public static bool Check(string name,string email)
		{
			strSQL ="Select ID FROM User Where (Name= '"+name+"')And( EMail='"+email+"')";
			try
			{
				EexecuteSqlValue(strSQL);
				return true;
			}
			catch
			{
				return false;
			}
		}
		/// <summary>
		/// 验证是否已通过了验证
		/// </summary>
		/// <param name="name"></param>
		/// <returns></returns>
		public static bool IsExist(string name)
		{
			strSQL = "Select Id from UserInfo where UserName ='"+name+"'";
			try
			{
				EexecuteSqlValue(strSQL);
				return true;
			}
			catch
			{
				return false;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="password"></param>
		/// <returns></returns>
		public static int Login(string name,string password)
		{
			strSQL = "Select Id From UserInfo Where UserName='"+name+"'"
				+" And Upassword = '"+TBLibrary.Shop.Functions.Functions.Encrypt(password,1)+"'";
			try
			{
				//bool login;
				int i = (int)EexecuteSqlValue(strSQL);			
				//LoginTimes(name);
				return i;
				
			}
			catch//(Exception ex)
			{
				//throw new Exception(ex.Message);
				return -1;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		private static bool LoginTimes(string name)
		{
			//strSQL1 = "Select Times From Where Id = '"+id+"'";
			string strSQL = "UpDate UserInfo Set Times=Times+1 Where UserName ='"+name+"'";
			try
			{
				EexecuteSqlValue(strSQL);				
				return true;
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}

		/*public static bool UpdateDetails(string TBCompanyName,string TBContactPerson,string CdBirthday,string TBBirthday ,string TBReceiveAddress)
		{
			TBCompanyName.Text = "";
			TBContactPerson.Text = "";
			CdBirthday.Text = "";
			TBBirthday.Text = "";
			TBReceiveAddress.Text = "";
			TBPostcode.Text = "";
			TBTel.Text = "";
			TBFAX.Text = "";
			TBICQ.Text = "";
			TBOICQ.Text = "";
			TBMSN.Text = "";
		}*/

		public static DataTable GetDetails(int id)
		{
			string conStr = "Select * From UserInfo2 where UserID = "+id;
			DataSet DS = new DataSet();
			DS = ExecuteSqlDs(conStr);
			return (DataTable)DS.Tables[0];
		}

		public static void UpDateMessage(int id,string CompanyName,string ContactPerson,string ReceiveAddress,string Birthday,string Postcode,string Tel,string FAX,string ICQ,string OICQ,string MSN)
		{
			string strSQL = "UpDate UserInfo2 set CompanyName ='"+CompanyName+"',ReceiveAddress ='"+ReceiveAddress+"',Birthday = '"+Birthday+"',"
				+"Postcode = '"+Postcode+"',Tel = '"+Tel+"',FAX = '"+FAX+"',ICQ = '"+ICQ+"',OICQ ='"+OICQ+"',MSN = '"+MSN+"',ContactPerson = '"+ContactPerson+"'"
				+"Where UserID ="+id;
			try
			{
				ExecuteSql(strSQL);				
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
		/// <summary>
		/// 返回用户基本信息
		/// </summary>
		/// <returns></returns>
		public static DataView ShowUsersMessage()
		{
			string strSQL = "SELECT * FROM UserInfo";
			try
			{
				DataSet ds;
				ds = ExecuteSqlDs(strSQL);
				return ds.Tables[0].DefaultView;
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
		public static void DeleteUser(int id)
		{
			string strSQL = "Delete From UserInfo Where id ="+id;
			try
			{
				ExecuteSql(strSQL);
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
		public static void ResetPassword(string question,string answer,string username,string password)
		{
			string strSql = "Update UserInfo set UPassword='"+TBLibrary.Shop.Functions.Functions.Encrypt(password,1)+"' Where (Question ='"+question+"')And(Answer='"+answer+"')And(Username='"+username+"')";
			try
			{
				ExecuteSql(strSql);
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
	}
}

⌨️ 快捷键说明

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