Esempio n. 1
0
        public void Buy_XRPTest()
        {
            User    test    = new MoneyTransfer657.User("Erik Lomas");
            decimal xrp_bal = test.Xrp;

            test.Buy_XRP(1m);
            Assert.AreEqual(test.Xrp, (xrp_bal + 1m));
        }
Esempio n. 2
0
        private void BuyCoinButton_Click(object sender, RoutedEventArgs e)
        {
            decimal amount_to_buy;
            bool    isNumeric = decimal.TryParse(coinBuySellAmountTextBox.Text, out amount_to_buy);

            if (isNumeric == false)
            {
                MessageBox.Show("Only enter numbers for amount of coins to buy/sell");
                return;
            }
            if (selectCoinComboBox.SelectedIndex == 0)
            {
                //BTC
                if ((amount_to_buy * btc_price) > user.Usd)
                {
                    MessageBox.Show("You dont have enough USD to make this purchase");
                    return;
                }
                Thread buy = new Thread(() =>
                {
                    user.Buy_BTC(amount_to_buy);
                    user.Add_Transaction("global", user.Username, "BTC", amount_to_buy.ToString(), "buy crypto");
                });
                buy.Start();
                buy.Join();
            }
            else if (selectCoinComboBox.SelectedIndex == 1)
            {
                //ETH
                if ((amount_to_buy * eth_price) > user.Usd)
                {
                    MessageBox.Show("You dont have enough USD to make this purchase");
                    return;
                }
                Thread buy = new Thread(() =>
                {
                    user.Buy_ETH(amount_to_buy);
                    user.Add_Transaction("global", user.Username, "ETH", amount_to_buy.ToString(), "buy crypto");
                });
                buy.Start();
                buy.Join();
            }
            else if (selectCoinComboBox.SelectedIndex == 2)
            {
                //XRP
                if ((amount_to_buy * xrp_price) > user.Usd)
                {
                    MessageBox.Show("You dont have enough USD to make this purchase");
                    return;
                }
                Thread buy = new Thread(() =>
                {
                    user.Buy_XRP(amount_to_buy);
                    user.Add_Transaction("global", user.Username, "XRP", amount_to_buy.ToString(), "buy crypto");
                });
                buy.Start();
                buy.Join();
            }
            else
            {
                MessageBox.Show("Please select a coin before buying or selling.");
            }

            Update_Owned();
            MessageBox.Show("Purchase Complete");
        }