📄 adminbusiness.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;
using DBaoBookingManagement.DataAccess;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.BusinessLogic
{
/// <summary>
/// 对Admin表进行业务逻辑操作
/// </summary>
public class AdminBusiness : Business
{
private AdminAccessor aa = new AdminAccessor();
private static AdminBusiness instance = null;
private AdminBusiness() { }//私有构造函数
/// <summary>
/// 获取AdminBusiness对象
/// </summary>
/// <returns></returns>
public static AdminBusiness GetInstance()
{
if (instance == null)
{
instance = new AdminBusiness();
}
return instance;
}
/// <summary>
/// 登录,成功返回管理员对象,失败返回null
/// </summary>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public Admin Login(string userName, string pwd)
{
Admin entity = null;
try
{
DataTable dt = aa.Login(userName, pwd);
if (dt.Rows.Count > 0)
{
entity = new Admin();
PropertyInfo[] props = typeof(Admin).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[0][columnName];
props[j].SetValue(entity, value, null);
}
}
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据管理员ID查询管理员
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Admin QueryAdminById(int id)
{
Admin entity = null;
try
{
DataTable dt = aa.QueryAdminById(id);
if (dt.Rows.Count > 0)
{
entity = new Admin();
PropertyInfo[] props = typeof(Admin).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[0][columnName];
props[j].SetValue(entity, value, null);
}
}
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据用户名查询管理员
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Admin QueryAdminByUserName(string userName)
{
Admin entity = null;
try
{
DataTable dt = aa.QueryAdminByUserName(userName);
if (dt.Rows.Count > 0)
{
entity = new Admin();
PropertyInfo[] props = typeof(Admin).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[0][columnName];
props[j].SetValue(entity, value, null);
}
}
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 查询所有管理员
/// </summary>
/// <returns></returns>
public Admin[] QueryAll()
{
Admin[] entityList = null;
try
{
DataTable dt = aa.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据管理员ID删除管理员
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteById(int id)
{
try
{
return aa.DeleteById(id);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 插入管理员
/// </summary>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="realName"></param>
/// <param name="accessId"></param>
/// <returns></returns>
public bool Insert(string userName,string pwd,string realName,int accessId)
{
Admin entity = new Admin();
entity.UserName = userName;
entity.Pwd = pwd;
entity.RealName = realName;
entity.AccessId = accessId;
try
{
return aa.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改管理员信息
/// </summary>
/// <param name="id"></param>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="realName"></param>
/// <param name="accessId"></param>
/// <returns></returns>
public bool Update(int id,string userName,string pwd,string realName,int accessId)
{
Admin entity = new Admin();
entity.AdminId = id;
entity.UserName = userName;
entity.Pwd = pwd;
entity.RealName = realName;
entity.AccessId = accessId;
try
{
return aa.Update(entity);
}
catch (Exception ex)
{
throw ex;
}
}
//填充实体类列表
private Admin[] FillEntityList(Admin[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new Admin[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
Admin entity = new Admin();
PropertyInfo[] props = typeof(Admin).GetProperties();
for (int j = 0; j < props.Length; j++)
{
string columnName = props[j].Name;
object value = dt.Rows[i][columnName];
props[j].SetValue(entity, value, null);
}
entityList[i] = entity;
}
}
return entityList;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -