Ejemplo n.º 1
0
        public IList <MUser> GetAllUser()
        {
            using (var session = MySQLClientHelper.OpenSession())
            {
                using (var cmd = session.CreateCommand())
                {
                    var list = new List <MUser>();

                    cmd.Connection  = session;
                    cmd.CommandText = "select * from users";
                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Console.WriteLine("id: " + reader.GetInt32("id") + " userName : "******"userName"));
                        var user = new MUser();
                        user.Id       = reader.GetInt32("id");
                        user.UserName = reader.GetString("userName");
                        user.PassWord = reader.GetString("passWord");
                        user.Age      = reader.GetInt32("age");
                        list.Add(user);
                    }


                    session.Close();
                    return(list);
                }
            }
        }
Ejemplo n.º 2
0
        public void SaveUser(MUser user)
        {
            using (var session = MySQLClientHelper.OpenSession())
            {
                using (var cmd = session.CreateCommand())
                {
                    var list = new List <MUser>();

                    cmd.Connection  = session;
                    cmd.CommandText = string.Format("insert into users(id,userName,passWord,age) values ({0},'{1}','{2}',{3})", user.Id, user.UserName, user.PassWord, user.Age);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        Console.WriteLine(" save succeed");
                    }
                    else
                    {
                        Console.WriteLine(" save failed");
                    }

                    session.Close();
                }
            }
        }
Ejemplo n.º 3
0
        public void UpdateUser(MUser user)
        {
            using (var session = MySQLClientHelper.OpenSession())
            {
                using (var cmd = session.CreateCommand())
                {
                    var list = new List <MUser>();

                    cmd.Connection  = session;
                    cmd.CommandText = string.Format("update users set userName = '******', age = {1}, passWord = '******' where id = {3}", user.UserName, user.Age, user.PassWord, user.Id);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        Console.WriteLine(" update succeed");
                    }
                    else
                    {
                        Console.WriteLine(" update failed");
                    }

                    session.Close();
                }
            }
        }
Ejemplo n.º 4
0
        public void DelUser(int id)
        {
            using (var session = MySQLClientHelper.OpenSession())
            {
                using (var cmd = session.CreateCommand())
                {
                    var list = new List <MUser>();

                    cmd.Connection  = session;
                    cmd.CommandText = string.Format("delete from users where id = {0}", id);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        Console.WriteLine(" delete succeed");
                    }
                    else
                    {
                        Console.WriteLine(" delete failed");
                    }

                    session.Close();
                }
            }
        }