public void update_Check(int checksID, int shiftReportID, Int16 locationID, byte checkSequence, string generalObservations, string correctionsMade, string reportNumber, GridView Officers, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var dl = (from a in model.tbl_Sup_ShiftReport where a.ShiftReportID == shiftReportID select a).First(); dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Update Checks table var checks = (from b in model.tbl_Sup_ShiftReportChecks where b.ChecksID == checksID select b).First(); checks.LocationID = locationID; checks.CheckSequence = checkSequence; checks.GeneralObservations = generalObservations; checks.CorrectionsMadeSuggested = correctionsMade; checks.LastModifiedBy = userID; checks.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Select all officers var officers = (from c in model.tbl_Sup_ShiftReportChecks_Officers where c.ChecksID == checksID select c).ToList(); if (officers != null) { //remove selected officers foreach (var val in officers) { model.tbl_Sup_ShiftReportChecks_Officers.Remove(val); model.SaveChanges(); } //insert new officers for (int i = 0; i < Officers.Rows.Count; i++) { DropDownList ddlOfficerName = (DropDownList)Officers.Rows[i].FindControl("ddlOfficerName"); TextBox tbTime = (TextBox)Officers.Rows[i].FindControl("tbTime"); if ((ddlOfficerName.SelectedIndex > 0) && (tbTime.Text != "")) { Int16 empID = Convert.ToInt16(ddlOfficerName.SelectedValue); TimeSpan time = new TimeSpan(); TimeSpan.TryParse(tbTime.Text, out time); EDM.tbl_Sup_ShiftReportChecks_Officers c = new EDM.tbl_Sup_ShiftReportChecks_Officers(); { c.ChecksID = checksID; c.EmployeeID = empID; c.Time = time; c.CreatedBy = userID; c.CreatedOn = DateTime.Now; }; model.tbl_Sup_ShiftReportChecks_Officers.Add(c); model.SaveChanges(); } } } //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = shiftReportID; x.TableName = "tbl_Sup_ShiftReport"; x.AuditProcess = "Updated Check for Shift Report " + reportNumber; x.DateTime = DateTime.Now; x.UserID = userID; }; model.tbl_AuditLog.Add(x); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void insert_Check(int shiftReportID, Int16 locationID, byte checkSequence, string generalObservations, string correctionsMade, string reportNumber, GridView Officers, byte userID) { try { Int64 checksID = new Int64(); using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //update header var dl = (from a in model.tbl_Sup_ShiftReport where a.ShiftReportID == shiftReportID select a).First(); dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert Chesk EDM.tbl_Sup_ShiftReportChecks b = new EDM.tbl_Sup_ShiftReportChecks(); { b.ShiftReportID = shiftReportID; b.LocationID = locationID; b.CheckSequence = checkSequence; b.GeneralObservations = generalObservations; b.CorrectionsMadeSuggested = correctionsMade; b.CreatedBy = userID; b.CreatedOn = DateTime.Now; }; model.tbl_Sup_ShiftReportChecks.Add(b); model.SaveChanges(); //Get the id checksID = b.ChecksID; if (checksID != 0) { //insert officers for (int i = 0; i < Officers.Rows.Count; i++) { DropDownList ddlOfficerName = (DropDownList)Officers.Rows[i].FindControl("ddlOfficerName"); TextBox tbTime = (TextBox)Officers.Rows[i].FindControl("tbTime"); if ((ddlOfficerName.SelectedIndex > 0) && (tbTime.Text != "")) { Int16 empID = Convert.ToInt16(ddlOfficerName.SelectedValue); TimeSpan time = new TimeSpan(); TimeSpan.TryParse(tbTime.Text, out time); EDM.tbl_Sup_ShiftReportChecks_Officers c = new EDM.tbl_Sup_ShiftReportChecks_Officers(); { c.ChecksID = checksID; c.EmployeeID = empID; c.Time = time; c.CreatedBy = userID; c.CreatedOn = DateTime.Now; }; model.tbl_Sup_ShiftReportChecks_Officers.Add(c); model.SaveChanges(); } } //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = shiftReportID; x.TableName = "tbl_Sup_ShiftReport"; x.AuditProcess = "Inserted Check for Shift Report " + reportNumber; x.DateTime = DateTime.Now; x.UserID = userID; }; model.tbl_AuditLog.Add(x); model.SaveChanges(); } else { successfulCommit = false; MISC.writetoAlertLog("No Checks ID returned after insert!!"); } } if (checksID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }