コード例 #1
0
        private void btnSell_Click(object sender, RoutedEventArgs e)
        {
            Entities.Portfolio userPortfolio = Model.DBA_Portfolio.GetUpdatedPortfolio(Globals.SelectedPortfolio);
            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(tbQuantitySell.Text, out quantity))
            {
                if (quantity != 0)
                {
                    String  symbol;
                    decimal sellPrice = 0;


                    Entities.PortfolioStock SelectedStockOwnedByUSer = (Entities.PortfolioStock)lvStockOwnedByUser.SelectedItem;
                    List <Entities.StockDb> DatabasePrices           = Globals.Db.GetAllStockPricesFromDatabase();


                    if (SelectedStockOwnedByUSer.SharesOwned >= quantity)
                    {
                        symbol = SelectedStockOwnedByUSer.Symbol;

                        foreach (Entities.StockDb E in DatabasePrices)
                        {
                            if (E.Symbol == symbol)
                            {
                                sellPrice = (decimal)E.Bid;
                            }
                        }

                        Globals.Db.AddSellTransaction(symbol, quantity, sellPrice, SelectedStockOwnedByUSer, userPortfolio);

                        Globals.Db.DelteAllRecordWhereQtyIsZeroFromPortfolio();
                        RefreshStockOwnedByPortfolio();
                        UpdateUserBalance();
                        UpdatePortfolioInfo();

                        tbQuantitySell.Text = "";
                        UpdatePortfolioInfo();
                        RefreshTransactions();
                        MessageBox.Show("Transaction completed", "Confirmation", MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("You can sell only: " + SelectedStockOwnedByUSer.SharesOwned, "Confirmation", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Qty cannot be 0", "Confirmation", MessageBoxButton.OK);
                }
            }
            else
            {
                MessageBox.Show("Invalid Qty", "Confirmation", MessageBoxButton.OK);
            }
        }
コード例 #2
0
        private void lvStockOwnedByUser_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Entities.PortfolioStock SelectedStock = (Entities.PortfolioStock)lvStockOwnedByUser.SelectedItem;

            if (lvStockQuotesList.SelectedItem == null)
            {
                btnSell.IsEnabled              = false;
                lbAskBuyOrder.Content          = "...";
                lbBidSellOrder.Content         = "....";
                lblCompanyNameBuyOrder.Content = ".....";
            }

            else
            {
                if (SelectedStock == null)
                {
                    btnSell.IsEnabled              = false;
                    lbAskBuyOrder.Content          = "...";
                    lbBidSellOrder.Content         = "....";
                    lblCompanyNameBuyOrder.Content = ".....";
                }
                else
                {
                    btnSell.IsEnabled               = true;
                    lbBidSellOrder.Content          = SelectedStock.CurrentBId;
                    lbAskSellOrder.Content          = SelectedStock.AveragePurchasedPrice;
                    lblCompanyNameSellOrder.Content = SelectedStock.Symbol;
                }
            }
        }