static int displayMenu() { int retVal = 0; string menuText = "\nWELCOME TO MARINA BERTH BOOKING SYSTEM.\n" + "What do you want to do?\n" + "1. Record a new booking.\n" + "2. Delete a Booking.\n" + "3. Display All Records.\n" +//and available marina space "4. Exit Application." ; try { DisplayManager.drawRectangle(menuText, ConsoleColor.White, ConsoleColor.DarkBlue); string strInput = Console.ReadLine(); int.TryParse(strInput, out retVal); } catch (Exception ex) { string message = "Please enter an valid number"; DisplayManager.displayInvalidInputMessage(message); } return(retVal); }
public static int getUserInput() { int retVal = -1; string strInput = Console.ReadLine(); try { int.TryParse(strInput, out retVal); } catch (Exception ex) { string message = "Please enter an valid number"; DisplayManager.displayInvalidInputMessage(message); } finally { } return(retVal); }
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); }
private void LoadDataFromFile() { // Marina marina = new Software_Implementation_Project.Marina(); try { FileOperations fileOps = new Software_Implementation_Project.FileOperations(); Factory.BoatFactory BoatFactory = new Factory.BoatFactory(); List <string> fileList = new List <string>(); Factory.Boat boat = null; fileList = fileOps.readDataFromFile(); if (fileList.Count < 1) { // throw new Exception("No data was returned from file"); } else { foreach (string item in fileList) { //split array at commas and put result into an array string[] arrSplitRow = item.Split(",".ToCharArray()); //create boat based on type string strBoatType = arrSplitRow[3]; string strBoatLen = arrSplitRow[4]; string strBoatDraft = arrSplitRow[2]; switch (strBoatType) { case "NarrowBoat": boat = Factory.BoatFactory.BuildBoat(strBoatType); //Factory.NarrowBoat NB =(Factory.NarrowBoat)BoatFactory.BuildBoat(strBoatType); boat = Factory.BoatFactory.BuildBoat(strBoatType); Factory.NarrowBoat NB = (Factory.NarrowBoat)boat; int boatSubType = BoatFactory.BuildBoatSubTypes(strBoatType); NB.TypeofBoat = strBoatType; NB.NameOfBoat = arrSplitRow[0]; NB.NameOfOwner = arrSplitRow[1]; int boatLen = 0; int boatDraft = 0; try { int.TryParse(strBoatLen, out boatLen); NB.BoatLength = boatLen; } catch (Exception ex) { NB.BoatLength = -1; } try { int.TryParse(strBoatDraft, out boatDraft); NB.BoatDraft = boatDraft; } catch (Exception ex) { NB.BoatDraft = 1; } NB.SternType = arrSplitRow[5]; boat = NB; break; case "Sailing": //boat = BoatFactory.BuildBoat(3); boat = Factory.BoatFactory.BuildBoat(strBoatType); Factory.SailingBoat SB = (Factory.SailingBoat)boat; // Factory.SailingBoat SB = (Factory.SailingBoat)(BoatFactory.BuildBoat(strBoatType)); SB.TypeofBoat = strBoatType; SB.TypeofBoat = strBoatType; SB.NameOfBoat = arrSplitRow[0]; SB.NameOfOwner = arrSplitRow[1]; boatLen = 0; try { int.TryParse(strBoatLen, out boatLen); SB.BoatLength = boatLen; } catch (Exception ex) { SB.BoatLength = -1; } try { int.TryParse(strBoatDraft, out boatDraft); SB.BoatDraft = boatDraft; } catch (Exception ex) { SB.BoatDraft = 1; } SB.SailingType = arrSplitRow[5]; boat = SB; break; case "MotorBoat": // boat = BoatFactory.BuildBoat(strBoatType); // Factory.MotorBoat MB = (Factory.MotorBoat)(BoatFactory.BuildBoat(strBoatType)); boat = Factory.BoatFactory.BuildBoat(strBoatType); Factory.MotorBoat MB = (Factory.MotorBoat)boat; MB.TypeofBoat = strBoatType; MB.NameOfBoat = arrSplitRow[0]; MB.NameOfOwner = arrSplitRow[1]; MB.DriveType = arrSplitRow[5]; try { int.TryParse(strBoatLen, out boatLen); MB.BoatLength = boatLen; } catch (Exception ex) { MB.BoatLength = -1; } try { int.TryParse(strBoatDraft, out boatDraft); MB.BoatDraft = boatDraft; } catch (Exception ex) { MB.BoatDraft = 1; } boat = MB; break; default: break; } //end of switch // marina.addBoatToMarina(boat); if (boat != null) { if (count == 0) { BoatNode boatNode = new Software_Implementation_Project.BoatNode(boat); Add(0, boatNode); } else { AddToEnd(boat); } // count++; } } //end of foreach loop } } catch (Exception ex) { DisplayManager.displayInvalidInputMessage(ex.ToString()); } //return Marina; }