Ejemplo n.º 1
0
 public static List <SimpleParameter> GetSim(T t)
 {
     PropertyInfo[] props = null;
     try
     {
         Type   type = typeof(T);
         object obj  = Activator.CreateInstance(type);
         props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
         List <SimpleParameter> list = new List <SimpleParameter>();
         foreach (PropertyInfo item in props)
         {
             if (!item.IsSpecialName)
             {
                 if (item.GetValue(t, null) != null)
                 {
                     SimpleParameter s = new SimpleParameter();
                     s.Name  = item.Name;
                     s.Value = item.GetValue(t, null);
                     list.Add(s);
                 }
             }
         }
         return(list);
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public static T SelectSingle(string tableName, string fields, SimpleParameter queryParams)
        {
            List <SimpleParameter> list = new List <SimpleParameter>();

            list.Add(queryParams);
            List <T> result = Select(tableName, fields, list, 1);

            if (result != null && result.Count > 0)
            {
                return(result[0]);
            }
            return(default(T));
        }
Ejemplo n.º 3
0
        public static List <T> Select(string tableName, string fields, SimpleParameter queryParams, int topNum = -1)
        {
            List <T> result;
            string   whereStr = " where 1=1 ";

            if (queryParams != null)
            {
                if (!string.IsNullOrEmpty(queryParams.Sql))
                {
                    whereStr += queryParams.Sql;
                }
                else
                {
                    whereStr += string.Format(" and {0}=@{1}", queryParams.Name, queryParams.Name);
                }
            }
            string topStr = " top {0}";

            if (topNum <= 0)
            {
                topStr = "";
            }
            else
            {
                topStr = string.Format(topStr, topNum);
            }

            string     sql     = string.Format("select {2} {0} from {1} {3}", fields, tableName, topStr, whereStr);
            IDbCommand command = Context().Sql(sql);

            if (queryParams != null)
            {
                if (string.IsNullOrEmpty(queryParams.Sql))
                {
                    command.Parameter(queryParams.Name, queryParams.Value);
                }
            }
            result = command.Query <T>();
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// count(*)语句
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="queryParams"></param>
        /// <param name="fileds">count(*)或者指定int列</param>
        /// <returns></returns>
        public static int SelectExecute(string tableName, string fileds, SimpleParameter queryParams)
        {
            string whereStr = "";

            if (queryParams != null)
            {
                if (!string.IsNullOrEmpty(queryParams.Sql))
                {
                    whereStr = string.Format(" where {0}=@{0} ", queryParams.Name);
                }
                else
                {
                    whereStr = queryParams.Sql;
                }
            }
            string     sql     = string.Format("select {2} from {1} {0}", whereStr, tableName, fileds);
            IDbCommand command = Context().Sql(sql);

            if (queryParams != null && !string.IsNullOrEmpty(queryParams.Sql))
            {
                command.Parameters(queryParams.Name, queryParams.Value);
            }
            return(command.QueryValue <int>());
        }
Ejemplo n.º 5
0
 public static int SelectExecute(string tableName, SimpleParameter queryParams)
 {
     return(SelectExecute(tableName, "count(*)", queryParams));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 更新单项
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="queryParme">queryParme.Name更新的列,queryParme.Value值,queryParme.Sql条件</param>
        /// <returns></returns>
        public static int Update(string tableName, SimpleParameter queryParme)
        {
            string sql = string.Format("update {0} set {1}={2} where {3}", tableName, queryParme.Name, queryParme.Value, queryParme.Sql);

            return(Context().Sql(sql).Execute());
        }