private void butOK_Click(object sender, EventArgs e) { TreatPlanCur.Heading = textHeading.Text; TreatPlanCur.Note = textNote.Text; TreatPlanCur.UserNumPresenter = 0; TreatPlanCur.TPType = (TreatPlanType)comboPlanType.SelectedIndex; if (TreatPlanCur.TreatPlanNum == 0) { TreatPlanCur.TreatPlanNum = TreatPlans.Insert(TreatPlanCur); } else { TreatPlans.Update(TreatPlanCur); } //get all TPAttaches for this TP where there is either a procedure with a TPAttach linking it to this TP //or, if this TP is active, a procedure linked to an appt by AptNum or PlannedAptNun List <TreatPlanAttach> listNew = _listTpAttachesCur.FindAll(x => _listTpProcsCur.Any(y => x.ProcNum == y.ProcNum)); _listTpProcsCur.FindAll(x => !listNew.Any(y => x.ProcNum == y.ProcNum)) .ForEach(x => listNew.Add(new TreatPlanAttach() { TreatPlanNum = TreatPlanCur.TreatPlanNum, ProcNum = x.ProcNum, Priority = 0 })); TreatPlanAttaches.Sync(listNew, TreatPlanCur.TreatPlanNum); if (_makeActive) { TreatPlans.SetOtherActiveTPsToInactive(TreatPlanCur); } if (TreatPlanCur.TPStatus == TreatPlanStatus.Active) { //we have to this whether we just made this the active or it was already active, otherwise any procs we move off of the active plan will //retain the TP status and AuditPlans will throw them back on this TP. //Changing the status to TPi of any procs that are not on this plan prevents that from happening. Procedures.SetTPActive(TreatPlanCur.PatNum, listNew.Select(x => x.ProcNum).ToList()); } DialogResult = DialogResult.OK; }