From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.DataAccessGrpc.Client/HotelAccess.cs |  269 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 269 insertions(+), 0 deletions(-)

diff --git a/HotelPms.DataAccessGrpc.Client/HotelAccess.cs b/HotelPms.DataAccessGrpc.Client/HotelAccess.cs
new file mode 100644
index 0000000..68c663b
--- /dev/null
+++ b/HotelPms.DataAccessGrpc.Client/HotelAccess.cs
@@ -0,0 +1,269 @@
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Net.Client;
+using HotelPms.Data;
+using HotelPms.Data.Client;
+using HotelPms.Data.Common;
+using HotelPms.Data.Common.Pagination;
+using HotelPms.Data.Master;
+using HotelPms.Share.Util;
+using System.Data;
+using System.Text.Json;
+
+namespace HotelPms.DataAccessGrpc.Client
+{
+    public class HotelAccess : IDisposable
+    {
+        /// <summary>
+        /// チャネル
+        /// </summary>
+        public GrpcChannel Channel { get; private set; } = null;
+        public HotelCore.HotelCoreClient Client { get; private set; } = null;
+
+        public HotelAccess(GrpcChannel channel)
+        {
+            Channel = channel;
+            Client = new HotelCore.HotelCoreClient(Channel);
+        }
+
+        public void Dispose()
+        {
+            
+        }
+
+        public async Task<bool> Exists(int pID)
+        {
+            return await GrpcClient.ExecuteScalar(Channel, $"IF EXISTS(SELECT 1 FROM S_Hotel WHERE ID = {pID}) SELECT 1 ELSE SELECT 0") == "1";
+
+        }
+
+        public async Task<FileGrpcData> OutputStream(PagingRequest request)
+        {
+            FileGrpcData data = null;
+            request.Table = "S_Hotel";
+            string json = JsonSerializer.Serialize(request);
+            using (var call = Client.OutputStream(GrpcClient.CreateDataRequest(2, json)))
+            {
+                var reaponseStream = call.ResponseStream;
+                //データの取得
+                while (await reaponseStream.MoveNext(CancellationToken.None))
+                {
+                    data = reaponseStream.Current;
+                }
+            }
+            return data;
+        }
+
+        public async Task<HotelTable> GetPageData(PagingRequest request)
+        {
+            request.Table = "S_Hotel";
+            string json = JsonSerializer.Serialize(request);
+            return await Client.GetDataAsync(GrpcClient.CreateDataRequest(1, json));
+        }
+
+
+        public DataTable GetMasterGridData(string where)
+        {
+            GrpcTable table = GrpcClient.GetTable(Channel, (int)ETableActionType.HotelMasterGrid, where);
+            return table.ToDataTable();
+        }
+
+        public async Task<DateTime> GetHotelDate()
+        {
+            GrpcTable table = await GrpcClient.GetTableAsync(Channel, (int)ETableActionType.HotelDate, string.Empty);
+            DateTime dateTime = CConvert.ToDateTimeFromBytes(table.Rows[0].Data.Span.Slice(0, 8).ToArray());
+            return dateTime;
+        }
+
+        /// <summary>
+        /// 同期データ取得
+        /// </summary>
+        /// <param name="where"></param>
+        /// <returns></returns>
+        public HotelTable GetData(string where)
+        {
+            return Client.GetData(GrpcClient.CreateDataRequest(0, where));
+        }
+
+        public async Task<HotelTable> GetDataAsync(string where)
+        {
+            return await Client.GetDataAsync(GrpcClient.CreateDataRequest(0, where));
+        }
+
+        /// <summary>
+        /// データ取得
+        /// </summary>
+        /// <returns></returns>
+        public Hotel GetItem(int pID)
+        {
+            HotelTable table = GetData($"ID = {pID}");
+            if(table == null || table.ErrNo != 0 || table.Rows.Count == 0) { return null; }
+            return table.Rows[0];
+        }
+
+        public async Task<HotelTable> GetDataStream()
+        {
+            return await GetDataStream(string.Empty);
+        }
+
+        /// <summary>
+        /// データ取得
+        /// </summary>
+        /// <returns></returns>
+        public async Task<HotelTable> GetDataStream(string where)
+        {
+            HotelTable table = null;
+            using (var call = Client.GetDataStream())
+            {
+                await call.RequestStream.WriteAsync(GrpcClient.CreateDataRequest(0, where));
+                await call.RequestStream.CompleteAsync();   // Finish call and report results
+
+                //データの取得
+                await foreach (var message in call.ResponseStream.ReadAllAsync<HotelTable>())
+                {
+                    table = message;
+                    break;
+                }
+            }
+            return table;
+        }
+
+        public async Task<DataResult> AddAsync(Hotel data)
+        {
+            return await Client.AddAsync(data);
+        }
+
+        public DataResult Add(Hotel data)
+        {
+            return Client.Add(data);
+        }
+
+        public async Task<DataResult> UpdateAsync(Hotel data)
+        {
+            return await Client.UpdateAsync(data);
+        }
+
+        public DataResult Update(Hotel data)
+        {
+            return Client.Update(data);
+        }
+
+        /// <summary>
+        /// 追加若しくは更新
+        /// </summary>
+        /// <param name="data"></param>
+        /// <param name="add"></param>
+        /// <returns></returns>
+        private async Task<DataResult> AddOrUpdateStream(Hotel data, bool add)
+        {
+            DataResult result = null;
+            using (var call = add ? Client.AddStream() : Client.UpdateStream())
+            {
+                await call.RequestStream.WriteAsync(data);
+                await call.RequestStream.CompleteAsync();   // Finish call and report results
+
+                //データの取得
+                await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+                {
+                    result = message;
+                    break;
+                }
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 追加
+        /// </summary>
+        /// <param name="data"></param>
+        /// <returns></returns>
+        public async Task<DataResult> AddStream(Hotel data)
+        {
+            return await AddOrUpdateStream(data, true);
+        }
+
+        /// <summary>
+        /// 更新
+        /// </summary>
+        /// <param name="data"></param>
+        /// <returns></returns>
+        public async Task<DataResult> UpdateStream(Hotel data)
+        {
+            return await AddOrUpdateStream(data, true);
+        }
+
+        public DataResult Remove(string where)
+        {
+            SqlWhere data = new SqlWhere()
+            {
+                Data = ByteString.CopyFromUtf8(where)
+            };
+            return Client.Remove(data);
+        }
+
+        public async Task<DataResult> RemoveAsync(string where)
+        {
+            SqlWhere data = new SqlWhere()
+            {
+                Data = ByteString.CopyFromUtf8(where)
+            };
+            return await Client.RemoveAsync(data);
+        }
+
+        /// <summary>
+        /// 削除
+        /// </summary>
+        /// <param name="where"></param>
+        /// <returns></returns>
+        public async Task<DataResult> RemoveStream(string where)
+        {
+            DataResult result = null;
+            SqlWhere data = new SqlWhere()
+            {
+                Data = ByteString.CopyFromUtf8(where)
+            };
+
+            using (var call = Client.RemoveStream())
+            {
+                await call.RequestStream.WriteAsync(data);
+                await call.RequestStream.CompleteAsync();   // Finish call and report results
+
+                //データの取得
+                await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+                {
+                    result = message;
+                    break;
+                }
+            }
+            return result;
+        }
+
+        public DataResult SetData(HotelTable table)
+        {
+            return Client.SetData(table);
+        }
+
+        /// <summary>
+        /// バッチ更新
+        /// </summary>
+        /// <param name="table"></param>
+        /// <returns></returns>
+        public async Task<DataResult> SetDataStream(HotelTable table)
+        {
+            DataResult result = null;
+            using (var call = Client.SetDataStream())
+            {
+                await call.RequestStream.WriteAsync(table);
+                await call.RequestStream.CompleteAsync();   // Finish call and report results
+
+                //データの取得
+                await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+                {
+                    result = message;
+                    break;
+                }
+            }
+            return result;
+        }
+    }
+}

--
Gitblit v1.10.0