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 Midterm 1

2017-01-01

Example Midterm 1

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 midterm1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

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

        private void listBox_workshops_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button_calculate_Click(object sender, EventArgs e)
        {

            // variables
            string workshop, location;
            int fee = 0;
            int days = 0;
            int lodging = 0;

            // only if both list boxes are selected, do calculation
            if ((listBox_workshops.SelectedIndex != -1) && (listBox_locations.SelectedIndex != -1))
            {
                workshop = listBox_workshops.SelectedItem.ToString().Substring(0, 2);
                location = listBox_locations.SelectedItem.ToString().Substring(0, 2);

                switch (workshop)
                {
                    case "Ha": fee = 1000; days = 3; break;
                    case "Ti": fee = 800; days = 3; break;
                    case "Su": fee = 1500; days = 3; break;
                    case "Ne": fee = 1300; days = 5; break;
                    case "Ho": fee = 500; days = 1; break;
                }

                switch (location)
                {
                    case "Au": lodging = 150; break;
                    case "Ch": lodging = 225; break;
                    case "Da": lodging = 175; break;
                    case "Or": lodging = 300; break;
                    case "Ph": lodging = 175; break;
                    case "Ra": lodging = 150; break;
                }

                int lodging_price = lodging * days;

                label_output.Text = "Registration: $" + fee + "
" +
                    "Lodging: $" + lodging + " x " + days + " days" + "= $" + lodging_price + "
" +
                    "Total: $" + (fee + lodging_price);
            }
            else
            {
                // one of the boxes was not selected. determine which box it was and show message.
                if (listBox_workshops.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select a workshop.");
                }
                else
                {
                    MessageBox.Show("Please select a location.");
                }

            }

        }

        private void button_clear_Click(object sender, EventArgs e)
        {
            // clear everything
            label_output.Text = "";
            listBox_workshops.SelectedIndex = -1;
            listBox_locations.SelectedIndex = -1;
        }
    }
}