C#

C# IF ListBox Arrays 2D Arrays Read File Example 1 Example Midterm 1 Example Midterm 2 Example 5 Example 7 Group Project 2 Example 9 Group Project 2
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

C# : Example 1

2017-01-01

alt text

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace assignment_6
{
    public partial class Automotive : Form
    {
        public Automotive()
        {
            InitializeComponent();
        }

        const double TAX_RATE = 0.06;
        const double LABOR_RATE = 20.00;

        double serviceLabor = 0;
        double parts = 0;

        private void validate()
        {
            bool parts_ok = false;
            bool labor_ok = false;
            double temp;

            if (double.TryParse(tb_parts.Text, out temp))
            {
                parts_ok = true;
            }
            if (double.TryParse(tb_labor.Text, out temp))
            {
                labor_ok = true;
            }

            if (parts_ok && labor_ok)
            {
                calculateSummary();
            }
            else
            {
                MessageBox.Show("Please only enter numbers in Parts and Labor.");
            }
        }

        private void calculateSummary()
        {
            serviceLabor = 0;
            parts = 0;

            serviceLabor = serviceLabor + OilLubeCharges();
            serviceLabor = serviceLabor + FlushCharges();
            serviceLabor = serviceLabor + MiscCharges();
            serviceLabor = serviceLabor + calculateLabor();

            parts = parts + calculateParts();

            print_service.Text = serviceLabor.ToString();
            print_parts.Text = parts.ToString();
            print_tax.Text = TaxCharges().ToString();
            print_total.Text = TotalCharges().ToString();

        }

        private double OilLubeCharges()
        {
            double m_return = 0;

            if (cb_oil.Checked)
            {
                m_return = m_return + 26;
            }
            if (cb_lube.Checked)
            {
                m_return = m_return + 18;
            }

            return m_return;
        }
        private double FlushCharges()
        {
            double m_return = 0;

            if (cb_radiator.Checked)
            {
                m_return = m_return + 30;
            }
            if (cb_transmission.Checked)
            {
                m_return = m_return + 80;
            }

            return m_return;
        }

        private double MiscCharges()
        {
            double m_return = 0;

            if (cb_inspection.Checked)
            {
                m_return = m_return + 15;
            }
            if (cb_muffler.Checked)
            {
                m_return = m_return + 100;
            }
            if (cb_tire.Checked)
            {
                m_return = m_return + 20;
            }
            return m_return;
        }

        private double calculateLabor()
        {
             double m_labor;

            if (double.TryParse(tb_labor.Text, out m_labor))
            {
                return m_labor * LABOR_RATE;
            } else
            {
                return 0;
            }

        }

        private double calculateParts()
        {
            double m_part;

            if (double.TryParse(tb_parts.Text, out m_part))
            {
                return m_part;
            }
            else
            {
                return 0;
            }

        }

        private double TaxCharges()
        {
            return parts * TAX_RATE;
        }

        private double TotalCharges()
        {
            return serviceLabor + parts + TaxCharges();
        }

        private void clearAll()
        {
            ClearOilLube();
            ClearFlushes();
            ClearMisc();
            ClearOther();
            ClearFees();
            cb_oil.Focus();
        }

        private void ClearOilLube()
        {
            cb_oil.Checked = false;
            cb_lube.Checked = false;
        }
        private void ClearFlushes()
        {
            cb_radiator.Checked = false;
            cb_transmission.Checked = false;
        }
        private void ClearMisc()
        {
            cb_inspection.Checked = false;
            cb_muffler.Checked = false;
            cb_tire.Checked = false;
        }
        private void ClearOther()
        {
            tb_parts.Text = "";
            tb_labor.Text = "";
        }
        private void ClearFees()
        {
            print_service.Text = "";
            print_parts.Text = "";
            print_tax.Text = "";
            print_total.Text = "";
        }

        private void btn_calculate_Click(object sender, EventArgs e)
        {
            validate();
        }

        private void btn_clear_Click(object sender, EventArgs e)
        {
            clearAll();
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}