📄 adminaccessor.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.DataAccess
{
/// <summary>
/// 对Admin表进行操作的类
/// </summary>
public class AdminAccessor:DataAccessor
{
//根据管理员ID查询管理员
public DataTable QueryAdminById(int id)
{
string sql = "select * from Admin where AdminId=" + id;
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据管理员ID查询Admin表时出错!", ex);
}
}
//登录
public DataTable Login(string userName, string pwd)
{
string sql = "select * from Admin where UserName='" + userName + "' and Pwd='" + pwd + "'";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("登录时出错!", ex);
}
}
//根据用户名查询管理员
public DataTable QueryAdminByUserName(string userName)
{
string sql = "select * from Admin where UserName='" + userName + "'";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据用户名查询管理员时出错!", ex);
}
}
//查询所有管理员
public DataTable QueryAll()
{
string sql = "select * from Admin";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("查询所有管理员时出错!", ex);
}
}
//根据管理员ID删除管理员
public bool DeleteById(int id)
{
string sql = "delete Admin where AdminId=" + id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("根据管理员ID删除Admin表时出错!", ex);
}
}
//插入管理员
public bool Insert(Admin entity)
{
string userName = entity.UserName;
string pwd = entity.Pwd;
string realName = entity.RealName;
int accessId = entity.AccessId;
string sql = "insert into Admin(UserName,Pwd,RealName,AccessId) values('" +
userName + "','" + pwd + "','" + realName + "'," + accessId + ")";
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("插入Admin表时出错!", ex);
}
}
//修改管理员信息
public bool Update(Admin entity)
{
int id = entity.AdminId;
string userName = entity.UserName;
string pwd = entity.Pwd;
string realName = entity.RealName;
int accessId = entity.AccessId;
string sql = "update Admin set UserName='" + userName + "',Pwd='" + pwd + "',RealName='" + realName
+ "',AccessId=" + accessId+" where AdminId="+entity.AdminId;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("修改Admin表时出错!", ex);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -