private void Delete_Click() { if (!Security.IsAuthorized(Permissions.AppointmentEdit)) { return; } if (grid.SelectedIndices.Length > 1) { if (!MsgBox.Show(MsgBoxButtons.OKCancel, "Delete all selected appointments permanently?")) { return; } } List <Appointment> listApptsWithNote = new List <Appointment>(); List <long> listSelectedAptNums = new List <long>(); foreach (int i in grid.SelectedIndices) { listSelectedAptNums.Add(_listUnschedApt[i].AptNum); if (!string.IsNullOrEmpty(_listUnschedApt[i].Note)) { listApptsWithNote.Add(_listUnschedApt[i]); } } if (listApptsWithNote.Count > 0) //There were notes in the appointment(s) we are about to delete and we must ask if they want to save them in a commlog. { string commlogMsg = ""; if (grid.SelectedIndices.Length == 1) { commlogMsg = Commlogs.GetDeleteApptCommlogMessage(listApptsWithNote[0].Note, listApptsWithNote[0].AptStatus); } else { commlogMsg = "One or more appointments have notes. Save appointment notes in CommLogs?"; } DialogResult result = MessageBox.Show(commlogMsg, "Question...", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Cancel) { return; } else if (result == DialogResult.Yes) { foreach (Appointment apptCur in listApptsWithNote) { Commlog commlogCur = new Commlog(); commlogCur.PatNum = apptCur.PatNum; commlogCur.CommDateTime = DateTime.Now; commlogCur.CommType = Commlogs.GetTypeAuto(CommItemTypeAuto.APPT); commlogCur.Note = Lan.g(this, "Deleted Appt. & saved note") + ": "; if (apptCur.ProcDescript != "") { commlogCur.Note += apptCur.ProcDescript + ": "; } commlogCur.Note += apptCur.Note; commlogCur.UserNum = Security.CurUser.UserNum; //there is no dialog here because it is just a simple entry Commlogs.Insert(commlogCur); } } } Appointments.Delete(listSelectedAptNums); foreach (int i in grid.SelectedIndices) { SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, _listUnschedApt[i].PatNum, Lan.g(this, "Appointment deleted from the Unscheduled list."), _listUnschedApt[i].AptNum, _listUnschedApt[i].DateTStamp); } FillGrid(); }