?? touristtypebusiness.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 TouristTypeBusiness : Business
{
private TouristTypeAccessor tta = new TouristTypeAccessor();
private static TouristTypeBusiness instance = null;
private TouristTypeBusiness() { }//私有構造函數
/// <summary>
/// 獲取TouristTypeBusiness對象
/// </summary>
/// <returns></returns>
public static TouristTypeBusiness GetInstance()
{
if (instance == null)
{
instance = new TouristTypeBusiness();
}
return instance;
}
/// <summary>
/// 根據游客類型ID查詢游客類型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public TouristType QueryById(int id)
{
TouristType entity = null;
try
{
DataTable dt = tta.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new TouristType();
PropertyInfo[] props = typeof(TouristType).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 TouristType QueryByName(string typeName)
{
TouristType entity = null;
try
{
DataTable dt = tta.QueryByName(typeName);
if (dt.Rows.Count > 0)
{
entity = new TouristType();
PropertyInfo[] props = typeof(TouristType).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 TouristType[] QueryAll()
{
TouristType[] entityList = null;
try
{
DataTable dt = tta.QueryAll();
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 插入游客類型
/// </summary>
/// <param name="typeName"></param>
/// <returns></returns>
public bool Insert(string typeName)
{
TouristType entity=new TouristType();
entity.TypeName = typeName;
try
{
return tta.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根據游客類型ID刪除游客類型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteById(int id)
{
try
{
return tta.DeleteById(id);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改游客類型
/// </summary>
/// <param name="id"></param>
/// <param name="typeName"></param>
/// <returns></returns>
public bool Update(int id,string typeName)
{
TouristType entity=new TouristType();
entity.TypeId = id;
entity.TypeName = typeName;
try
{
return tta.Update(entity);
}
catch (Exception ex)
{
throw ex;
}
}
//填充實體類列表
private TouristType[] FillEntityList(TouristType[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new TouristType[dt.Rows.Count];
//用反射給實體類賦值
for (int i = 0; i < entityList.Length; i++)
{
TouristType entity = new TouristType();
PropertyInfo[] props = typeof(TouristType).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 + -