📄 users.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using HouseSystem.SQLDAL;
using HouseSystem.Modal;
namespace HouseSystem.Components
{
/// <summary>
/// Users 的摘要说明。
/// </summary>
public class Users
{
public static int Add(UserInfo entity)
{
string text1 = "SELECT UserName FROM Users WHERE UserName='" + entity.UserName + "'";
DataRow row1 = SQLHelper.ExecuteDataRow(text1);
if (row1 != null)
{
return -1;
}
object[] objArray1 = new object[0x13] {
"INSERT INTO Users(UserName ,UserPass ,Question ,Answer ,Name ,Sex ,Tel1 ,Tel2 ,Email) VALUES ('", entity.UserName, "' ,'", entity.UserPass, "' ,'", entity.Question, "' ,'", entity.Answer, "' ,'", entity.Name, "' ,", entity.Sex, " ,'", entity.Tel1, "' ,'", entity.Tel2,
"' ,'", entity.Email, "')"
} ;
text1 = string.Concat(objArray1);
return SQLHelper.ExecuteNonQuery(text1);
}
public static int Delete(int userId)
{
string text1 = "DELETE FROM Users WHERE User_ID = " + userId + "";
return SQLHelper.ExecuteNonQuery(text1);
}
public static DataTable GetAllUserList()
{
string text1 = "SELECT * FROM Users ORDER BY Addtime DESC";
return SQLHelper.ExecuteDataTable(text1);
}
public static DataRow GetAnswerByUserName(string strUserName)
{
string text1 = "SELECT UserPass,Answer,Question FROM Users WHERE UserName = '" + strUserName + "'";
return SQLHelper.ExecuteDataRow(text1);
}
public static DataRow GetUserInfoByEmail(string strEmail)
{
string text1 = "SELECT UserName,UserPass FROM Users WHERE Email='" + strEmail + "'";
return SQLHelper.ExecuteDataRow(text1);
}
public static DataRow GetUserInfoByID(string UserId)
{
string text1 = "SELECT UserName,Question ,Answer ,Name ,Sex ,Tel1 ,Tel2 ,Email FROM Users WHERE User_ID=" + UserId + "";
return SQLHelper.ExecuteDataRow(text1);
}
public static bool IsUserExist(string strUserName)
{
string text1 = "SELECT UserName FROM Users WHERE UserName='" + strUserName + "'";
DataRow row1 = SQLHelper.ExecuteDataRow(text1);
if (row1 != null)
{
return true;
}
return false;
}
public static bool IsUserLogin()
{
if (Tools.GetUserCookie("UserId") == "")
{
return false;
}
return true;
}
public static DataRow Login(string UserName, string UserPass)
{
string[] textArray1 = new string[5] { "SELECT User_ID,UserName ,UserPass ,Name ,Sex ,Tel1 ,Tel2 ,Email,LoginNum FROM [Users] WHERE UserName = '", UserName, "' AND UserPass = '", UserPass, "' AND State = 1" } ;
string text1 = string.Concat(textArray1);
DataRow row1 = SQLHelper.ExecuteDataRow(text1);
if (row1 != null)
{
string text2 = row1["User_ID"].ToString();
text1 = "UPDATE Users SET LoginNum=LoginNum+1,Updatetime=getdate() WHERE User_ID=" + text2;
SQLHelper.ExecuteNonQuery(text1);
return row1;
}
return null;
}
public static int Update(UserInfo entity)
{
string text1;
object[] objArray1;
if ((entity.Question == null) || (entity.Question == ""))
{
objArray1 = new object[13] { "UPDATE Users SET Name = '", entity.Name, "',Sex = ", entity.Sex, " ,Tel1 = '", entity.Tel1, "',Tel2 = '", entity.Tel2, "' ,Email = '", entity.Email, "' WHERE User_ID = ", entity.UserId, "" } ;
text1 = string.Concat(objArray1);
}
else
{
objArray1 = new object[0x11] {
"UPDATE Users SET Question = '", entity.Question, "' ,Answer = '", entity.Answer, "',Name = '", entity.Name, "',Sex = ", entity.Sex, " ,Tel1 = '", entity.Tel1, "',Tel2 = '", entity.Tel2, "' ,Email = '", entity.Email, "' WHERE User_ID = ", entity.UserId,
""
} ;
text1 = string.Concat(objArray1);
}
return SQLHelper.ExecuteNonQuery(text1);
}
public static int UpdateMyPassword(string userName, string OldPwd, string NewPwd)
{
string[] textArray1 = new string[5] { "SELECT UserName from Users WHERE State=1 AND UserName='", userName, "' and UserPass='", OldPwd, "'" } ;
string text1 = string.Concat(textArray1);
DataSet set1 = SQLHelper.ExecuteDataset(SQLHelper.CONN_STRING, CommandType.Text, text1, new SqlParameter[0]);
if ((set1.Tables.Count <= 0) || (set1.Tables[0].Rows.Count <= 0))
{
return -1;
}
textArray1 = new string[5] { "UPDATE Users SET UserPass='", NewPwd, "' WHERE UserName='", userName, "'" } ;
text1 = string.Concat(textArray1);
int num1 = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING, CommandType.Text, text1, new SqlParameter[0]);
if (num1 > 0)
{
return 1;
}
return 0;
}
public static int UpdateUserState(int userId, int state)
{
if (state == 1)
{
state = 0;
}
else
{
state = 1;
}
object[] objArray1 = new object[5] { "UPDATE Users SET State=", state, " WHERE User_ID = ", userId, "" } ;
string text1 = string.Concat(objArray1);
return SQLHelper.ExecuteNonQuery(text1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -