Exemplo n.º 1
0
        /// <summary>
        /// 设置编号
        /// </summary>
        /// <param name="item"></param>
        /// <param name="entity"></param>
        /// <param name="DisplayName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool SetNumber(PropertyInfo item, T entity, string DisplayName, object Value)
        {
            var    _TableInfo = TableInfo.Get(entity);
            string TableName  = _TableInfo.TableName;
            //获取有特性标记的属性【编号】
            var sign = ReflexHelper.GetAttribute <CSetNumberAttribute>(entity.GetType(), item.Name);

            if (sign != null)
            {
                //取ID的值
                string KeyValue = string.Empty;
                var    list     = ReflexHelper.GetPropertyInfos(entity.GetType());
                KeyValue = _TableInfo.KeyFieldInfo.Value.ToStr();
                if (string.IsNullOrEmpty(KeyValue) || KeyValue.ToString().Equals(Guid.Empty.ToString()))
                {
                    var MaxNumber = _FindAnalysis.FindMaxNumber(TableName, item.Name, "", null) + 1;

                    if (MaxNumber == 0)
                    {
                        throw new AggregateException("设置编号错误:数据无法查出!");
                    }
                    if (item.PropertyType == typeof(int))
                    {
                        item.SetValue(entity, (MaxNumber.ToString().PadLeft(sign.Length, sign.Str)).ToInt32());
                    }
                    else
                    {
                        item.SetValue(entity, (MaxNumber).ToStr().PadLeft(sign.Length, sign.Str));
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 比较两字段值是否相同
        /// </summary>
        /// <param name="item"></param>
        /// <param name="_Model"></param>
        /// <param name="DisplayName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool CCompare(PropertyInfo item, T _Model, string DisplayName, object Value)
        {
            if (Value == null)
            {
                return(true);
            }
            //获取有特性标记的属性【比较两字段值是否相同】
            var _Attribute = ReflexHelper.GetAttribute <CCompareAttribute>(_Model.GetType(), item.Name);

            if (_Attribute == null)
            {
                return(true);
            }
            var list = ReflexHelper.GetPropertyInfos(_Model.GetType());

            foreach (var info in list)
            {
                var infoname = ReflexHelper.GetAttribute <CCompareAttribute>(_Model.GetType(), info.Name);
                if (info.Name.Equals(_Attribute.OtherProperty) && !info.GetValue(_Model).Equals(Value))
                {
                    return(SetErrorMessage(_Attribute.ErrorMessage, DisplayName + "的值与" + infoname + "不匹配", DisplayName));
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将多个实体组合成为一个 字典类型
        /// </summary>
        /// <param name="di"></param>
        /// <returns></returns>
        public Dictionary <string, object> EntityToDictionary(Dictionary <string, object> di)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            foreach (var item in di)
            {
                if (item.Value is Models.Class.BaseClass)
                {
                    ReflexHelper.GetPropertyInfos(item.Value.GetType()).ToList().ForEach(pi =>
                    {
                        if (pi.GetValue(item.Value, null) == null)
                        {
                            r.Add(pi.Name, null);
                        }
                        else
                        {
                            if (pi.PropertyType == typeof(DateTime))
                            {
                                r.Add(pi.Name, pi.GetValue(item.Value, null).ToDateTimeFormat("yyyy-MM-dd HH:mm:ss"));
                            }
                            else
                            {
                                r.Add(pi.Name, pi.GetValue(item.Value, null));
                            }
                        }
                    });
                }
                else
                {
                    r.Add(item.Key, item.Value);
                }
            }
            return(r);
        }
Exemplo n.º 4
0
 private StringBuilder GetByModel <T>(T Model, StringBuilder sb)
 {
     ReflexHelper.GetPropertyInfos(Model.GetType()).ToList().ForEach(item =>
     {
         sb.Append("this." + item.Name + "=ko.observable('');");
     });
     return(sb);
 }
Exemplo n.º 5
0
        public bool Check(T _Model)
        {
            var list = ReflexHelper.GetPropertyInfos(_Model.GetType());

            foreach (var item in list)
            {
                if (!this.Start(item, _Model))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 验证数据是否重复
        /// </summary>
        /// <param name="item"></param>
        /// <param name="_Model"></param>
        /// <param name="DisplayName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool CRepeat(PropertyInfo item, T _Model, string DisplayName, object Value)
        {
            if (Value == null)
            {
                return(true);
            }
            var    _TableInfo = TableInfo.Get(_Model);
            string TableName  = _TableInfo.TableName;
            //获取有特性标记的属性【非空】
            var _Attribute = ReflexHelper.GetAttribute <CRepeatAttribute>(_Model.GetType(), item.Name);

            if (_Attribute == null)
            {
                return(true);
            }
            //取ID的值
            string KeyValue = string.Empty, KeyName = string.Empty;
            var    list = ReflexHelper.GetPropertyInfos(_Model.GetType());

            KeyValue     = _TableInfo.KeyFieldInfo.Value.ToStr();
            KeyName      = _TableInfo.KeyFieldInfo.FieldName;
            string where = string.Empty;
            if (!string.IsNullOrEmpty(KeyValue) && !KeyValue.ToString().Equals(Guid.Empty.ToString()))
            {
                where = " AND " + KeyName + "<>'" + KeyValue + "'";
            }

            //判断条件,是否存在  || 自定义条件 语法  :and filed1='{filed1}' ||
            if (!string.IsNullOrEmpty(_Attribute.Where))
            {
                foreach (var pi in list)
                {
                    if (_Attribute.Where.Contains("{" + pi.Name + "}"))
                    {
                        where += _Attribute.Where + " ";
                        where  = where.Replace("{" + pi.Name + "}", pi.GetValue(_Model) == null ? "" : pi.GetValue(_Model).ToString());
                    }
                }
            }

            string sql = "SELECT COUNT(1) FROM " + TableName + " WHERE 1=1 AND " + item.Name + "='" + Value + "' " + where;

            if (_DbHelper.QuerySingleOrDefault <int>(sql, null) > 0)
            {
                return(SetErrorMessage(_Attribute.ErrorMessage, DisplayName + "已存在", DisplayName));
            }
            return(true);
        }
Exemplo n.º 7
0
        public override bool EditById <T>(T Set, List <SQL> li)
        {
            var list       = new List <MemberBinding>();
            var fileds     = ReflexHelper.GetPropertyInfos(typeof(T));//.Where(w => w.Name != Set.GetKey().FieldName);
            var _TableInfo = TableInfo.Get(Set);

            foreach (var item in fileds)
            {
                //检测有无忽略字段
                if (_TableInfo.Fields.Where(w => w.IsIgnore == true && w.FieldName == item.Name).FirstOrDefault() != null)
                {
                    continue;
                }
                list.Add(Expression.Bind(item, Expression.Constant(item.GetValue(Set), item.PropertyType)));
            }

            return(ExecuteById <T>(Expression.MemberInit(Expression.New(typeof(T)), list), li));
        }
Exemplo n.º 8
0
        public Sys_PagingEntity NewPagingEntity(Sys_PagingEntity pe, params object[] ArryEntity)
        {
            var dic      = new Dictionary <string, object>();
            var list     = new List <PropertyInfo>();
            var colNames = new List <Dictionary <string, string> >();

            ArryEntity.ToList().ForEach(item =>
            {
                //将所有实体里面的属性放入list中
                ReflexHelper.GetPropertyInfos(item.GetType()).ToList().ForEach(p =>
                {
                    list.Add(p);
                });
            });
            foreach (DataColumn dc in pe.Table.Columns)
            {
                dic = new Dictionary <string, object>();
                var col = new Dictionary <string, string>();
                var pro = list.Find(item => item.Name.Equals(dc.ColumnName));

                dic["field"] = dc.ColumnName;
                dic["align"] = "left";
                if (pro == null)
                {
                    dic["title"]   = dc.ColumnName;
                    dic["visible"] = !dc.ColumnName.Equals("_ukid");
                    col.Add(dc.ColumnName, dc.ColumnName);
                }
                else
                {
                    //获取有特性标记的属性【获取字段别名(中文名称)】
                    var FiledConfig = pro.GetCustomAttribute(typeof(FieldAttribute)) as FieldAttribute;
                    dic["title"]   = (FiledConfig.Alias == "" ? dc.ColumnName : FiledConfig.Alias);
                    dic["visible"] = true;
                    col.Add(dc.ColumnName, dic["title"].ToStr());
                }
                pe.ColNames.Add(col);
                pe.ColModel.Add(dic);
            }

            return(pe);
        }