Exemplo n.º 1
0
        /// <summary>
        /// 用拼接SQL的方式,
        /// 把当前表以及其使用到的所有外键表链接起来,
        /// 拼接成一条SQL子查询,供分页的存储过程使用
        /// </summary>
        private String PreparedTable(T_User entity, bool isFuzzySearch, bool isSignleResult)
        {
            String sql = getFKColumnsSQL("[gdce_task].dbo.T_User", T_User.DBColumns, isFuzzySearch, isSignleResult);


            if (entity == null)
            {
                return(sql);
            }

            if (entity.id != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.id = '{0}' ", AntiInjection(entity.id));
            }

            if (entity.account != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.account = '{0}' ", AntiInjection(entity.account));
            }

            if (entity.roleId != null)
            {
                sql += " and [gdce_task].dbo.T_User.roleId = " + entity.roleId;
            }

            if (entity.name != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.name = '{0}' ", AntiInjection(entity.name));
            }

            if (entity.password != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.password = '******' ", AntiInjection(entity.password));
            }

            if (entity.createTime != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.createTime = '{0}' ", entity.createTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
            }

            if (entity.phone != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.phone = '{0}' ", AntiInjection(entity.phone));
            }

            if (entity.dept != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.dept = '{0}' ", AntiInjection(entity.dept));
            }

            if (entity.descr != null)
            {
                sql += String.Format(" and [gdce_task].dbo.T_User.descr = '{0}' ", AntiInjection(entity.descr));
            }

            if (entity.status != null)
            {
                sql += " and [gdce_task].dbo.T_User.status =  " + (entity.status.Value ? "1" : "0");
            }

            return(AntiInjection(sql));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 以实体类作为查询条件获取符合条件的数据集,NULL值不作为查询条件
        /// </summary>
        public List <T_User> GetAllByModel(T_User entity)
        {
            String sql = String.Format("exec sp_executesql N'{0}'", PreparedTable(entity, false, false));

            return(DtToList(DBHelper.ExecuteDataTable(sql)));
        }