using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; /// /// RegionRoomBed 的摘要描述 /// namespace Model { public partial class RegionRoomBed { public const string STATUS_BED_FREE = "101"; // 空閒,可使用 public const string STATUS_BED_OCCUPIED = "102"; // 已佔用 public const string STATUS_BED_MAINTENANCE = "103"; // 維護中,不可使用 public bool IsAvailable() { //判断床位是否可用:自身是否启用 //床位使用排程是否可用 //是否需要传入时间?指定时间间隔内 if (!this.IsActive) { return false; } return this.Room.IsAvailable(); //根据床位排程判定床位是否可用 } public bool IsAvailableDuring(DateTime checkInAt, DateTime? checkOutAt, ezEntities _db) { // 床位本身不可用,直接返回 false if (!this.IsActive || !this.Room.IsAvailable()) { return false; } // 如果資料庫 ScheduleDate 是 date 型別,本身沒有時間部分,可以直接比較 var conflict = _db.RegionAndRoomAndBedSchedule.Any(s => s.TargetUuid == this.Uuid && s.GuaDanOrderGuest.StatusCode != "403" && s.GuaDanOrderGuest.StatusCode != "404" && !s.IsCancel && !s.IsDeleted && ( s.ScheduleDate == null || // 長期占用 (checkOutAt.HasValue ? (s.ScheduleDate >= checkInAt && s.ScheduleDate <= checkOutAt.Value) : s.ScheduleDate >= checkInAt) ) ); return !conflict; } } }