using Grpc.Net.Client;
|
using HotelPms.Client.Blazor.Util;
|
using HotelPms.Data.Master;
|
using HotelPms.DataAccessGrpc.Client;
|
using HotelPms.Share.Util;
|
using Microsoft.VisualBasic;
|
using MudBlazor;
|
using System.Collections.Concurrent;
|
using System.Data;
|
using System.Text;
|
using System.Threading.Channels;
|
using static MudBlazor.CategoryTypes;
|
using static System.Net.Mime.MediaTypeNames;
|
|
namespace HotelPms.Client.Blazor.Models
|
{
|
/// <summary>
|
/// 客室状況を持つデータ
|
/// </summary>
|
public class RoomViewData
|
{
|
/// <summary>
|
/// 現在選択されているTabのインデックス
|
/// </summary>
|
public int ActiveTabIndex { get; set; } = 0;
|
|
/// <summary>
|
/// 全部行数
|
/// </summary>
|
public int RowCount { get; set; } = 0;
|
|
/// <summary>
|
/// 全部列数
|
/// </summary>
|
public int ColCount { get; set; } = 0;
|
|
/// <summary>
|
/// 部屋タブ一覧
|
/// </summary>
|
public List<RoomViewTab> Tabs { get; set; } = new List<RoomViewTab>();
|
|
/// <summary>
|
/// 選択されているタブのレイアウトデータ
|
/// 行⇒列
|
/// </summary>
|
public List<List<RoomViewLayout>> Data { get; set; } = new List<List<RoomViewLayout>>();
|
|
/// <summary>
|
/// 現在のセルレイアウト
|
/// </summary>
|
public List<RoomCell> Cells { get; set; } = new List<RoomCell>();
|
|
/// <summary>
|
/// Tab毎のレイアウトを持つ
|
/// M_RoomCellを編集されたら、SignalRより受信し、更新される
|
/// </summary>
|
public ConcurrentDictionary<int, List<RoomCell>> CellsBuffer = new ConcurrentDictionary<int, List<RoomCell>>();
|
|
/// <summary>
|
/// 部屋ID, 部屋属性データ
|
/// </summary>
|
public Dictionary<int, RoomViewAtt> RoomData = new Dictionary<int, RoomViewAtt>();
|
|
/// <summary>
|
/// 部屋ID, [SortKey, 利用データ]
|
/// </summary>
|
public Dictionary<int, SortedDictionary<string, RoomViewUse>> UseData = new Dictionary<int, SortedDictionary<string, RoomViewUse>>();
|
|
/// <summary>
|
/// メニュー
|
/// </summary>
|
public RoomViewMenu Menu = new RoomViewMenu();
|
|
/// <summary>
|
/// 現在の利用日
|
/// </summary>
|
public DateTime UseDate { get; set; } = DateTime.Today;
|
|
public RoomViewData()
|
{
|
}
|
|
/// <summary>
|
/// 表示Tabのデータクリア
|
/// </summary>
|
private void Clear()
|
{
|
Data.Clear();
|
RoomData.Clear();
|
UseData.Clear();
|
RowCount = 0;
|
ColCount = 0;
|
}
|
|
/// <summary>
|
/// 客室状況画面初期化
|
/// </summary>
|
/// <returns></returns>
|
public async Task Init()
|
{
|
using RoomViewLayoutAccess access = new RoomViewLayoutAccess(EnvironmentSetting.GrpcChannel);
|
using DataSet ds = await access.GetRoomViewData($"NULL,0,1");
|
|
//データを取得してから、クリア:データを取得時、画面再表示されないように
|
Clear();
|
|
//レイアウトデータ
|
SetLayoutData(ds.Tables[0]);
|
|
//部屋状態・属性
|
SetRoomData(ds.Tables[1]);
|
|
//部屋の利用データ
|
SetUseData(ds.Tables[2]);
|
|
//レイアウト
|
SetRoomCell(ds.Tables[3]);
|
|
//ホテル日
|
UseDate = (DateTime)ds.Tables[4].Rows[0][0];
|
|
//Tab一覧
|
SetTabs(ds.Tables[5]);
|
}
|
|
/// <summary>
|
/// 表示用データ
|
/// </summary>
|
/// <param name="channel"></param>
|
/// <returns></returns>
|
public async Task GetData(DateTime useDate, bool tabChanged)
|
{
|
Clear();
|
int tabID = Tabs[ActiveTabIndex].ID;
|
using RoomViewLayoutAccess access = new RoomViewLayoutAccess(EnvironmentSetting.GrpcChannel);
|
using DataSet ds = await access.GetRoomViewData($"{CConvert.ToDateString(useDate)},{tabID},{(tabChanged ? 2 : 0)}");
|
|
//レイアウトデータ
|
SetLayoutData(ds.Tables[0]);
|
|
//部屋状態・属性
|
SetRoomData(ds.Tables[1]);
|
|
//部屋の利用データ
|
SetUseData(ds.Tables[2]);
|
|
//レイアウト
|
if (tabChanged) { SetRoomCell(ds.Tables[3]); }
|
}
|
|
/// <summary>
|
/// セルのレイアウト情報取得
|
/// </summary>
|
/// <param name="table"></param>
|
private void SetRoomCell(DataTable table)
|
{
|
List<RoomCell> list;
|
if (CellsBuffer.TryGetValue(ActiveTabIndex, out list))
|
{
|
Cells = list;
|
return;
|
}
|
|
list = new List<RoomCell>();
|
foreach (DataRow row in table.Rows)
|
{
|
RoomCell item = new RoomCell();
|
item.ConvertDataRow(row);
|
list.Add(item);
|
}
|
CellsBuffer[ActiveTabIndex] = list;
|
Cells = list;
|
}
|
|
/// <summary>
|
/// Tabの情報
|
/// </summary>
|
/// <param name="table"></param>
|
private void SetTabs(DataTable table)
|
{
|
Tabs.Clear();
|
foreach (DataRow row in table.Rows)
|
{
|
RoomViewTab item = new RoomViewTab();
|
item.ConvertDataRow(row);
|
Tabs.Add(item);
|
}
|
}
|
|
/// <summary>
|
/// レイアウトデータ
|
/// </summary>
|
/// <param name="table"></param>
|
private void SetLayoutData(DataTable table)
|
{
|
List<RoomViewLayout> rowData = new List<RoomViewLayout>();
|
foreach (DataRow row in table.Rows)
|
{
|
RoomViewLayout item = new RoomViewLayout();
|
item.Read(row);
|
|
if (item.Row > RowCount) { RowCount = item.Row; }
|
if (item.Col > ColCount) { ColCount = item.Col; }
|
if (item.Col == 1)
|
{
|
//改行
|
rowData = new List<RoomViewLayout>();
|
Data.Add(rowData);
|
}
|
|
//行毎の各列
|
rowData.Add(item);
|
}
|
}
|
|
/// <summary>
|
/// 部屋状態・属性
|
/// </summary>
|
/// <param name="table"></param>
|
private void SetRoomData(DataTable table)
|
{
|
foreach (DataRow row in table.Rows)
|
{
|
RoomViewAtt room = new RoomViewAtt();
|
room.Read(row);
|
RoomData.Add(room.RoomID, room);
|
}
|
}
|
|
/// <summary>
|
/// 部屋の利用データ
|
/// </summary>
|
/// <param name="table"></param>
|
private void SetUseData(DataTable table)
|
{
|
foreach (DataRow row in table.Rows)
|
{
|
RoomViewUse use = new RoomViewUse();
|
use.Read(row);
|
|
SortedDictionary<string, RoomViewUse> dict;
|
if (!UseData.TryGetValue(use.RoomID, out dict))
|
{
|
dict = new SortedDictionary<string, RoomViewUse>();
|
UseData.Add(use.RoomID, dict);
|
}
|
|
dict.Add(use.SortKey, use);
|
}
|
}
|
|
/// <summary>
|
/// セルのアイテム毎の表示文言
|
/// </summary>
|
/// <param name="roomCell"></param>
|
/// <param name="roomID"></param>
|
/// <returns></returns>
|
public string GetText(Data.Master.RoomCell roomCell, int roomID)
|
{
|
try
|
{
|
if (roomCell.ID == 0) { return roomCell.Content; }
|
else if (roomCell.ID == 1) { return roomID.ToString(); }
|
else if (roomCell.ID == 9) { return RoomData.ContainsKey(roomID) ? RoomData[roomID].RoomName : string.Empty; }
|
else
|
{
|
return UseData.ContainsKey(roomID) ? UseData[roomID].FirstOrDefault().Value.UseData[$"F{roomCell.ID}"] : string.Empty;
|
}
|
}
|
catch
|
{
|
return $"error:{roomCell.ID}";
|
}
|
}
|
|
/// <summary>
|
/// セル色
|
/// </summary>
|
/// <param name="item"></param>
|
/// <returns></returns>
|
public string GetCellColor(Data.Master.RoomViewLayout item)
|
{
|
int roomID = item.RoomID;
|
StringBuilder text = new StringBuilder();
|
//優先順位:部屋状態>利用状態>固定色
|
string backColor = item.BackColor, foreColor = item.ForeColor;
|
if (roomID > 0)
|
{
|
int maidType = RoomData.ContainsKey(roomID) ? RoomData[roomID].MaidType : 0;
|
if (maidType > 0)
|
{
|
foreColor = RoomData[roomID].ForeColor;
|
backColor = RoomData[roomID].BackColor;
|
}
|
else if (UseData.ContainsKey(roomID))
|
{
|
var use = UseData[roomID].FirstOrDefault().Value;
|
foreColor = use.ForeColor;
|
backColor = use.BackColor;
|
}
|
}
|
text.Append($"color:{CConvert.ToHtmlColor(foreColor)};");
|
text.Append($"background:{CConvert.ToHtmlColor(backColor)};");
|
return text.ToString();
|
}
|
|
/// <summary>
|
/// セルのアイテム毎のスタイル
|
/// </summary>
|
/// <param name="roomCell"></param>
|
/// <returns></returns>
|
public string GetRoomCellStyle(Data.Master.RoomCell roomCell)
|
{
|
StringBuilder text = new StringBuilder();
|
text.Append("position: absolute;");
|
text.Append($"left: {roomCell.Left}px;");
|
text.Append($"top: {roomCell.Top}px;");
|
text.Append($"width:{roomCell.Width}px;");
|
text.Append($"height:{roomCell.Heigh}px;");
|
text.Append($"font-family:{roomCell.FontName};");
|
text.Append($"font-size:{roomCell.FontSize}pt;");
|
if (roomCell.FontItalic) { text.Append("font-style:italic;"); }
|
if (roomCell.FontBold) { text.Append("font-weight:bold;"); }
|
string backColor = roomCell.BackColor, foreColor = roomCell.ForeColor;
|
text.Append($"color:{CConvert.ToHtmlColor(foreColor)};");
|
if (!CConvert.IsTransparent(backColor)) { text.Append($"background:{CConvert.ToHtmlColor(backColor)};"); }
|
|
if(roomCell.FontUnderline)
|
{
|
text.Append("text-decoration: underline;");
|
text.Append("text-underline-offset: 0.2em;");
|
}
|
|
return text.ToString();
|
}
|
|
/// <summary>
|
/// セルの文字寄せ
|
/// </summary>
|
/// <param name="roomCell"></param>
|
/// <returns></returns>
|
public Align ToTextAlignCSS(Data.Master.RoomCell roomCell)
|
{
|
//TopLeft = 1,
|
//TopCenter = 2,
|
//TopRight = 4,
|
//MiddleLeft = 16,
|
//MiddleCenter = 32,
|
//MiddleRight = 64,
|
//BottomLeft = 256,
|
//BottomCenter = 512,
|
//BottomRight = 1024,
|
|
if (roomCell.TextAlign == 1 || roomCell.TextAlign == 16 || roomCell.TextAlign == 256)
|
{
|
return Align.Left;
|
}
|
else if (roomCell.TextAlign == 4 || roomCell.TextAlign == 64 || roomCell.TextAlign == 1024)
|
{
|
return Align.Right;
|
}
|
else
|
{
|
return Align.Center;
|
}
|
}
|
}
|
}
|