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/RoomTypeAccess.cs |  272 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 272 insertions(+), 0 deletions(-)

diff --git a/HotelPms.DataAccessGrpc.Client/RoomTypeAccess.cs b/HotelPms.DataAccessGrpc.Client/RoomTypeAccess.cs
new file mode 100644
index 0000000..3572853
--- /dev/null
+++ b/HotelPms.DataAccessGrpc.Client/RoomTypeAccess.cs
@@ -0,0 +1,272 @@
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Net.Client;
+using HotelPms.Data.Client;
+using HotelPms.Data.Common;
+using HotelPms.Data.Master;
+using HotelPms.Share.Util;
+using System;
+using System.Data;
+using System.Threading.Tasks;
+using HotelPms.Data;
+using System.Collections.Generic;
+using HotelPms.Data.Common.Pagination;
+using System.Text.Json;
+using System.Threading;
+
+namespace HotelPms.DataAccessGrpc.Client;
+
+public class RoomTypeAccess : IDisposable
+{
+    /// <summary>
+    /// チャネル
+    /// </summary>
+    public GrpcChannel Channel { get; private set; } = null;
+    public RoomTypeCore.RoomTypeCoreClient Client { get; private set; } = null;
+
+
+    public RoomTypeAccess(GrpcChannel channel)
+    {
+        Channel = channel;
+        Client = new RoomTypeCore.RoomTypeCoreClient(Channel);
+    }
+
+    public void Dispose()
+    {
+            
+    }
+
+    public bool Exists(int pID)
+    {
+        return GrpcClient.ExecuteScalarSync(Channel, $"IF EXISTS(SELECT 1 FROM M_RoomType WHERE ID = {pID}) SELECT 1 ELSE SELECT 0") == "1";
+
+    }
+
+    public async Task<bool> ExistsAsync(int pID)
+    {
+        return await GrpcClient.ExecuteScalar(Channel, $"IF EXISTS(SELECT 1 FROM M_RoomType WHERE ID = {pID}) SELECT 1 ELSE SELECT 0") == "1";
+
+    }
+
+    public async Task<FileGrpcData> OutputStream(PagingRequest request)
+    {
+        FileGrpcData data = null;
+        request.Table = "M_RoomType";
+        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<RoomTypeTable> GetPageData(PagingRequest request)
+    {
+        request.Table = "M_RoomType";
+        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.BuildingMasterGrid, where);
+        return table.ToDataTable();
+    }
+
+    /// <summary>
+    /// 同期データ取得
+    /// </summary>
+    /// <param name="where"></param>
+    /// <returns></returns>
+    public RoomTypeTable GetData(string where)
+    {
+        return Client.GetData(GrpcClient.CreateDataRequest(0, where));
+    }
+
+    public async Task<RoomTypeTable> GetDataAsync(string where)
+    {
+        return await Client.GetDataAsync(GrpcClient.CreateDataRequest(0, where));
+    }
+
+    /// <summary>
+    /// データ取得
+    /// </summary>
+    /// <returns></returns>
+    public RoomType GetItem(int pID)
+    {
+        RoomTypeTable table = GetData($"ID = {pID}");
+        if(table == null || table.ErrNo != 0 || table.Rows.Count == 0) { return null; }
+        return table.Rows[0];
+    }
+
+    public async Task<RoomTypeTable> GetDataStream()
+    {
+        return await GetDataStream(string.Empty);
+    }
+
+    /// <summary>
+    /// データ取得
+    /// </summary>
+    /// <returns></returns>
+    public async Task<RoomTypeTable> GetDataStream(string where)
+    {
+        RoomTypeTable 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<RoomTypeTable>())
+            {
+                table = message;
+                break;
+            }
+        }
+        return table;
+    }
+
+    public async Task<DataResult> AddAsync(RoomType data)
+    {
+        return await Client.AddAsync(data);
+    }
+
+    public DataResult Add(RoomType data)
+    {
+        return Client.Add(data);
+    }
+
+    public async Task<DataResult> UpdateAsync(RoomType data)
+    {
+        return await Client.UpdateAsync(data);
+    }
+
+    public DataResult Update(RoomType data)
+    {
+        return Client.Update(data);
+    }
+
+    /// <summary>
+    /// 追加若しくは更新
+    /// </summary>
+    /// <param name="data"></param>
+    /// <param name="add"></param>
+    /// <returns></returns>
+    private async Task<DataResult> AddOrUpdateStream(RoomType 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(RoomType data)
+    {
+        return await AddOrUpdateStream(data, true);
+    }
+
+    /// <summary>
+    /// 更新
+    /// </summary>
+    /// <param name="data"></param>
+    /// <returns></returns>
+    public async Task<DataResult> UpdateStream(RoomType 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(RoomTypeTable table)
+    {
+        return Client.SetData(table);
+    }
+
+    /// <summary>
+    /// バッチ更新
+    /// </summary>
+    /// <param name="table"></param>
+    /// <returns></returns>
+    public async Task<DataResult> SetDataStream(RoomTypeTable 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