public void updateMarketStatus() { Stock marketCheck = new Stock(); if (marketCheck.IsOpenStockMarket()) { marketStatus.Text = "Open"; marketStatus.ForeColor = System.Drawing.Color.Green; } else { marketStatus.Text = "Closed"; marketStatus.ForeColor = System.Drawing.Color.Red; } }
private void whatButton_Click(object sender, EventArgs e) { try { DateTime from = fromPicker.Value; DateTime to = toPicker.Value; Stock stock = new Stock(); string[] splitResults = stock.getHistory(companySymbolBox.Text, from, from, 'm').Split(new Char[] { ',' }); double fromPrice = Convert.ToDouble(splitResults[7]); splitResults = stock.getHistory(companySymbolBox.Text, to, to, 'm').Split(new Char[] { ',' }); double toPrice = Convert.ToDouble(splitResults[7]); int numShares = Convert.ToInt32(purchasedSharesBox.Text); double profit = (toPrice - fromPrice) * numShares; if (profit >= 0) MessageBox.Show("You would have made " + profit.ToString("C2") + " had you bought " + numShares + " share(s) of " + companySymbolBox.Text + " in " + from.Year + " and then sold in " + to.Year + "\nFrom: " + fromPrice.ToString("C2") + "\nTo: " + toPrice.ToString("C2")); else MessageBox.Show("You would have lost " + profit.ToString("C2") + " had you bought " + numShares + " share(s) of " + companySymbolBox.Text + " in " + from.Year + " and then sold in " + to.Year + "\nFrom: " + fromPrice.ToString("C2") + "\nTo: " + toPrice.ToString("C2")); } catch { MessageBox.Show("Something is wrong with this."); } }
private void searchResults_SelectedIndexChanged(object sender, EventArgs e) { Stock stock = new Stock(); int index = searchResults.SelectedIndex; if (index >= 0) { Company company = results[index]; tradeCompanyName.Text = company.Name; tradeSymbol.Text = company.Symbol; tradeStockPrice.Text = company.getStockPrice().ToString("C2"); tradeExchange.Text = stock.getExchange(company.Symbol); tradeIPO.Text = company.IPOyear; tradeIndustry.Text = company.Industry; tradeHigh.Text = stock.getStockYearHigh(company.Symbol).ToString("C2"); tradeLow.Text = stock.getStockYearLow(company.Symbol).ToString("C2"); List<Holding> holdings = user.Holdings; //loop through the purchased stocks. foreach (Holding holding in holdings) { if (holding.stockSymbol.Equals(company.Symbol)) { tradeCurrentSharesBox.Text = holding.numOfShares.ToString(); break; } else { tradeCurrentSharesBox.Text = "0"; } } } }
public double getStockPrice() { Stock stock = new Stock(); return stock.getLatestValue(Symbol); }