static void Main(string[] args) { //diplays main menu and int user_Input = 0; MarinaMaintenanceObj MarinaMaintenanceObject = new Software_Implementation_Project.MarinaMaintenanceObj(); Marina Marina = new Software_Implementation_Project.Marina(); do { try { user_Input = DisplayManager.displayHeaderMenu(); FileOperations FP = new Software_Implementation_Project.FileOperations(); switch (user_Input) { case 1: //Console.WriteLine("Add new boat"); Boat _boat = MarinaMaintenanceObject.createBoat(); if (_boat != null) { try { int currentMarinaCapacity = 0; currentMarinaCapacity = Marina.getCurrentCapacityMarinaLength(); int availableCapacity = MarinaMaintenanceObject.marinaLength - currentMarinaCapacity; if (_boat.BoatLength > availableCapacity) { throw new Exception("The boat, " + _boat.NameOfBoat.ToUpper() + " has a length of " + _boat.BoatLength.ToString() + ".\nThis exceeds the marina capacity and cannot fit into fit into the marina"); } //bool proceed = MarinaMaintenanceObject.calculateBoatResrvation(_boat); //if (proceed) //{ Marina.ClearAllMarinaItems(); //add new boat to marina Marina.addBoatToMarina(_boat); List <string> listData = new List <string>(); listData = Marina.convertMarinaToList(); //write to file FP.writeToFile(listData); //} } catch (Exception ex) { DisplayManager.displayInvalidInputMessage(ex.Message); } finally { DisplayManager.displayInvalidInputMessage("\n\nPress Enter to go back to main menu"); Console.ReadLine(); DisplayManager.clearScreen(); } } else { //Error in creeating boat try { throw new Exception(""); } catch (Exception ex) { DisplayManager.displayInvalidInputMessage("Error in creating boat.Please Try again.\n\n"); DisplayManager.displayInvalidInputMessage(ex.Message + "\n\n"); DisplayManager.displayInvalidInputMessage("Press Any Key to go back to main menu"); Console.ReadLine(); DisplayManager.clearScreen(); } } break; case 2: Marina.listAllBoats(); bool exit = false; DisplayManager.displayMessage("\n\n"); string strNameOfBoatToDelete = string.Empty; while (true) { DisplayManager.displayMessage("Enter the name of the boat you to delete" + " or press x to go back to main menu"); strNameOfBoatToDelete = DisplayManager.getUserInputStr(); if (string.IsNullOrEmpty(strNameOfBoatToDelete)) { break; } else { if (strNameOfBoatToDelete.ToUpper().Equals("x".ToUpper())) { throw new Exception("User Cancncelled the operation"); } DisplayManager.displayMessage("Please Enter the name of the boat you to delete"); } } int index = Marina.GetIndexOfBoatNodeByName(strNameOfBoatToDelete); if (index < 1) { throw new ArgumentOutOfRangeException("Could not find the requested boat " + strNameOfBoatToDelete + " in the marina"); } Marina.DeleteBoat(index); DisplayManager.displayMessage("The boat " + strNameOfBoatToDelete.ToUpper() + " has been removed from the marina"); List <string> data = new List <string>(); data = Marina.convertMarinaToList(); //write to file FP.writeToFile(data); DisplayManager.displayInvalidInputMessage("Press Any key to go back to main menu"); Console.ReadLine(); DisplayManager.clearScreen(); break; case 3: Console.WriteLine("display all boats".ToUpper()); Marina.listAllBoats(); DisplayManager.displayInvalidInputMessage("Press any key to go back to main menu"); Console.ReadLine(); DisplayManager.clearScreen(); break; default: break; } } catch (Exception ex) { DisplayManager.displayMessage(ex.Message); DisplayManager.displayInvalidInputMessage("\n\nPress any key to go back to main menu"); Console.ReadLine(); DisplayManager.clearScreen(); } } while (user_Input != 4); }
internal static int getBoatSubTypes(int type) { string subMenuType = ""; string subTypeMessage = string.Empty; int retVal = 0; switch (type) { case 1: //"MotorBoat" subTypeMessage = "\n Please Select an Option \n" + "1. Inboard Drive \n" + "2. OutboardMotors \n"; while (true) { //displayMessage(subTypeMessage); drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue); subMenuType = DisplayManager.getUserInputStr(); if (!string.IsNullOrEmpty(subMenuType)) { try { int.TryParse(subMenuType, out retVal); Factory.MotorBoat MB = new Factory.MotorBoat(); int enumLen = MB.GetEnumLength(); if (retVal > enumLen || retVal < 1) { throw new ArgumentOutOfRangeException("Invalid Option for Drive Types; Please Choose an option between 1 and " + enumLen); } else { break; } } catch (Exception ex) { DisplayManager.displayMessage(ex.Message); } } } break; case 2: // "NarrowBoat" subTypeMessage = "\n Please Select an Option \n" + "1. Traditional stern\n" + "2. Cruiser stern \n" + "3. Semi-traditional stern \n"; while (true) { drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue); subMenuType = DisplayManager.getUserInputStr(); if (!string.IsNullOrEmpty(subMenuType)) { try { int.TryParse(subMenuType, out retVal); Factory.NarrowBoat NB = new Factory.NarrowBoat(); int enumLen = NB.GetEnumLength(); if (retVal > enumLen || retVal < 1) { throw new ArgumentOutOfRangeException("Invalid Option for Stern Types; Please Choose an option between 1 and " + enumLen); } else { break; } } catch (Exception ex) { DisplayManager.displayMessage(ex.Message); } } } break; case 3: //Sailing subTypeMessage = "\n Please Select an Option \n" + "1. Ketch\n" + "2. Cutter \n" + "3. Junk \n"; while (true) { drawRectangle(subTypeMessage, ConsoleColor.White, ConsoleColor.DarkBlue); subMenuType = DisplayManager.getUserInputStr(); if (!string.IsNullOrEmpty(subMenuType)) { try { int.TryParse(subMenuType, out retVal); Factory.SailingBoat SB = new Factory.SailingBoat(); int enumLen = SB.GetEnumLength(); if (retVal > enumLen || retVal < 1) { throw new ArgumentOutOfRangeException("Invalid Option for Stern Types; Please Choose an option between 1 and " + enumLen); } else { break; } } catch (Exception ex) { DisplayManager.displayMessage(ex.Message); } } } break; default: break; } return(retVal); }
public bool calculateBoatResrvation() { bool proceed = false; string strStartDate = string.Empty; string strEndDate = string.Empty; DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); while (true) { DisplayManager.displayMessage("Please Enter The Start Date For Reservation:"); strStartDate = DisplayManager.getUserInputStr(); if (!string.IsNullOrEmpty(strStartDate)) { try { startDate = DateTime.Parse(strStartDate); break; } catch (Exception) { DisplayManager.displayMessage("Invalid date for start date"); } finally { } } else { DisplayManager.displayMessage("Please Enter a value for start date"); } } while (true) { DisplayManager.displayMessage("Please Enter The End Date For Reservation:"); try { strEndDate = DisplayManager.getUserInputStr(); if (!string.IsNullOrEmpty(strEndDate)) { endDate = DateTime.Parse(strEndDate); //check if start date is greater than end date if (startDate > endDate) { throw new InvalidOperationException("Start Date cannot be greater than End date"); } else { //calculate date difference double totalDays = (endDate - startDate).TotalDays; try { decimal _totalDays = 0; decimal.TryParse(totalDays.ToString(), out _totalDays); //are both days the same if (startDate.Date == endDate.Date) { _totalDays = 1; } string strAmt = Factory.BoatHelperClass.FormatCurrency((_totalDays * rate), "GBP"); string message = "The total cost for the period ('" + startDate.ToShortDateString() + "') to '"; message += endDate.ToShortDateString() + "('" + _totalDays.ToString() + "days') is :" + strAmt; message += "\n\n Do you wish to proceed(Press Y to Proceed or N to Cancel)"; while (true) { DisplayManager.displayMessage(message); string ans = DisplayManager.getUserInputStr(); if (string.IsNullOrEmpty(ans)) { throw new InvalidOperationException("Please Enter a valid answer in order to proceed"); } if (ans.ToUpper() == "Y") { proceed = true; break; } else if (ans.ToUpper() == "N") { break; } else { } } break; } catch (Exception ex) { DisplayManager.displayMessage(ex.Message.ToString()); } } } else { DisplayManager.displayMessage("Please Enter a value for End date"); } } catch (Exception ex) { DisplayManager.displayMessage(ex.Message.ToString()); } } return(proceed); }