public string this[string vehicle]
        {
            get
            {
                string result = null;
                switch (vehicle)
                {
                case "RegistrationNumber":
                    if (string.IsNullOrEmpty(RegistrationNumber))
                    {
                        result = "It cannot be empty";
                    }
                    break;

                case "Model":
                    if (string.IsNullOrEmpty(Model))
                    {
                        result = "It cannot be empty";
                    }
                    break;

                case "Manufacturer":
                    if (string.IsNullOrWhiteSpace(Manufacturer))
                    {
                        result = "it cannot be empty";
                    }
                    else if (Manufacturer.Length < 3)
                    {
                        result = "it must be minimum of 3 characters";
                    }
                    break;

                case "MakeYear":
                    if (string.IsNullOrWhiteSpace(MakeYear.ToString()))
                    {
                        result = "it cannot be empty";
                    }
                    break;

                case "TankCapacity":
                    if (string.IsNullOrWhiteSpace(TankCapacity.ToString()))
                    {
                        result = "it cannot be empty";
                    }
                    break;
                }
                if (ErrorCollection.ContainsKey(vehicle))
                {
                    ErrorCollection[vehicle] = result;
                }
                else if (result != null)
                {
                    ErrorCollection.Add(vehicle, result);
                }

                OnPropertyChanged("ErrorCollection");
                return(result);
            }
        }
Пример #2
0
        //Method to withdraw water from tank
        public string WithdrawWater(int gallonsToWithdraw)
        {
            //Declare local variables
            string withdrawString;

            //Add water if not at capacity
            if (gallonsToWithdraw <= WaterLevel)
            {
                WaterLevel     = (WaterLevel - gallonsToWithdraw);
                withdrawString = $" Gallons Drained: {gallonsToWithdraw.ToString()} \r\n Current Water Level: {WaterLevel.ToString()} \r\n Tank Capacity: {TankCapacity.ToString()}";
            }
            else
            {
                withdrawString = $" Insufficient water level. \r\n Maximum Allowed Gallons: {WaterLevel.ToString()}";
            }

            //Return value
            return(withdrawString);
        }
Пример #3
0
        //Method to add water to tank
        public string AddWater(int gallonsToAdd)
        {
            //Declare local variables
            string addString;

            //Add water if not at capacity
            if (gallonsToAdd <= (TankCapacity - WaterLevel))
            {
                WaterLevel += gallonsToAdd;
                addString   = $" Gallons Added: {gallonsToAdd.ToString()} \r\n Current Water Level: {WaterLevel.ToString()} \r\n Tank Capacity: {TankCapacity.ToString()}";
            }
            else
            {
                addString = $" WARNING! Tank will overflow. \r\n Current Water Level: {WaterLevel.ToString()} \r\n Maximum Additional Gallons: {(TankCapacity - WaterLevel).ToString()}";
            }

            //Return value
            return(addString);
        }