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 showInputErrorMessage(InputErrors errorFlags) { StringBuilder message = new StringBuilder(); if (errorFlags.HasFlag(InputErrors.FundNameNotEntered)) { message.Append("- No fund name was entered.\n\n"); } if (errorFlags.HasFlag(InputErrors.FundNotFound)) { message.Append("- Fund not found.\n\n"); } if (errorFlags.HasFlag(InputErrors.PeriodsFormat)) { message.Append("- Wrong format for periods. Ex: \"30 60 180 365\"\n\n"); } if (errorFlags.HasFlag(InputErrors.NumberOfSharesFormat)) { message.Append("- Wrong format for current number of shares. Ex: \"123.1234\"\n\n"); } if (errorFlags.HasFlag(InputErrors.SharePriceFormat)) { message.Append("- Wrong format for current share price. Ex: \"10.14\"\n\n"); } if (errorFlags.HasFlag(InputErrors.TransacHistoryNotEntered)) { message.Append("- No transaction history was copied to the console.\n\n"); } MessageBox.Show(message.ToString(), "Input Formatting Problem", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private bool IsValid() { bool valid = true; if (string.IsNullOrWhiteSpace(InputName.Text)) { InputErrors.SetError(InputName, "Cannot be empty"); valid = false; } if (string.IsNullOrWhiteSpace(InputDescription.Text)) { InputErrors.SetError(InputDescription, "Cannot be empty"); valid = false; } if (string.IsNullOrWhiteSpace(InputCategory.Text)) { InputErrors.SetError(InputCategory, "Cannot be empty"); valid = false; } if (string.IsNullOrWhiteSpace(InputBarcode.Text)) { InputErrors.SetError(InputBarcode, "Cannot be empty"); valid = false; } if (string.IsNullOrWhiteSpace(InputPrice.Text)) { InputErrors.SetError(InputPrice, "Cannot be empty"); valid = false; } return(valid); }
public void InvalidCommand() { var inputProcessor = new InputProcessor(Robot, Board); var invalidCommand = "INVALIDINPUT"; Assert.Equal(inputProcessor.ProcessInput(invalidCommand), InputErrors.RobotNotPlaced(invalidCommand)); }
public void NoOtherRobotCommandsValidUntilRobortPlace() { var inputProcessor = new InputProcessor(Robot, Board); Assert.Equal(inputProcessor.ProcessInput(ValidInputs.Move), InputErrors.RobotNotPlaced(ValidInputs.Move)); Assert.Equal(inputProcessor.ProcessInput(ValidInputs.Left), InputErrors.RobotNotPlaced(ValidInputs.Left)); Assert.Equal(inputProcessor.ProcessInput(ValidInputs.Right), InputErrors.RobotNotPlaced(ValidInputs.Right)); Assert.Equal(inputProcessor.ProcessInput(ValidInputs.Report), InputErrors.RobotNotPlaced(ValidInputs.Report)); }
public void RobotFallsOffBoard() { var inputProcessor = new InputProcessor(Robot, Board); var placeCommand = $"{ValidInputs.Place} 0,0,{Direction.South.ToString()}"; inputProcessor.ProcessInput(placeCommand); var moveCommand = ValidInputs.Move; Assert.Equal(inputProcessor.ProcessInput(moveCommand), InputErrors.InvalidMove(inputProcessor.Robot)); }
public void fire_InputError(InputError error, EditField_DialogEntry entry) { logError(error); if (InputErrors != null) { try { InputErrors.Invoke(this, new InputErrorEventArgs(error, entry)); } catch { } } }
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); }