Ejemplo n.º 1
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            bool isCar        = CarRadioButton.Checked;
            bool isTruck      = TruckRadioButton.Checked;
            bool isCarOrTruck = isCar || isTruck;

            if (isCar)
            {
                CalculatiorResultLabel.Visible = true;
                ErrorLabel.Text            = "";
                EmployeeSalaryTextBox.Text = "0";
            }
            else if (isTruck)
            {
                CalculatiorResultLabel.Visible = true;
                ErrorLabel.Text = "";
            }

            if (isCarOrTruck)
            {
                VehicleInformation vehicle = new VehicleInformation
                {
                    PurchaseCost      = Decimal.Parse(PurchaseCostTextBox.Text),
                    PurchaseYear      = int.Parse(PurchaseYearTextBox.Text),
                    MileageOnPurchase = int.Parse(MileagePurchaseTextBox.Text),
                    MileageCurrent    = int.Parse(MileageCurrentTextBox.Text),
                    ValueCurrent      = Decimal.Parse(CurrentValueTextBox.Text),
                    FuelCosts         = Decimal.Parse(FuelCostTextBox.Text),
                    InsuranceCosts    = Decimal.Parse(InsuranceTextBox.Text),
                    CarWashCosts      = Decimal.Parse(CarWashTextBox.Text),
                    ServiceCosts      = Decimal.Parse(ServiceCostTextBox.Text),
                    ParkingCosts      = Decimal.Parse(ParkingCostTextBox.Text),
                    OtherCosts        = Decimal.Parse(OthersTextBox.Text),
                    EmployeeSalary    = Decimal.Parse(EmployeeSalaryTextBox.Text)
                };

                if (isCar)
                {
                    Car car = new Car();
                    Dictionary <string, decimal> carCosts = car.CalculateMaintenanceCosts(vehicle);
                    CalculatiorResultLabel.Text = car.GenerateFormattedReport(carCosts);
                }
                else if (isTruck)
                {
                    Truck truck = new Truck();
                    Dictionary <string, decimal> truckCosts = truck.CalculateMaintenanceCosts(vehicle);
                    CalculatiorResultLabel.Text = truck.GenerateFormattedReport(truckCosts);
                }
            }
            else
            {
                ErrorLabel.Text = "Set the type of the Vehicle!";
            }
        }