?? 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 + -