Beispiel #1
0
        public static User AddUser(User user)
        {
            if (user.UserState == null)
            {
                user.UserState = UserStateManager.GetDefaultUserState();
            }

            if (user.UserRole == null)
            {
                user.UserRole = UserRoleManager.GetDefaultUserRole();
            }

            return UserService.AddUser(user);
        }
Beispiel #2
0
 /// <summary>
 /// ������û�
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static User AddUser(User user)
 {
     string sql =
         "INSERT Users (LoginId, LoginPwd, Name, Address, Phone, Mail, UserRoleId, UserStateId)" +
         "VALUES (@LoginId, @LoginPwd, @Name, @Address, @Phone, @Mail, @UserRoleId, @UserStateId)";
     sql += " ; SELECT @@IDENTITY";
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@UserStateId", user.UserState.Id),    //FK
         new SqlParameter("@UserRoleId", user.UserRole.Id),      //FK
         new SqlParameter("@LoginId", user.LoginId),
         new SqlParameter("@LoginPwd", user.LoginPwd),
         new SqlParameter("@Name", user.Name),
         new SqlParameter("@Address", user.Address),
         new SqlParameter("@Phone", user.Phone),
         new SqlParameter("@Mail", user.Mail)
     };
     int newId = DBHelper.GetScalar(sql, para);
     return GetUserById(newId);
 }
Beispiel #3
0
        /// <summary>
        /// ��¼
        /// </summary>
        /// <param name="loginId">��¼��</param>
        /// <param name="loginPwd">��¼����</param>
        /// <param name="validUser">����û�</param>
        /// <returns></returns>
        public static bool Login(string loginId, string loginPwd, out User validUser)
        {
            User user = UserService.GetUserByLoginId(loginId);
            if (user == null)
            {
                //�û���������
                validUser = null;
                return false;
            }

            if (user.LoginPwd == loginPwd)
            {
                validUser = user;
                return true;
            }
            else
            {
                //�������
                validUser = null;
                return false;
            }
        }
Beispiel #4
0
 public static void DeleteUser(User user)
 {
     UserService.DeleteUser(user);
 }
Beispiel #5
0
 /// <summary>
 /// ע�����û�
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static bool Register(User user)
 {
     if (LoginIdExists(user.LoginId))
     {
         return false;
     }
     else
     {
         AddUser(user);
         return true;
     }
 }
Beispiel #6
0
 public static void ModifyUser(User user)
 {
     UserService.ModifyUser(user);
 }
Beispiel #7
0
 /// <summary>
 /// ����id��ѯ�����û�
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static User GetUserById(int id)
 {
     string sql = "SELECT * FROM Users WHERE Id = @Id";
     int userStateId;
     int userRoleId;
     using (SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id)))
     {
         if (reader.Read())
         {
             User user = new User();
             user.Id = (int)reader["Id"];
             user.LoginId = (string)reader["LoginId"];
             user.LoginPwd = (string)reader["LoginPwd"];
             user.Name = (string)reader["Name"];
             user.Address = (string)reader["Address"];
             user.Phone = (string)reader["Phone"];
             user.Mail = (string)reader["Mail"];
             userStateId = (int)reader["UserStateId"]; //FK
             userRoleId = (int)reader["UserRoleId"]; //FK
             reader.Close();
             user.UserState = UserStateService.GetUserStateById(userStateId);
             user.UserRole = UserRoleService.GetUserRoleById(userRoleId);
             return user;
         }
         else
         {
             reader.Close();
             return null;
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// ɾ���û�
 /// </summary>
 /// <param name="user"></param>
 public static void DeleteUser(User user)
 {
     DeleteUserById(user.Id);
 }
Beispiel #9
0
        /// <summary>
        /// ����sql����ز�����ѯ�û�
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        private static IList<User> GetUsersBySql(string sql, params SqlParameter[] values)
        {
            List<User> list = new List<User>();

            using (DataTable table = DBHelper.GetDataSet(sql, values))
            {
                foreach (DataRow row in table.Rows)
                {
                    User user = new User();

                    user.Id = (int)row["Id"];
                    user.LoginId = (string)row["LoginId"];
                    user.LoginPwd = (string)row["LoginPwd"];
                    user.Name = (string)row["Name"];
                    user.Address = (string)row["Address"];
                    user.Phone = (string)row["Phone"];
                    user.Mail = (string)row["Mail"];
                    user.UserState = UserStateService.GetUserStateById((int)row["UserStateId"]); //FK
                    user.UserRole = UserRoleService.GetUserRoleById((int)row["UserRoleId"]); //FK

                    list.Add(user);
                }
                return list;
            }
        }
Beispiel #10
0
 /// <summary>
 /// �޸��û���Ϣ
 /// </summary>
 /// <param name="user"></param>
 public static void ModifyUser(User user)
 {
     string sql =
         "UPDATE Users " +
         "SET " +
             "UserStateId = @UserStateId, " + //FK
             "UserRoleId = @UserRoleId, " + //FK
             "LoginId = @LoginId, " +
             "LoginPwd = @LoginPwd, " +
             "Name = @Name, " +
             "Address = @Address, " +
             "Phone = @Phone, " +
             "Mail = @Mail " +
         "WHERE Id = @Id";
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@Id", user.Id),
         new SqlParameter("@UserStateId", user.UserState.Id), //FK
         new SqlParameter("@UserRoleId", user.UserRole.Id), //FK
         new SqlParameter("@LoginId", user.LoginId),
         new SqlParameter("@LoginPwd", user.LoginPwd),
         new SqlParameter("@Name", user.Name),
         new SqlParameter("@Address", user.Address),
         new SqlParameter("@Phone", user.Phone),
         new SqlParameter("@Mail", user.Mail)
     };
     DBHelper.ExecuteCommand(sql, para);
 }