/**
         * Removes a user from the system.
         */
        private void removeUser()
        {
            List <User> users    = Application.appInstance.users;
            string      response = "";
            bool        inMenu   = true;
            User        userToRemove;

            try
            {
                while (inMenu)
                {
                    response = GeneralFunctions.getOptionalInput("User: "******"")
                    {
                        if (DataSearching.userExists(response))              //Checks if user exists with given response.
                        {
                            userToRemove = DataSearching.findUser(response); //Find users matching with response
                            DataIO.deleteUserFile(userToRemove);             //Delete the user in the file
                            users.Remove(userToRemove);                      //Remove the user from the list
                        }
                    }
                    else
                    {
                        inMenu = false;
                    }
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
        /*
         * Promts the user for a username and password. if nothing is entered in the username, will exit the loop.
         */
        private bool loginUser()
        {
            bool active             = true; // feeds back to Application to determine if the system should keep requesting credentials or exit.
            bool invalidCredentials = true;


            string username; // holds the username following input.
            string password; // Holds the password following input.

            try
            {
                do
                {
                    Console.Write("Username: "******""; //checks to see if username is not empty and stores the boolean result in the active variable.

                    if (active)
                    {
                        Console.Write("Password: "******"Invalid credentials");
                        }
                    }
                    else
                    {
                        break; //Exits out of loop when active is false.
                    }
                }while (invalidCredentials);
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
            return(active);
        }
Exemplo n.º 3
0
 /**
  * gets the Receptionist object from the receptionistId.
  */
 public void associateReceptionist() //Void for the return type of variable/object
 {
     try
     {
         if (receptionistId != "")
         {
             receptionist = (Receptionist)DataSearching.findUser(receptionistId); //Because we are taking from a list of Users and wish to assign this to a Receptionist, it must be casted back.
         }
     }
     catch (Exception e)
     {
         GeneralFunctions.errorHandler(e);
     }
 }
        /**
         * Manages a practice
         */
        private void managePractice(DentalPractice practice)
        {
            bool inMenu;

            string       receptionist = "";
            Receptionist recObj;

            try
            {
                inMenu = true;

                do
                {
                    DataPrinting.printReceptionists();                             //Prints out all receptionists
                    Console.Write($"Receptionist for {practice.getLocation()}: "); //Request receptionist based on location.
                    receptionist = Console.ReadLine();
                    Console.Clear();

                    if (receptionist == "")
                    {
                        inMenu = false;
                    }
                    else if (DataSearching.userExists(receptionist))                 //Checks receptionist exsist
                    {
                        recObj = (Receptionist)DataSearching.findUser(receptionist); //Finds receptionist based on previous check.
                        recObj.setPractice(practice);                                //Sets Practice to recpetionist
                        practice.setReceptionist(recObj);                            // sets receptionist on the practice

                        DataIO.saveUser(recObj);                                     //saves file
                        DataIO.savePracticeFile(practice);                           //saving file

                        inMenu = false;
                    }
                    else
                    {
                        Console.WriteLine("User does not exist");
                    }
                }while (inMenu);
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }
 /**
  * Allocates dentists and nurses to the room.
  */
 public void associateStaff()
 {
     dentist = (DentistNurse)DataSearching.findUser(dentistId);  //Finds the user with the provided ID to set as rooms the dentist.
     nurse   = (DentistNurse)DataSearching.findUser(nurseId);
 }
        /**
         * Shows the interface to manage a room.
         */
        private void manageRoom(TreatmentRoom room)
        {
            string       response;
            bool         invalidResponse;
            Staff        userToCheck;
            DentistNurse userToAssign;

            try
            {
                invalidResponse = true;

                while (invalidResponse) // Prints all staff at practice.
                {
                    DataPrinting.printStaffAtPractice(room.getPractice());
                    Console.Write("Dentist to assign: (Enter nothing to skip)");
                    response = Console.ReadLine();
                    Console.Clear();

                    if (response != "")
                    {
                        if (DataSearching.userExists(response))                    //Validates the response
                        {
                            userToCheck = (Staff)DataSearching.findUser(response); //Find staff users with the given username response.
                            if (userToCheck is DentistNurse)
                            {
                                userToAssign = (DentistNurse)DataSearching.findUser(response); //Checks wether they are dentist or nurse and find them usign findUser method

                                if (userToAssign.getPractitionerType() != "Dentist")           //if not equal to dentist
                                {
                                    Console.WriteLine("Selected staff is not dentist.");
                                }
                                else
                                {
                                    room.setDentist(userToAssign); // sets the given room to the dentist user.
                                    invalidResponse = false;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Selected staff is not dentist.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("user does not exist.");
                        }
                    }
                    else
                    {
                        invalidResponse = false;
                    }
                }

                invalidResponse = true;

                while (invalidResponse) // Selecting the Nurse. works the same as Dentist
                {
                    DataPrinting.printStaffAtPractice(room.getPractice());
                    Console.Write("Nurse to assign: (Enter nothing to skip)");
                    response = Console.ReadLine();
                    Console.Clear();

                    if (response != "")
                    {
                        if (DataSearching.userExists(response))
                        {
                            userToCheck = (Staff)DataSearching.findUser(response);
                            if (userToCheck is DentistNurse)
                            {
                                userToAssign = (DentistNurse)DataSearching.findUser(response);

                                if (userToAssign.getPractitionerType() != "Nurse")
                                {
                                    Console.WriteLine("Selected staff is not nurse.");
                                }
                                else
                                {
                                    room.setNurse(userToAssign);
                                    invalidResponse = false;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Selected staff is not nurse.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("user does not exist.");
                        }
                    }
                    else
                    {
                        invalidResponse = false;
                    }
                }
            }
            catch (Exception e)
            {
                GeneralFunctions.errorHandler(e);
            }
        }