/// <summary> /// Read all boats in a boatlist connected to the member with member id m_memberID /// </summary> /// <returns>List<Boat>. A list of boats the member owns</returns> public List <model.Boat> GetBoatsFromFile() { try { List <model.Boat> boats = new List <model.Boat>(); int uniqueBoatID = 1; if (File.Exists(m_boatFilePath)) { using (StreamReader sr = new StreamReader(m_boatFilePath)) { while (!sr.EndOfStream) { model.Boat.Type type = (model.Boat.Type) int.Parse(sr.ReadLine()); double length = double.Parse(sr.ReadLine()); int memberID = int.Parse(sr.ReadLine()); if (memberID == m_memberID) { boats.Add(new model.Boat(type, length, uniqueBoatID)); uniqueBoatID += 1; } } sr.Close(); } } return(boats); } catch (Exception ex) { throw ex; } }
private string BoatTypeToString(model.Boat.Type a_type) { String[] types = new String[(int)model.Boat.Type.BT_Count] { "Motorbåt", "Segelbåt", "Motorseglare", "Kanot/Kajak", "Övrigt" }; return(types[(int)a_type]); }
private bool DoBoatTypeField(out model.Boat.Type a_value, model.Boat.Type a_default) { Console.Out.WriteLine("Välj Båttyp"); for (int i = 0; i < (int)model.Boat.Type.BT_Count; i++) { Console.Out.WriteLine("\t{0} för {1}", i, BoatTypeToString((model.Boat.Type)i)); } Console.Write("Val: "); string choice; DoFormField(out choice, ((int)a_default).ToString(), "Val: "); int choiceInt; if (Int32.TryParse(choice, out choiceInt)) { if (choiceInt >= 0 && choiceInt < (int)model.Boat.Type.BT_Count) { a_value = (model.Boat.Type)choiceInt; return(true); } } a_value = model.Boat.Type.BT_Count; return(false); }
private model.Boat DoBoatForm(model.Boat a_defaultValues) { string lengthStr = ""; model.Boat.Type boatType = model.Boat.Type.BT_Motor; if (a_defaultValues != null) { boatType = a_defaultValues.GetTypeOfBoat(); lengthStr = Convert.ToString(a_defaultValues.GetLength()); } ; if (DoBoatTypeField(out boatType, boatType) != true || DoFormField(out lengthStr, lengthStr, "Längd") != true) { return(null); } double length; if (Double.TryParse(lengthStr, out length) != true) { return(null); } return(new model.Boat(boatType, length)); }