using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLHelper;
using System.Text;
using System.Data.SqlClient;
/// <summary>
/// UserInfo 的摘要说明
/// </summary>
namespace BLL
{
public class UserInfo
{
#region增
///<summary>
///创建一个新用户
///</summary>
///<param name="username">用户名称</param>
///<param name="password">用户密码</param>
///<param name="email">电子邮件</param>
///<param name="question">密码问题</param>
///<param name="answer">问题答案</param>
///<returns></returns>
public int createUser(string username, string password, int power, string email, string question, string answer)
{
StringBuilder sb= new StringBuilder();
sb.Append("insert into UserInfo ([UserName],[Password],[Power],[Email],[Question],[Answer]) values");
sb.Append("(@UserName,@Password,@Power,@Email,@Question,@Answer)");
SqlParameter[] param=
{
DBHelper.GetParameter("@UserName",SqlDbType.NVarChar,50,"[UserName]",username),
DBHelper.GetParameter("@Password",SqlDbType.NVarChar,50,"[Password]",password),
DBHelper.GetParameter("@Power",SqlDbType.Int,4,"[Power]",power),
DBHelper.GetParameter("@Email",SqlDbType.NVarChar,50,"[Email]",email),
DBHelper.GetParameter("@Question",SqlDbType.NVarChar,50,"[Question]",question),
DBHelper.GetParameter("@Answer",SqlDbType.NVarChar,50,"[Answer]",answer)
};
return DBHelper.ExecuteSql(sb.ToString(), param);
}
#endregion
#region删
///<summary>
///删除一个用户
///</summary>
///<param name="userid">用户编号</param>
///<returns></returns>
public int deleteUser(int userid)
{
StringBuilder sb= new StringBuilder();
sb.Append("delete from UserInfo where [UserID]=@UserID");
SqlParameter[] param= { DBHelper.GetParameter("@UserID", SqlDbType.Int,4, "[UserID]", userid) };
return DBHelper.ExecuteSql(sb.ToString(), param);
}
#endregion
#region改
///<summary>
///修改密码
///</summary>
///<param name="userid">用户编号</param>
///<param name="newpassword">新密码</param>
///<returns></returns>
public int updateUserPassword(int userid, string newpassword)
{
StringBuilder sb= new StringBuilder();
sb.Append("update UserInfo set [Password]=@newpassword where [UserID]=@UserID");
SqlParameter[] param=
{
DBHelper.GetParameter("@UserID", SqlDbType.Int, 4,"[UserID]", userid) ,
DBHelper.GetParameter("@newpassword",SqlDbType.NVarChar,50,"[Password]",newpassword)
};
return DBHelper.ExecuteSql(sb.ToString(), param);
}
///<summary>
///修改用户资料
///</summary>
///<param name="userid">用户编号</param>
///<param name="password">用户密码</param>
///<param name="email">电子邮件</param>
///<param name="question">密码问题</param>
///<param name="answer">问题答案</param>
///<returns></returns>
public int updateUser(int userid, string password, string email, string question, string answer)
{
StringBuilder sb= new StringBuilder();
sb.Append("update UserInfo set [Password]=@Password,[Email]=@Email,[Question]=@Question,");
sb.Append("[Answer]=@Answer where [UserID]=@UserID");
SqlParameter[] param=
{
DBHelper.GetParameter("@UserID",SqlDbType.Int,4,"[UserID]",userid),
DBHelper.GetParameter("@Password",SqlDbType.NVarChar,50,"[Password]",password),
DBHelper.GetParameter("@Email",SqlDbType.NVarChar,50,"[Email]",email),
DBHelper.GetParameter("@Question",SqlDbType.NVarChar,50,"[Question]",question),
DBHelper.GetParameter("@Answer",SqlDbType.NVarChar,50,"[Answer]",answer)
};
return DBHelper.ExecuteSql(sb.ToString(), param);
}
#endregion
#region查
///<summary>
///找回用户密码
///</summary>
///<param name="username">用户名</param>
///<param name="question">密码问题</param>
///<param name="answer">问题答案</param>
///<returns></returns>
public stringresearchPassword(stringusername, stringquestion, stringanswer)
{
StringBuilder sb= new StringBuilder();
sb.Append("select [Password] from UserInfo where [UserName]=@UserName");
sb.Append("and [Question]=@Question and [Answer]=@Answer");
SqlParameter[] param=
{
DBHelper.GetParameter("@UserName",SqlDbType.NVarChar,50,"[UserName]",username),
DBHelper.GetParameter("@Question",SqlDbType.NVarChar,50,"[Question]",question),
DBHelper.GetParameter("@Answer",SqlDbType.NVarChar,50,"[Answer]",answer)
};
DataTable table= DBHelper.ExecuteDt(sb.ToString(), param);
if (table.Rows.Count > 0)
{
return table.Rows[0]["Password"].ToString();
}
else
{
return "";
}
}
///<summary>
///获得一个用户资料
///</summary>
///<param name="userid"></param>
///<returns></returns>
public DataTable getUser(intuserid)
{
StringBuilder sb= new StringBuilder();
sb.Append("select [UserID],[UserName],[Password],[Power],[Email],[Question],[Answer]");
sb.Append("from UserInfo where [UserID]=@UserID");
SqlParameter[] param= { DBHelper.GetParameter("@UserID", SqlDbType.Int,4, "[UserID]", userid) };
return DBHelper.ExecuteDt(sb.ToString(), param);
}
#endregion
publicUserInfo()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}
文章出自:http://blog.sina.com.cn/s/blog_64310abb0100i0lc.html