// 返回UserID public static int AddUser(User user) { int minLength = 4; if (user.Password.Length < minLength) { return(1); } else { int status = DAO.CheckRepeatUserName(user.UserId, user.UserName); if (status == 0) { SqlConnection conn = DAO.Connection(); string addUser = "******"; addUser = string.Format(addUser, user.UserId, user.UserName, user.Password); //Console.WriteLine(addAccount); try { conn.Open(); SqlCommand command = conn.CreateCommand(); command.CommandText = addUser; int rows = command.ExecuteNonQuery(); if (rows == 1) { return(0); } else { Console.WriteLine("影响行数为{0}", rows); return(-1); } } catch (Exception exception) { Debug.WriteLine(exception.Message.ToString()); return(-1); } } else { return(2); } } }
// 返回UserID public static int ChangeUserName(string OldUserName, string NewUserName, User user) { int minLength = 2; if (OldUserName == "") { return(1); } else { if (OldUserName != user.UserName) { return(2); } else { if (NewUserName.Length < minLength) { return(3); } else { if (OldUserName == NewUserName) { return(4); } else { int status = DAO.CheckRepeatUserName(user.UserId, NewUserName); if (status == 0) { SqlConnection conn = DAO.Connection(); string updateUserName = "******" + NewUserName + "' WHERE UserID = '" + user.UserId + "'"; //Console.WriteLine(updateUserName); try { conn.Open(); SqlCommand command = conn.CreateCommand(); command.CommandText = updateUserName; int rows = command.ExecuteNonQuery(); conn.Close(); if (rows > 0) { return(0); } else { return(-1); } } catch (Exception exception) { Debug.WriteLine(exception.Message.ToString()); return(-1); } } else if (status == 2) { return(5); } else if (status == 3) { return(6); } else { return(7); } } } } } }