///<summary>Adds the procedure code of the repeating charge to a credit card on the patient's account if the user okays it.</summary> private void AddProcedureToCC() { List <CreditCard> activeCards = CreditCards.GetActiveCards(RepeatCur.PatNum); if (activeCards.Count == 0) { return; } CreditCard cardToAddProc = null; if (activeCards.Count == 1) //Only one active card so ask the user to add the procedure to that one { if (MsgBox.Show(this, MsgBoxButtons.YesNo, "There is one active credit card on this patient's account.\r\nDo you want to add this procedure to " + "that card?")) { cardToAddProc = activeCards[0]; } } else if (activeCards.FindAll(x => x.Procedures != "").Count == 1) //Only one card has procedures attached so ask the user to add to that card { if (MsgBox.Show(this, MsgBoxButtons.YesNo, "There is one active credit card on this patient's account with authorized procedures attached.\r\n" + "Do you want to add this procedure to that card?")) { cardToAddProc = activeCards.FirstOrDefault(x => x.Procedures != ""); } } else //At least two cards have procedures attached to them or there are multiple active cards and none have procedures attached { MsgBox.Show(this, "If you would like to add this procedure to a credit card, go to Credit Card Manage to choose the card."); } if (cardToAddProc == null) { return; } //Check if the procedure is already attached to this card; CreditCard.Procedures is a comma delimited list. List <string> procsOnCard = cardToAddProc.Procedures.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (procsOnCard.Exists(x => x == RepeatCur.ProcCode)) { return; } procsOnCard.Add(RepeatCur.ProcCode); cardToAddProc.Procedures = String.Join(",", procsOnCard); CreditCards.Update(cardToAddProc); }