C # выбирая из списка и поля ввода и передавая параметры - PullRequest
0 голосов
/ 24 февраля 2019

Я пытаюсь создать небольшое приложение.Один из которых берет выбранный выбор из списка, в данном примере это автомобиль на прокат.Затем он отображает цену аренды автомобиля в зависимости от выбранного автомобиля и сохраняет этот выбор.Затем пользователь вводит количество дней, в течение которых он хотел бы арендовать автомобиль, после чего на отдельной странице отображаются результаты стоимости, выбора автомобиля и продолжительности наемных дней.

Я заполнил список ивозможность нажать кнопку, чтобы перейти на следующую страницу.Моя основная проблема заключается в передаче данных для отображения на новой странице.

Ниже приведен код из главного окна:

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();

        }
    }
}

, а следующее из окна результатов:

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;
        }
    }

}

Я полный нуб в этом и просто пытаюсь справиться с этим.Любая помощь будет оценена.Это первое сообщение о Stackoverflow, поэтому оно может показаться повсеместным.

Спасибо 101

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...