0

I'm trying to create a small app. One of which takes the chosen selection from a list box, in this example a car for hire. It then displays the price of the car hire depending on the car chosen and stores this selection. The user then inputs the number of days they would wish to hire the car for than on a separate page displays the results of the cost, car selection and length of hired days.

I've populated the list and am able to press the button to navigate to the next page. My main problem is passing the data over to be displayed onto the new page.

Below is the code from the Main window:

namespace CarHireLtd
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //Declare variables to be used throughout the program
        int cost;
        string carSelection;
        string hireLength;



        public MainWindow()
        {
            InitializeComponent();
            // we need to populate the listbox with the selection of
            //vehicles to hire when the window loads

            lstCars.Items.Add("TOYOTA IQ");
            lstCars.Items.Add("MINI COOPER S");
            lstCars.Items.Add("VW POLO");
            lstCars.Items.Add("AUDI TT");
            lstCars.Items.Add("MERCEDES A 220");
            lstCars.Items.Add("RANGE ROVER EVOQUE");
            lstCars.Items.Add("JAGUAR XJ");


        }

        private void LstCars_SelectionChanged(object sender, 
SelectionChangedEventArgs e)
    {
            // find out which item the user has selected
            int table = lstCars.SelectedIndex + 1;

            // initialise the textblock to be empty
            txtCost.Text = "";
            if (table == 1) //If the table matches a certain item, display 
                           //  the cost of 
                            //the rental and store the cost in the 
                               //variable 'cost'
            {
                carSelection = "TOYOTA IQ";
                cost = 10;
                txtCost.Text = "Your rental for this vehicle is £10 per 
day";
            }
            else if (table == 2)
            {
                {
                    carSelection = "MINI COOPER S";
                    cost = 18;
                    txtCost.Text = "Your rental for this vehicle is £18 
per day";
                }
            }
            else if (table == 3)
            {
                {
                    carSelection = "VW POLO";
                    cost = 15;
                    txtCost.Text = "Your rental for this vehicle is £15 
per day";
                }
            }
            else if (table == 4)
            {
                {
                    carSelection = "AUDI TT";
                    cost = 30;
                    txtCost.Text = "Your rental for this vehicle is £30 
per day";
                }
            }
            else if (table == 5)
            {
                {
                    carSelection = "MERCEDES A 220";
                    cost = 40;
                    txtCost.Text = "Your rental for this vehicle is £40 
per day";
                }
            }
            else if (table == 6)
            {
                {
                    carSelection = "RANGE ROVER EVOQUE";
                    cost = 50;
                    txtCost.Text = "Your rental for this vehicle is £50 
per day";
                }
            }
            else if (table == 7)
            { 
                {
                    carSelection = "JAGUAR XJ";
                    cost = 55;
                    txtCost.Text = "Your rental for this vehicle is £55 
per day";
                }
            }





        }

        private void TxtHireLength_TextChanged(object sender, 
TextChangedEventArgs e)
        {
            hireLength = txtHireLength.Text; //Read in amount of hired 
days from input box
        }

        public void BtnNextAge_Click(object sender, RoutedEventArgs e)
        {
            AgeWindow Window2 = new AgeWindow();
            Window2.Show();
            this.Close();

        }
    }
}

and the following is from the ResultsWindow:

namespace CarHireLtd
{
    /// <summary>
    /// Interaction logic for ResultsWindow.xaml
    /// </summary>
    public partial class ResultsWindow : Window
    {
        public ResultsWindow(string cost, string carSelection, string 
hireLength)
        {
            InitializeComponent();

            blkResults.Text = "You selected a " + carSelection + "\nfor: " 
+ hireLength + "\nthe total hire cost will be " + cost +hireLength;
        }
    }

}

I'm a complete noob at this and just trying to get to grips with it. Any help would be appreciated. This is the first post on Stackoverflow too so it might seem all over the place.

Thanks

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Colin Swan
  • 13
  • 3

0 Answers0