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

📄 roomaccessor.cs

📁 本系统是基于三层架构和Ajax控件结合的酒店预订系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;

namespace DBaoBookingManagement.DataAccess
{
    /// <summary>
    /// 对Room进行操作的类
    /// </summary>
    public class RoomAccessor:DataAccessor
    {
        //根据房间ID查询房间
        public DataTable QueryById(int id)
        {
            string sql = "select * from Room where RoomId=" + id;
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据房间ID查询房间时出现错误:" + ex.Message);
            }
        }

        //根据酒店ID及到期时间查询空房
        public DataTable QueryNullRoomByHotelId(int hotelId,DateTime endTime)
        {
            string sql = "select * from Room where HotelId=" + hotelId+" and EndTime <'"+endTime+"'";
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据酒店ID及到期时间查询空房时出现错误:" + ex.Message);
            }
        }

        //根据酒店ID查询空房
        public DataTable QueryRoomByHotelId(int hotelId)
        {
            string sql = "select * from Room where HotelId=" + hotelId;
            try
            {
                return base.Query(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据酒店ID查询空房时出现错误:" + ex.Message);
            }
        }

        //增加房间
        public bool Insert(Room entity)
        {
            string roomNum = entity.RoomNum;
            DateTime endTime = entity.EndTime;
            double normalPrice = entity.NormalPrice;
            double dBaoPrice = entity.DBaoPrice;
            string desciption = entity.Desciption;
            int roomTypeId = entity.RoomTypeId;
            int hotelId = entity.HotelId;
            string sql = "insert into Room(RoomNum,EndTime,NormalPrice,DBaoPrice,Desciption,RoomTypeId,HotelId)" +
                " values('" + roomNum + "','" + endTime + "','" + normalPrice + "'," + dBaoPrice + ",'" + desciption +
                "'," + roomTypeId + "," + hotelId + ")";
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("增加房间时出现错误:" + ex.Message);
            }
        }

        //修改房间
        public bool Update(Room entity)
        {
            int id = entity.RoomId;
            string roomNum = entity.RoomNum;
            DateTime endTime = entity.EndTime;
            double normalPrice = entity.NormalPrice;
            double dBaoPrice = entity.DBaoPrice;
            string desciption = entity.Desciption;
            int roomTypeId = entity.RoomTypeId;
            int hotelId = entity.HotelId;
            string sql = "update Room set RoomNum='" + roomNum + "',EndTime='" + endTime + "',NormalPrice=" +
                normalPrice + ",DBaoPrice=" + dBaoPrice + ",Desciption='" + desciption + "',RoomTypeId=" +
                roomTypeId + ",HotelId=" + hotelId + " where RoomId=" + id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("增加房间时出现错误:" + ex.Message);
            }
        }

        //根据房间ID删除房间
        public bool DeleteById(int id)
        {
            string sql = "delete Room where RoomId=" + id;
            try
            {
                return base.ExecuteSqlNoneQuery(sql);
            }
            catch (Exception ex)
            {
                throw new Exception("根据房间ID删除房间时出现错误:" + ex.Message);
            }
        }
    }
}

⌨️ 快捷键说明

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