Beispiel #1
0
        public static void Query <T>(string name)
        {
            //select * from admin
            String sql = $"select * from {typeof(T).Name} where {typeof(T).GetProperty(name)} like '{name}'";

            Sqlhelp.Query(sql);
        }
Beispiel #2
0
        public static DataTable Query <T>(int id)
        {
            //select * from admin
            String sql = $"select * from {typeof(T).Name} where {typeof(T).GetProperty(id.ToString())} = '{id}'";

            return(Sqlhelp.Query(sql, null));
        }
Beispiel #3
0
        public static DataTable Query <T>()
        {
            //select * from admin
            String sql = $"select * from {typeof(T).Name}";

            return(Sqlhelp.Query(sql, null));
        }
Beispiel #4
0
        public static int Add <T>(T t)
        {
            //String sql = $"insert into {typeof(T).Name} values";
            //for(int i = 0; i < typeof(T).GetProperties().Length ;i++)
            //{
            //    sql+=($" '{typeof(T).GetProperties()[i].GetValue(t,null)}',");
            //}

            //sql.Remove(sql.Length-1);
            //sql += ")";
            //Sqlhelp.AnModel(sql);
            String sql = $"insert into {typeof(T).Name} values(";

            foreach (var a in typeof(T).GetProperties())
            {
                sql += $"@{a.Name},";
            }

            sql.Remove(sql.Length - 1);
            sql += ")";
            SqlParameter[] param = new SqlParameter[typeof(T).GetProperties().Length - 1];
            for (int i = 0; i < typeof(T).GetProperties().Length; i++)
            {
                param[i] = new SqlParameter($"{typeof(T).GetProperties()[i].Name}",
                                            typeof(T).GetProperties()[i].GetValue(t, null));
            }
            return(Sqlhelp.AnModel(sql, param));
        }
Beispiel #5
0
        public static void Update <T>(int id, T t)
        {
            //UPDATE   Customers SET cust_email = ' [email protected]' WHERE cust_id = '10000005';
            String sql = $"update {typeof(T).Name} set ";

            foreach (var item in typeof(T).GetProperties())
            {
                sql += $"{item.Name}={item.GetValue(t, null)},";
            }

            sql.Remove(sql.Length - 1);
            sql += "where id=" + id + "";
            Sqlhelp.AnModel(sql);
        }
Beispiel #6
0
        public static void Query <T>(bool l)
        {
            string sql = "";

            //select * from admin
            if (l)
            {
                sql = $"select * from {typeof(T).Name} order by updatetime";
                Sqlhelp.Query(sql);
            }
            else
            {
                sql = $"select * from {typeof(T).Name} order by updatetime desc";
            }
            Sqlhelp.Query(sql);
        }
Beispiel #7
0
        public static int Del <T>(int id)
        {
            ////delete from testss.dbo.test1 where id='12';
            //String sql = $"delete from {typeof(T).Name} where";
            //for (int i = 0; i < typeof(T).GetProperties().Length; i++)
            //{
            //    if (typeof(T).GetProperties()[i].GetValue(t, null) != null)
            //        sql += ($"{typeof(T).GetProperties()[i].Name} = '{typeof(T).GetProperties()[i].GetValue(t, null)}',");
            //    continue;
            //}
            //sql.Remove(sql.Length - 1);
            //sql += ")";
            //Sqlhelp.AnModel(sql);
            string sql = $"delete from {typeof(T).Name} where {typeof(T).GetProperties()[0].Name}=@{typeof(T).GetProperties()[0].Name}";

            SqlParameter[] param =
            {
                new SqlParameter($"@{typeof(T).GetProperties()[0].Name}", id)
            };
            return(Sqlhelp.AnModel(sql, param));
        }