Ejemplo n.º 1
0
        private void lvStockQuotesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Entities.StockDb SelectedStock = (Entities.StockDb)lvStockQuotesList.SelectedItem;

            string symbol = SelectedStock.Symbol;

            List <Entities.QuotesHistory> QuotesHistoryList = Entities.QuotesHistoryLoader.LoadQuotesHistory(symbol);

            RefreshStockList();
            FirstChartControl.DataSource = QuotesHistoryList;
            chartControl.DataSource      = QuotesHistoryList;
            chartControl2.DataSource     = QuotesHistoryList;
        }
Ejemplo n.º 2
0
        private void lvStockQuotesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lvStockQuotesList.SelectedItem == null)
            {
                //if there is no selection dissable buttons Update and Add
                btnBuy.IsEnabled = false;
            }

            else
            {
                btnBuy.IsEnabled = true;
                Entities.StockDb SelectedStock = (Entities.StockDb)lvStockQuotesList.SelectedItem;

                lblCompanyNameBuyOrder.Content = SelectedStock.Symbol;
                lbBidBuyOrder.Content          = SelectedStock.Bid;
                lbAskBuyOrder.Content          = SelectedStock.Ask;
            }
        }
Ejemplo n.º 3
0
        private void btnBuy_Click(object sender, RoutedEventArgs e)
        {
            int Quantity;

            // this part is cheking if record already exists in database
            // if exists it updates record
            // if not it adds new record

            if (int.TryParse(tbQuantityBuy.Text, out Quantity))
            {
                Entities.StockDb   SelectedStock               = (Entities.StockDb)lvStockQuotesList.SelectedItem;
                Entities.Portfolio SelectedPortfolio           = Model.DBA_Portfolio.GetUpdatedPortfolio(Globals.SelectedPortfolio);
                List <String>      SymbolStringLIstOwnedByUser = new List <String>();
                SymbolStringLIstOwnedByUser = Globals.Db.GetAllStockOwnedByUser(Globals.SelectedPortfolio);

                decimal maxQty = (decimal)SelectedPortfolio.Cash / (decimal)SelectedStock.Ask;

                maxQty = Math.Floor(maxQty);

                if (Quantity != 0)
                {
                    if ((Quantity * SelectedStock.Ask) <= SelectedPortfolio.Cash)
                    {
                        if (SymbolStringLIstOwnedByUser.Contains(SelectedStock.Symbol, StringComparer.OrdinalIgnoreCase))
                        {
                            //adds transaction record and updates cash in portfolio
                            Globals.Db.AddBuyTransaction(SelectedPortfolio, SelectedStock, Quantity);

                            //adds stock into users portfolio
                            Globals.Db.UpdatePortfolioStock(SelectedPortfolio, SelectedStock, Quantity);
                        }
                        else
                        {
                            //adds transaction record and updates cash in portfolio
                            Globals.Db.AddBuyTransaction(SelectedPortfolio, SelectedStock, Quantity);

                            //updates stock volume and average price in portfolio
                            Globals.Db.AddPortfolioStock(SelectedPortfolio, SelectedStock, Quantity);
                        }

                        tbQuantityBuy.Text = "";
                        RefreshStockOwnedByPortfolio();
                        UpdateUserBalance();
                        UpdatePortfolioInfo();
                        RefreshTransactions();



                        MessageBox.Show("Transaction completed", "Confirmation", MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("You can buy only:  " + maxQty + "  Shares of: " + SelectedStock.Name, "Confirmation", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Qty cannot be 0", "Confirmation", MessageBoxButton.OK);
                }
            }
            else
            {
                MessageBox.Show("Invalid Qty", "Confirmation", MessageBoxButton.OK);
            }
        }