static int Main(string[] args) { Municipality myCity = new Municipality(); if (myCity == null) { Console.WriteLine("Error in creation city!"); return 1; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("B.H."); List<muniLibrary> libraries = addLibraries(ref myCity); Console.ForegroundColor = ConsoleColor.Red; addResidents(ref myCity); Console.ForegroundColor = ConsoleColor.Magenta; foreach (muniLibrary myLibrary in libraries) printLibrary(myLibrary); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Good bye..."); Console.ResetColor(); return 0; }
static List<muniLibrary> addLibraries(ref Municipality city) { List<muniLibrary> libraries = new List<muniLibrary>(); int counter = 0; do { Console.Write("\nPlease insert a name of a library in the city: "); muniLibrary library = new muniLibrary(ref city, Console.ReadLine()); if (library != null) { library.NewClientAdded += new EventHandler(library_NewClientAdded); libraries.Add(library); } Console.WriteLine(libraries.Count != ++counter ? "Error in insert." : "The library has been inserted successfully."); Console.Write("\nDo you want to add another library (yes/no)? "); } while ((Console.ReadLine() + 'n').TrimStart().StartsWith("y", true, calendarType)); return libraries; }
static void addResidents(ref Municipality city) { do { Console.Write("\nPlease insert a name of a resident for the library: "); string name = Console.ReadLine(); Console.Write("\nPlease insert male/female: "); Sex sex = (Console.ReadLine() + 'w').TrimStart().StartsWith("m", true, calendarType) ? Sex.Male : Sex.Female; Console.Write("\nDoes this resident have a job (yes/no)? "); bool job = (Console.ReadLine() + 'n').TrimStart().StartsWith("y", true, calendarType); Console.Write("\nPlaese insert the birth-date, seperated by slashes"); DateTime born; DateTime.TryParse(Console.ReadLine(), calendarType, DateTimeStyles.None, out born); ulong ID; Console.WriteLine("Please insert an israeli ID."); ulong.TryParse(Console.ReadLine(), out ID); while (!(Checkings.CheckIdNum(ID))) { Console.WriteLine("The ID {0} is wrong! Please insert a valid israeli ID.", ID); ulong.TryParse(Console.ReadLine(), out ID); } int index = city.add(new Resident(name, sex, job, born, ID)); Console.WriteLine(string.Format(index > 0 ? "Client no. {0} has been inserted successfully." : "Error in insert.", index)); Console.Write("\nDo you want to add another client (yes/no)? "); } while ((Console.ReadLine() + 'n').TrimStart().StartsWith("y", true, calendarType)); }
public muniLibrary(ref Municipality city, string n) { city.NewResidents += new EventHandler(muny_NewResidents); name = n; }