📄 usersaccessor.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.DataAccess
{
/// <summary>
/// 对Users表进行操作的类
/// </summary>
public class UsersAccessor:DataAccessor
{
//增加会员
public bool Insert(Users entity)
{
string userName = entity.UserName;
string pwd = entity.Pwd;
string realName = entity.RealName;
string sex = entity.Sex;
string iDCard = entity.IDCard;
string phoneNum = entity.PhoneNum;
int goal = entity.Goal;
int userTypeId = entity.UserTypeId;
int recId = entity.RecId;
string sql = "insert into Users(UserName,Pwd,RealName,Sex,IDCard,PhoneNum,Goal,UserTypeId,RecId) values('" +
userName + "','" + pwd + "','" + realName + "','" + sex + "','" + iDCard + "','" + phoneNum + "'," +
goal + "," + userTypeId + ","+recId+")";
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("增加会员时出现错误:" + ex.Message);
}
}
//修改会员
public bool Update(Users entity)
{
int id = entity.UserId;
string userName = entity.UserName;
string pwd = entity.Pwd;
string realName = entity.RealName;
string sex = entity.Sex;
string iDCard = entity.IDCard;
string phoneNum = entity.PhoneNum;
int goal = entity.Goal;
int userTypeId = entity.UserTypeId;
int recId = entity.RecId;
string sql = "update Users set UserName='" + userName + "',Pwd='" + pwd + "',RealName='" + realName +
"',Sex='" + sex + "',IDCard='" + iDCard + "',PhoneNum='" + phoneNum + "',Goal=" + goal + ",UserTypeId=" +
userTypeId + ",RecId="+recId+" where UserId=" + id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("修改会员时出现错误:" + ex.Message);
}
}
//根据会员ID删除会员
public bool DeleteById(int id)
{
string sql = "delete Users where UserId=" + id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("根据会员ID删除会员时出现错误:" + ex.Message);
}
}
//根据会员ID查询会员
public DataTable QueryById(int id)
{
string sql = "select * from Users where UserId=" + id;
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据会员ID查询会员时出现错误:" + ex.Message);
}
}
//根据用户名查询会员
public DataTable QueryByUserName(string userName)
{
string sql = "select * from Users where UserName='" + userName + "'";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据用户名查询会员时出现错误:" + ex.Message);
}
}
//查询所有会员
public DataTable QueryAll()
{
string sql = "select * from Users";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("查询所有会员时出现错误:" + ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -