📄 usertypebusiness.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>
/// 对会员类型进行业务逻辑操作
/// </summary>
public class UserTypeBusiness : Business
{
private UserTypeAccessor uta = new UserTypeAccessor();
private static UserTypeBusiness instance = null;
private UserTypeBusiness() { }//私有构造函数
/// <summary>
/// 获取UserTypeBusiness对象
/// </summary>
/// <returns></returns>
public static UserTypeBusiness GetInstance()
{
if (instance == null)
{
instance = new UserTypeBusiness();
}
return instance;
}
/// <summary>
/// 添加会员类型
/// </summary>
/// <param name="typeName"></param>
/// <returns></returns>
public bool Insert(string typeName)
{
UserType ut = new UserType();
ut.TypeName = typeName;
try
{
return uta.Insert(ut);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 查询所有会员类型
/// </summary>
/// <returns></returns>
public UserType[] QueryAll()
{
UserType[] entityList = null;
try
{
DataTable dt = uta.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据会员类型ID查询会员类型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public UserType QueryById(int id)
{
UserType entity = null;
try
{
DataTable dt = uta.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new UserType();
PropertyInfo[] props = typeof(UserType).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="typeName"></param>
/// <returns></returns>
public UserType QueryByName(string typeName)
{
UserType entity = null;
try
{
DataTable dt = uta.QueryByName(typeName);
if (dt.Rows.Count > 0)
{
entity = new UserType();
PropertyInfo[] props = typeof(UserType).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 uta.DeleteById(id);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改会员类型
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool Update(int id,string typeName)
{
UserType u = new UserType();
u.TypeId = id;
u.TypeName = typeName;
try
{
return uta.Update(u);
}
catch (Exception ex)
{
throw ex;
}
}
//填充实体类列表
private UserType[] FillEntityList(UserType[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new UserType[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
UserType entity = new UserType();
PropertyInfo[] props = typeof(UserType).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 + -