Example #1
0
        private void purchaseButton_Click(object sender, EventArgs e)
        {
            double newBalance       = 0.0;
            double cost_of_purchase = 0.0;

            int selectedQty = System.Convert.ToInt32(this.qtyNumericUpDown.Value.ToString());

            //MessageBox.Show("Current qty: " + selectedQty.ToString());

            cost_of_purchase = selectedQty * current_price;
            // MessageBox.Show("current_price" + current_price);
            if (cost_of_purchase == 0.0)
            {
                MessageBox.Show("Sorry, we couldn't obtain current bid price.\n please try again later.\n", "Couldn't retreive bid pricing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (cost_of_purchase > loggedUser.balance)
            {
                MessageBox.Show("Sorry, you don't have sufficient funds to purchase the stocks.\n", "Insufficient funds", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                //  MessageBox.Show("newbalance " + newBalance);
                // MessageBox.Show("loggedUser.balance " + this.loggedUser.balance);
                newBalance = this.loggedUser.balance - cost_of_purchase;
                bool         result;
                DialogResult dialogRes = MessageBox.Show("You are about to purchase " + selectedQty + " stock from " + stock[0].name + "\nIt will cost you " + cost_of_purchase.ToString() + "\nYour new balance will be " + newBalance.ToString(),
                                                         "Confirmation for purchase", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                DateTime today = DateTime.Today;
                if (dialogRes == DialogResult.Cancel)
                {
                    return;
                }

                result = bLogic.UpdateBalance(newBalance, loggedUser.userName, loggedUser.id, stockId, current_price, today, selectedQty, "Bought");
                if (result == true)
                {
                    cashTextBox.Text        = newBalance.ToString();
                    this.loggedUser.balance = newBalance;
                }
                qtyNumericUpDown.Value = 1;
            }
            return;
        }
Example #2
0
        private void sellButton_Click(object sender, EventArgs e)
        {
            double newBalance = 0.0;
            double bid        = System.Convert.ToDouble(stockDataGridView.SelectedRows[0].Cells["Current Bid"].Value.ToString());
            string symbol     = stockDataGridView.SelectedRows[0].Cells["Symbol"].Value.ToString();
            string name       = stockDataGridView.SelectedRows[0].Cells["Name"].Value.ToString();

            int selectedQty = System.Convert.ToInt32(this.qtyNumericUpDown.Value.ToString());

            if (selectedQty > System.Convert.ToInt32(stockDataGridView.SelectedRows[0].Cells["Total Stocks"].Value.ToString()))
            {
                MessageBox.Show("Sorry, you selected too much Qty to sell.\n", "Invalid QTY", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (bid <= 0.00)
            {
                MessageBox.Show("Sorry, invalid bid price to sell.\n", "Invalid Bid price", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                newBalance = this.loggedUser.balance + (bid * selectedQty);
                bool         result;
                DialogResult dialogRes = MessageBox.Show("You are about to sell " + selectedQty + " stock from " + name + "\nYour new balance will be " + newBalance.ToString(),
                                                         "Confirmation for purchase", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                DateTime today = DateTime.Today;
                if (dialogRes == DialogResult.Cancel)
                {
                    return;
                }
                int stockID = bLogic.GetStockID(symbol);
                //MessageBox.Show("Arguments-> newBalance "+newBalance+" loggedID "+loggedUser.id+" stockID "+stockID);
                result = bLogic.UpdateBalance(newBalance, loggedUser.userName, loggedUser.id, stockID, bid, today, selectedQty, "Sold");
                if (result == true)
                {
                    cashTextBox.Text        = newBalance.ToString();
                    this.loggedUser.balance = newBalance;
                }
                qtyNumericUpDown.Value = 1;
            }
            populateControls(this.zedPieControl);
            return;
        }
Example #3
0
        private void purchaseButton_Click(object sender, EventArgs e)
        {
            if (watchlistDataGridView.SelectedCells.Count > 0)
            {
                int selectedrowindex = watchlistDataGridView.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = watchlistDataGridView.Rows[selectedrowindex];

                watchlistGridSelectedSymbol = Convert.ToString(selectedRow.Cells["Symbol"].Value);

                current_price = System.Convert.ToDouble(selectedRow.Cells["Current Ask"].Value);

                stock   = null;
                stock   = bLogic.GetStockInfo(watchlistGridSelectedSymbol);
                stockId = stock[0].id;
            }
            else
            {
                MessageBox.Show("Sorry, nothing selected to purchase.\n", "None selected to purchase", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            double newBalance       = 0.0;
            double cost_of_purchase = 0.0;

            int selectedQty = System.Convert.ToInt32(this.qtyNumericUpDown.Value.ToString());

            cost_of_purchase = selectedQty * current_price;


            if (cost_of_purchase == 0.0)
            {
                MessageBox.Show("Sorry, we couldn't obtain current bid price.\n please try again later.\n", "Couldn't retreive bid pricing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (cost_of_purchase > loggedUser.balance)
            {
                MessageBox.Show("Sorry, you don't have sufficient funds to purchase the stocks.\n", "Insufficient funds", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                newBalance = this.loggedUser.balance - cost_of_purchase;
                bool         result;
                DialogResult dialogRes = MessageBox.Show("You are about to purchase " + selectedQty + " stock from " + stock[0].name + "\nIt will cost you " + cost_of_purchase.ToString() + "\nYour new balance will be " + newBalance.ToString(),
                                                         "Confirmation for purchase", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                DateTime today = DateTime.Today;
                if (dialogRes == DialogResult.Cancel)
                {
                    return;
                }

                result = bLogic.UpdateBalance(newBalance, loggedUser.userName, loggedUser.id, stockId, current_price, today, selectedQty, "Bought");

                if (result == true)
                {
                    //cashTextBox.Text = newBalance.ToString();
                    this.loggedUser.balance = newBalance;
                }
                qtyNumericUpDown.Value = 1;
            }
            return;
        }