Exemple #1
0
 public void CalculateResults()
 {
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     decimal TotalDividendCount = 0;
     decimal TotalDividendStockValue = 0;
     decimal YearDiv = 0;
     decimal QuarterDiv = 0;
     decimal MonthlyDiv = 0;
     decimal DividendTotalPercentage = 0;
     decimal MarketTotalPrice = 0;
     DataTable dt = DividendStocks.GetCurrentDividends();
     decimal Purchaseprice = 0;
     string Stocks = Uti.GetMultiSymbols(dt);
     string[] AnnualDiv = Uti.SplitStockData(YahooFinance.GetValues(Stocks, "d", true));
     string[] DivYield = Uti.SplitStockData(YahooFinance.GetValues(Stocks, "y", true));
     // l1 is last trade price, c1 change in price, b is bid price, a is ask price; Ask price is current price as you're asking for a price when selling therefore that is the price of your portfolio
     string[] CurrentStockPrice = Uti.SplitStockData(YahooFinance.GetValues(Stocks, "a", true));
     //decimal val = dt.Rows.Count;
     //decimal StatusVal = 0;
     //val = Math.Round(90 / val, 0);
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         string id = dt.Rows[i]["id"].ToString();
         Purchaseprice = Convert.ToDecimal(dt.Rows[i]["purchaseprice"]);
         YearDiv += (Convert.ToDecimal(dt.Rows[i]["numberofshares"]) * Convert.ToDecimal(AnnualDiv[i]));
         TotalDividendStockValue += (Convert.ToDecimal(dt.Rows[i]["numberofshares"]) * Purchaseprice);
         TotalDividendCount++;
         DividendTotalPercentage += DivYield[i] == "N/A" ? 0 : Convert.ToDecimal(DivYield[i]);
         if (dt.Rows[i]["symbol"].ToString() == "SIL")
         {
             DividendTotalPercentage += (decimal).09;
         }
         //if (dt.Rows[i]["symbol"].ToString() == "GDX")
         //{
         //    DividendTotalPercentage -= Convert.ToDecimal(DivYield[i]);
         //    DividendTotalPercentage += (decimal).80;
         //}
         MarketTotalPrice += (Convert.ToDecimal(dt.Rows[i]["numberofshares"]) * Convert.ToDecimal(CurrentStockPrice[i]));
         //StatusVal += val;
         //if (StatusVal < 88)
         //    pbStatus.InvokeEx(x => x.Value = Convert.ToInt32(StatusVal));
     }
     DividendTotalPercentage = DividendTotalPercentage / TotalDividendCount;
     QuarterDiv = (YearDiv / 4);
     MonthlyDiv = (YearDiv / 12);
     //pbStatus.InvokeEx(x => x.Value = 100);
     //pbStatus.InvokeEx(x => x.Visible = false);
     //lblStatus.InvokeEx(x => x.Visible = false);
     pw.Close();
     MessageBox.Show("Cost Basis: $" + Math.Round(TotalDividendStockValue, 2) + "\n\nMarket Value: $" + Math.Round(MarketTotalPrice, 2) + "\n\nAnnual Dividend: $" + Math.Round(YearDiv, 2) + "\n\n" + "Quarterly Dividend: $" + Math.Round(QuarterDiv, 2) + "\n\nMonthly Dividend: $" + Math.Round(MonthlyDiv, 2) + "\n\nPortfolio Dividend Yield: " + Math.Round(DividendTotalPercentage, 2) + "%");
 }
Exemple #2
0
 public void AddRemoveDividends(ListBox lb, string stockActive)
 {
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     lstID.Clear();
     int selectedItemsCount = lb.SelectedItems.Count;
     if (selectedItemsCount > 1)
     {
         foreach (DataRowView drv in lb.SelectedItems)
         {
             DividendStocks.UpdateDividendStock(drv.Row["id"].ToString(), stockActive);
             lstID.Add(Convert.ToInt32(drv.Row["id"]));
         }
     }
     else
     {
         DividendStocks.UpdateDividendStock(lb.SelectedValue.ToString(), stockActive);
     }
     LoadAllDividends();
     LoadCurrentDividends();
     SelectStocks(selectedItemsCount);
     pw.Close();
 }
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (!ValidateAll())
     {
         return;
     }
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     if (Edit)
     {
         DividendStocks.UpdateDividendStock(ID, txtSymbol.Text, txtStockName.Text, ddlIndustry.Text, ddlDividendInterval.Text);
         ReloadMainDividends();
         Program.MainMenu.lbAllDividends.SelectedValue = Convert.ToInt32(ID);
         pw.Close();
         this.Close();
     }
     else
     {
         ID = DividendStocks.NewDividendStock(txtSymbol.Text, txtStockName.Text, ddlIndustry.Text, ddlDividendInterval.Text);
         Program.MainMenu.LoadAllDividends();
         Program.MainMenu.lbAllDividends.SelectedValue = Convert.ToInt32(ID);
         pw.Close();
         this.Close();
     }
 }
 private void btnDeleteShares_Click(object sender, EventArgs e)
 {
     if (txtSharePrice.Text != "")
     {
         if (MessageBox.Show("Delete?", "Delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             PleaseWait pw = new PleaseWait();
             pw.Show();
             Application.DoEvents();
             DividendStocks.DeleteShare(ddlSharePurchaseDate.SelectedValue.ToString());
             LoadPurchaseDates();
             LoadPurchaseData();
             ReloadMainDividends();
             pw.Close();
         }
     }
 }
Exemple #5
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (txtNumberOfShares.Text == "")
     {
         MessageBox.Show("Please enter number of shares.");
         return;
     }
     try
     {
         decimal.Parse(txtNumberOfShares.Text);
     }
     catch
     {
         MessageBox.Show("Please enter numbers only.");
         txtNumberOfShares.Focus();
         return;
     }
     if (txtPurchasePrice.Text == "")
     {
         MessageBox.Show("Please enter purchase price.");
         return;
     }
     try
     {
         decimal.Parse(txtPurchasePrice.Text);
     }
     catch
     {
         MessageBox.Show("Please enter numbers only.");
         txtPurchasePrice.Focus();
         return;
     }
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     if (Edit)
     {
         DividendStocks.UpdateShare(Convert.ToDecimal(txtPurchasePrice.Text), Convert.ToDecimal(txtNumberOfShares.Text), DividendPriceID, dtpPurchaseDate.Value);
     }
     else
     {
         DividendStocks.NewShare(Convert.ToDecimal(txtPurchasePrice.Text), Convert.ToDecimal(txtNumberOfShares.Text), ID, dtpPurchaseDate.Value);
     }
     MainMenu._Dividends.LoadDividendStock();
     LoadAllMainDividends();
     SelectCurrentStock();
     pw.Close();
     this.Close();
 }
Exemple #6
0
 public void OpenDividends(bool edit, string id, string symbol)
 {
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     if (_Dividends == null || _Dividends.IsDisposed)
     {
         _Dividends = new Dividends(edit, id, CurrentDiv, symbol);
         _Dividends.Show();
     }
     else
     {
         if (_Dividends.WindowState == FormWindowState.Minimized)
         {
             _Dividends.WindowState = FormWindowState.Normal;
         }
         else
         {
             _Dividends.BringToFront();
         }
     }
     pw.Close();
 }
Exemple #7
0
 public void HighlightPayDate(ListBox lb)
 {
     PleaseWait pw = new PleaseWait();
     pw.Show();
     Application.DoEvents();
     lb.ClearSelected();
     decimal totalDiv = 0;
     decimal quarterlyDiv = 0;
     int cnt = 0;
     string monthYear = "";
     string dtpMonthYear = "";
     string individualDivData = "";
     DataTable dt = DividendStocks.GetCurrentDividends();
     for (int i = 0; i < lb.Items.Count; i++)
     {
         DataRowView drv = lb.Items[i] as DataRowView;
         string[] date = drv["symbolName"].ToString().Split('*');
         string[] symbolSplit = date[0].Split('-');
         string symbol = symbolSplit[0].Trim();
         if (date.Length == 2)
         {
             monthYear = date[1].ToString();
             if (monthYear != "N/A")
             {
                 date = monthYear.Split('/');
                 monthYear = date[0].Trim() + "/" + date[2];
                 dtpMonthYear = dtpPayDate.Value.ToString("MM/yyyy");
                 //string dividendInterval = GetDividendInterval(Convert.ToInt32(drv["id"]), dt);
                 //if (dividendInterval == "Monthly")
                 //{
                 //    lb.SelectedIndices.Add(i);
                 //    totalDiv += GetDiv(Convert.ToInt32(drv["id"]), dt);
                 //    individualDivData += symbol + ": $" + Math.Round((GetDiv(Convert.ToInt32(drv["id"]), dt) / 4), 2) + "\n\n";
                 //}
                 if (monthYear == dtpMonthYear)
                 {
                     lb.SelectedIndices.Add(i);
                     totalDiv += GetDiv(Convert.ToInt32(drv["id"]), dt);
                     individualDivData += symbol + ": $" + Math.Round((GetDiv(Convert.ToInt32(drv["id"]), dt) / 4), 2) + "\n\n";
                     cnt++;
                 }
             }
         }
     }
     HighlightActive = false;
     quarterlyDiv = totalDiv / 4;
     pw.Close();
     if (cnt != 0)
     {
         MessageBox.Show(string.Format("{0} results\n\n" + "{1} \n\n" + individualDivData + "Total: ${2}\n\n", cnt, "Dividends for " + dtpMonthYear + ":",  Math.Round(quarterlyDiv, 2)));
     }
     else
     {
         MessageBox.Show(string.Format("No Results for {0}", dtpMonthYear));
     }
 }