Пример #1
0
        //根据用户Id查询用户信息
        public static Users GetUserById(int id)
        {
            string sql = "select * from Users where Id=" + id;
            int    userStateId;
            int    userRoleId;

            using (SqlDataReader reader = DBHelper.GetReader(sql))
            {
                if (reader.Read())
                {
                    Users us = new Users();
                    us.Id       = (int)reader["Id"];
                    us.LoginId  = (string)reader["LoginId"];
                    us.LoginPwd = (string)reader["LoginPwd"];
                    us.Name     = (string)reader["Name"];
                    us.Address  = (string)reader["Address"];
                    us.Phone    = (string)reader["Phone"];
                    us.Mail     = (string)reader["Mail"];

                    userStateId = (int)reader["UserStateId"];
                    userRoleId  = (int)reader["UserRoleId"];
                    reader.Close();

                    us.UserStates = UserStateService.GetUserStateById(userStateId); //FK
                    us.UserRoles  = UserRoleService.GetUserRoleById(userRoleId);    //FK

                    return(us);
                }
                else
                {
                    reader.Close();
                    return(null);
                }
            }
        }
Пример #2
0
        //查询所有用户
        public static IList <Users> GetUsersAll()
        {
            IList <Users> list  = new List <Users>();
            string        sql   = "select * from Users";
            DataTable     table = DBHelper.GetDataSet(sql);

            foreach (DataRow row in table.Rows)
            {
                Users us = new Users();
                us.Id       = (int)row["Id"];
                us.LoginId  = (string)row["LoginId"];
                us.LoginPwd = (string)row["LoginPwd"];
                us.Name     = (string)row["Name"];
                us.Address  = (string)row["Address"];
                us.Phone    = (string)row["Phone"];
                us.Mail     = (string)row["Mail"];

                us.UserStates = UserStateService.GetUserStateById((int)row["UserStateId"]); //FK
                us.UserRoles  = UserRoleService.GetUserRoleById((int)row["UserRoleId"]);    //FK

                list.Add(us);
            }
            return(list);
        }