static public bool SaveCalendar(ref DdCalendarExt item, RevisionInfo revisionInfo) { DaCalendar da = new DaCalendar(DataStore.DbConnection); if (!da.GetById(item.Id)) return false; da.DayDate = item.DayDate; da.DayNumber = item.DayNumber; da.EndOfPeriod = item.EndOfPeriod; da.InvoiceDue = item.InvoiceDue; da.PeriodNumber = item.PeriodNumber; bool ok = true; if (da._IsModified) { da.Modified = DateTime.Now; da.ModifiedBy = Environment.UserName; ok = da.Save(); if (ok) AddChangeLog(da.TableName, da.Id, da.Timestamp, revisionInfo); if (ok) item = new DdCalendarExt(da.GetBuffer()); } return ok; }
static public void UpdateCalendar(BindingSource binding, RevisionInfo revInfo) { BindingList<DdCalendarExt> list = (BindingList<DdCalendarExt>)binding.DataSource; try { using (TransactionScope scope = new TransactionScope()) { DaCalendar da = new DaCalendar(DataStore.CloneDbConnection()); foreach (DdCalendarExt item in list) {// do deletes first bool existing = da.GetById(item.Id); if (existing && item.DeleteFlag) {// delete here - avoid validation da.DeleteById(item.Id); AddChangeLog(da.TableName, item.Id, da.Timestamp, revInfo); } } foreach (DdCalendarExt item in list) { if (item.DeleteFlag) continue; // already done above //if (item.DayDate == string.Empty) continue; // already done above bool existing = da.GetById(item.Id); if (!existing) { da.Clear(); } da.DayDate = item.DayDate; da.DayNumber = item.DayNumber; da.EndOfPeriod = item.EndOfPeriod; da.InvoiceDue = item.InvoiceDue; da.PeriodNumber = item.PeriodNumber; if (!existing) { da.Insert(); AddChangeLog(da.TableName, da.Id, da.Timestamp, revInfo); } else { if (!da._IsModified) continue; da.Modified = DateTime.Now; da.ModifiedBy = Environment.UserName; da.Save(); AddChangeLog(da.TableName, da.Id, da.Timestamp, revInfo); } } scope.Complete(); } binding.DataSource = GetCalendarList(); } catch (AppEx) { throw; } catch (Exception exc) { throw new AppEx(exc, "Error updating Calendar"); } }