Esempio n. 1
0
        public override string DbConditionSqlBuilder(List <DBMemberEntity> entities)
        {
            StringBuilder sb = new StringBuilder();

            if (entities == null || entities.Count == 0)
            {
                return(null);
            }
            sb.Append(" where ");
            for (int i = 0; i < entities.Count; i++)
            {
                DBMemberEntity entity = entities[i];
                if (!string.IsNullOrEmpty(entity.MemberBelong))
                {
                    sb.Append(entity.MemberBelong);
                    sb.Append(".");
                }
                sb.Append(entity.MemberName);

                switch (entity.QueryType)
                {
                case QueryTypeEnum.equal:
                    sb.Append("=");
                    break;

                case QueryTypeEnum.lt:
                    sb.Append("<");
                    break;

                case QueryTypeEnum.grant:
                    sb.Append(">");
                    break;

                case QueryTypeEnum.fruzz:
                    sb.Append(" like ");
                    break;

                case QueryTypeEnum.notequal:
                    sb.Append(" <> ");
                    break;

                default:
                    break;
                }

                sb.Append("@");
                sb.Append(entity.MemberName);
                if (entity.QueryType == QueryTypeEnum.fruzz)
                {
                    entity.MemberValue = string.Format("%{0}%", entity.MemberValue);
                }

                if (i < entities.Count - 1)
                {
                    sb.Append(" and ");
                }
            }
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 获得不为空的实体信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <DBMemberEntity> GetEntityInfo <T>(T model) where T : new()
        {
            List <DBMemberEntity> entitylist = new List <DBMemberEntity>();

            PropertyInfo[] piinfo = typeof(T).GetProperties();
            foreach (PropertyInfo pi in piinfo)
            {
                if (pi.GetValue(model) == null)
                {
                    continue;
                }
                if (typeof(List <>).Name == pi.PropertyType.Name)
                {
                    continue;
                }

                DBMemberEntity entity = new DBMemberEntity();
                entity.MemberName  = pi.Name;
                entity.MemberValue = pi.GetValue(model);

                //Int32 置空
                if (pi.GetType() == typeof(System.Int32))
                {
                    entity.MemberType = DbType.Int32;
                    if (Convert.ToInt32(entity.MemberValue) == Int32.MinValue)
                    {
                        entity.MemberValue = DBNull.Value;
                    }
                }

                //Decimal 置空
                if (pi.GetType() == typeof(System.Decimal))
                {
                    entity.MemberType = DbType.Decimal;
                    if (Convert.ToDecimal(entity.MemberValue) == Decimal.MinValue)
                    {
                        entity.MemberValue = DBNull.Value;
                    }
                }

                //Datetime 置空
                if (pi.GetType() == typeof(System.DateTime))
                {
                    entity.MemberType = DbType.DateTime;
                    if (Convert.ToDateTime(entity.MemberValue) == DateTime.MinValue)
                    {
                        entity.MemberValue = DBNull.Value;
                    }
                }

                entitylist.Add(entity);
            }

            return(entitylist);
        }
Esempio n. 3
0
        /// <summary>
        /// 添加对象
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="MemberName">成员名称</param>
        /// <param name="MemberValue">成员值</param>
        /// <param name="MemberBelong">成员所属表 t,a,b等</param>
        /// <param name="MemberType">成员数据对象</param>
        /// <param name="qte">成员条件类型</param>
        public static void AddMember(this List <DBMemberEntity> entities, string MemberName, object MemberValue, QueryTypeEnum qte = QueryTypeEnum.equal, string MemberBelong = null, DbType MemberType = DbType.String)
        {
            DBMemberEntity entity = new DBMemberEntity()
            {
                MemberName   = MemberName,
                MemberType   = MemberType,
                MemberValue  = MemberValue,
                QueryType    = qte,
                MemberBelong = MemberBelong
            };

            entities.Add(entity);
        }