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); } }
/** * 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); } }