Example #1
0
        public void Add(int index, BoatNode b)
        {
            if (index < 0)
            {
                throw new IndexOutOfRangeException("Index cannot be less than zero");
            }
            if (index > count)
            {
                index = count;
            }
            //get head
            BoatNode current = Head;

            if (Count == 0 || index == 0)
            {
                Head = b;
            }
            else
            {
                for (int i = 0; i < index - 1; i++)
                {
                    current = current.GetNext();
                }
                // BoatNode nextBoat = new Software_Implementation_Project.BoatNode(b, current.GetNext());
                current.SetNext(b);
            }
            Count = Count + 1;;
        }
Example #2
0
        public int getCurrentCapacityMarinaLength()
        {
            int total = 0;

            try
            {
                BoatNode _current = head;
                //if (marina ==null)
                //{
                //    throw new Exception("Null Marina Object passed to getOutStandingMarinaLength ");
                //}
                if (_current != null)
                {
                    int currentBoatLen = _current.GetItemData().BoatLength;
                    total += currentBoatLen;
                    while (_current.GetNext() != null)
                    {
                        _current = _current.GetNext();
                        total   += _current.GetItemData().BoatLength;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayManager.displayMessage(ex.ToString());
            }
            finally
            {
            }

            return(total);
        }
Example #3
0
        public int GetIndexOfBoatNodeByName(string boatName)
        {
            int      result      = 0;
            BoatNode currentBoat = head;

            if (Count < 1)
            {
                LoadDataFromFile();
                currentBoat = head;
            }
            if (currentBoat.GetItemData().NameOfBoat.ToUpper() == boatName.ToUpper())
            {
                result = 0;
                return(result);
            }
            for (int i = 1; i <= Count - 1; i++)
            {
                currentBoat = currentBoat.GetNext();
                if (currentBoat.GetItemData().NameOfBoat.ToUpper() == boatName.ToUpper())
                {
                    result = i;
                    break;
                }
            }
            return(result);
        }
Example #4
0
        public void DeleteBoat(int index)
        {
            if (index < 0)
            {
                throw new IndexOutOfRangeException("Index for delete boat is out of range");
            }

            BoatNode currentBoat = head;

            if (index > Count)
            {
                index = Count - 1;
            }
            if (index == 0)
            {
                head = currentBoat.GetNext();
            }
            else
            {
                for (int i = 0; i < index - 1; i++)
                {
                    currentBoat = currentBoat.GetNext();
                }
                currentBoat.SetNext(currentBoat.GetNext().GetNext());
            }
            count--;
        }
Example #5
0
        public List <string> convertMarinaToList()
        {
            List <string> list = new List <string>();

            BoatNode current = head;

            while (current != null)
            {
                string data = string.Empty;
                //nameof boat
                data += (current.GetItemData().NameOfBoat + ",");
                //owner
                data += (current.GetItemData().NameOfOwner + ",");
                // draft
                data += (current.GetItemData().BoatDraft.ToString() + ",");
                //get boat type
                string boatType = current.GetItemData().TypeofBoat;
                data += (boatType + ",");
                switch (boatType)
                {
                case "MotorBoat":
                    //MotorBoat
                    // sb.Append("MotorBoat" + " ");
                    Factory.MotorBoat TempMB = new Factory.MotorBoat("MotorBoat");
                    TempMB = (Factory.MotorBoat)current.GetItemData();
                    data  += (TempMB.BoatLength.ToString() + ",");
                    data  += (TempMB.DriveType + ",");
                    break;

                case "NarrowBoat":
                    //NarrowBoat
                    //sb.Append("NarrowBoat" + " ");
                    Factory.NarrowBoat TempNB = new Factory.NarrowBoat("NarrowBoat");
                    TempNB = (Factory.NarrowBoat)current.GetItemData();
                    data  += (TempNB.BoatLength + ",");
                    data  += (TempNB.SternType + ",");
                    break;

                case "Sailing":
                    //Sailing
                    // sb.Append("Sailing" + " ");
                    Factory.SailingBoat TempSB = new Factory.SailingBoat("Sailing");
                    TempSB = (Factory.SailingBoat)current.GetItemData();
                    data  += (TempSB.BoatLength + ",");
                    data  += (TempSB.SailingType + ",");
                    break;

                default:
                    break;
                }
                //add to list
                //sb.AppendLine(data);
                list.Add(data);
                //get next
                current = current.GetNext();
            }
            return(list);
        }
 public void ClearData(BoatNode toAppend)
 {
     toAppend.data = null;
     // toAppend.next = null;
 }
 public void SetNext(BoatNode toAppend)
 {
     this.next = toAppend;
 }
 public BoatNode(Factory.Boat d, BoatNode nextBoat)
 {
     data = d;
     next = nextBoat;
 }
 public BoatNode(Factory.Boat d)
 {
     data = d;
     next = null;
 }
Example #10
0
        private string PrintElements()
        {
            int           result      = 0;
            BoatNode      currentBoat = head;
            StringBuilder sb          = new StringBuilder();

            if (currentBoat != null)
            {
                //print curent boat
                sb.Append(currentBoat.GetItemData().NameOfBoat).Append(",");
                sb.Append(currentBoat.GetItemData().NameOfOwner).Append(",");
                sb.Append(currentBoat.GetItemData().BoatDraft.ToString()).Append(",");
                sb.Append(currentBoat.GetItemData().BoatLength.ToString()).Append(",");
                string strBoatType = string.Empty;
                strBoatType = currentBoat.GetItemData().TypeofBoat.ToString();
                //sb.Append(current.GetItemData().strBoatType).Append(",");
                switch (strBoatType)
                {
                case "MotorBoat":
                    Factory.MotorBoat MB = (Factory.MotorBoat)currentBoat.GetItemData();
                    sb.Append(MB.TypeofBoat).Append(",");
                    sb.Append(MB.DriveType).Append(",");
                    break;



                case "NarrowBoat":
                    Factory.NarrowBoat NB = (Factory.NarrowBoat)currentBoat.GetItemData();
                    sb.Append(NB.TypeofBoat).Append(",");
                    sb.Append(NB.SternType).Append(",");

                    break;

                case "Sailing":
                    Factory.SailingBoat SB = (Factory.SailingBoat)currentBoat.GetItemData();
                    sb.Append(SB.TypeofBoat).Append(",");
                    sb.Append(SB.SailingType).Append(",");

                    break;


                default:
                    break;
                }
                //remove last index of ,
            }
            sb.AppendLine("");
            if (currentBoat.GetNext() != null)
            {
                for (int i = 1; i < Count; i++)
                {
                    currentBoat = currentBoat.GetNext();
                    sb.Append(currentBoat.GetItemData().NameOfBoat).Append(",");
                    sb.Append(currentBoat.GetItemData().NameOfOwner).Append(",");
                    sb.Append(currentBoat.GetItemData().BoatDraft.ToString()).Append(",");
                    sb.Append(currentBoat.GetItemData().BoatLength.ToString()).Append(",");
                    string strBoatType = string.Empty;
                    strBoatType = currentBoat.GetItemData().TypeofBoat.ToString();
                    //sb.Append(current.GetItemData().strBoatType).Append(",");
                    switch (strBoatType)
                    {
                    case "MotorBoat":
                        Factory.MotorBoat MB = (Factory.MotorBoat)currentBoat.GetItemData();
                        sb.Append(MB.TypeofBoat).Append(",");
                        sb.Append(MB.DriveType).Append(",");
                        break;



                    case "NarrowBoat":
                        Factory.NarrowBoat NB = (Factory.NarrowBoat)currentBoat.GetItemData();
                        sb.Append(NB.TypeofBoat).Append(",");
                        sb.Append(NB.SternType).Append(",");

                        break;

                    case "Sailing":
                        Factory.SailingBoat SB = (Factory.SailingBoat)currentBoat.GetItemData();
                        sb.Append(SB.TypeofBoat).Append(",");
                        sb.Append(SB.SailingType).Append(",");

                        break;


                    default:
                        break;
                    }
                    sb.AppendLine("");
                }
            }

            return(sb.ToString());;
        }
Example #11
0
 public Marina()
 {
     head        = null;
     BoatFactory = new Factory.BoatFactory();
     count       = 0;
 }
Example #12
0
 public void ClearAllMarinaItems()
 {
     Head = new BoatNode();
     Head.SetNext(null);
     count = 0;
 }