Пример #1
0
        public static DataTable GetUserOnline()
        {
            string sql = "select * from userinfo where login_state=1";

            DataTable dt = MysqlTool.ExecuteDataTable(sql);

            return(dt);
        }
Пример #2
0
        public static DataTable GetUser(string username)
        {
            string sql = "select * from userinfo where username=@username";

            MySqlParameter[] param = new MySqlParameter[1];
            param[0] = new MySqlParameter("username", username);

            DataTable dt = MysqlTool.ExecuteDataTable(sql, param);

            return(dt);
        }
Пример #3
0
        private static bool IsExist <T>(Expression <Func <T, bool> > expression, MySqlParameter[] param) where T : UserInfoModel
        {
            string where = ExpressionTransform.DealExpress(expression);
            string sql = $"select count(1) from userinfo where {where}";
            var    dt  = MysqlTool.ExecuteDataTable(sql, param);

            if (dt != null && dt.Rows.Count > 0)
            {
                var total = int.Parse(dt.Rows[0][0].ToString());
                if (total > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
        public static UserInfoModel GetModel(int id)
        {
            string sql = "select * from userinfo where id=@id";

            MySqlParameter[] param = new MySqlParameter[1];
            param[0] = new MySqlParameter("id", id);

            DataTable dt = MysqlTool.ExecuteDataTable(sql, param);

            if (dt != null && dt.Rows.Count > 0)
            {
                var dataJson = JsonConvert.SerializeObject(dt);
                var model    = JsonConvert.DeserializeObject <List <UserInfoModel> >(dataJson);
                return(model[0]);
            }
            return(null);
        }
Пример #5
0
        public static UserInfoModel GetModel(string username, string pass)
        {
            string sql = "select * from userinfo where username=@username and userpass=@pass";

            MySqlParameter[] param = new MySqlParameter[2];
            param[0] = new MySqlParameter("username", username);
            param[1] = new MySqlParameter("pass", pass.Replace(" ", "+"));

            DataTable dt = MysqlTool.ExecuteDataTable(sql, param);

            if (dt != null && dt.Rows.Count > 0)
            {
                var dataJson = JsonConvert.SerializeObject(dt);
                var model    = JsonConvert.DeserializeObject <List <UserInfoModel> >(dataJson);
                return(model[0]);
            }
            return(null);
        }