public static string patientPath = rootPath + @"\" + MyDentistMgr.Default.PatientsPath; //creates a path to the patients directory /** * Saves a singe practice file. */ public static void savePracticeFile(DentalPractice practice) { StreamWriter practiceFile; //writes a textfile to the computer, Reader reads string practiceFilePath; try { practiceFilePath = practicePath + "\\" + practice.getLocation(); // \\ escape key for backslash, takes root directory and add the backslash to determine the path in the dental practice folder. if (!Directory.Exists(practiceFilePath)) //Creates a folder for the practice if it does not exist already. { Directory.CreateDirectory(practiceFilePath); Directory.CreateDirectory(practiceFilePath + @"\Rooms"); } practiceFile = new StreamWriter(practiceFilePath + @"\info.txt", false); //Give true as the second parameter to append to a file or false to overwrite. practiceFile.WriteLine(practice.getLocation()); //First line is location. if (practice.getReceptionist() is Receptionist) { practiceFile.WriteLine(practice.getReceptionist().getUsername()); //Receptionist is second line. } else { practiceFile.WriteLine(); } practiceFile.WriteLine(practice.getAddress()); //Address is third. practiceFile.Close(); //closes streamwriter } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Saves all treatment rooms. */ public static void saveAllRooms(DentalPractice practice) { List <TreatmentRoom> rooms; StreamWriter roomFile; string roomInfoPath; //Path to the specific Practice Rooms folder. string roomFilePath; try { rooms = practice.getRooms(); //Gets lsit of rooms from give practice. roomInfoPath = practicePath + "\\" + practice.getLocation() + "\\Rooms"; //Determines the path of the directory where the given locations room files are stored. if (Directory.Exists(roomInfoPath)) { Directory.Delete(roomInfoPath, true); //true tells Directory.Delete() to delete any contents within the folder. Directory.CreateDirectory(roomInfoPath); //Recreates the empty Room directory. } Directory.CreateDirectory(roomInfoPath); //Recreates the empty Room directory. roomInfoPath += "\\Room "; //Concatenates string, joins strings together. for (int i = 0; i < rooms.Count; i++) { roomFilePath = roomInfoPath + (i + 1) + ".txt"; roomFile = new StreamWriter(roomFilePath); roomFile.WriteLine(rooms[i].getDentistId()); roomFile.WriteLine(rooms[i].getNurseId()); roomFile.Close(); } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * loads treatment rooms for a given location. */ public static void loadTreatmentRooms(List <TreatmentRoom> rooms, DentalPractice practice) { string[] treatmentRoomFiles; StreamReader treatmentRoomFile; //opens file to read string roomPath = practicePath + "\\" + practice.getLocation() + "\\Rooms"; //Takes root directory and add the backslash to determine the path in the Rooms folder within locations folder. string assignedDentist; string assignedNurse; try { if (Directory.Exists(roomPath)) //find whether it exsists { treatmentRoomFiles = Directory.GetFiles(roomPath); //Get files for stored in the rooms folder for (int i = 0; i < treatmentRoomFiles.Length; i++) //Iterates over all the room files { treatmentRoomFile = new StreamReader(roomPath + "\\Room " + (i + 1) + ".txt"); //Opens up the first room file for the given location assignedDentist = treatmentRoomFile.ReadLine(); //first line will be the dentist. assignedNurse = treatmentRoomFile.ReadLine(); //second will be the nurse. treatmentRoomFile.Close(); rooms.Add(new TreatmentRoom(i + 1, practice, assignedDentist, assignedNurse)); } } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Prints staff at a given Practice. */ public static void printStaffAtPractice(DentalPractice practice) { List <Staff> staff = DataSearching.getStaff(); List <Staff> staffAtPractice = new List <Staff>(); DentistNurse denNurseToPrint; try { staffAtPractice = staff.FindAll(staffMem => (staffMem.getPractice() is DentalPractice) && (staffMem.getPractice().Equals(practice))); //Returns a list of all staff with the given location. Console.WriteLine("Staff at {0}:", practice.getLocation()); for (int i = 0; i < staffAtPractice.Count; i++) { Console.Write("{0}: {1} - ", staffAtPractice[i].getUsername(), staffAtPractice[i].getName()); //Printing role if (staffAtPractice[i] is Receptionist) { Console.WriteLine("Receptionist"); } else { denNurseToPrint = (DentistNurse)staffAtPractice[i]; //Shortened version to select practioner type & write it Console.WriteLine(denNurseToPrint.getPractitionerType()); } ; } } catch (Exception e) { GeneralFunctions.errorHandler(e); } }
/** * Views a practice */ public static void viewPractice(DentalPractice practice) { List <TreatmentRoom> rooms = practice.getRooms(); //geta all rooms at practice try { Console.Clear(); Console.WriteLine(practice.getLocation()); //writes the name of specific pratice Console.WriteLine($"Address: {practice.getAddress()}"); //writes the address of the practice Console.Write("Receptionist: "); if (practice.getReceptionist() is Receptionist) //Checks if receptionist is assigned { Console.WriteLine(practice.getReceptionist().getName()); //writes the name of receptionist } else { Console.WriteLine("Unassigned"); //if not } Console.WriteLine("\nRooms\n====="); for (int i = 0; i < rooms.Count; i++) //iterates over room no. { Console.WriteLine($"Room {i + 1}:"); //writes room no. adding +1 to index so more human friendly Console.Write("Dentist: "); if (rooms[i].getDentist() is DentistNurse) //checks if dentist is assigned { Console.WriteLine(rooms[i].getDentist().getName()); //gets the assigned name of the dentist } else { Console.WriteLine("Unassigned"); } Console.Write("Nurse: "); if (rooms[i].getNurse() is DentistNurse) //checks if nurse is assigned { Console.WriteLine(rooms[i].getNurse().getName()); //writes the name of the assigned nurse. } else { Console.WriteLine("Unassigned"); } } Console.ReadLine(); Console.Clear(); } 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); } }