From a38b50675f2cf8e813bd337ca2f9d9456cc421d3 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 17 十月 2024 09:50:14 +0800
Subject: [PATCH] WCS

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs |   83 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 1 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
index ab489a0..ab77042 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
@@ -8,6 +8,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Core.Const;
+using WIDESEA_Core.DB.Models;
 using WIDESEA_Core.Helper;
 
 namespace WIDESEA_Core.Utilities
@@ -127,6 +128,19 @@
             return SqlDbTypeName.NVarChar;
         }
 
+        public static string ValidateDicInEntity(this Type typeinfo, List<Dictionary<string, object>> dicList, bool removerKey, string[] ignoreFields = null)
+        {
+            PropertyInfo[] propertyInfo = typeinfo.GetProperties();
+            string reslutMsg = string.Empty;
+            foreach (Dictionary<string, object> dic in dicList)
+            {
+                reslutMsg = typeinfo.ValidateDicInEntity(dic, removerKey, propertyInfo, ignoreFields);
+                if (!string.IsNullOrEmpty(reslutMsg))
+                    return reslutMsg;
+            }
+            return reslutMsg;
+        }
+
         /// <summary>
         /// 鍒ゆ柇hash鐨勫垪鏄惁涓哄搴旂殑瀹炰綋锛屽苟涓斿�兼槸鍚︽湁鏁�
         /// </summary>
@@ -169,7 +183,7 @@
                 {
                     if (!sugarColumn.IsNullable)
                     {
-                        if (sugarColumn.DefaultValue == null)
+                        if (sugarColumn.DefaultValue != null)
                             return sugarColumn.ColumnDescription + "涓哄繀椤绘彁浜ら」";
                         continue;
                     }
@@ -212,5 +226,72 @@
             }
             return null;
         }
+
+        public static Type GetDetailType(this Type typeinfo)
+        {
+            PropertyInfo[] properties = typeinfo.GetProperties();
+            foreach (PropertyInfo property in properties)
+            {
+                Navigate? navigate = property.GetCustomAttribute<Navigate>();
+                if (navigate is not null)
+                {
+                    if (navigate.GetNavigateType() == NavigateType.OneToOne)
+                        return property.PropertyType;
+                    else
+                        return property.PropertyType.GenericTypeArguments[0];
+                }
+            }
+            return null;
+        }
+
+        public static string GetMainIdByDetail(this Type typeinfo)
+        {
+            PropertyInfo[] properties = typeinfo.GetProperties();
+            foreach (PropertyInfo property in properties)
+            {
+                Navigate? navigate = property.GetCustomAttribute<Navigate>();
+                if (navigate is not null)
+                {
+                    return navigate.GetName();
+                }
+            }
+            return null;
+        }
+
+        public static void SetDetailId<T>(this Type typeinfo, T enetiy, object id, string name)
+        {
+            PropertyInfo property = typeinfo.GetProperty(name);
+            if (property != null)
+            {
+                property.SetValue(enetiy, id);
+            }
+        }
+
+        public static PropertyInfo? GetNavigatePro(this Type typeinfo)
+        {
+            PropertyInfo[] properties = typeinfo.GetProperties();
+            foreach (PropertyInfo property in properties)
+            {
+                Navigate? navigate = property.GetCustomAttribute<Navigate>();
+                if (navigate is not null)
+                {
+                    return property;
+                }
+            }
+            return null;
+        }
+
+        public static object GetPropertyValue<T>(this Type typeinfo, T data, string propertyName)
+        {
+            if (typeinfo != typeof(T))
+                return null;
+
+            PropertyInfo? property = typeinfo.GetProperty(propertyName);
+            if (property != null)
+            {
+                return property.GetValue(data);
+            }
+            return null;
+        }
     }
 }

--
Gitblit v1.9.3