Пример #1
0
        // car:        i_VehicelParams = (  enum color,                 enum num_OfDoors)
        // motorcycle: i_VehicelParams = (  float engine volume,        enum licence)
        // Truck:      i_VehicelParams = (  bool IsTruckRefrigerated,   float TrunkSize)
        public void AddVehicleToGarage(HoldAddGarageVehicleParams i_UserParams, params float[] i_VehicelParams) // (1) in menu
        {
            Vehicle         myVehicle = null;
            VehicleInGarage vehicleInGarage;
            bool            vehicleExist = r_VehiclesDataBase.TryGetValue(i_UserParams.LicencePlate, out vehicleInGarage);

            if (vehicleExist)
            {
                this.ChangeStatusOfListedCar(i_UserParams.LicencePlate, eVehicleStatus.Repairing);
                throw new ArgumentException(k_ErrVehicleExsit);
            }
            else
            {
                try
                {
                    myVehicle = VehicalGarageCreator.CreateVehicleForGarage(i_UserParams, i_VehicelParams);
                    if (myVehicle == null)
                    {
                        throw new ArgumentException(k_ErrVehicleNotSupported);
                    }
                    else
                    {
                        vehicleInGarage = new VehicleInGarage(myVehicle, i_UserParams.ClientName, i_UserParams.PhoneNumber);
                        r_VehiclesDataBase.Add(i_UserParams.LicencePlate, vehicleInGarage);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        public static Vehicle CreateVehicleForGarage(HoldAddGarageVehicleParams i_UserParams, params float[] i_VehicelParams)
        {
            Vehicle      myVehicle = null;
            Engine       engine    = getEngine(i_UserParams.Engine);
            List <Wheel> wheels    = new List <Wheel>();

            try
            {
                for (int i = 0; i < i_UserParams.Wheels.AmountOfWheels; i++)
                {
                    wheels.Add(new Wheel(i_UserParams.Wheels.WheelManufacturerName, i_UserParams.Wheels.MaxManufacturerPressure, i_UserParams.Wheels.WheelPressureStatus));
                }

                HoldVehicleParams vehicleParams = new HoldVehicleParams(i_UserParams.VehicleModel, i_UserParams.LicencePlate, engine, wheels);
                switch (i_UserParams.VehicleType)
                {
                case eVehicleTypes.Car:
                    myVehicle = new Car((Car.eColors)i_VehicelParams[0], (Car.eNumOfDoors)i_VehicelParams[1], vehicleParams);
                    break;

                case eVehicleTypes.Motorcycle:
                    myVehicle = new Motorcycle((uint)i_VehicelParams[0], vehicleParams, (Motorcycle.eMotorcycleLicenceType)i_VehicelParams[1]);
                    break;

                case eVehicleTypes.Truck:
                    bool coldTrank = i_VehicelParams[0] == 1;
                    myVehicle = new Truck(coldTrank, (float)i_VehicelParams[1], vehicleParams);
                    break;
                }

                if (!isVehicleSupported(myVehicle))
                {
                    myVehicle = null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(myVehicle);
        }