CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2013
    Posts
    7

    Cool Inexperienced Needing Help

    I know it is a mess right now, but I've been trying to figure out a solution for a few days and tried several things. Basically, I have two list boxes for locations and workshops(. I don't know how to store the number of days a workshop lasts so that I can use that data in the final total(workshopListBox and locationListBox). Each workshop choice has a registration fee and a number of days tied to it. Each location has lodging fee tied to it. When both options are selected, data needs to be stored for the registration fee, the total lodging fee(lodging fee * days), and the total cost(total lodging fee + registration fee). My lack of understanding has caused me issue with being able to store the number of days(based on the workshop selection) so that it can be used to calculate the total lodging fee when the location is selected.

    ANY help is appreciated, as I clearly don't know what I'm doing. Even if I am totally doing this wrong, I would love to know. Thank you in advance, and let me know if I didn't provide enough info.

    Code:
    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 workshopselector
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void workshopListBoxrm_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            private void calculateButtonrm_Click(object sender, EventArgs e)
            {
                
                string workshop;
                string location;
    
             
    
                decimal handlingstressregfee = 1000m;
                decimal timemanagementregfee = 800m;
                decimal supervisionskillsregfee = 1500m;
                decimal negotiationregfee = 1300m;
                decimal howtointerviewregfee = 500m;
    
                decimal regfee;
                decimal lodgingfee;
                decimal totalcost;
                
                
              
                
    
                
    
                decimal austinlodgingfee = 150m;
                decimal chicagolodgingfee = 225m;
                decimal dallaslodgingfee = 175m;
                decimal orlandolodgingfee = 300m;
                decimal phoenixlodgingfee = 175m;
                decimal raleighlodgingfee = 150m;
    
                
    
    
    
                //throw down the workshop situations
                if (workshopListBoxrm.SelectedIndex != -1)
                {
                    workshop = workshopListBoxrm.SelectedItem.ToString();
    
                    //determine the registration costs
                   
                    switch (workshop)
                    {
                    
                    
                    
                        if (workshop == "Handling Stress")
                        {
                            days = 3;
                           
                            regoutputLabelrm.Text = handlingstressregfee.ToString("c");
                            regfee = 1000m;
                        }
                        else if (workshop == "Time Management")
                        {
                            days = 3;
                            
                    regfee = 800m;
                   regoutputLabelrm.Text = supervisionskillsregfee.ToString("c");
                        }
                        else if (workshop == "Supervision Skills")
                        {
                            days = 3;
                            
                            regfee = 1500m;
                             regoutputLabelrm.Text = supervisionskillsregfee.ToString("c");
                        }
                        else if (workshop == "Negotiation")
                        {
                            days = 5;
                            
                    regfee = 1300m;
                    regoutputLabelrm.Text = negotiationregfee.ToString("c");
                        }
                        else if(workshop == "How to Interview")
                            days = 1;
                   
                    regfee = 500m;
                     regoutputLabelrm.Text = howtointerviewregfee.ToString("c");
               
    
    
                }
                else
                {
                    MessageBox.Show("Select a Workshop");
                
           
    
    
    
                   
                            
                            
                          
          
    
    
                    {
                         if (locationListBoxrm.SelectedIndex != -1)
                         {
                    location = locationListBoxrm.SelectedItem.ToString();
    
                    //determine the location costs
    
                    switch (location)
                    {
                        case "Austin":
                            lodgingoutputLabelrm.Text = austinlodgingfee.ToString();
                            lodgingfee = 150m * days;
                            break;
                        case "Chicago":
                            lodgingoutputLabelrm.Text = chicagolodgingfee.ToString();
                            lodgingfee = 225m * days;
                            break;
                        case "Dallas":
                            lodgingoutputLabelrm.Text = dallaslodgingfee.ToString();
                                lodgingfee = 175m * days;
                            break;
                        case "Orlando":
                            lodgingoutputLabelrm.Text = orlandolodgingfee.ToString();
                            lodgingfee = 300m * days;
                            break;
                        case "Phoenix":
                            lodgingoutputLabelrm.Text = phoenixlodgingfee.ToString();
                            lodgingfee = 175m * days;
                            break;
                        case "Raleigh":
                            lodgingoutputLabelrm.Text = raleighlodgingfee.ToString();
                            lodgingfee = 150m * days;
                            break;
                            totalcost = regfee + lodgingfee;
                           totaloutputLabelrm.Text = totalcost.ToString("c");
                    }
                         }

  2. #2
    Join Date
    Feb 2013
    Posts
    7

    Re: Inexperienced Needing Help

    Can anyone point me in the right direction to solve this? I still haven't found a solution.

  3. #3
    Join Date
    Mar 2013
    Posts
    3

    Re: Inexperienced Needing Help

    You need to create the Workshop class and the Location class. Something like this:

    Code:
    class Workshop
    {
      public string Name { get; set; } // or public int ID to use it as a key
      public decimal RegistrationFee { get; set; }
      public int Days { get; set; }
    
      public Workshop(string name, decimal registrationFee, int days) { ... }
    }
    
    class Location
    {
      public string Name { get; set; }
      public decimal LodgingFee { get; set; }
    
      public Location(string name, decimal lodgingFee) { ... }
    }
    Then you create lists of the workshops and locations:

    Code:
    var workshops = new List<Workshop>()
    {
      new Workshop("Bla bla", 100, 20),
      new Workshop("Muahaha", 10, 10)
    };
    
    var locations = new List<Location>()
    {
      new Location("My super location 1", 10),
      new Location("My super location 2", 20),
    }
    Then you set these lists to your listboxes' datasources and set DisplayMember:

    Code:
    lbWorkshops.DataSource = workshops;
    lbWorkshops.DisplayMember = "Name"; // note this, it will use Name property to display it in the listbox
    
    lbLocations.DataSource = locations;
    lbLocations.DisplayMember = "Name";
    When you need to get selected workshop and location you write this:

    Code:
    var workshop = (Workshop)lbWorkshops.SelectedItem;
    var location = (Location)lbLocations.SelectedItem;
    // now you can get the necessary properties:
    decimal workshopRegFee = workshop.RegistrationFee;
    decimal locationLodgingFee = location.LodgingFee;
    I wrote this code in the browser and didn't test it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured