www.pudn.com > HttpProxy.rar > User.cs


using System; 
using System.Data; 
using System.Collections; 
 
namespace HttpProxy.Component 
{ 
	///  
	/// User Àà 
	///  
	public class User 
	{ 
		private int id; 
		private string name; 
		private string password; 
		private string description; 
 
		internal static SqlHelper Helper; 
 
		///  
		/// Initializes a new instance of the  class. 
		///  
		public User() 
		{ 
		} 
 
		///  
		/// Creates this instance. 
		///  
		///  
		public bool Create() 
		{ 
			string sql = "insert into tbl_User(name,password,description) values('"+this.Name+"','"+this.Password+"','"+this.Description+"')"; 
			return Helper.Execute(sql); 
		} 
 
		///  
		/// Deletes the specified id. 
		///  
		/// The id. 
		///  
		public bool Delete(int id) 
		{ 
			string sql = string.Format("delete from tbl_User where id={0}",id); 
			return Helper.Execute(sql); 
		} 
 
		///  
		/// Updates this instance. 
		///  
		///  
		public bool Update() 
		{ 
			string sql = string.Format("update tbl_User set name='{0}',password='{1}',description='{2}' where id={3}",this.Name,this.Password,this.Description,this.id); 
			return Helper.Execute(sql); 
		} 
 
		///  
		/// Retrieves the specified id. 
		///  
		/// The id. 
		///  
		public User Retrieve(int id) 
		{ 
			string sql=string.Format("select id,name,password,description from tbl_User where id={0}",id); 
			DataRow dr = Helper.Retrieve(sql); 
			this.id=Convert.ToInt32(dr["id"]); 
			this.Name=Convert.ToString(dr["name"]); 
			this.Password=Convert.ToString(dr["password"]); 
			this.Description=Convert.ToString(dr["description"]); 
			return this; 
		} 
 
		///  
		/// Retrieves the specified name. 
		///  
		/// The name. 
		/// The PWD. 
		///  
		public User Retrieve(string name,string pwd) 
		{ 
			string sql=string.Format("select id,name,password,description from tbl_User where name='{0}' and password='{1}'",name,pwd); 
			DataRow dr=Helper.Retrieve(sql); 
			if(dr!=null) 
			{ 
				return this.Retrieve(Convert.ToInt32(dr["id"])); 
			} 
			else 
				return null; 
 
		} 
 
		///  
		/// Gets the users list. 
		///  
		///  
		public DataSet GetUsersList() 
		{ 
			string sql="select id, name,password,description from tbl_User"; 
			return Helper.GetList(sql); 
		} 
 
		///  
		/// Gets the id. 
		///  
		/// The id. 
		public int Id 
		{ 
			get 
			{ 
				return id; 
			} 
		} 
 
		///  
		/// Gets or sets the name. 
		///  
		/// The name. 
		public string Name 
		{ 
			get 
			{ 
				return name; 
			} 
			set 
			{ 
				name=value; 
			} 
		} 
 
		///  
		/// Gets or sets the password. 
		///  
		/// The password. 
		public string Password 
		{ 
			get 
			{ 
				return password; 
			} 
			set 
			{ 
				password=value; 
			} 
		} 
 
		///  
		/// Gets or sets the description. 
		///  
		/// The description. 
		public string Description 
		{ 
			get 
			{ 
				return description; 
			} 
			set 
			{ 
				description=value; 
			} 
		} 
	} 
}