Example #1
0
        // Display view to delete a boat (pick boat, confirmation window), delete the boat from the member
        private void DeleteBoat(model.Member member)
        {
            if (member.Boats.Count() == 0)
            {
                DoMemberView(member);
            }
            else
            {
                try
                {
                    model.Boat boatToDelete = _boatView.GetBoatToEditOrDelete(member, "delete");
                    if (_boatView.ConfirmDelete() == true)
                    {
                        member.DeleteBoat(boatToDelete);
                        _list.SaveMemberList();
                    }

                    DoMemberView(member);
                }
                catch (Exception ex)
                {
                    _boatView.DisplayErrorMessage(ex.Message);
                    _boatView.PressKeyToContinue();
                    DoMemberView(member);
                }
            }
        }
Example #2
0
 // Display views, get inputs to create/save boat to a member
 private void AddBoat(model.Member member) // Which member to add the boat to
 {
     try
     {
         _memberView.DisplayMember(member);
         model.Boat.BoatType type    = _boatView.GetTypeFromUser();
         double     length           = _boatView.GetLengthFromUser();
         DateTime   registrationDate = _boatView.GetRegistrationDate();
         model.Boat boat             = new model.Boat(type, length, registrationDate);
         member.AddBoat(boat);
         _list.SaveMemberList();
         DoMemberView(member);
     }
     catch (Exception ex)
     {
         _memberView.DisplayMember(member);
         _boatView.DisplayErrorMessage(ex.Message);
         if (_boatView.DoesUserWantsToQuit() == true)
         {
             DoMemberView(member);
         }
         else
         {
             AddBoat(member);
         }
     }
 }
 // Which member to add the boat to
 // Display views, get inputs to create/save boat to a member
 private void AddBoat(model.Member member)
 {
     try
     {
         _memberView.DisplayMember(member);
         model.Boat.BoatType type = _boatView.GetTypeFromUser();
         double length = _boatView.GetLengthFromUser();
         DateTime registrationDate = _boatView.GetRegistrationDate();
         model.Boat boat = new model.Boat(type, length, registrationDate);
         member.AddBoat(boat);
         _list.SaveMemberList();
         DoMemberView(member);
     }
     catch (Exception ex)
     {
         _memberView.DisplayMember(member);
         _boatView.DisplayErrorMessage(ex.Message);
         if (_boatView.DoesUserWantsToQuit() == true)
         {
             DoMemberView(member);
         }
         else
         {
             AddBoat(member);
         }
     }
 }
Example #4
0
 // Display view to change a boat's lenght, get new length and do the change
 // Note: Edit boat? isn't more correct to remove a boat and register a new? or is it when you "remodel" an existing boat
 private void EditBoat(model.Member member)
 {
     // Only able to edit and delete boats if you own a boat
     if (member.Boats.Count() == 0)
     {
         DoMemberView(member);
     }
     else
     {
         try
         {
             model.Boat boatToEdit = _boatView.GetBoatToEditOrDelete(member, "edit");
             boatToEdit.Length = _boatView.GetLengthFromUser();
             _list.SaveMemberList();
             DoMemberView(member);
         }
         catch (Exception ex)
         {
             _memberView.DisplayMember(member);
             _memberView.DisplayErrorMessage(ex.Message);
             if (_memberView.DoesUserWantsToQuit() == true)
             {
                 DoMemberView(member);
             }
             else
             {
                 EditBoat(member);
             }
         }
     }
 }
Example #5
0
        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));
        }
Example #6
0
 private void DoAddBoat(view.MainView a_view, model.Member selectedMember)
 {
     model.Boat b = a_view.m_memberView.m_boatView.DoAddBoatForm();
     if (b != null)
     {
         selectedMember.AddBoat(b);
         a_view.SetSelectedBoat(selectedMember, b);
     }
 }
Example #7
0
        public BoatMenuChoice DoBoatMenu(model.Boat a_boat)
        {
            Console.Clear();
            Console.Out.WriteLine("Båt");
            Console.Out.WriteLine("Typ: {0}\tLängd:{1}", BoatTypeToString(a_boat.GetTypeOfBoat()), a_boat.GetLength());


            String[] menuStrings = new String[] { "Ändra", "Ta Bort", "Tillbaka" };

            return(DoMenu <BoatMenuChoice>(menuStrings, BoatMenuChoice.Invalid, "Båtmeny"));
        }
        public void EditBoat(model.Member member)
        {
            string id = BoatView.EditBoatMenu(member.getBoats());

            model.Boat boat = new model.Boat("Other", 1, "0");
            foreach (model.Boat b in member.getBoats())
            {
                if (b.GetId() == id)
                {
                    boat = b;
                }
            }
            if (boat.GetId() == "0")
            {
                BoatView.BoatNotFound();
            }
            else
            {
                string choice = BoatView.EditBoatChoice();
                if (choice == "1")
                {
                    BoatView.ChangeType();
                    string type = BoatType();

                    if (type.Length == 0)
                    {
                        BoatView.InvalidChoice();
                    }
                    else
                    {
                        boat.setType(type);
                        BoatView.Success();
                    }
                }
                else if (choice == "2")
                {
                    string lengthAsString = BoatView.GetBoatLength();
                    if (Int32.TryParse(lengthAsString, out int length))
                    {
                        boat.setLength(length);
                        BoatView.Success();
                    }
                    else
                    {
                        BoatView.InvalidChoice();
                    }
                }
                else
                {
                    BoatView.InvalidChoice();
                }
            }
        }
Example #9
0
 private void SetPickedBoat(int pickedBoat)
 {
     pickedBoat--;
     for (int i = 0; i < _pickedMember.Boats.Count; i++)
     {
         if (i == pickedBoat)
         {
             _pickedBoat   = _pickedMember.Boats[i];
             _pickedBoatId = i;
         }
     }
 }
Example #10
0
        public bool Do(model.MemberRegistry a_model, view.MainView a_view)
        {
            model.Member selectedMember = a_view.GetSelectedMember(a_model);
            model.Boat   selectedBoat   = a_view.GetSelectedBoat(a_model);

            if (selectedMember == null)
            {
                view.MainView.MainMenuChoice choice;
                choice = a_view.DoMainMenu();

                switch (choice)
                {
                case view.MainView.MainMenuChoice.AddMember:
                    DoAddMember(a_model, a_view);
                    return(true);

                case view.MainView.MainMenuChoice.ListMembers:
                    a_view.PrintMemberList(a_model.GetMembers());
                    return(true);

                case view.MainView.MainMenuChoice.ListMembersFull:
                    a_view.PrintFullMemberList(a_model.GetMembers());
                    return(true);

                case view.MainView.MainMenuChoice.SelectMember:
                    model.Member m = a_view.DoSelectMember(a_model.GetMembers());
                    if (m != null)
                    {
                        a_view.SetSelectedMember(m);
                    }
                    return(true);

                case view.MainView.MainMenuChoice.Quit:
                default:
                    return(false);
                }
            }
            else
            {
                if (selectedBoat != null)
                {
                    DoSelectedBoat(a_view, selectedMember, selectedBoat);
                }
                else
                {
                    DoSelectedMember(a_model, a_view, selectedMember);
                }

                return(true);
            }
        }
Example #11
0
 public void SetSelectedBoat(model.Member a_member, model.Boat a_boat)
 {
     m_selectedBoatIx = -1;
     if (a_member == null || a_boat == null)
     {
         return;
     }
     for (int ix = 0; ; ix++)
     {
         model.Boat b = a_member.GetBoat(ix);
         if (b == a_boat)
         {
             m_selectedBoatIx = ix;
             return;
         }
         else if (b == null)
         {
             return;
         }
     }
 }
Example #12
0
        //adding a member and saving the new members
        private void addNewBoat(int memberLocation)
        {
            consoleView.clear();
            consoleView.displayBoatLenghtInstruktions();
            float length;
            float.TryParse(consoleView.getInput(), out length);

            consoleView.clear();
            consoleView.displayBoatTypeInstruktions();
            showBoatType();
            try
            {
                int value = int.Parse(consoleView.getInput());
                var boatType = Enum.ToObject(typeof(model.Boat.BoatType), value);
                model.Boat boat = new model.Boat((model.Boat.BoatType)boatType, length);
                DAL.addBoatToMember(memberLocation, boat);
            }
            catch (Exception e)
            {
                consoleView.displayExeptions(e.ToString());
            }
        }
Example #13
0
 public List<Boat> RegisterBoat(float length, string boatType)
 {
     model.Boat newBoat = new model.Boat(length, boatType);
     BoatRegister.Add(newBoat);
     return BoatRegister;
 }
Example #14
0
 private static void DoChangeBoat(view.MainView a_view, model.Member selectedMember, model.Boat selectedBoat)
 {
     model.Boat b;
     b = a_view.m_memberView.m_boatView.DoChangeBoatForm(selectedBoat);
     if (b != null)
     {
         selectedMember.UpdateBoat(selectedBoat, b);
     }
 }
Example #15
0
 private static void DoDeleteBoat(view.MainView a_view, model.Member selectedMember, model.Boat selectedBoat)
 {
     selectedMember.RemoveBoat(selectedBoat);
     a_view.SetSelectedBoat(null, null);
 }
Example #16
0
        private void DoSelectedBoat(view.MainView a_view, model.Member selectedMember, model.Boat selectedBoat)
        {
            view.BoatView.BoatMenuChoice choice;
            choice = a_view.m_memberView.m_boatView.DoBoatMenu(selectedBoat);
            switch (choice)
            {
            case view.BoatView.BoatMenuChoice.ChangeBoat:
                DoChangeBoat(a_view, selectedMember, selectedBoat);
                break;

            case view.BoatView.BoatMenuChoice.DeleteBoat:
                DoDeleteBoat(a_view, selectedMember, selectedBoat);
                break;

            default:
                a_view.SetSelectedBoat(null, null);
                break;
            }
        }
Example #17
0
 public string BoatToString(model.Boat b)
 {
     return($"[ Boattype: {b.Type},  Length: {b.LengthInFeet} feet. ]");
 }
Example #18
0
 /// <summary>
 /// Displays a boat to the user
 /// </summary>
 /// <param name="a_boat">model.Boat. The boat to be displayed</param>
 public void DisplayBoat(model.Boat a_boat)
 {
     System.Console.WriteLine("BoatID: {0}", a_boat.GetBoatID());
     System.Console.WriteLine("Type: {0}", a_boat.GetBoatType());
     System.Console.WriteLine("Length: {0}", a_boat.GetLength());
 }
Example #19
0
 public model.Boat DoChangeBoatForm(model.Boat a_defaultValues)
 {
     Console.Out.WriteLine("Ändra Båt");
     return(DoBoatForm(a_defaultValues));
 }
 public void CreateBoat(int memberID, string boatType, int length)
 {
     model.Boat m_boat = new model.Boat(memberID, boatType, length);
     m_boats.Add(m_boat);
 }
Example #21
0
 public List <Boat> RegisterBoat(float length, string boatType)
 {
     model.Boat newBoat = new model.Boat(length, boatType);
     BoatRegister.Add(newBoat);
     return(BoatRegister);
 }