private void GetMostRecentAnnualizedData_Click(object sender, EventArgs e) { // Input Formatting Errors InputErrors errorFlags = InputErrors.None; if (!IsPeriodsFormatValid(periods_textBox.Text)) { errorFlags |= InputErrors.PeriodsFormat; } if (!IsFundNameValid(fundNameTextBox.Text)) { errorFlags |= InputErrors.FundNotFound; } if (errorFlags > 0) { showInputErrorMessage(errorFlags); return; } // Regular Processing Annualizer annualizer = new Annualizer(); annualizer.FundName = fundNameTextBox.Text.Trim(); int[] periods = GetPeriods(); string tsvFilePath = TsvUpdater.GetTsvFilePath(annualizer.FundName); using (StreamReader reader = new StreamReader(tsvFilePath)) { reader.ReadLine(); // first field names string presentData = reader.ReadLine(); string[] f = presentData.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); annualizer.PresentPrice = double.Parse(f[0]); annualizer.PresentNumberOfShares = double.Parse(f[1]); annualizer.FinalDate = new DateTime( int.Parse(f[2]), int.Parse(f[3]), int.Parse(f[4])); } try { textBoxConsole.Text = annualizer.getCustom(tsvFilePath, periods); } catch { showAnnualizerErrorMessage(tsvFilePath); } annualizer.ResetFundFields(); // push the console output content to the history stack backHistoryStack.Push(textBoxConsole.Text); return; }
private void UpdateAndGetAnnualized_Click(object sender, EventArgs e) { // Input Format Errors InputErrors errorFlags = InputErrors.None; if (String.IsNullOrWhiteSpace(fundNameTextBox.Text)) { errorFlags |= InputErrors.FundNameNotEntered; } if (!IsPeriodsFormatValid(periods_textBox.Text)) { errorFlags |= InputErrors.PeriodsFormat; } if (!IsNumSharesFormatValid(currentNumShares_TextBox.Text)) { errorFlags |= InputErrors.NumberOfSharesFormat; } if (!IsPriceFormatValid(currentPriceTextBox.Text)) { errorFlags |= InputErrors.SharePriceFormat; } if (String.IsNullOrWhiteSpace(textBoxConsole.Text)) { errorFlags |= InputErrors.TransacHistoryNotEntered; } if (errorFlags > 0) { showInputErrorMessage(errorFlags); return; } // Regular processing // push the console input content to the history stack backHistoryStack.Push(textBoxConsole.Text); var now = DateTime.Now; Annualizer annualizer = new Annualizer(); annualizer.FinalDate = now; annualizer.FundName = fundNameTextBox.Text.Trim(); annualizer.PresentNumberOfShares = double.Parse(currentNumShares_TextBox.Text); annualizer.PresentPrice = double.Parse(currentPriceTextBox.Text.Replace("$", string.Empty)); int[] periods = GetPeriods(); string tsvFilePath = TsvUpdater.GetTsvFilePath(annualizer.FundName); var sr = new StringReader(textBoxConsole.Text); if (TsvUpdater.BMO( sr, tsvFilePath, annualizer.PresentPrice, annualizer.PresentNumberOfShares, now.Year, now.Month, now.Day)) { try { textBoxConsole.Text = annualizer.getCustom(tsvFilePath, periods); } catch { showAnnualizerErrorMessage(tsvFilePath); } annualizer.ResetFundFields(); } else { showTsvErrorMessage(tsvFilePath); } sr.Close(); UpdateFundNameList(); // push the current console output content to the history stack backHistoryStack.Push(textBoxConsole.Text); }