/// <summary> /// Create boat, get boat info using view, add to member and save it. /// </summary> /// <param name="member"></param> private void addBoat(Member member) { //Create new boat.. Boat b = new Boat(); double length; //Delete the current info about the member _memberDAL.Delete(member); //Get the type of the boat, set it to new boat. Boat.Type boatType = _editUpdateMenu.chooseBoatType(); //Get the length of the boat, set it to new boat. string lengthInput = _editUpdateMenu.getStrInput(messages.inputLength); try { double.TryParse(lengthInput, out length); b.BoatType = boatType; b.Length = length; //add boat to the member. member.add(b); //save member saveMember(member); _editUpdateMenu.ShowMessage(messages.boatCreated); } catch (Exception) { _editUpdateMenu.ShowMessage(messages.invalidInput); } }
private Boat LoadBoat(XmlReader a_xml) { Boat.Type type = Boat.Type.BT_Count; double length = 0; while (a_xml.Read()) { if (a_xml.IsStartElement()) { switch (a_xml.Name) { case "type": int t; Int32.TryParse(a_xml.ReadString(), out t); type = (Boat.Type)t; break; case "length": double.TryParse(a_xml.ReadString(), out length); break; } } } if (type != Boat.Type.BT_Count && length != 0) { return(new Boat(type, length)); } return(null); }
/// <summary> /// Read all boats in a boatlist connected to the member with member id m_memberID /// </summary> private void GetBoatsFromFile() { try { if (File.Exists(m_filePath)) { using (StreamReader sr = new StreamReader(m_filePath)) { while (!sr.EndOfStream) { Boat.Type type = (Boat.Type) int.Parse(sr.ReadLine()); double length = double.Parse(sr.ReadLine()); int memberID = int.Parse(sr.ReadLine()); if (memberID == m_memberID) { m_boats.Add(new Boat(type, length, GetUniqueBoatID())); } } sr.Close(); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Add a boat to the boat list /// </summary> /// <param name="a_type">Boat.Type. Type of boat</param> /// <param name="a_length">double. The length of the boat</param> public void AddBoat(Boat.Type a_type, double a_length) { try { m_boats.Add(new Boat(a_type, a_length, GetUniqueBoatID())); m_boatDAL.SaveBoats(this); } catch (Exception ex) { throw ex; } }
/// <summary> /// Choose boat type, if can be parsed to proper type, return type. /// </summary> /// <returns>Boat.Type boatType</returns> internal Boat.Type chooseBoatType() { ShowMessage(messages.specType, true); Boat.Type boatType = Boat.Type.None; string rl = Console.ReadLine(); foreach (Boat.Type t in Enum.GetValues(typeof(Boat.Type))) { if (Enum.GetName(typeof(Boat.Type), t) == rl) { boatType = t; break; } } return(boatType); }
/// <summary> /// Change a boats information /// </summary> /// <param name="a_boatID">int. The boats ID</param> /// <param name="a_type">Boat.Type. The type of boat</param> /// <param name="a_length">double. The length of the boat</param> public void ChangeBoatInfo(int a_boatID, Boat.Type a_type, double a_length) { try { foreach (Boat boat in m_boats) { if (boat.GetBoatID() == a_boatID) { boat.SetType(a_type); boat.SetLength(a_length); m_boatDAL.SaveBoats(this); break; } } } catch (Exception ex) { throw ex; } }