Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int userRegistration()
- {
- int RegistrationMenuChoice;
- int newUserRole;
- string newUserRoleChoice;
- //string user;
- ofstream UserRegistration;
- try
- {
- do{
- cout << "-----------------------------------" << endl;
- cout << "User Registration Menu" << endl;
- cout << "-----------------------------------" << endl;
- cout << "1. Add User" << endl;
- cout << "2. Edit User" << endl;
- cout << "3. Delete User" << endl;
- cout << "4. Display All Users" << endl;
- cin >> RegistrationMenuChoice;
- if (RegistrationMenuChoice == 1)
- {
- string newUserName;
- cout << "Enter New Username: " << endl;
- cin >> newUserName;
- for (int i = 0; i <= arrayIndex; i++)
- {
- while (newUserName == user[i].getUsername())
- {
- cout << "The username you entered is currently not available." << endl;
- cout << "Please enter your new username: " << endl;
- cin >> newUserName;
- }
- }
- cout << "Enter New User Password: " << endl;
- cin >> newUserPassword;
- cout << "Enter User Role" << endl;
- cout << "1. Purchase Manager" << endl;
- cout << "2. Sales Manager" << endl;
- cout << "3. Administrator" << endl;
- cin >> newUserRole;
- if (newUserRole == 1)
- {
- newUserRoleChoice = "PM";
- }
- else if (newUserRole == 2)
- {
- newUserRoleChoice = "SM";
- }
- else if (newUserRole == 3)
- {
- newUserRoleChoice = "Admin";
- }
- //Load array and add new info from new variables
- User userTemp(NextUserID, newUserName, newUserPassword, newUserRoleChoice);
- user[arrayIndex] = userTemp;
- arrayIndex++;
- UserRegistration.open("UserRegistration.dat");
- for (int i = 0; i <= arrayIndex; i++)
- {
- UserRegistration << user[i].getUserID() << "\t";
- UserRegistration << user[i].getUsername() << "\t";
- UserRegistration << user[i].getPassword() << "\t";
- UserRegistration << user[i].getRole() << endl;
- }
- NextUserID++;
- }
- //-------------------------------------------------------
- else if (RegistrationMenuChoice == 2)
- {
- string userEditUserName;
- string userEditPassword;
- int userEditRole;
- int userEditID;
- string userEditRoleChoice;
- cout << "Enter User ID to edit: ";
- cin >> userEditID;
- for (int i = 0; i <= arrayIndex; i++)
- {
- if (userEditID == user[i].getUserID())
- {
- userRegistrationIndex = i;
- }
- }
- if (userRegistrationIndex == -1)
- {
- cout << "There is no such ID" << endl;
- }
- else
- {
- cout << endl << "Enter New Username for that user: " << endl;
- cin >> userEditUserName;
- cout << endl << "Enter New Password for the user: " << endl;
- cin >> userEditPassword;
- cout << endl << "Enter New Role for the user: " << endl;
- cout << "1. Sales Manager" << endl;
- cout << "2. Purchase Manager" << endl;
- cout << "3. Administrator" << endl;
- cin >> userEditRole;
- if (userEditRole == 1)
- {
- userEditRoleChoice = "PM";
- }
- else if (userEditRole == 2)
- {
- userEditRoleChoice = "SM";
- }
- else if (userEditRole == 3)
- {
- userEditRoleChoice = "Admin";
- }
- User userTemp(userEditID, userEditUserName, userEditPassword, userEditRoleChoice);
- user[userRegistrationIndex] = userTemp;
- UserRegistration.open("UserRegistration.dat");
- for (int i = 0; i <= arrayIndex; i++)
- {
- UserRegistration << user[i].getUserID() << "\t";
- UserRegistration << user[i].getUsername() << "\t";
- UserRegistration << user[i].getPassword() << "\t";
- UserRegistration << user[i].getRole() << endl;
- }
- }
- }
- //-------------------------------------------------------
- else if (RegistrationMenuChoice == 3)
- {
- int removeUserID;
- cout << "Enter User ID to remove: " << endl;
- cin >> removeUserID;
- //Checking if information is in the array
- for (int i = 0; i <= arrayIndex; i++)
- {
- if (removeUserID == user[i].getUserID())
- {
- userDeleteIndex = i;
- }
- }
- if (userDeleteIndex == -1)
- {
- cout << "There is no such ID" << endl;
- }
- else
- {
- cout << "" << userDeleteIndex;
- while (userDeleteIndex < arrayIndex){
- user[userDeleteIndex] = user[userDeleteIndex + 1];
- userDeleteIndex++;
- }
- arrayIndex--;
- }
- ofstream userRegistration;
- userRegistration.open("UserRegistration.dat");
- for (int i = 0; i <= arrayIndex; i++)
- {
- userRegistration << user[i].getUserID() << "\t";
- userRegistration << user[i].getUsername() << "\t";
- userRegistration << user[i].getPassword() << "\t";
- userRegistration << user[i].getRole() << endl;
- }
- }
- //-------------------------------------------------------
- else if (RegistrationMenuChoice == 4)
- {
- for (int i = 0; i <= arrayIndex-1; i++)
- {
- cout << "ID: " << user[i].getUserID() << endl;
- cout << "Username: " << user[i].getUsername() << endl;
- cout << "Password: " << user[i].getPassword() << endl;
- cout << "Role: " << user[i].getRole() << endl << endl;
- }
- }
- UserRegistration.close();
- return 0;
- } while (RegistrationMenuChoice > 4);
- }
- catch (int e)
- {
- cout << "Exception Error";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement