using Grpc.Net.Client;
using HotelPms.Data.Client;
using HotelPms.Data.Common;
using HotelPms.DataAccessGrpc.Client;
using HotelPms.Share.Util;
namespace HotelPms.Client.Blazor.Util
{
public class EnvironmentSetting
{
///
/// どこでも取得できるように
///
public static IServiceCollection ServiceCollection { get; set; }
public static IServiceProvider ServiceProvider { get; set; }
///
/// どこでも取得できるように
///
public static GrpcChannel GrpcChannel { get; set; }
///
/// 端末ID
///
public static string ClientID = string.Empty;
///
/// マスタ設定一覧の頁毎表示行設定
///
public static int[] CountOfPage = new int[] { 5, 10, 50, 100, 999999 };
///
/// マスタ設定一覧画面の操作列幅
///
public const int MasterOpeColWidth = 250;
///
/// マスタ設定一覧画面の操作列幅のCSS
///
///
public static string GetOpeColWidthCss()
{
return GetWidthCss(MasterOpeColWidth);
}
///
/// 幅CSSの取得
///
///
///
public static string GetWidthCss(int width)
{
return $"width: {width}px;";
}
///
/// データ設定関係のUserName
///
public static string UserName { get; set; } = "Web";
///
/// バックグラウンドのイメージ
///
public static string BackgroundImage { get; set; } = "/bg1.jpg";
///
/// gRPCのroot URL
///
public static string BackendUrl { get; set; } = string.Empty;
///
/// gRPCのサブDir
///
public static string SubDir { get; set; } = string.Empty;
///
/// サイトのサブPath
/// 例:「/pms/」後ろに「/」が必要
/// index.htmlのと一致するもの
///
public static string SiteSubDir { get; set; } = string.Empty;
public static bool IsDevelopment { get; set; } = false;
///
/// appsettings.jsonを読む
///
///
public static void Init(IConfiguration config)
{
ClientID = Guid.NewGuid().ToString();
BackendUrl = CConvert.ToString(config["BackendUrl"]);
SubDir = CConvert.ToString(config["SubDir"]);
SiteSubDir = CConvert.ToString(config["SiteSubDir"]);
EnvironmentSetting.Debug($"ClientID={ClientID},BackendUrl={BackendUrl},SubDir={SubDir},SiteSubDir={SiteSubDir}");
}
///
/// ホテル日取得
///
///
///
public static async Task GetHotelDate()
{
using HotelAccess access = new DataAccessGrpc.Client.HotelAccess(GrpcChannel);
return await access.GetHotelDate();
}
///
/// 採番
///
///
///
public static async Task GetSeq(ESeqType type)
{
Data.GrpcTable table = await GrpcClient.GetTableAsync(GrpcChannel, (int)ETableActionType.Sequence, ((int)type).ToString());
return CConvert.ToInt(table.GetValue(typeof(System.Int32)));
}
///
/// 消費税率の取得
///
/// 利用日
/// 0.消費税 1.軽減税
///
public static async Task GetTaxRate(string date, int type)
{
Data.GrpcTable table = await GrpcClient.GetTableAsync(GrpcChannel, (int)ETableActionType.TaxRate, $"{date},{type}");
return CConvert.ToInt(table.GetValue(typeof(System.Int32)));
}
///
/// システム全体ログON/OFF制御
///
///
public static void Debug(string text)
{
if(!IsDevelopment) { return; }
Console.WriteLine($"【{DateTime.Now.ToString("HH:mm:ss fff")}】{text}");
}
}
}