/// <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); }
private FlowLayoutPanel mainPanel; // main panel used when adding the NewsReader class /// <summary> /// Class for creating a FlowLayoutout panel containing a list of news /// </summary> /// <param name="s"></param> /// <param name="m"></param> public IntegratedNewsList(String s, String m) { // set market and symbol Market = m; Symbol = s; // initilize classes c = new Controller(); jh = new JsonHandler(); // set the panels margin this.Margin = new Padding(1); // get hte news from the particular symbol newsList = jh.getSingleNews(Symbol, Market); // if the news list is not empty, sort it after date of published if (newsList.Count != 0) { // initilize buttons newsList = c.sortNewsList(newsList, "pubDate", true); initilizeNewsList(); } else { listsNotEmpty = false; } }
/// <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); } }
JsonHandler js; //Json handler /// <summary> /// Displays information about a stock. /// </summary> /// <param name="type"></param> /// <param name="s"></param> /// <param name="m"></param> public InfoDisplay(String type, String s, String m) { //Set generic width of mercury buttons buttonWidth = 120; buttonHeight = 30; js = new JsonHandler(); chartPanel = new Panel(); //Initialize controller class c = new Controller(); symbol = s; market = m; //Check if type is a stock or market typeOfStock = type; if (typeOfStock == "stock") { stockList = js.getSingleStock(market, symbol, "month"); } //Type is market, create dummy stocks from market values else if (typeOfStock == "market") { //Markets can't be added to portfolio portfolioCompatible = false; //Empty stock list stockList = new List <Stock>(); List <Market> marketList = js.getSingleMarket(market, "month"); foreach (Market temp in marketList) { //Assign stock from current market value Stock tempStock = new Stock(); tempStock.Symbol = temp.MarketName; tempStock.Latest = temp.Latest; tempStock.OpenVal = temp.OpenVal; tempStock.Updated = temp.Updated; tempStock.Volume = "-"; stockList.Add(tempStock); } } stockList = checkStock(stockList); stockList = c.sortStockList(stockList, "Updated", false); Padding = new Padding(5, 3, 5, 3); this.BackColor = c.highlightWhite; //Get latest stock info Stock info = stockList.ElementAt(stockList.Count - 1); //Initialize panels chartTypePanel = new FlowLayoutPanel(); timeSpanPanel = new FlowLayoutPanel(); centerChartType = new FlowLayoutPanel(); centerTimeSpan = new FlowLayoutPanel(); timeSpanFiller = new Panel(); chartTypeFiller = new Panel(); stockInfoPanel = new FlowLayoutPanel(); //Create and add chart type buttons and listeners for charts //Candlestick candlestickButton = new MercuryButton("Candlestick", "candlestick"); candlestickButton.Click += new EventHandler(chooseChartType); candlestickButton.Width = buttonWidth; candlestickButton.Height = buttonHeight; //Line chart (Latest) lineChartButton = new MercuryButton("Latest", "line"); lineChartButton.Click += new EventHandler(chooseChartType); lineChartButton.Width = buttonWidth; lineChartButton.Height = buttonHeight; //Bar chart (Change) barChartButton = new MercuryButton("Change", "bar"); barChartButton.Click += new EventHandler(chooseChartType); barChartButton.Width = buttonWidth; barChartButton.Height = buttonHeight; //Add chart type buttons to panel chartTypePanel.Controls.Add(lineChartButton); chartTypePanel.Controls.Add(candlestickButton); chartTypePanel.Controls.Add(barChartButton); //Add button and event listener to control timespan value dayButton = new MercuryButton("Day", "day"); dayButton.Click += new EventHandler(chooseTimeSpan); dayButton.Width = buttonWidth; dayButton.Height = buttonHeight; weekButton = new MercuryButton("Week", "week"); weekButton.Click += new EventHandler(chooseTimeSpan); weekButton.Width = buttonWidth; weekButton.Height = buttonHeight; monthButton = new MercuryButton("Month", "month"); monthButton.Click += new EventHandler(chooseTimeSpan); monthButton.Width = buttonWidth; monthButton.Height = buttonHeight; //Add timespan buttons to panel timeSpanPanel.Controls.Add(monthButton); timeSpanPanel.Controls.Add(weekButton); timeSpanPanel.Controls.Add(dayButton); //Add stock control panel to display this.Controls.Add(stockInfoPanel); //Initialize labels containing stock info stockInfoLabel = new Label(); stockNameLabel = new Label(); stockInfoLabel.Height = 30; stockNameLabel.Height = 30; stockInfoLabel.Margin = new Padding(0, 1, 0, 1); stockNameLabel.Margin = new Padding(0, 1, 0, 1); stockInfoPanel.Padding = new Padding(0, 1, 0, 1); //Initialize stock name String stockName = ""; /* * If the info panel displays market info, set the name * of the market based on the symbol. */ switch (info.Symbol) { case "LSE": stockName = "London Stock Exchange"; break; case "OMX": stockName = "Stockholm Stock Exchange"; break; case "NYSE": stockName = "New York Stock Exchange"; break; default: stockName = info.Name; break; } //Initialize new tooltip ToolTip tt = new ToolTip(); /* * Set text of first label. * - Latest * - Opening value * - Change (percent) * - Volume */ stockInfoLabel.Text = "Latest: " + info.Latest + " | Opening: " + info.OpenVal + " | Change: " + info.Percent + " | Volume: " + info.Volume; //Add tooltip to stock info label tt.SetToolTip(stockInfoLabel, stockInfoLabel.Text); //Set label to name and symbol of stock stockNameLabel.Text = stockName + " | " + info.Symbol; //Set font of info labels stockInfoLabel.Font = c.mercuryFont; stockNameLabel.Font = new Font("Segoe UI", 12, FontStyle.Regular); //Add labels to panel stockInfoPanel.Controls.Add(stockNameLabel); stockInfoPanel.Controls.Add(stockInfoLabel); //Add button for adding stocks to portfolio MercuryButton portfolio = new MercuryButton("Add to portfolio", info.Symbol); portfolio.Width = 170; portfolio.Height = 30; //Disable portfolio if current type is market if (!portfolioCompatible) { portfolio.Enabled = false; portfolio.BackColor = Color.LightGray; } //Add listener to portfolio button portfolio.Click += new EventHandler(addStockToPortfolio); //Add portfolio button to panel stockInfoPanel.Controls.Add(portfolio); //Add panels to info display this.Controls.Add(chartPanel); this.Controls.Add(centerChartType); //Add chart type and filler centerChartType.Controls.Add(chartTypeFiller); centerChartType.Controls.Add(chartTypePanel); //Add panel that centers time span buttons this.Controls.Add(centerTimeSpan); //Add time span and filler panel centerTimeSpan.Controls.Add(timeSpanFiller); centerTimeSpan.Controls.Add(timeSpanPanel); //Set all chart buttons to unclicked resetchartButtons(); //Set all time span buttons to unclicked resetTimeSpanButtons(); //Initialize new chart initilizeChart(typeOfChart, timeSpan); //Set line chart button to clicked lineChartButton.BackColor = c.mercuryBlue; //Set month button to clicked monthButton.BackColor = c.mercuryBlue; //Initliaze new integrated news list news = new IntegratedNewsList(symbol, m); //Set background color of news list news.BackColor = c.highlightWhite; //Assign news panel to news list newsPanel = news; //Add news panel to info display this.Controls.Add(newsPanel); }