public bool FixRecord(DateTime frtDate, DateTime sndDate, IList<string> rclist)
 {
     List<int> lsroomnum = new List<int>();
     for (int i = 0; i < rclist.Count; i++)
     {
         lsroomnum.Add(CY.HotelBooking.Core.Services.DALService.RoomInfoService.GetRoomCountByType(rclist[i]));
     }
     CY.HotelBooking.Core.Business.TJ_KFFLHZB record;
     for (int i = 0; i < (sndDate - frtDate).Days; i++)
     {
         for (int j = 0; j < rclist.Count; j++)
         {
             record = new CY.HotelBooking.Core.Business.TJ_KFFLHZB();
             record.Id = new CY.HotelBooking.Core.Business.TJ_KFFLHZBKey();
             record.Id.date = frtDate.AddDays(1);
             record.Id.kfcode = rclist[j];
             record.kfzs = lsroomnum[j];
             record.zdkyfs = lsroomnum[j];
             record.ydfs = 0;
             record.kyfs = lsroomnum[j];
             Insert(record);
         }
     }
     return true;
 }
        /// <summary>
        /// 根据时间段获取总表信息
        /// </summary>
        /// <param name="minDate">起始时间</param>
        /// <param name="maxDate">结束时间</param>
        /// <returns></returns>
        public List<CY.HotelBooking.Core.Business.TJ_KFFLHZB> GetGeneralTableByDateInterval(DateTime minDate, DateTime maxDate)
        {
            List<CY.HotelBooking.Core.Business.TJ_KFFLHZB> generalRecordList = new List<CY.HotelBooking.Core.Business.TJ_KFFLHZB>();

            SqlServerUtility db = new SqlServerUtility();

            db.AddParameter("@minDate", SqlDbType.DateTime, minDate);
            db.AddParameter("@maxDate", SqlDbType.DateTime, maxDate);

            SqlDataReader reader = db.ExecuteSqlReader(SqlSelectByDateInterval);

            if (reader != null && !reader.IsClosed)
            {
                while (reader.Read())
                {
                    CY.HotelBooking.Core.Business.TJ_KFFLHZB tj = new CY.HotelBooking.Core.Business.TJ_KFFLHZB();

                    if (!reader.IsDBNull(0) && !reader.IsDBNull(1))
                    {
                        tj.Id = new CY.HotelBooking.Core.Business.TJ_KFFLHZBKey { kfcode = reader.GetString(1), date = reader.GetDateTime(0) };

                    }
                    if (!reader.IsDBNull(2)) tj.kfzs = reader.GetInt16(2);
                    if (!reader.IsDBNull(3)) tj.kyfs = reader.GetInt16(3);
                    if (!reader.IsDBNull(4)) tj.zdkyfs = reader.GetInt16(4);
                    if (!reader.IsDBNull(5)) tj.ydfs = reader.GetInt16(5);

                    generalRecordList.Add(tj);

                }

                reader.Close();

                return generalRecordList;

            }
            else
            {
                if (reader != null || !reader.IsClosed)
                {
                    reader.Close();
                }

                return null;
            }
        }
        /// <summary>
        /// 对预订后的客房统计表进行更新
        /// </summary>
        /// <param name="roomOrderList">客房预订订单列表</param>
        /// <returns></returns>
        public bool UpdateAvailableRoomsAfterOrdered(IList<CY.HotelBooking.Core.Business.XX_KFFJYDB> roomOrderList)
        {
            //CY.HotelBooking.DALProviders.SqlServerProvider.TJ_KFFLHZB provider = new CY.HotelBooking.DALProviders.SqlServerProvider.TJ_KFFLHZB();
            DateTime minDate = new DateTime();
            DateTime maxDate = new DateTime();

            minDate = roomOrderList.First().ddrq;
            maxDate = roomOrderList.First().ldrq;

            if (roomOrderList.Count > 1)
            {
                for (int i = 0; i < roomOrderList.Count; i++)
                {
                    if (roomOrderList[i].ddrq < minDate)
                    {
                        minDate = roomOrderList[i].ddrq;
                    }
                    else if (roomOrderList[i].ldrq > maxDate)
                    {
                        maxDate = roomOrderList[i].ldrq;
                    }

                }
            }

            // 根据预订单的最小时间minDate和最大时间maxDate构建可比较总表,
            // 构建可比总表的目的是为了减少比较运算
            List<CY.HotelBooking.Core.Business.TJ_KFFLHZB> gerneralTable = new List<CY.HotelBooking.Core.Business.TJ_KFFLHZB>();
            gerneralTable = GetGeneralTableByDateInterval(minDate, maxDate);

            for (int i = 0; i < roomOrderList.Count; i++)
            {
                // stayDays: 表示客人在酒店入住的天数
                int stayDays = 0;
                // 客人当天入住,当天离开,入住天数记为1天
                if ((roomOrderList[i].ldrq - roomOrderList[i].ddrq).Days == 0)
                {
                    stayDays = 1;
                }
                else
                {
                    stayDays = (roomOrderList[i].ldrq - roomOrderList[i].ddrq).Days;
                }

                //
                double increasingDay = 0.0;

                for (int d = 0; d < stayDays; d++)
                {
                    // isExistRecord: 是否存在该日该房类的记录
                    bool isExistRecord = false;

                    increasingDay = Double.Parse(d.ToString());

                    for (int j = 0; j < gerneralTable.Count; j++)
                    {
                        if ((gerneralTable[j].Id.date - roomOrderList[i].ddrq.AddDays(increasingDay)).Days == 0 && gerneralTable[j].Id.kfcode.Equals(roomOrderList[i].kfcode))
                        {
                            // 更新已存在的房间信息
                            CY.HotelBooking.Core.Business.TJ_KFFLHZBKey recordKey = new CY.HotelBooking.Core.Business.TJ_KFFLHZBKey { date = roomOrderList[i].ddrq.AddDays(increasingDay), kfcode = roomOrderList[i].kfcode };
                            CY.HotelBooking.Core.Business.TJ_KFFLHZB record = CY.HotelBooking.Core.Business.TJ_KFFLHZB.Load(recordKey);
                            // 可用房间数
                            record.kyfs = record.kyfs - roomOrderList[i].fjs;
                            // 预订房间数
                            record.ydfs = record.ydfs + roomOrderList[i].fjs;
                            // 总的可用房间数 = ?
                            //record.zdkyfs = record.zdkyfs;

                            //Update(record);
                            record.Save();

                            // 已找到当日房类记录, isExistRecord 设置为true
                            isExistRecord = true;

                        }

                    }
                    if (!isExistRecord)
                    {
                        // 插入一条新的房间信息
                        CY.HotelBooking.Core.Business.TJ_KFFLHZB newRecord = new CY.HotelBooking.Core.Business.TJ_KFFLHZB();
                        newRecord.Id = new CY.HotelBooking.Core.Business.TJ_KFFLHZBKey { date = roomOrderList[i].ddrq.AddDays(increasingDay), kfcode = roomOrderList[i].kfcode };

                        //
                        // 未考虑房间维修情况
                        // 客房总数
                        newRecord.kfzs = CY.HotelBooking.Core.Services.DALService.RoomInfoService.GetRoomCountByType(roomOrderList[i].kfcode);
                        // 总的可用房数 = 客房总数 - 在住客房数 - 本次预订房数????
                        newRecord.zdkyfs = newRecord.kfzs - CY.HotelBooking.Core.Services.DALService.CheckedRoomInfoService.GetCheckedRoomCount(roomOrderList[i].kfcode, roomOrderList[i].ddrq.AddDays(increasingDay));
                        // newRecord.zdkyfs = newRecord.kfzs;
                        // 可用房数 = 总的可用房数 - 本次预订房数
                        newRecord.kyfs = newRecord.zdkyfs - roomOrderList[i].fjs;
                        // 本次预订房数
                        newRecord.ydfs = roomOrderList[i].fjs;

                        //Insert(newRecord);
                        newRecord.Save();

                    }
                }

            }

            return true;
        }
        public CY.HotelBooking.Core.Business.TJ_KFFLHZB Select(CY.HotelBooking.Core.Business.TJ_KFFLHZBKey id)
        {
            SqlServerUtility db = new SqlServerUtility();

            db.AddParameter("@Date0", SqlDbType.DateTime, id.date);
            db.AddParameter("@Kfcode", SqlDbType.Char, id.kfcode);

            SqlDataReader reader = db.ExecuteSqlReader(SqlSelect);

            if (reader != null && !reader.IsClosed && reader.Read())
            {
                CY.HotelBooking.Core.Business.TJ_KFFLHZB tj = new CY.HotelBooking.Core.Business.TJ_KFFLHZB();

                if (!reader.IsDBNull(0) && !reader.IsDBNull(1))
                {
                    tj.Id = new CY.HotelBooking.Core.Business.TJ_KFFLHZBKey { kfcode = reader.GetString(1), date = reader.GetDateTime(0) };
                }
                if (!reader.IsDBNull(2)) tj.kfzs = reader.GetInt16(2);
                if (!reader.IsDBNull(3)) tj.kyfs = reader.GetInt16(3);
                if (!reader.IsDBNull(4)) tj.zdkyfs = reader.GetInt16(4);
                if (!reader.IsDBNull(5)) tj.ydfs = reader.GetInt16(5);

                reader.Close();

                return tj;
            }
            else
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();

                return null;
            }
        }