///<summary></summary> protected override void Dispose(bool disposing) { if (disposing) //managed resources { components?.Dispose(); //get rid of temp appts on pinboard. =jordan I don't see any docs on why this is here. Doesn't seem quite right, but it works. for (int i = 0; i < ListPinBoardItems.Count; i++) { if (PIn.Int(ListPinBoardItems[i].DataRowAppt["AptStatus"].ToString()) != (int)ApptStatus.UnschedList) { continue; } if (PIn.DateT(ListPinBoardItems[i].DataRowAppt["AptDateTime"].ToString()).Year > 1880) { continue; } Appointment appt = null; try{ appt = Appointments.GetOneApt(ListPinBoardItems[i].AptNum); } catch { break; //db connection no longer present. } if (appt == null) { continue; } if (appt.AptDateTime.Year > 1880) //date was updated since put on the pinboard { continue; } Appointments.Delete(appt.AptNum, true); if (Security.CurUser == null) // E.g. clicking Log Off invalidates the user. { continue; } //Make a security log if we still have a valid user logged in. string logText = Lan.g(this, "Deleted from pinboard while closing Open Dental") + ": "; if (appt.AptDateTime.Year > 1880) { logText += appt.AptDateTime.ToString() + ", "; } logText += appt.ProcDescript; SecurityLogs.MakeLogEntry(Permissions.AppointmentEdit, appt.PatNum, logText); } } base.Dispose(disposing); }
//Delete not allowed for this table //public static void Delete(long aptNum) { // //} ///<summary>Inserts, updates, or deletes database rows to match supplied list. Returns true if db changes were made. ///Supply Security.CurUser.UserNum, used to set the SecUserNumEntry field for Inserts.</summary> public static bool Sync(List <Appointment> listNew, List <Appointment> listDB, long userNum) { //Adding items to lists changes the order of operation. All inserts are completed first, then updates, then deletes. List <Appointment> listIns = new List <Appointment>(); List <Appointment> listUpdNew = new List <Appointment>(); List <Appointment> listUpdDB = new List <Appointment>(); List <Appointment> listDel = new List <Appointment>(); listNew.Sort((Appointment x, Appointment y) => { return(x.AptNum.CompareTo(y.AptNum)); }); //Anonymous function, sorts by compairing PK. Lambda expressions are not allowed, this is the one and only exception. JS approved. listDB.Sort((Appointment x, Appointment y) => { return(x.AptNum.CompareTo(y.AptNum)); }); //Anonymous function, sorts by compairing PK. Lambda expressions are not allowed, this is the one and only exception. JS approved. int idxNew = 0; int idxDB = 0; int rowsUpdatedCount = 0; Appointment fieldNew; Appointment fieldDB; //Because both lists have been sorted using the same criteria, we can now walk each list to determine which list contians the next element. The next element is determined by Primary Key. //If the New list contains the next item it will be inserted. If the DB contains the next item, it will be deleted. If both lists contain the next item, the item will be updated. while (idxNew < listNew.Count || idxDB < listDB.Count) { fieldNew = null; if (idxNew < listNew.Count) { fieldNew = listNew[idxNew]; } fieldDB = null; if (idxDB < listDB.Count) { fieldDB = listDB[idxDB]; } //begin compare if (fieldNew != null && fieldDB == null) //listNew has more items, listDB does not. { listIns.Add(fieldNew); idxNew++; continue; } else if (fieldNew == null && fieldDB != null) //listDB has more items, listNew does not. { listDel.Add(fieldDB); idxDB++; continue; } else if (fieldNew.AptNum < fieldDB.AptNum) //newPK less than dbPK, newItem is 'next' { listIns.Add(fieldNew); idxNew++; continue; } else if (fieldNew.AptNum > fieldDB.AptNum) //dbPK less than newPK, dbItem is 'next' { listDel.Add(fieldDB); idxDB++; continue; } //Both lists contain the 'next' item, update required listUpdNew.Add(fieldNew); listUpdDB.Add(fieldDB); idxNew++; idxDB++; } //Commit changes to DB for (int i = 0; i < listIns.Count; i++) { listIns[i].SecUserNumEntry = userNum; Insert(listIns[i]); } for (int i = 0; i < listUpdNew.Count; i++) { if (Update(listUpdNew[i], listUpdDB[i])) { rowsUpdatedCount++; } } for (int i = 0; i < listDel.Count; i++) { Appointments.Delete(listDel[i].AptNum); } if (rowsUpdatedCount > 0 || listIns.Count > 0 || listDel.Count > 0) { return(true); } return(false); }