Files
17168ERP/web/App_Code/Model/Partial/RegionRoomBed.cs
2025-09-04 18:30:54 +08:00

51 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
/// <summary>
/// RegionRoomBed 的摘要描述
/// </summary>
namespace Model
{
public partial class RegionRoomBed
{
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.IsActive &&
!s.IsDeleted &&
(
s.ScheduleDate == null || // 長期占用
(checkOutAt.HasValue
? (s.ScheduleDate >= checkInAt && s.ScheduleDate <= checkOutAt.Value)
: s.ScheduleDate >= checkInAt)
)
);
return !conflict;
}
}
}