/// <summary> /// Method used for loading the stocks from the portfolio, reads the symbols and get the stock object from these /// </summary> /// <returns>List of stocks</returns> public List <Stock> loadFromPortfolio() { List <Stock> stocks = new List <Stock>(); // get the symbols from the portfolio List <string> symbols = readFromPortfolio(); // get all the stocks JsonHandler jh = new JsonHandler(); List <Stock> allStocks = jh.getAllStocks(); // sort the stock list List <Stock> sortedAllStocks = quickSort(allStocks, "Symbol", false); // foreach symbol foreach (string s in symbols) { // search the stock list for the symbol int searchResult = SearchAlgorithm.binarySearch(s, sortedAllStocks); if (searchResult != -1) { // if a match is found add it to the list stocks.Add(sortedAllStocks[searchResult]); } } return(stocks); }
/// <summary> /// resultList loads a list with content depending on what button is pressed, i.e. market, stocks, news, portfolio or search /// </summary> /// <param name="Data"></param> /// <param name="Market"></param> /// <param name="o"></param> public ResultList(String Data, String Market, object o) { // initilize classes mw = o as MainWindow; jh = new JsonHandler(); c = new Controller(); //this.Controls.Add() DataButtonClicked = Data; // set background color this.BackColor = c.highlightWhite; // initilize all components except the list inilizeComponents(); // check databutton and prodcede accordingly switch (DataButtonClicked) { case "market": // if market is clicked we load all news and filter for selected market allNewsList = jh.getAllNews(); newsList = c.filterNews(allNewsList, Market); if (newsList.Count == 0) { listsEmpty = true; } break; case "stocks": // if stocks is clicked we load all stocks and filter for selected market allStocksList = jh.getAllStocks(); filteredStockList = c.filterStocks(allStocksList, Market); if (filteredStockList.Count == 0) { listsEmpty = true; } break; case "news": // if news is clicked we load all news allNewsList = jh.getAllNews(); newsList = c.filterNews(allNewsList, Market); if (newsList.Count == 0) { listsEmpty = true; } break; case "portfolio": // if portfolio is clicked we load from the portfolio file filteredStockList = c.loadFromPortfolio(); if (filteredStockList.Count == 0) { listsEmpty = true; } break; case "search": // if a search inputed we load all stocks and search them for matches and load those allStocksList = jh.getAllStocks(); filteredStockList = c.search(allStocksList, Market); if (filteredStockList.Count == 0) { listsEmpty = true; } break; } // if the list isnĀ“t empty we procede if (!listsEmpty) { currentSide = 1; contentAdder(currentSide); } }