📄 accessbussiness.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>
/// 对Access表进行逻辑操作
/// </summary>
public class AccessBusiness:Business
{
private AccessAccessor aa = new AccessAccessor();
private static AccessBusiness instance = null;
private AccessBusiness() { }//私有构造函数
/// <summary>
/// 获取AccessBusiness对象
/// </summary>
/// <returns></returns>
public static AccessBusiness GetInstance()
{
if (instance == null)
{
instance = new AccessBusiness();
}
return instance;
}
/// <summary>
/// 根据权限ID查询权限
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Access QueryById(int id)
{
Access entity = null;
try
{
DataTable dt = aa.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new Access();
PropertyInfo[] props = typeof(Access).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 Access[] QueryAll()
{
Access[] entityList = null;
try
{
DataTable dt = aa.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据权限名称查询权限
/// </summary>
/// <param name="typeName"></param>
/// <returns></returns>
public Access QueryByTypeName(string accessName)
{
Access entity = null;
try
{
DataTable dt = aa.QueryByTypeName(accessName);
if (dt.Rows.Count > 0)
{
entity = new Access();
PropertyInfo[] props = typeof(Access).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 bool DeleteById(int id)
{
try
{
return aa.DeleteById(id);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 添加权限
/// </summary>
/// <param name="accessName"></param>
/// <returns></returns>
public bool Insert(string accessName)
{
Access entity = new Access();
entity.AccessName = accessName;
try
{
return aa.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改权限
/// </summary>
/// <param name="id"></param>
/// <param name="accessName"></param>
/// <returns></returns>
public bool Update( int id,string accessName)
{
Access entity=new Access();
entity.AccessId = id;
entity.AccessName = accessName;
try
{
return aa.Update(entity);
}
catch (Exception ex)
{
throw ex;
}
}
//填充实体类列表
private Access[] FillEntityList(Access[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new Access[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
Access entity = new Access();
PropertyInfo[] props = typeof(Access).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 + -