private async Task fillLabels(string str) { try { IEX_API.DTOs.QuoteDto qd = await IEX_API.API.GetQuote(Main_Menu.getSymbol(str)); IEX_API.DTOs.CompanyInfoDto cid = await IEX_API.API.GetCompanyInfo(Main_Menu.getSymbol(str)); IEX_API.DTOs.FinancialDataDto fd = await IEX_API.API.GetFinancialData(Main_Menu.getSymbol(str)); if (cid != null && qd != null) { LBL_Company_Name.Text = qd.CompanyName != "" ? qd.CompanyName : "No Information"; LBL_Company_market.Text = qd.PrimaryExchange.ToString() != "" ? qd.PrimaryExchange.ToString() : "No Information"; LBL_Company_Sector.Text = qd.Sector.ToString() != "" ? qd.Sector.ToString() : "No Information"; if (qd.Open > qd.LatestPrice) { LBL_Company_Current_Price.Text = qd.LatestPrice.ToString() != null ? "$" + qd.LatestPrice.ToString("0.##") + " ▼" : "No Information"; } else { LBL_Company_Current_Price.Text = qd.LatestPrice.ToString() != null ? "$" + qd.LatestPrice.ToString("0.##") + " ▲" : "No Information"; } LBL_Company_Opening_price.Text = qd.Open.ToString() != null ? "$" + qd.Open.ToString("0.##") : "No Information"; LBL_Company_CEO.Text = cid.Ceo != "" ? cid.Ceo : "No Information"; LBL_LINK.Text = cid.Website != "" ? cid.Website : "No Information"; LB_DESCRIPTION.Text = LB_DESCRIPTION.Text != "" ? $"{cid.Description}" : "No Information"; LB_DAY_RANGE.Text = qd.Low.ToString() != null && qd.High.ToString() != null ? $"{qd.Low.ToString("0.##")} - {qd.High.ToString("0.##")}" : "No Information"; LB_WEEK_RANGE.Text = qd.Week52Low.ToString() != null && qd.Week52High.ToString() != null ? $"{qd.Week52Low.ToString("0.##")} - {qd.Week52High.ToString("0.##")}" : "No Information"; LB_PE_RATIO.Text = qd.PeRatio.ToString() != null ? $"{qd.PeRatio}" : "No Information"; LB_BETA.Text = fd.Beta != 0 ? $"{fd.Beta}" : "No Information"; LB_REVENUE.Text = fd.Revenue != 0 ? $"{fd.Revenue.ToString("#,##0,,M")}" : "No Information"; LB_REV_PER_EMPLOYEE.Text = fd.RevenuePerEmployee != 0 ? $"{fd.RevenuePerEmployee.ToString("#,##0,K")}" : "No Information"; LB_MARKETCAP.Text = fd.Marketcap != 0 ? $"{fd.Marketcap.ToString("#,##0,,M")}" : "No Information"; } } catch (System.Net.WebException e) { MessageBox.Show(e.Message); } catch (Exception e) { MessageBox.Show("Error " + e.Message); } }
private async void btnSearchNews_Click(object sender, EventArgs e) { System.IO.Stream str = Properties.Resources.Windows_Navigation_Start; System.Media.SoundPlayer snd = new System.Media.SoundPlayer(str); snd.Play(); var searchString = tbSearchNews.Text; try { if (!Main_Menu.searchableNames.Contains(searchString)) { newsSearchErrorProvider.SetError(tbSearchNews, "Please enter a valid search"); } else { newsSearchErrorProvider.Clear(); _newsSymbol = Main_Menu.getSymbol(searchString); await updateNews(_newsSymbol); } } catch (System.Net.WebException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show("Something bad happened"); } }
private async Task paintGraph(string str) { try { foreach (var series in stocksChart.Series) { series.Points.Clear(); } IReadOnlyDictionary <DateTimeOffset, IEX_API.DTOs.HistoricalDataDto> dictionary = await IEX_API.API.GetHistoricalData(Main_Menu.getSymbol(str)); int i = 0; stocksChart.ChartAreas[0].AxisX.Minimum = 0; foreach (DateTimeOffset data in dictionary.Keys) { stocksChart.Series["Price"].Points.AddXY(i, dictionary[data].High); i++; } } catch (System.Net.WebException e) { MessageBox.Show(e.Message); } catch (Exception e) { MessageBox.Show("Error " + e.Message); } }
private async void btnCalculate_Click(object sender, EventArgs e) { System.IO.Stream str = Properties.Resources.Windows_Navigation_Start; System.Media.SoundPlayer snd = new System.Media.SoundPlayer(str); snd.Play(); if (!companyError && !numberError && !priceError) { string company = tbCompany.Text; IEX_API.DTOs.QuoteDto qd = await IEX_API.API.GetQuote(Main_Menu.getSymbol(company)); double price = qd.LatestPrice; int numberBought = Convert.ToInt32(tbNumberBought.Text); double priceBought = Convert.ToDouble(tbPrice.Text); double priceSumNow = price * numberBought; double priceSumThen = priceBought * numberBought; tbTotalEarnings.Text = "$" + (priceSumNow - priceSumThen).ToString("0.##"); if (priceSumNow > priceSumThen) { lblMessage.Text = "Congratulations!"; if (voiceEnabled) { Stream s = Properties.Resources.applause; System.Media.SoundPlayer snds = new System.Media.SoundPlayer(s); snds.Play(); } } else { lblMessage.Text = "We are sorry to hear that!"; if (voiceEnabled) { Stream strs = Properties.Resources.sadTrombone; System.Media.SoundPlayer snds = new System.Media.SoundPlayer(strs); snds.Play(); } } } /*else * { * if(!Main_Menu.searchableNames.Contains(tbCompany.Text)) * { * errorProvider_company.SetError(tbCompany, "Please enter a valid name"); * } * else * { * errorProvider_company.Clear(); * } * if (String.IsNullOrWhiteSpace(tbPrice.Text) && String.IsNullOrWhiteSpace(tbNumberBought.Text)) * { * errorProviderBuyingPrice.SetError(tbPrice, "Please enter a valid number"); * errorProviderNumberStocks.SetError(tbNumberBought, "Please enter a valid number"); * } * else if (String.IsNullOrWhiteSpace(tbPrice.Text) && !String.IsNullOrWhiteSpace(tbNumberBought.Text)) * { * errorProviderBuyingPrice.SetError(tbPrice, "Please enter a valid number"); * errorProviderNumberStocks.Clear(); * } * else if (String.IsNullOrWhiteSpace(tbNumberBought.Text) && !String.IsNullOrWhiteSpace(tbPrice.Text)) * { * errorProviderNumberStocks.SetError(tbNumberBought, "Please enter a valid number"); * errorProviderBuyingPrice.Clear(); * } * }*/ }