⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roomtypebusiness.cs

📁 本系统是基于三层架构和Ajax控件结合的酒店预订系统
💻 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>
    /// 对RoomType表进行业务逻辑操作
    /// </summary>
    public class RoomTypeBusiness : Business
    {
        private RoomTypeAccessor rta = new RoomTypeAccessor();

        private static RoomTypeBusiness instance = null;
        private RoomTypeBusiness() { }//私有构造函数

        /// <summary>
        /// 获取RoomTypeBusiness对象
        /// </summary>
        /// <returns></returns>
        public static RoomTypeBusiness GetInstance()
        {
            if (instance == null)
            {
                instance = new RoomTypeBusiness();
            }
            return instance;
        }

        /// <summary>
        /// 根据房间类型名称查询房间类型
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public RoomType QueryByTypeName(string typeName)
        {
            RoomType entity = null;
            try
            {
                DataTable dt = rta.QueryByTypeName(typeName);
                if (dt.Rows.Count > 0)
                {
                    entity = new RoomType();
                    PropertyInfo[] props = typeof(RoomType).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 RoomType QueryById(int id)
        {
            RoomType entity = null;
            try
            {
                DataTable dt = rta.QueryById(id);
                if (dt.Rows.Count > 0)
                {
                    entity = new RoomType();
                    PropertyInfo[] props = typeof(RoomType).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 RoomType[] QueryAll()
        {
            RoomType[] entityList = null;
            try
            {
                DataTable dt = rta.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)
        {
            RoomType entity = new RoomType();
            entity.TypeName = typeName;
            try
            {
                return rta.Insert(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 修改房间类型
        /// </summary>
        /// <param name="id"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public bool Update(int id,string typeName)
        {
            RoomType entity = new RoomType();
            entity.TypeId = id;
            entity.TypeName = typeName;
            try
            {
                return rta.Update(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据房间类型ID删除房间类型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteById(int id)
        {
            try
            {
                return rta.DeleteById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //填充实体类列表
        private RoomType[] FillEntityList(RoomType[] entityList, DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                entityList = new RoomType[dt.Rows.Count];

                //用反射给实体类赋值
                for (int i = 0; i < entityList.Length; i++)
                {
                    RoomType entity = new RoomType();
                    PropertyInfo[] props = typeof(RoomType).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 + -