public ItemReturn(Data data) { this.data = data; resources = data.Resources; reader = new FileReader(data); writer = new FileWriter(data); }
public void CheckOutResource(Dictionary<string, List<string>> studentCheckOuts, string name) { //writes the student's file when checking out and updates the resources dictionary bools FileWriter writer = new FileWriter(data); Dictionary <string, bool> resources = data.Resources; foreach (KeyValuePair<string, List<string>> pair in studentCheckOuts) { if (pair.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase)) { name = pair.Key; break; } } List<string> studentList = studentCheckOuts[name]; string fileName = name + ".txt"; string header = writer.StudentHeader(name); StreamWriter writing = new StreamWriter(fileName); using (writing) { writing.WriteLine(header); writing.WriteLine(); writing.WriteLine("Checked Out Resources: "); for (int i = 0; i < studentList.Count; i++) { writing.WriteLine(studentList[i]); } } for (int i = 0; i < studentList.Count; i++) //updates the resources dictionary { if (resources.ContainsKey(studentList[i])) { resources[studentList[i]] = false; //false because its no longer available } } }
//makes a new file for a new student in admin menu public void WriteNewStudentFile(string name) { StringBuilder makeName = new StringBuilder(); makeName.Append(name); makeName.Append(".txt"); string filename = makeName.ToString(); FileWriter writing = new FileWriter(data); StreamWriter writer = new StreamWriter(filename); using (writer) { writer.WriteLine(writing.StudentHeader(name)); } }
public AdminMenu(Data data) { this.data = data; reader = new FileReader(data); writer = new FileWriter(data); }
//initializes all the classes and handles menu option input public void Menu() { bool close = false; Data data = new Data(); FileReader reader = new FileReader(data); FileWriter writer = new FileWriter(data); ItemCheckOut checkout = new ItemCheckOut(data); ItemReturn returnItem = new ItemReturn(data); Dictionary<string, bool> resources = data.Resources; Dictionary<string, List<string>> studentCheckOuts = data.StudentCheckOuts; AdminMenu admin = new AdminMenu(data); while (close == false) { Console.Clear(); PrintMenu(); int choice; string menuChoice = Console.ReadLine(); Console.WriteLine(); bool quitter = data.MenuQuitter(menuChoice); if (quitter == true) { return; } bool result = int.TryParse(menuChoice, out choice); switch (choice) { case 1: reader.ViewStudentList(); break; case 2: reader.PrintAvailableResources(); break; case 3: reader.PrintCheckedOutResources(); break; case 4: reader.ViewStudentAccount(); break; case 5: checkout.CheckOut(); break; case 6: returnItem.ReturnItem(); break; case 7: ClosingImage(); close = true; break; /* case 8: admin.RunAdminMenu(); break; */ default: continue; } } }