//public void ClearAllMarinaItems() //{ // //empties the marina // BoatNode tempNode = head; // BoatNode currentBoatNode = head; // BoatNode previousBoatNode = null; // while (tempNode != null) // { // currentBoatNode = tempNode; // if (previousBoatNode != null) // { // previousBoatNode.SetNext(currentBoatNode.GetNext()); // } // else // { // //head.SetFirst(null); // //head.SetNext(null); // //string srtt = ""; // head.ClearData(head); // } // previousBoatNode = currentBoatNode; // tempNode.SetNext(tempNode.GetNext()); // break; // } //} //public void DeleteBoat( ) //{ // try // { // string strNameOfBoatToDelete = string.Empty; // FileOperations fp = new FileOperations(); // BoatFactory = new Factory.BoatFactory(); // List<string> currentmarina = new List<string>(); // while (true) // { // DisplayManager.displayMessage("Enter the name of the boat you to delete"); // strNameOfBoatToDelete = DisplayManager.getUserInputStr(); // if (!string.IsNullOrEmpty(strNameOfBoatToDelete)) // { // break; // } // else // { // DisplayManager.displayMessage("Please Enter the name of the boat you to delete"); // } // } // //clear marina // ClearAllMarinaItems(); // //load data from file // LoadDataFromFile(); // BoatNode temp = head, prev = null; // // If head node itself holds the key to be deleted // if (temp != null && temp.GetItemData().NameOfBoat.ToUpper() == strNameOfBoatToDelete.ToUpper()) // { // head = temp.GetNext(); // Changed head // // Unlink the node from linked list // //prev.next = temp.next; // // prev.SetNext(temp.GetNext()); // currentmarina = convertMarinaToList(); // fp.writeToFile(true, currentmarina); // listAllBoats(); // return; // } // // Search for the key to be deleted, keep track of the // // previous node as we need to change temp.next // while (temp != null && temp.GetItemData().NameOfBoat.ToUpper() != strNameOfBoatToDelete.ToUpper()) // { // string currentBoatName = temp.GetItemData().NameOfBoat.ToUpper(); // Console.WriteLine(currentBoatName); // if (currentBoatName.ToUpper() != strNameOfBoatToDelete.ToUpper()) // { // prev = temp; // temp = temp.GetNext(); // } // } // // If key was not present in linked list // if (temp == null) // { // return; // } // // Unlink the node from linked list // //prev.next = temp.next; // prev.SetNext(temp.GetNext()); // currentmarina = convertMarinaToList(); // fp.writeToFile(true,currentmarina); // listAllBoats(); // } // catch (Exception ex) // { // DisplayManager.displayMessage(ex.Message); // } //} public void listAllBoats() { //clear marina ClearAllMarinaItems(); //load from file if (Count < 1) { LoadDataFromFile(); } //print string sb = string.Empty; sb = PrintElements(); //get current marina length sb += "\n\n Current marina capacity :" + getCurrentCapacityMarinaLength().ToString() + " meters"; DisplayManager.displayMessage(sb); }
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); }
public static int displayBoatTypesMenu() { // Console.Clear(); string menuText = "\n" + "1. Narrow.\n" + "2. Sailing.\n" + "3. Motor.\n" //and available marina space ; //Console.WriteLine(menuText); drawRectangle(menuText, ConsoleColor.White, ConsoleColor.DarkBlue); int userInput = DisplayManager.getUserInput(); if (userInput < 1 || userInput > 3) { throw new ArgumentException("Please choose an option between 1 and 3"); } return(userInput); }
public static int displayHeaderMenu() { // Console.Clear(); 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."; //Console.WriteLine(menuText); drawRectangle(menuText, ConsoleColor.White, ConsoleColor.DarkBlue); int userInput = DisplayManager.getUserInput(); if (userInput < 1 || userInput > 4) { throw new ArgumentException("Please Enter an option between 1 and 4"); } return(userInput); }
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); }
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); }
public Boat createBoat() { int boatLen = 0; int boatType = 0; int boatDraft = 0; string strBoatOwner = string.Empty; string strBoatName = string.Empty; Boat Boat = null; while (true) { Console.WriteLine("Enter Boat Length"); string strBoatLength = Console.ReadLine(); if (!string.IsNullOrEmpty(strBoatLength)) { int.TryParse(strBoatLength, out boatLen); } if (boatLen < 1) { Console.WriteLine("Boat Length Cannot be less tha 1 meter"); } if (boatLen > marinaLength || boatLen < 1) { Console.WriteLine("Boat Length Cannot be Greater than Marina Length or less than 1 meter"); } //else if(boatLen>(Marina.getCurrentCapacityMarinaLength()-Marina.MarinaLength)) else if (boatLen > (marinaLength - Marina.getCurrentCapacityMarinaLength())) { throw new ArgumentException("The current marina capacity of " + Marina.getCurrentCapacityMarinaLength().ToString() + " will not be enough to accomodate this boat"); } else { break; } } while (true) { Console.WriteLine("Enter Boat Draft"); string strBoatDraft = Console.ReadLine(); if (!string.IsNullOrEmpty(strBoatDraft)) { int.TryParse(strBoatDraft, out boatDraft); } if (boatDraft < 1) { Console.WriteLine("Boat Draft Cannot be less tha 1 meter"); } if (boatDraft > 5 || boatDraft < 1) { Console.WriteLine("Boat Draft Cannot be Greater than 5 meters or less than 1 meter"); } else { break; } } //check reservation here bool proceed = calculateBoatResrvation(); if (proceed) { while (true) { Console.WriteLine("Enter Boat Owner"); strBoatOwner = Console.ReadLine(); if (!string.IsNullOrEmpty(strBoatOwner)) { break; } } while (true) { Console.WriteLine("Enter Boat Name"); strBoatName = Console.ReadLine(); if (!string.IsNullOrEmpty(strBoatName)) { break; } } Console.WriteLine("Choose Boat Type:"); while (true) { try { boatType = DisplayManager.displayBoatTypesMenu(); break; } catch (Exception ex) { DisplayManager.displayMessage(ex.Message); } } switch (boatType) { case 1: MotorBoat MB = (Factory.MotorBoat)BoatFactory.BuildBoat(boatType); int mbSubtype = BoatFactory.BuildBoatSubTypes(boatType); MB.DriveType = MB.GetEnumNameFromValue(mbSubtype); Boat = MB; break; case 2: // NarrowBoat NB = new NarrowBoat("NarrowBoat", boatType); NarrowBoat NB = (Factory.NarrowBoat)BoatFactory.BuildBoat(boatType); int nbSubtype = BoatFactory.BuildBoatSubTypes(boatType); NB.SternType = NB.GetEnumNameFromValue(nbSubtype); Boat = NB; break; case 3: //SailingBoat SB = new SailingBoat("Sailing", boatType); SailingBoat SB = (Factory.SailingBoat)BoatFactory.BuildBoat(boatType); int sbSubtype = BoatFactory.BuildBoatSubTypes(boatType); SB.SailingType = SB.GetEnumNameFromValue(sbSubtype); Boat = SB; break; default: break; } if (Boat != null) { Boat.BoatLength = boatLen; Boat.NameOfBoat = strBoatName; Boat.NameOfOwner = strBoatOwner; Boat.BoatDraft = boatDraft; Factory.BoatHelperClass.showDetails(Boat); } } else { throw new Exception("User terminated Booking transaction"); } return(Boat); }
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); }
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; }