Exemple #1
0
 /// <summary>
 /// Assign equipment to divers and update equipment status
 /// </summary>
 /// <param name="dive">Dive object</param>
 public void AssignEquipmentToDivers(Dive dive)
 {
     foreach (Diver diver in dive.Divers)
     {
         allEquipment.EquipDiver(diver, dive);
         diver.UpdateEquipmentStatus(dive);
     }
 }
        /// <summary>
        /// Parse dives and add them to list
        /// </summary>
        /// <param name="divesRaw">Array of strings. Each row represents row in file</param>
        public void AddDivesToList(string[] divesRaw)
        {
            string[] dive;

            foreach (string d in divesRaw)
            {
                dive = d.Split(';');

                // Create instance of dive class
                string   date         = dive[0] + " " + dive[1];
                DateTime diveDateTime = DateTime.ParseExact(date, "yyyy.MM.dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None);
                Dive     diveObj      = new Dive(diveDateTime, Int32.Parse(dive[2]), Int32.Parse(dive[3]), Int32.Parse(dive[4]), dive[5] == "1", Int32.Parse(dive[6]));

                // Add dive to list
                diveList.Add(diveObj);
            }
        }
        /// <summary>
        /// Update diver equipment status
        /// FULLY EQUIPED       - basic equipment + all additional equipment
        /// PARTIALLY EQUIPED   - basic equipment
        /// NOT EQUIPED         - without basic equipment
        /// </summary>
        public void UpdateEquipmentStatus(Dive dive)
        {
            int basicEquipmentCounter = 0;

            // Check if user have all basic equipment
            foreach (ConcreteEquipment equipment in equipmentList)
            {
                if (EquipmentHelper.IsBasicEquipment(equipment))
                {
                    basicEquipmentCounter++;
                }
            }

            // Basic equipment
            if (basicEquipmentCounter == Constants.NUM_OF_BASIC_EQUIPMENT && equipmentList.Count() == Constants.NUM_OF_BASIC_EQUIPMENT)
            {
                equipmentStatus = Constants.PARTIALLY_EQUIPED;
            }

            // Diver is not adequate equiped for dive
            else if (basicEquipmentCounter < Constants.NUM_OF_BASIC_EQUIPMENT)
            {
                equipmentStatus = Constants.NOT_EQUIPED;
            }

            // Basic + additional equipment
            else if (
                // If it's cold dive then check if diver is adequate equipped for cold dive
                (dive.temperature < Constants.TEMPERATURE_BOUNDARY && EquipmentHelper.IsDiverAdequatEquippedForColdDive(equipmentList)) ||

                // If it's dive with temp above 15 and diver is adequate equipped for that dive
                (dive.temperature >= Constants.TEMPERATURE_BOUNDARY && EquipmentHelper.IsDiverAdequateEquippedForWarmDive(equipmentList)) &&

                // If it's night dive then check if diver is adequate equipped for night dive
                ((dive.isNightDive && EquipmentHelper.IsDiverAdequateEquippedForNightDive(EquipmentList)) || !dive.isNightDive)
                )
            {
                equipmentStatus = Constants.FULLY_EQUIPED;
            }
        }
        /// <summary>
        /// Filter diver list by depth, temperature and night dive specialty
        /// and count how many divers have underwater photography specialty
        /// </summary>
        /// <param name="depth"></param>
        /// <param name="temperature"></param>
        /// <param name="isNightDive"></param>
        private void FilterDivers(Dive dive, List <Diver> diverList)
        {
            int diversNo = diverList.Count();

            foreach (Diver diver in diverList.ToArray())
            {
                // Filter by depth, dry suit and night dive specialty
                if ((diver.certificate.depth + 10 < dive.depth) ||
                    (dive.temperature < 15 && !diver.CheckIfDiverHasSuperPower(Constants.DRY_SUIT)) ||
                    (dive.isNightDive && !diver.CheckIfDiverHasSuperPower(Constants.NIGHT_DIVE)))
                {
                    continue;
                }

                // Count how many divers has photography specialty
                if (diver.CheckIfDiverHasSuperPower(Constants.PHOTOGRAPHER))
                {
                    numOfUnderwaterPhotographers++;
                }

                dive.AddDiver(diver);
                diver.AddDiveToList(dive);
            }
        }
 public void AddDiveToList(Dive dive)
 {
     diveList.Add(dive);
 }