static public bool SaveTimeReport(ref DdTimeReportExt item, RevisionInfo revisionInfo) { DaTimeReport da = new DaTimeReport(DataStore.DbConnection); if (!da.GetById(item.Id)) return false; da.CalendarREF = item.CalendarREF; da.Description = item.Description; da.EffectiveDate = item.EffectiveDate; da.Hours = item.Hours; da.PersonREF = item.PersonREF; da.TaskChargeCodeREF = item.TaskChargeCodeREF; 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 DdTimeReportExt(da.GetBuffer()); } return ok; }
static public void UpdateTimeReport(BindingSource binding, int personREF, RevisionInfo revInfo) { BindingList<DdTimeReportExt> list = (BindingList<DdTimeReportExt>)binding.DataSource; try { using (TransactionScope scope = new TransactionScope()) { DaTimeReport da = new DaTimeReport(DataStore.CloneDbConnection()); foreach (DdTimeReportExt 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 (DdTimeReportExt item in list) { if (item.DeleteFlag) continue; // already done above //if (item.Id == string.Empty) continue; // already done above bool existing = da.GetById(item.Id); if (!existing) { da.Clear(); } da.CalendarREF = item.CalendarREF; da.Description = item.Description; da.EffectiveDate = item.EffectiveDate; da.Hours = item.Hours; da.PersonREF = item.PersonREF; da.TaskChargeCodeREF = item.TaskChargeCodeREF; if (!existing) { da.PersonREF = personREF; 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 = GetTimeReportList(personREF); } catch (AppEx) { throw; } catch (Exception exc) { throw new AppEx(exc, "Error updating TimeReport"); } }