private void AddToListBox(PayToEntryDTO payToEntryDTO) { // Build this out more for a complete description. The "TotalOwed" will need update // based on other entries. StringBuilder sb = new StringBuilder(); sb.Append($"{payToEntryDTO.ToName}"); sb.Append($" (Total: {payToEntryDTO.TotalOwed})"); sb.Append($" [Minimum Monthly Payment: {payToEntryDTO.MinimumPayment}]"); lbPayees.Items.Add(sb.ToString()); }
private void ValidateEntries(IEnumerable <TextBox> TextBoxes) { Validator validate = new Validator(); bool fail = false; payToEntryDTO = new PayToEntryDTO(); foreach (TextBox tb in TextBoxes) { switch (tb.Name) { case "tbPayTo": if (!string.IsNullOrWhiteSpace(tb.Text)) { payToEntryDTO.ToName = tb.Text; tb.BackColor = Color.White; } else { tb.BackColor = Color.Red; } break; case "tbDueDate": if (validate.ValidateInteger(tb.Text)) { payToEntryDTO.DateOfMonthDue = Convert.ToInt32(tb.Text); tb.BackColor = Color.White; } else { tb.BackColor = Color.Red; } break; case "tbAPR": if (validate.ValidateDecimal(tb.Text, true)) { payToEntryDTO.APR = string.IsNullOrWhiteSpace(tb.Text) ? 0.0M : Convert.ToDecimal(tb.Text); tb.BackColor = Color.FromArgb(255, 255, 178); } else { tb.BackColor = Color.Red; } break; case "tbTotalOwed": // if there is an APR, there must be a TotalOwed // there can be a totalowed without an apr if (validate.ValidateDecimal(tb.Text, true)) { payToEntryDTO.TotalOwed = string.IsNullOrWhiteSpace(tb.Text) ? 0.0M : Convert.ToDecimal(tb.Text); tb.BackColor = Color.FromArgb(255, 255, 178); if (!string.IsNullOrWhiteSpace(tbAPR.Text) && string.IsNullOrWhiteSpace(tb.Text)) { tb.BackColor = Color.Red; } } break; case "tbMinimumPayment": if (validate.ValidateDecimal(tb.Text)) { payToEntryDTO.MinimumPayment = Convert.ToDecimal(tb.Text); tb.BackColor = Color.White; } else { tb.BackColor = Color.Red; } break; } } fail = CheckForFailure(); if (!fail) { payToEntryList.Add(payToEntryDTO); AddToListBox(payToEntryDTO); } }