📄 users.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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;
/// <summary>
/// Users 的摘要说明
/// </summary>
public class Users:SqlDataBase
{
public Users()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 返回用户详细列表
/// </summary>
/// <param name="orderby">排序字段</param>
/// <returns></returns>
public DataView Dv_VUser(string orderby)
{
return GetDv("select * from v_user order by " + orderby + " desc");
}
/// <summary>
/// 返回在线用户详细信息
/// </summary>
/// <returns></returns>
public DataView GetUserOnlineInfo()
{
return GetDv("select * from users where online=1 order by qx desc");
}
/// <summary>
/// 判断用户是否可以注册
/// </summary>
/// <param name="strUid">用户名</param>
/// <returns></returns>
public bool GetVldUser(string strUid)
{
if (int.Parse(RunSqlReturn("select count(id) from users where name='" + strUid + "'")) == 0)
return true;
else
return false;
}
/// <summary>
/// 通过用户ID返回用户信息
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public DataView GetUserInfo(string strUid)
{
return GetDv("select id,name,point,money,headpic,(select count(id) from theme where sender =" + strUid + ")as themecount,(select count(id) from theme where sender =" + strUid + ")+(select count(id) from back where sender=" + strUid + ") as backcount from v_user where id=" + strUid);
}
/// <summary>
/// 通过用户名密码返回记录数
/// </summary>
/// <param name="strUid">用户名</param>
/// <param name="strPwd">密码</param>
/// <returns></returns>
public bool GetLoginUser(string name, string pwd,string url) //要改成存储过程
{
SqlParameter[] prams ={
MakeInParam("@name",SqlDbType.VarChar ,50,name),
MakeInParam("@pwd",SqlDbType.VarChar,50,pwd),
MakeInParam("@url",SqlDbType.VarChar ,200,url),
MakeInParam("@ip",SqlDbType.VarChar ,50,System.Web.HttpContext.Current.Request.UserHostAddress),
MakeOutParam("@bs",SqlDbType.Bit,1)
};
try
{
RunProc("Up_LoginUser", prams);
return Convert.ToBoolean(prams[4].Value);
}
catch { return false; }
}
/// <summary>
/// 获得用户总数
/// </summary>
/// <returns></returns>
public int GetUserCount()
{
return int.Parse(RunSqlReturn("select count(id) from users"));
}
/// <summary>
/// 获得最后一个用户名
/// </summary>
/// <returns></returns>
public DataView GetLastUser()
{
return GetDv("select top 1 id,name from users order by id desc");
}
/// <summary>
/// 返回用户名
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public string GetUserName(string strUid)
{
return RunSqlReturn("select name from users where id=" + strUid );
}
/// <summary>
/// 返回用户ID
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public string GetUserId(string strUid)
{
return RunSqlReturn("select id from users where name='" + strUid+"'");
}
/// <summary>
/// 返回用户权限ID
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public string GetQxId(string strUid)
{
return RunSqlReturn("select qx from users where id=" + strUid);
}
/// <summary>
/// 返回用户基本信息
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public DataView GetUserBase(string strUid)
{
return GetDv("select * from users_base where id=" + strUid);
}
/// <summary>
/// 返回用户详细信息
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public DataView GetVUser(string strUid)
{
return GetDv("select * from v_user where id=" + strUid);
}
/// <summary>
/// 更新用户登陆时间
/// </summary>
/// <param name="strUid">用户ID</param>
/// <returns></returns>
public bool ChangeUsersDate(string strUid,string strUrl)
{
string strSql = "update users set logindate= '" + DateTime.Now.ToString() + "',url='"+strUrl+"',online =1 where id=" + strUid;
try
{
RunSql(strSql);
return true;
}
catch { return false; }
}
/// <summary>
/// 更新用户在线状态
/// </summary>
/// <returns></returns>
public bool ChangeUsersOnline()
{
string strSql = "update users set online = 0 where logindate < GetDate()-0.042";
try
{
RunSql(strSql);
return true;
}
catch { return false; }
}
/// <summary>
/// 添加用户表
/// </summary>
/// <param name="name">用户名</param>
/// <param name="pwd">密码</param>
/// <param name="ask">问题</param>
/// <param name="anwser">答案</param>
/// <returns></returns>
public bool AddUsers(string name, string pwd, string ask, string anwser)
{
string strSql = "insert into Users(name,pwd,ask,anwser)values('" + name + "','" + pwd + "','" + ask + "','" + anwser + "')";
try
{
RunSql(strSql);
RunSql("update users set logincount= logincount+1,logindate='" + DateTime.Now + "',ip='" + System.Web.HttpContext.Current.Request.UserHostAddress + "' where name='" + name + "'");
return true;
}
catch { return false;}
}
/// <summary>
/// 修改用户基本资料
/// </summary>
/// <param name="sex">性别</param>
/// <param name="birthday">生日</param>
/// <param name="headpic">头像</param>
/// <param name="ink">个性签名</param>
/// <param name="userid">用户ID</param>
/// <returns></returns>
public bool ChangeUserBase(string sex, string birthday, string headpic, string ink,string userid)
{
string strSql = "update users_base set sex = '" + sex + "',birthday = '" + birthday + "',headpic = '" + headpic + "',ink ='" + ink + "' where userid =" + userid;
try
{
RunSql(strSql);
return true;
}
catch{ return false; }
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="id">ID</param>
/// <param name="pwd">密码</param>
/// <returns></returns>
public bool ChangeUserPwd(string id,string pwd)
{
string strSql = "update users set pwd = '" + pwd + "' where id=" + id;
try
{
RunSql(strSql);
return true;
}
catch { return false; }
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="id">ID</param>
/// <param name="pwd">密码</param>
/// <returns></returns>
public bool ChangeVldUserPwd(string id, string pwd)
{
string strSql = "select count(*) from users where id=" + id + " and pwd ='" + pwd + "'";
if (RunSqlReturn(strSql) == "1")
return true;
else
return false;
}
/// <summary>
/// 搜索用户表
/// </summary>
/// <param name="name">用户名</param>
/// <returns></returns>
public DataView Dv_Search(string name)
{
string strSql = "select * from users where name like '%" + name + "%' and qx <>4";
return GetDv(strSql);
}
/// <summary>
/// 删除用户
/// </summary>
/// <param name="id"></param>
public void DelUsers(string id)
{
string strSql = "delete users where id =" + id;
RunSql(strSql);
}
/* ------------------------- 管理员 ------------------ */
/// <summary>
/// 通过用户名密码返回记录条数
/// </summary>
/// <param name="name">用户名</param>
/// <param name="pwd">密码</param>
/// <returns></returns>
public int GetVldManage(string name, string pwd)
{
return int.Parse(RunSqlReturn("select count(*) from manage where username='" + name + "' and password ='" + pwd + "'"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -