Esempio n. 1
0
        /// <summary>
        /// Method to find a list of the newest vehicles
        /// </summary>
        /// <returns></returns>
        public VehicleContainer FindNewestVehicles()
        {
            VehicleContainer NewestVehicles = new VehicleContainer();

            for (int i = 0; i < this.AllVehicles.Count; i++)
            {
                if (NewestVehicles.Count == 0)
                {
                    NewestVehicles.Add(this.AllVehicles[i]);
                    continue;
                }

                Vehicle vehicleToCompare = NewestVehicles[0];

                if (this.AllVehicles[i] < vehicleToCompare)
                {
                    NewestVehicles.Clear();
                    NewestVehicles.Add(this.AllVehicles[i]);
                }
                else if (this.AllVehicles[i].Age == vehicleToCompare.Age)
                {
                    NewestVehicles.Add(this.AllVehicles[i]);
                }
            }
            return(NewestVehicles);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to find vehicles with an expired technical inspection and add them to a list
        /// </summary>
        /// <returns>a VehicleContainer that contains all vehicles with their expired TI</returns>
        public VehicleContainer FindVehiclesWithExpiredTI()
        {
            VehicleContainer VehiclesWithExpiredTI = new VehicleContainer();

            DateTime Today = DateTime.Today;

            for (int i = 0; i < this.AllVehicles.Count; i++)
            {
                Vehicle vehicle = this.AllVehicles[i];
                if (Today.Year > vehicle.TechnicalInspection.Year)
                {
                    vehicle.TechnicalInspection = Convert.ToDateTime("1111/1/1");
                    VehiclesWithExpiredTI.Add(vehicle);
                }
                else if (vehicle.TechnicalInspection.Year == Today.Year && vehicle.TechnicalInspection.Month - vehicle.TechnicalInspection.Month <= 1)
                {
                    VehiclesWithExpiredTI.Add(vehicle);
                }
            }


            VehiclesWithExpiredTI.SortWithDelegate((left, right) => {
                if (left.Producer.CompareTo(right.Producer) > 0)
                {
                    return(1);
                }
                else if (left.Producer.CompareTo(right.Producer) < 0)
                {
                    return(-1);
                }

                // producer names are equal, sort by model next
                if (left.Model.CompareTo(right.Model) > 0)
                {
                    return(1);
                }
                else if (left.Model.CompareTo(right.Model) < 0)
                {
                    return(-1);
                }

                // model names are equal, sort by ID
                if (left.LicensePlate.CompareTo(right.LicensePlate) > 0)
                {
                    return(1);
                }
                else if (left.LicensePlate.CompareTo(right.LicensePlate) < 0)
                {
                    return(-1);
                }

                return(0); // vehicles are identical
            });

            //VehiclesWithExpiredTI.Sort();


            return(VehiclesWithExpiredTI);
        }
Esempio n. 3
0
        /// <summary>
        /// a method to find all matching vehicles from another VehiclesRegister
        /// </summary>
        /// <param name="other">a vehicle register to which to compare against</param>
        /// <returns>a VehicleContainer that contains all matching vehicles</returns>
        public VehicleContainer FindMatches(VehiclesRegister other)
        {
            VehicleContainer matches = new VehicleContainer();

            VehicleContainer selfContainer  = this.AllVehicles;
            VehicleContainer otherContainer = other.AllVehicles;

            for (int i = 0; i < selfContainer.Count; i++)
            {
                for (int j = 0; j < otherContainer.Count; j++)
                {
                    if (selfContainer[i].Equals(otherContainer[j]))
                    {
                        matches.Add(selfContainer[i]);
                    }
                }
            }

            return(matches);
        }
Esempio n. 4
0
 /// <summary>
 /// Method adds a vehicle to the list
 /// </summary>
 /// <param name="vehicle"></param>
 public void Add(Vehicle vehicle)
 {
     AllVehicles.Add(vehicle);
 }