예제 #1
0
 public StockListitem buildWatchlistStockItem(int watchlistID, YahooStockSearchResult selectedItem, decimal quantity, double price = 0, decimal pricePurchase = 0)
 {
     return(new StockListitem()
     {
         CategoryID = watchlistID,
         symbol = selectedItem.symbol,
         name = selectedItem.name,
         exch = selectedItem.exch,
         exchDisp = selectedItem.exchDisp,
         typeDisp = selectedItem.typeDisp,
         Quantity = Convert.ToInt32(quantity),
         PriceCurrent = price,
         PricePurchase = pricePurchase
     });
 }
예제 #2
0
        /// <summary>
        /// Selects the stock which the user searched for
        /// </summary>
        private void btnGetStock_Click(object sender, EventArgs e)
        {
            ComboBox cbMultiLine = stockSearchView.SearchBox;

            StockListitem          watchlistStock = new StockListitem();
            YahooStockSearchResult selectedItem   = (YahooStockSearchResult)cbMultiLine.SelectedItem;

            // Add Stock to List
            if (selectedItem != null)
            {
                watchlistStock = depotModel.buildWatchlistStockItem(selectedItem, nupStockQuantity.Value);
                selectedStock  = watchlistStock;
                makeBuyProposition();
            }
        }
예제 #3
0
        /// <summary>
        /// Adds stock to watchlist
        /// </summary>
        private void btnAddStock_Click(object sender, EventArgs e)
        {
            ComboBox cbMultiLine = stockSearchView.SearchBox;

            StockListitem          watchlistStock = new StockListitem();
            YahooStockSearchResult selectedItem   = (YahooStockSearchResult)cbMultiLine.SelectedItem;

            // Add Stock to List
            if (selectedItem != null)
            {
                watchlistStock = model.buildWatchlistStockItem(watchlist.WatchListID, selectedItem, nupStockQuantity.Value);

                // Save to data
                insertStockAsync(watchlistStock);
                updateStockPricesInListView();
            }
        }
예제 #4
0
        public void measureItem(ref object sender, ref MeasureItemEventArgs e)
        {
            // Get the ComboBox and the item.
            ComboBox lst = sender as ComboBox;
            string   txt = "";

            if (lst.Items.Count > 0)
            {
                YahooStockSearchResult stock = (YahooStockSearchResult)lst.Items[e.Index];
                txt = stock.Display;
            }

            // Measure the string.
            SizeF txt_size = e.Graphics.MeasureString(txt, this.Font);

            // Set the required size.
            e.ItemHeight = (int)txt_size.Height + 2 * ItemMargin;
            e.ItemWidth  = (int)txt_size.Width;
        }
예제 #5
0
 /// <summary>
 /// transforms the JSON string into a C# object
 /// </summary>
 public static IList<YahooStockSearchResult> getSearchResultsList(string jsonString)
 {
     IList<YahooStockSearchResult> result = new List<YahooStockSearchResult>();
     if(jsonString != null && jsonString.Length > 0)
     {
         JObject json = JObject.Parse(jsonString);
         var jsonResultSet = json["ResultSet"]["Result"];
         if(jsonResultSet != null)
         {
             IList<JToken> jsonResults = jsonResultSet.Children().ToList();
             if(jsonResults.Count > 0)
             {
                 foreach (JToken jsonResult in jsonResults)
                 {
                     YahooStockSearchResult searchResult = JsonConvert.DeserializeObject<YahooStockSearchResult>(jsonResult.ToString());
                     result.Add(searchResult);
                 }
             }
         }
     }
     return result;
 }
예제 #6
0
        public void drawItem(ref object sender, ref DrawItemEventArgs e)
        {
            // Get the ComboBox and the item.
            ComboBox lst = sender as ComboBox;
            string   txt = "";

            if (lst.Items.Count > 0)
            {
                YahooStockSearchResult stock = (YahooStockSearchResult)lst.Items[e.Index];
                txt = stock.Display;
            }

            // Draw the background.
            e.DrawBackground();

            // See if the item is selected.
            if ((e.State & DrawItemState.Selected) ==
                DrawItemState.Selected)
            {
                // Selected. Draw with the system highlight color.
                e.Graphics.DrawString(txt, this.Font,
                                      SystemBrushes.HighlightText, e.Bounds.Left,
                                      e.Bounds.Top + ItemMargin);
            }
            else
            {
                // Not selected. Draw with ComboBox's foreground color.
                using (SolidBrush br = new SolidBrush(e.ForeColor))
                {
                    e.Graphics.DrawString(txt, this.Font, br,
                                          e.Bounds.Left, e.Bounds.Top + ItemMargin);
                }
            }

            // Draw the focus rectangle if appropriate.
            e.DrawFocusRectangle();
        }