Files
17168ERP/web/App_Code/Model/Partial/GuaDanOrderGuest.cs
2025-09-09 16:25:28 +08:00

58 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
/// <summary>
/// GuaDanOrderGuest 的摘要描述
/// </summary>
namespace Model
{
public partial class GuaDanOrderGuest
{
// 状态常量定义
public const string STATUS_BOOKED = "401"; // 预订成功
public const string STATUS_CHECKED_IN = "402"; // 已入住
public const string STATUS_CHECKED_OUT = "403"; // 已退房
public const string STATUS_CANCELLED = "404"; // 已取消
public static bool IsStatusTransitionValid(ezEntities db, string targetStatus, Guid guestId)
{
// 获取当前客人对象
GuaDanOrderGuest currentGuest = db.GuaDanOrderGuest.Find(guestId);
if (currentGuest == null)
{
// 如果没有客人对象,只能创建新的预订
return targetStatus == STATUS_BOOKED;
}
// 安全获取当前状态处理null情况
string currentStatus = currentGuest.RegionRoomBedStatus?.Code;
// 如果当前状态为空,只能进入预订成功状态
if (string.IsNullOrEmpty(currentStatus))
{
return targetStatus == STATUS_BOOKED;
}
// 定义有效的状态转换规则
var validTransitions = new Dictionary<string, List<string>>
{
{ STATUS_BOOKED, new List<string> { STATUS_CHECKED_IN, STATUS_CANCELLED } },
{ STATUS_CHECKED_IN, new List<string> { STATUS_CHECKED_OUT } },
{ STATUS_CHECKED_OUT, new List<string> { } }, // 终态,不能再转换
{ STATUS_CANCELLED, new List<string> { } } // 终态,不能再转换
};
// 检查转换是否有效
if (validTransitions.ContainsKey(currentStatus))
{
return validTransitions[currentStatus].Contains(targetStatus);
}
return false; // 未知的当前状态
}
}
}