📄 recommandbusiness.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
{
public class RecommandBusiness:Business
{
private RecommendAccessor ra = new RecommendAccessor();
private static RecommandBusiness instance = null;
private RecommandBusiness() { }//私有构造函数
/// <summary>
/// 获取RecommendBusiness对象
/// </summary>
/// <returns></returns>
public static RecommandBusiness GetInstance()
{
if (instance == null)
{
instance = new RecommandBusiness();
}
return instance;
}
/// <summary>
/// 查询所有推荐人
/// </summary>
/// <returns></returns>
public Recommend[] QueryAll()
{
Recommend[] entityList = null;
try
{
DataTable dt = ra.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据ID查询推荐人
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Recommend QueryById(int id)
{
Recommend entity = null;
try
{
DataTable dt = ra.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new Recommend();
PropertyInfo[] props = typeof(Recommend).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 ra.DeleteById(id);
}
catch (Exception ex)
{
throw new Exception("根据ID删除推荐人时出现错误:" + ex.Message);
}
}
/// <summary>
/// 插入推荐人
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool Insert(string recName)
{
Recommend entity=new Recommend();
entity.RecName=recName;
try
{
return ra.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改推荐人
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool Update(int id,string recName)
{
Recommend entity = new Recommend();
entity.RecId=id;
entity.RecName=recName;
try
{
return ra.Update(entity);
}
catch (Exception ex)
{
throw ex;
}
}
//填充实体类列表
private Recommend[] FillEntityList(Recommend[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new Recommend[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
Recommend entity = new Recommend();
PropertyInfo[] props = typeof(Recommend).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 + -