Example #1
0
        public void addBoatToMarina(Factory.Boat _boat)
        {
            try
            {
                //boat length cannot exceed marina Length
                if (_boat.BoatLength > marinaLength)
                {
                    throw new Exception("Boat length Exceeds Length of marina");
                }
                //do we have enough space for this boat in the marina
                //get marina
                LoadDataFromFile();
                int currentCapacity = getCurrentCapacityMarinaLength();
                if ((marinaLength - currentCapacity) > _boat.BoatLength || marinaLength == 0)
                {
                    AddToEnd(_boat);
                    //write to file

                    //FileOperations fp = new FileOperations();
                    //fp.writeToFile()
                }
                else
                {
                    throw new Exception("Cannot add " + _boat.NameOfBoat + " to the marina as it will not fit");
                }
            }
            catch (Exception ex)
            {
                throw(ex);
            }
        }
 public BoatNode(Factory.Boat d, BoatNode nextBoat)
 {
     data = d;
     next = nextBoat;
 }
 public BoatNode(Factory.Boat d)
 {
     data = d;
     next = null;
 }
Example #4
0
        public void AddToEnd(Factory.Boat boat)
        {
            BoatNode node = new Software_Implementation_Project.BoatNode(boat);

            Add(Count, node);
        }
Example #5
0
        private void LoadDataFromFile()
        {
            // Marina marina = new Software_Implementation_Project.Marina();

            try
            {
                FileOperations      fileOps     = new Software_Implementation_Project.FileOperations();
                Factory.BoatFactory BoatFactory = new Factory.BoatFactory();
                List <string>       fileList    = new List <string>();
                Factory.Boat        boat        = null;
                fileList = fileOps.readDataFromFile();

                if (fileList.Count < 1)
                {
                    // throw new Exception("No data was returned from file");
                }
                else
                {
                    foreach (string item in fileList)
                    {
                        //split array at commas and put result into an array
                        string[] arrSplitRow = item.Split(",".ToCharArray());
                        //create boat based on type
                        string strBoatType  = arrSplitRow[3];
                        string strBoatLen   = arrSplitRow[4];
                        string strBoatDraft = arrSplitRow[2];
                        switch (strBoatType)
                        {
                        case "NarrowBoat":
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);

                            //Factory.NarrowBoat NB =(Factory.NarrowBoat)BoatFactory.BuildBoat(strBoatType);
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.NarrowBoat NB = (Factory.NarrowBoat)boat;
                            int boatSubType       = BoatFactory.BuildBoatSubTypes(strBoatType);
                            NB.TypeofBoat = strBoatType;

                            NB.NameOfBoat  = arrSplitRow[0];
                            NB.NameOfOwner = arrSplitRow[1];
                            int boatLen   = 0;
                            int boatDraft = 0;
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                NB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                NB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                NB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                NB.BoatDraft = 1;
                            }
                            NB.SternType = arrSplitRow[5];
                            boat         = NB;
                            break;

                        case "Sailing":
                            //boat = BoatFactory.BuildBoat(3);
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.SailingBoat SB = (Factory.SailingBoat)boat;
                            //  Factory.SailingBoat SB = (Factory.SailingBoat)(BoatFactory.BuildBoat(strBoatType));
                            SB.TypeofBoat  = strBoatType;
                            SB.TypeofBoat  = strBoatType;
                            SB.NameOfBoat  = arrSplitRow[0];
                            SB.NameOfOwner = arrSplitRow[1];
                            boatLen        = 0;
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                SB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                SB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                SB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                SB.BoatDraft = 1;
                            }
                            SB.SailingType = arrSplitRow[5];
                            boat           = SB;
                            break;

                        case "MotorBoat":
                            //  boat = BoatFactory.BuildBoat(strBoatType);
                            // Factory.MotorBoat MB = (Factory.MotorBoat)(BoatFactory.BuildBoat(strBoatType));
                            boat = Factory.BoatFactory.BuildBoat(strBoatType);
                            Factory.MotorBoat MB = (Factory.MotorBoat)boat;
                            MB.TypeofBoat  = strBoatType;
                            MB.NameOfBoat  = arrSplitRow[0];
                            MB.NameOfOwner = arrSplitRow[1];
                            MB.DriveType   = arrSplitRow[5];
                            try
                            {
                                int.TryParse(strBoatLen, out boatLen);
                                MB.BoatLength = boatLen;
                            }
                            catch (Exception ex)
                            {
                                MB.BoatLength = -1;
                            }
                            try
                            {
                                int.TryParse(strBoatDraft, out boatDraft);
                                MB.BoatDraft = boatDraft;
                            }
                            catch (Exception ex)
                            {
                                MB.BoatDraft = 1;
                            }
                            boat = MB;
                            break;

                        default:
                            break;
                        }
                        //end of switch
                        // marina.addBoatToMarina(boat);
                        if (boat != null)
                        {
                            if (count == 0)
                            {
                                BoatNode boatNode = new Software_Implementation_Project.BoatNode(boat);

                                Add(0, boatNode);
                            }
                            else
                            {
                                AddToEnd(boat);
                            }
                            // count++;
                        }
                    }
                    //end of foreach loop
                }
            }
            catch (Exception ex)
            {
                DisplayManager.displayInvalidInputMessage(ex.ToString());
            }


            //return Marina;
        }