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.Share/Util/ScriptCreator.cs |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 165 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Share/Util/ScriptCreator.cs b/HotelPms.Share/Util/ScriptCreator.cs
new file mode 100644
index 0000000..c1dd97d
--- /dev/null
+++ b/HotelPms.Share/Util/ScriptCreator.cs
@@ -0,0 +1,165 @@
+using HotelPms.Share.Data;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HotelPms.Share.Util
+{
+    /// <summary>
+    /// ソースコード自動作成
+    /// </summary>
+    public static class ScriptCreator
+    {
+        /// <summary>
+        ///   クラス名でCreateInstance
+        /// </summary>
+        /// <param name="hoObj">hoObj</param>
+        /// <returns>string</returns>
+        public static object ClassForName(string codeBase, string hsClsName)
+        {
+            System.Reflection.Assembly woAssem = null;
+            Type woType = null;
+            try
+            {
+                woAssem = System.Reflection.Assembly.Load(codeBase);
+                woType = woAssem.GetType(hsClsName);
+                return Activator.CreateInstance(woType);
+            }
+            catch(Exception ex)
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        ///   クラス名でCreateInstance
+        /// </summary>
+        /// <param name="hoObj">hoObj</param>
+        /// <returns>string</returns>
+        public static object ClassForName(string hsClsName)
+        {
+            return ClassForName(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, hsClsName);
+        }
+
+        /// <summary>
+        /// クラス ⇒ テキストボックス
+        /// </summary>
+        /// <param name="codeBase"></param>
+        /// <param name="className"></param>
+        /// <returns></returns>
+        public static string GetClassToTextBox(string codeBase, string className)
+        {
+            StringBuilder sb = new StringBuilder();
+            object item = ClassForName(codeBase, className);
+            Type type = item.GetType();
+            PropertyInfo[] infos = type.GetProperties();
+            foreach (PropertyInfo field in infos)
+            {
+                string name = field.Name;
+                if (field.PropertyType.FullName.Contains("System.Collections.Generic.List")) { continue; }
+                if (field.PropertyType.FullName.Contains("System.Data.DataSet")) { continue; }
+                if (field.PropertyType.FullName.Contains("System.Object")) { continue; }
+
+                if ("System.Boolean".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = item.{name} ? \"1\" : \"0\";");
+                }
+                else if ("System.Decimal".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = item.{name}.ToString();");
+                }
+                else if ("System.Int32".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = item.{name}.ToString();");
+                }
+                else if ("System.String".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = item.{name};");
+                }
+                else if ("System.DateTime".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = CConvert.ToDateString(item.{name});");
+                }
+                else if ("customTypes.Date".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = CConvert.ToDateString(item.{name}.ToDateTime());");
+                }
+                else if ("customTypes.DecimalValue".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = item.{name}.ToText();");
+                }
+                else if ("Google.Protobuf.WellKnownTypes.Timestamp".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"txt{name}.Text = CConvert.ToDateString(item.{name}.ToDateTime());");
+                }
+                else
+                {
+                    continue;
+                }
+            }
+            return sb.ToString();
+        }
+
+        /// <summary>
+        /// テキストボックス⇒クラス
+        /// </summary>
+        /// <param name="codeBase">Projectの名称:例えば Forms、Lib</param>
+        /// <param name="className"></param>
+        /// <returns></returns>
+        public static string GetTextBoxToClass(string codeBase, string className)
+        {
+            StringBuilder sb = new StringBuilder();
+            object item = ClassForName(codeBase, className);
+            Type type = item.GetType();
+            PropertyInfo[] infos = type.GetProperties();
+            foreach(PropertyInfo field in infos)
+            {
+                string name = field.Name;
+                if (field.PropertyType.FullName.Contains("System.Collections.Generic.List")) { continue; }
+                if (field.PropertyType.FullName.Contains("System.Data.DataSet")) { continue; }
+                if (field.PropertyType.FullName.Contains("System.Object")) { continue; }
+
+                if ("System.Boolean".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToBool(txt{name}.Text);");
+                }
+                else if ("System.Decimal".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToDecimal(txt{name}.Text);");
+                }
+                else if ("System.Int32".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToInt(txt{name}.Text);");
+                }
+                else if ("System.String".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = txt{name}.Text;");
+                }
+                else if ("System.DateTime".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToDateTime(txt{name}.Text);");
+                }
+                else if ("customTypes.Date".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = new Date(CConvert.ToDateInt(txt{name}.Text));");
+                }
+                else if ("customTypes.DecimalValue".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToDecimal(txt{name}.Text);");
+                }
+                else if ("Google.Protobuf.WellKnownTypes.Timestamp".Equals(field.PropertyType.FullName))
+                {
+                    sb.AppendLine($"item.{name} = CConvert.ToTimestamp(CConvert.ToDateTime(txt{name}.Text));");
+                }
+                else
+                {
+                    continue;
+                }
+            }
+            return sb.ToString();
+        }
+    }
+}

--
Gitblit v1.10.0