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

📄 roomoperatorbll.cs

📁 酒店管理 主要实现了基础设施管理(客房管理、客房类型管理)、业务管理(入住、退房、数据库切换) 本系统简单明了,适合初学者学习,采用三层加抽象工厂实现
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

using System.Collections;
using Model;
using IDAL;
using Factory;
using System.Data;

namespace BLL
{
    public class RoomOperatorBLL
    {
        //根据配置文件Web.Config中的<appSettings>中的值确定该创建SQLServer还是Access工厂

        private static IRoom op = null;

        public RoomOperatorBLL()
        { 
            op = AbstractFactory.GetFactory().CreateRoomOperator();
        }

        /// <summary>
        /// 查询所有的房间信息
        /// </summary>
        /// <returns></returns>
        public DataTable SelectAllDataByRoom()
        {
            List<Room> temp = null;
            DataTable table = null;
            try
            {
                temp = op.SelectAllDataByRoom() as List<Room>;

                table = GetDataTable(temp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return table;
        }

        /// <summary>
        /// 按房间号查询房间信息
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public DataTable GetRoomByNumber(string number)
        {
            List<Room> temp = null;
            DataTable table = null;
            try
            {
                temp = op.SelectRoomByNumber(number) as List<Room>;
                if (temp.Count > 0)
                    table = GetDataTable(temp);
                else
                    table = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return table;
        }

        /// <summary>
        /// 按类型编号查询房间信息
        /// </summary>
        /// <param name="roomTypeID"></param>
        /// <returns></returns>
        public DataTable GetAllRoomsByTypeId(int roomTypeID)
        {
            List<Room> temp = null;
            DataTable table = null;
            try
            {
                temp = op.GetAllRoomsByTypeId(roomTypeID) as List<Room>;

                table = GetDataTable(temp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return table;
        }

        /// <summary>
        /// 按房间号查询房间编号
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public int GetRoomIdByRoomNumber(string number)
        {
            int id = 0;
            try
            {
                id = op.GetRoomIdByRoomNumber(number);
            }
            catch(Exception ex)
            {
                throw ex;
            }
            return id;
        }

        /// <summary>
        /// 按编号查询房间信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Room GetRoomByRoomID(int id)
        {
            Room temp = null;
            try
            {
                temp = op.SelectRoomByID(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return temp;
        }

        /// <summary>
        /// 根据房间类型查询房间信息
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public DataTable GetRoomBySafeSql(string sql)
        {
            List<Room> temp = null;
            DataTable table = null;
            try
            {
                temp = op.GetRoomBySafeSql(sql) as List<Room>;

                table = GetDataTable(temp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return table;
        }

        /// <summary>
        /// 添加新房间信息
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public bool InsertValuesToRoom(Room room)
        {
            bool insert = false;
            try
            {
                insert = op.InsertRoomValues(room);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return insert;
        }

        /// <summary>
        /// 修改房间信息
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public bool ModifyValuesFormRoom(Room room)
        {
            bool insert = false;
            try
            {
                insert = op.ModifyRoomValues(room);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return insert;
        }

        /// <summary>
        /// 删除房间信息
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public bool DeleteValuesFormRoom(Room room)
        {
            bool insert = false;
            try
            {
                insert = op.DeleteRoomValues(room);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return insert;
        }

        /// <summary>
        /// 根据泛型集合返回DataTable对象
        /// </summary>
        /// <param name="temp"></param>
        /// <returns></returns>
        private DataTable GetDataTable(List<Room> temp)
        {
            DataTable table = null;
            if (temp != null)
            {
                //创建内存表的字段
                table = new DataTable("Room");
                table.Columns.Add("RoomId");
                table.Columns.Add("Number");
                table.Columns.Add("BedNumber");
                table.Columns.Add("GuessNumber");
                table.Columns.Add("State");
                table.Columns.Add("Description");
                table.Columns.Add("TypeId");
                //遍历泛型集合中的对象并分别赋给object数组
                foreach(Room room in temp)
                {
                    DataRow row = table.NewRow();
                    object[] items = new object[7];
                    items[0] = (object)room.Roomid;
                    items[1] = (object)room.Roomnumber;
                    items[2] = (object)room.Bednumber;
                    items[3] = (object)room.Guessnumber;
                    items[4] = (object)room.State;
                    items[5] = (object)room.Description;
                    if (room.TypeId != null)
                        items[6] = (object)room.TypeId.Typename;
                    else
                        items[6] = "暂无类型";
                    row.ItemArray = items;//将数组中的值依次赋给这一行的所有值
                    table.Rows.Add(row);//将DataRow添加到表集合中
                }
            }
            return table;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -