コード例 #1
0
        private void SellAll_btn_Click(object sender, EventArgs e)
        {
            // get selected item value
            Stock stock = MyStocks_listView.SelectedItems.Count > 0 ?
                          (Stock)MyStocks_listView.SelectedItems[0].Tag : null;

            if (stock == null)
            {
                return;
            }                              // to handle listView idiot 2 step item selection process

            // get the current price
            double askPrice = 0.0;

            for (int i = 0; i < StockMarket_listView.Items.Count; i++)
            {
                Stock s = (Stock)StockMarket_listView.Items[i].Tag;
                if (s.Company.Equals(stock.Company))
                {
                    askPrice = (double)s.AskPrice;
                    break;
                }
            }

            // make the sell
            Console.WriteLine(stock.PurchasePrice + ", " + askPrice);
            DB_API.DeleteStocksByCompany(account_id, stock.Company, (double)stock.PurchasePrice, askPrice);

            // update MyStocks listView
            PopulateMyStocksListView();
        }