Beispiel #1
0
        private void buttonPERatio_Click(object sender, RoutedEventArgs e)
        {
            // Clear the display, then validate the inputs...
            labelPERatio.Content = "£-.--";
            stockData stock      = null;
            Decimal   stockPrice = 0.0M;

            if (ValidateGetPrice(textPrice.Text, out stockPrice) == false)
            {
                return;
            }
            if (ValidateGetStock(out stock) == false)
            {
                return;
            }
            // Call the calculation function and display...
            Decimal?dividendYield = GetDividendYield(stock, stockPrice);

            if (dividendYield != null)
            {
                if (dividendYield == 0)
                {
                    if (sender is Button) // Don't show messagebox if called from listbox)
                    {
                        MessageBox.Show("Sorry, cannot calculate the P/E Ration with a dividend of zero.", "JP", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    labelPERatio.Content = ((decimal)(stockPrice / dividendYield)).ToString("0.000");
                }
            }
        }
Beispiel #2
0
        private bool ValidateGetStock(out stockData stockData)
        {
            if (listStockType.SelectedItem == null)
            {
                MessageBox.Show("Please select a stock symbol.", "JP", MessageBoxButton.OK, MessageBoxImage.Error);
                stockData = null;
                return(false);
            }
            //Find the relevant stock details from our allStock list...
            string stockSymbol = listStockType.SelectedItem.ToString();

            stockData = allStock.FirstOrDefault(st => st.symbol == stockSymbol);
            if (stockData == null)
            {
                MessageBox.Show("Sorry, unrecognised stock symbol [" + stockSymbol + "].", "JP", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return(stockData != null);
        }
Beispiel #3
0
        private decimal?GetDividendYield(stockData stock, decimal stockPrice)
        {
            // Perform the correct dividend calculation, according to the information in the class
            decimal?dividendYield = null;

            switch (stock.type)
            {
            case "Common":
                dividendYield = stock.lastDividend / stockPrice;
                break;

            case "Preferred":
                dividendYield = (stock.fixedDividend * stock.parValue / 100M) / stockPrice;
                break;

            default:
                MessageBox.Show("Sorry, unrecognised stock type [" + stock.type + "].", "JP", MessageBoxButton.OK, MessageBoxImage.Error);
                break;
            }
            return(dividendYield);
        }
Beispiel #4
0
        private void buttonDividendYield_Click(object sender, RoutedEventArgs e)
        {
            // Clear the display, then validate the inputs...
            labelDividendYield.Content = "£-.--";
            stockData stock      = null;
            Decimal   stockPrice = 0.0M;

            if (ValidateGetPrice(textPrice.Text, out stockPrice) == false)
            {
                return;
            }
            if (ValidateGetStock(out stock) == false)
            {
                return;
            }
            // Call the calculation function and display...
            Decimal?dividendYield = GetDividendYield(stock, stockPrice);

            if (dividendYield != null)
            {
                labelDividendYield.Content = "£" + ((Decimal)dividendYield).ToString("0.000");
            }
        }