📄 roombusiness.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>
/// 对Room表进行业务逻辑操作
/// </summary>
public class RoomBusiness : Business
{
private RoomAccessor ra = new RoomAccessor();
private static RoomBusiness instance = null;
private RoomBusiness() { }//私有构造函数
/// <summary>
/// 获取RoomBusiness对象
/// </summary>
/// <returns></returns>
public static RoomBusiness GetInstance()
{
if (instance == null)
{
instance = new RoomBusiness();
}
return instance;
}
/// <summary>
/// 根据房间ID查询房间
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Room QueryById(int id)
{
Room entity = null;
try
{
DataTable dt = ra.QueryById(id);
if (dt.Rows.Count > 0)
{
entity = new Room();
PropertyInfo[] props = typeof(Room).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="hotelId"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public Room[] QueryNullRoomByHotelId(int hotelId, DateTime endTime)
{
Room[] entityList = null;
try
{
DataTable dt = ra.QueryNullRoomByHotelId(hotelId, endTime);
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 根据酒店ID查询空房
/// </summary>
/// <param name="hotelId"></param>
/// <returns></returns>
public Room[] QueryRoomByHotelId(int hotelId)
{
Room[] entityList = null;
try
{
DataTable dt = ra.QueryRoomByHotelId(hotelId);
entityList = FillEntityList(entityList, dt);
return entityList;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 增加房间
/// </summary>
/// <param name="roomNum"></param>
/// <param name="endTime"></param>
/// <param name="normalPrice"></param>
/// <param name="dBaoPrice"></param>
/// <param name="desciption"></param>
/// <param name="roomTypeId"></param>
/// <param name="hotelId"></param>
/// <returns></returns>
public bool Insert(string roomNum,DateTime endTime,double normalPrice,double dBaoPrice,
string desciption,int roomTypeId,int hotelId)
{
Room entity = new Room();
entity.RoomNum = roomNum;
entity.EndTime = endTime;
entity.NormalPrice = normalPrice;
entity.DBaoPrice = dBaoPrice;
entity.Desciption = desciption;
entity.RoomTypeId = roomTypeId;
entity.HotelId = hotelId;
try
{
return ra.Insert(entity);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 修改房间
/// </summary>
/// <param name="id"></param>
/// <param name="roomNum"></param>
/// <param name="endTime"></param>
/// <param name="normalPrice"></param>
/// <param name="dBaoPrice"></param>
/// <param name="desciption"></param>
/// <param name="roomTypeId"></param>
/// <param name="hotelId"></param>
/// <returns></returns>
public bool Update(int id, string roomNum, DateTime endTime, double normalPrice, double dBaoPrice,
string desciption, int roomTypeId, int hotelId)
{
Room entity = new Room();
entity.RoomId = id;
entity.RoomNum = roomNum;
entity.EndTime = endTime;
entity.NormalPrice = normalPrice;
entity.DBaoPrice = dBaoPrice;
entity.Desciption = desciption;
entity.RoomTypeId = roomTypeId;
entity.HotelId = hotelId;
try
{
return ra.Update(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 ex;
}
}
//填充实体类列表
private Room[] FillEntityList(Room[] entityList, DataTable dt)
{
if (dt.Rows.Count > 0)
{
entityList = new Room[dt.Rows.Count];
//用反射给实体类赋值
for (int i = 0; i < entityList.Length; i++)
{
Room entity = new Room();
PropertyInfo[] props = typeof(Room).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 + -