Beispiel #1
0
        private void CalculateButton_OnClick(object sender, RoutedEventArgs e)
        {
            double fuel, distance;

            if (!double.TryParse(_viewModel.Fuel, out fuel) || !double.TryParse(_viewModel.Distance, out distance))
            {
                return;
            }

            FuelEconomyType ecoType = _viewModel.SelectedFuelEcoType;
            double          result  = 0;

            switch (ecoType.Id)
            {
            case "lpk":
                if (Math.Abs(distance) > double.Epsilon)
                {
                    result = fuel / (distance / 100);
                }
                break;

            case "mpg":
                if (Math.Abs(fuel) > double.Epsilon)
                {
                    result = distance / fuel;
                }
                break;
            }
            _viewModel.Result = result.ToString("F");
        }
Beispiel #2
0
        private void InitializeFullEcoTypes()
        {
            var firstEconomyType = new FuelEconomyType
            {
                Id           = "lpk",
                Text         = "L/100 km",
                DistanceText = "Distance (kilometers)",
                FuelText     = "Fuel used (liters)"
            };
            var secondEconomyType = new FuelEconomyType
            {
                Id           = "mpg",
                Text         = "Miles per gallon",
                DistanceText = "Distance (miles)",
                FuelText     = "Fuel used (gallons)"
            };

            FuelEcoTypes = new List <FuelEconomyType>
            {
                firstEconomyType,
                secondEconomyType
            };
        }