huangxiaoqiang
2025-04-21 2a20cd300ab6d9233a708a0f4558ba3d92c9f0a2
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Utilities/EntityProperties.cs
@@ -147,6 +147,58 @@
        /// <param name="removeNotContains">移除不存在字段</param>
        /// <param name="removerKey">移除主键</param>
        /// <returns></returns>
        //public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null)
        //{
        //    if (dic == null || dic.Count == 0) { return "参数无效"; }
        //    // 不存在的字段直接移除
        //    dic.Where(x => !propertyInfo.Any(p => p.Name.ToUpper() == x.Key.ToUpper())).Select(s => s.Key).ToList().ForEach(f =>
        //    {
        //        dic.Remove(f);
        //    });
        //    string keyName = typeinfo.GetKeyName();
        //    //移除主键
        //    if (removerKey)
        //        dic.Remove(keyName);
        //    //else
        //    //{
        //    //    if (!dic.ContainsKey(keyName))
        //    //        return "请传入主键参数";
        //    //}
        //    foreach (PropertyInfo property in propertyInfo)
        //    {
        //        SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>();
        //        if (sugarColumn == null)
        //            return "请配置SugarColumn属性";
        //        //忽略与主键的字段不做验证
        //        if (property.Name.ToUpper() == keyName.ToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore)
        //            continue;
        //        //不在编辑中的列,是否也要必填
        //        if (!dic.ContainsKey(property.Name.ToUpper()))
        //        {
        //            if (!sugarColumn.IsNullable)
        //            {
        //                if (sugarColumn.DefaultValue == null)
        //                    return sugarColumn.ColumnDescription + "为必须提交项";
        //                continue;
        //            }
        //            continue;
        //        }
        //        if(dic[property.Name.ToUpper()] != null)
        //        {
        //            string str = dic[property.Name.ToUpper()].ToString();
        //            //将所有空值设置为null
        //            if (str == string.Empty)
        //                dic[property.Name.ToUpper()] = null;
        //        }
        //    }
        //    return string.Empty;
        //}
        public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null)
        {
            if (dic == null || dic.Count == 0) { return "参数无效"; }
@@ -187,14 +239,14 @@
                    }
                    continue;
                }
                if(dic[property.Name.FirstLetterToLower()] != null)
                if (dic[property.Name.FirstLetterToLower()] != null)
                {
                    string str = dic[property.Name.FirstLetterToLower()].ToString();
                    //将所有空值设置为null
                    if (str == string.Empty)
                        dic[property.Name.FirstLetterToLower()] = null;
                }
            }
            return string.Empty;
        }