Esempio n. 1
0
 /// <summary>
 /// Add boat to list _boats.
 /// </summary>
 /// <param name="boat"></param>
 public void add(Boat boat)
 {
     _boats.Add(boat);
 }
Esempio n. 2
0
 /// <summary>
 /// Removes boat from list of boats.
 /// </summary>
 /// <param name="b"></param>
 public void remove(Boat b)
 {
     _boats.Remove(b);
 }
Esempio n. 3
0
 /// <summary>
 /// Returns string representation of a certain boat.
 /// </summary>
 /// <param name="boat"></param>
 /// <returns></returns>
 public string viewBoat(Boat boat)
 {
     return String.Format("Boat:\nLength: {0} Feet\nType: {1}\n", boat.Length, boat.BoatType);
 }
Esempio n. 4
0
        /// <summary>
        /// Loads member info from text file, saves to member repository
        /// and returns it as readonlycollection
        /// </summary>
        /// <returns>_memberReository (as readonly)</returns>
        public IReadOnlyCollection<Member> LoadMemberData()
        {
            using (StreamReader listreader = new StreamReader(_path))
            {
                List<Member> members = new List<Member>();
                Member member = null;
                Boat boat = null;
                string line;
                MemberReadStatus status = MemberReadStatus.Other;

                while ((line = listreader.ReadLine()) != null)
                {
                     switch (line)
                    {
                        case "":
                            continue;

                        case sectionMember:
                            status = MemberReadStatus.NewMember;
                            break;

                        case sectionID:
                            status = MemberReadStatus.ID;
                            continue;

                        case sectionName:
                            status = MemberReadStatus.Name;
                            continue;

                        case sectionPersonalNumber:
                            status = MemberReadStatus.PersonalNumber;
                            continue;

                        case sectionBoat:
                            status = MemberReadStatus.NewBoat;
                            break;

                        case sectionLength:
                            status = MemberReadStatus.Length;
                            continue;

                        case sectionType:
                            status = MemberReadStatus.Type;
                            continue;
                    }

                    switch (status)
                    {
                        case MemberReadStatus.NewMember:
                            member = new Member();
                            members.Add(member);
                            continue;

                        case MemberReadStatus.ID:
                            member.ID = line;
                            continue;

                        case MemberReadStatus.Name:
                            string[] names = line.Split(new char[] { ';' });
                            if (names.Length < 2)
                            {
                                throw new FormatException();
                            }
                            member.FirstName = names[0];
                            member.LastName = names[1];
                            continue;

                        case MemberReadStatus.PersonalNumber:
                            member.PersonalNumber = line;
                            continue;

                        case MemberReadStatus.NewBoat:
                            boat = new Boat();
                            member.add(boat);
                            continue;

                        case MemberReadStatus.Length:
                            string[] length = line.Split(new char[] { ';' });

                                boat.Length = double.Parse(length[0]);

                            continue;

                        case MemberReadStatus.Type:

                            foreach (Boat.Type t in Enum.GetValues(typeof(Boat.Type)))
                            {
                                if (Enum.GetName(typeof(Boat.Type),t) == line)
                                {
                                    boat.BoatType = t;
                                }
                            }
                            continue;
                        }
                      }

                members.TrimExcess();
                members = members.OrderBy(m => m.ID).ToList();
                _memberRepository = members;

                return members.AsReadOnly();
            }
        }
Esempio n. 5
0
 /// <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);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Removes boat from list of boats.
 /// </summary>
 /// <param name="b"></param>
 public void remove(Boat b)
 {
     _boats.Remove(b);
 }
Esempio n. 7
0
 /// <summary>
 /// Add boat to list _boats.
 /// </summary>
 /// <param name="boat"></param>
 public void add(Boat boat)
 {
     _boats.Add(boat);
 }