예제 #1
0
        private void BuyGame_Click(object sender, RoutedEventArgs e)
        {
            //get games from CartBox
            if (CartBox.SelectedItems.Count < 1)
            {
                MessageBox.Show("No game has been selected yet!");
                return;
            }
            //check prices
            string valueincart = valueTxtBox.Text;

            valueincart = valueincart.Replace("$", string.Empty);
            string moneyinwallet = moneyTxtBox.Text;

            moneyinwallet = moneyinwallet.Replace("$", string.Empty);
            //get double values;
            double value = Convert.ToDouble(valueincart);
            double money = Convert.ToDouble(moneyinwallet);

            //check salary
            if (value > money)
            {
                MessageBox.Show("You do not have sufficient funds for this purchase!");
                return;
            }
            double endMoney = money - value;

            //create shop list
            List <MyGameData> sGames = new List <MyGameData>();

            for (int i = 0; i < CartBox.SelectedItems.Count; i++)
            {
                GameData game = this.CartBox.SelectedItems[i] as GameData;
                sGames.Add(new MyGameData()
                {
                    Image = game.Image, Name = game.Title
                });
            }
            string sMoney = endMoney + "$";
            //instantiate the event args and pass it each value
            CartUpdateEventArgs args = new CartUpdateEventArgs(sGames, sMoney);

            //raise the event with the updated arguments
            CartUpdated(this, args);
            //close window
            this.Close();
        }
예제 #2
0
        private void AddtoCart_ButtonClicked(object sender, CartUpdateEventArgs e)
        {
            Consoletxtblock.Text += "Add to Cart Button Clicked..." + Environment.NewLine;
            List <MyGameData> myNewGamelst = new List <MyGameData>();

            myNewGamelst      = e.Games;
            MoneyTextBox.Text = e.Money;

            //add new games to MyGamesBox
            for (int i = 0; i < myNewGamelst.Count; i++)
            {
                my_games_items.Add(myNewGamelst[i]);
            }

            //add items to ListView MyGamesBox.
            //MyGamesBox.Items.Clear(); //empty mygamesbox
            MyGamesBox.ItemsSource = my_games_items;
        }