//save audit log protected void AuditLog(int sourceID, string tableName, string AuditProcess, byte loggedInUser) { //Insert AuditTrail using (EDM.DataSource model = new EDM.DataSource()) { EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = sourceID; z.TableName = tableName; z.AuditProcess = AuditProcess; z.DateTime = DateTime.Now; z.UserID = loggedInUser; }; model.tbl_AuditLog.Add(z); try { model.SaveChanges(); //success = true; } catch (Exception exec) { MISC.writetoAlertLog(exec.ToString()); ShowMessage("Something went wrong and the auditlog could not be created. Kindly try again and if the error persists, refer to the error log for details.", MessageType.Error); } } }
//Insert new incidents public int insert_Incident(byte areaID, Int16 locationID, DateTime dateOccured, TimeSpan timeOccured, byte incidentTypeID, string otherTypeDescription, string description, string incidentNumber, byte userID, byte shiftID, string actionTaken) { int incidentID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert transaction EDM.tbl_Op_Incidents a = new EDM.tbl_Op_Incidents(); { a.AreaID = areaID; a.LocationID = locationID; a.DateOccured = dateOccured; a.TimeOccured = timeOccured; a.IncidentTypeID = incidentTypeID; a.OtherTypeDescription = otherTypeDescription.Length > 0 ? firstCharToUpper(otherTypeDescription) : null; a.Description = description.Length > 0 ? firstCharToUpper(description) : null; a.ActionTaken = actionTaken.Length > 0 ? firstCharToUpper(actionTaken) : null; a.IncidentNumber = incidentNumber; a.ShiftID = shiftID == 0 ? null : (byte?)shiftID; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_Incidents.Add(a); model.SaveChanges(); //Get the incidentID incidentID = (from b in model.tbl_Op_Incidents where b.IncidentNumber == incidentNumber select b.IncidentID ).FirstOrDefault(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = incidentID; z.TableName = "tbl_Op_Incidents"; z.AuditProcess = "Created Incident Report - " + incidentNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { incidentID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(incidentID); }
public void insert_Shift(byte positionID, TimeSpan fromTime, TimeSpan toTime, string shiftName, string hrsInShift, bool isActive, byte userID) { int shiftID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert header EDM.tbl_Ref_Shifts a = new EDM.tbl_Ref_Shifts(); { a.PositionID = positionID; a.FromTime = fromTime; a.ToTime = toTime; a.HoursInShift = hrsInShift; a.IsActive = isActive; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Ref_Shifts.Add(a); model.SaveChanges(); //Get the id shiftID = a.ShiftID; if (shiftID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = shiftID; z.TableName = "tbl_Ref_Shifts"; z.AuditProcess = "Created Shift (" + shiftName + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { successfulCommit = false; MISC.writetoAlertLog("No Shift ID returned after insert!!"); } } if (shiftID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void insert_Location(byte areaID, string location, bool isActive, byte userID) { int locationID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert header EDM.tbl_Ref_Locations a = new EDM.tbl_Ref_Locations(); { a.AreaID = areaID; a.LocationName = firstCharToUpper(location); a.IsActive = isActive; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Ref_Locations.Add(a); model.SaveChanges(); //Get the id locationID = a.LocationID; if (locationID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = locationID; z.TableName = "tbl_Ref_Locations"; z.AuditProcess = "Created Location (" + location + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { successfulCommit = false; MISC.writetoAlertLog("No location ID returned after insert!!"); } } if (locationID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void insert_Grant(DateTime dtDateFrom, DateTime dtDateTo, string comments, byte userID) { int grantID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { EDM.tbl_Mgr_DateTimeGrant a = new EDM.tbl_Mgr_DateTimeGrant(); { a.DateTimeFrom = dtDateFrom; a.DateTimeTo = dtDateTo; a.Comments = comments; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Mgr_DateTimeGrant.Add(a); model.SaveChanges(); //Get the id grantID = a.GrantID; if (grantID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = grantID; z.TableName = "tbl_Mgr_DateTimeGrant"; z.AuditProcess = "Created Date/Time Grant for period " + dtDateFrom + " to " + dtDateTo + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { successfulCommit = false; MISC.writetoAlertLog("No grant ID returned after insert!!"); } } if (grantID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_dailyPostAssignment(int postAssignmentID, DateTime date, byte shiftID, Int16 lateArrivals, Int16 callsForAssistance, Int16 officersPresent, Int16 officersAbsent, Int16 officersAssigned, Int16 officersCalledOut, Int16 officersCallInForDayOff, Int16 officersOnDayOff, Int16 notDressedProperly, string shiftSummary, string shiftBriefingNotes, string PassedOnFrom, string passedOnTo, string summaryOfIncidents, string reportNumber, byte userID, Int16 sleeping) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var dl = (from a in model.tbl_Sup_DailyPostAssignment where a.PostAssignmentID == postAssignmentID select a).First(); dl.LateArrivals = lateArrivals; dl.CallsForAssistance = callsForAssistance; dl.OfficersPresent = officersPresent; dl.OfficersAbsent = officersAbsent; dl.OfficersAssigned = officersAssigned; dl.OfficersCalledOut = officersCalledOut; dl.OfficersCallInForDayOff = officersCallInForDayOff; dl.OfficersOnDayOff = officersOnDayOff; dl.NotDressedProperly = notDressedProperly; dl.ShiftSummary = shiftSummary; dl.ShiftBriefingNotes = shiftBriefingNotes; dl.PassedOnFrom = PassedOnFrom; dl.PassedOnTo = passedOnTo; dl.SummaryOfIncidents = summaryOfIncidents; dl.ReportNumber = reportNumber; dl.Sleeping = sleeping; dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = postAssignmentID; x.TableName = "tbl_Sup_DailyPostAssignment"; x.AuditProcess = "Modified Daily Post Assignment " + 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()); } }
//Update complaint public void update_Absence(int callInOffID, bool isCallIn, Int16 employeeID, DateTime date, TimeSpan time, Int16 callTakenByID, Int16 callForwardedToID, string workSchedule, string phoneNumber, byte absentType, string otherTypeDescription, byte sickLeaveForID, string otherSickLeaveForDescription, string comments, byte userID, string reportNumber, DateTime startDate, DateTime endDate) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var recordToUpdate = (from a in model.tbl_Op_CallIn_Absent where a.CallInOffID == callInOffID select a).First(); recordToUpdate.IsCallIn = isCallIn; recordToUpdate.EmployeeID = employeeID; recordToUpdate.Date = date; recordToUpdate.Time = time; recordToUpdate.CallTakenByID = callTakenByID == 0 ? null : (Int16?)callTakenByID; recordToUpdate.ForwardedToID = callForwardedToID == 0 ? null : (Int16?)callForwardedToID; recordToUpdate.WorkSchedule = workSchedule == "" ? null : firstCharToUpper(workSchedule); recordToUpdate.PhoneNumber = phoneNumber == "" ? null : phoneNumber; recordToUpdate.AbsentTypeID = absentType; recordToUpdate.OtherTypeDescription = otherTypeDescription == "" ? null : firstCharToUpper(otherTypeDescription); recordToUpdate.SickLeaveForID = sickLeaveForID == 0 ? null : (byte?)sickLeaveForID; recordToUpdate.OtherSickLeaveForTypeDescription = otherSickLeaveForDescription == "" ? null : firstCharToUpper(otherSickLeaveForDescription); recordToUpdate.Comments = comments == "" ? null : firstCharToUpper(comments); recordToUpdate.StartDate = startDate.Date; recordToUpdate.EndDate = endDate.Date; //recordToUpdate.ShiftID = shiftID; recordToUpdate.LastModifiedBy = userID; recordToUpdate.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = callInOffID; z.TableName = "tbl_Op_CallIn_Absent"; z.AuditProcess = "Modified Call In/Absent Report - " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void insert_IncidentPersonAffected(byte affectedTypeID, string firstName, string lastName, string description, string address, string otherTypeDescription, int incidentID, string phoneNumber, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert transaction EDM.tbl_Op_IncidentPersonsAffected a = new EDM.tbl_Op_IncidentPersonsAffected(); { a.AffectedTypeID = affectedTypeID; a.FirstName = firstName.Length > 0 ? firstCharToUpper(firstName) : null; a.LastName = firstCharToUpper(lastName); a.Description = firstCharToUpper(description); a.Address = address.Length > 0 ? firstCharToUpper(address) : null; a.OtherTypeDescription = otherTypeDescription.Length > 0 ? firstCharToUpper(otherTypeDescription) : null; a.IncidentID = incidentID; a.PhoneNumber = phoneNumber.Length > 0 ? phoneNumber : null; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_IncidentPersonsAffected.Add(a); model.SaveChanges(); //Get the incidentID string incidentNumber = (from b in model.tbl_Op_Incidents where b.IncidentID == incidentID select b.IncidentNumber ).FirstOrDefault(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = incidentID; z.TableName = "tbl_Op_IncidentPersonsAffected"; z.AuditProcess = "Created Person Affected - " + incidentNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
//insert doubles public void insert_double(int dailyLogID, Int16 employeeID, DateTime date, string areaName, string locationName, string shiftTime, byte userID, string logNumber) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var dl = (from t in model.tbl_Op_DailyLogs where t.DailyLogID == dailyLogID select t).First(); dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert doubles EDM.tbl_Op_DailyLogsPersonWorking a = new EDM.tbl_Op_DailyLogsPersonWorking(); { a.DailyLogID = dailyLogID; a.EmployeeID = employeeID; a.IsPresent = true; a.TimeClocked = DateTime.Now; a.IsDouble = true; a.IsSwitch = false; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogsPersonWorking.Add(a); model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dailyLogID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Added Double to Daily Log (" + logNumber + ") " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
//Update complaint public void update_Complaint(int complaintID, byte complaintChannelID, string personMakingReport, string contactNumber, byte areaID, Int16 locationID, DateTime dateOfIncident, TimeSpan timeofIncident, Int16 receivedByID, DateTime dateReceived, byte acknowledgementID, string clientcomplaint, bool feedbackProvided, DateTime dateOfFeedback, string actionTaken, byte userID, string complaintNumber, byte shiftID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var recordToUpdate = (from a in model.tbl_Op_Complaints where a.ComplaintID == complaintID select a).First(); recordToUpdate.ComplaintChannelID = complaintChannelID; recordToUpdate.DateOfIncident = dateOfIncident; recordToUpdate.TimeOfIncident = timeofIncident; recordToUpdate.AreaID = areaID; recordToUpdate.LocationID = locationID; recordToUpdate.PersonMakingReport = firstCharToUpper(personMakingReport); recordToUpdate.ContactNumber = contactNumber.Length > 0 ? contactNumber : null; recordToUpdate.ReceivedByID = receivedByID; recordToUpdate.DateReceived = dateReceived; recordToUpdate.ShiftID = shiftID; recordToUpdate.AcknowledgementID = acknowledgementID == 0 ? null : (byte?)acknowledgementID; recordToUpdate.ClientComplaint = clientcomplaint.Length > 0 ? firstCharToUpper(clientcomplaint) : null; recordToUpdate.FeedbackProvided = feedbackProvided; recordToUpdate.DateOfFeedback = dateOfFeedback.ToString() == "1/1/0001 12:00:00 AM" ? null : (DateTime?)dateOfFeedback; recordToUpdate.ActionTaken = actionTaken.Length > 0 ? firstCharToUpper(actionTaken) : null; recordToUpdate.LastModifiedBy = userID; recordToUpdate.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = complaintID; z.TableName = "tbl_Op_Complaints"; z.AuditProcess = "Modified Complaint Report - " + complaintNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
//insert Call Log public void insert_CallLog(int dailyLogID, TimeSpan time, string reports, bool supCheckLocation, DateTime date, string areaName, string locationName, string shiftTime, byte userID, string logNumber) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var dl = (from t in model.tbl_Op_DailyLogs where t.DailyLogID == dailyLogID select t).First(); dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert call log header EDM.tbl_Op_DailyLogsCallLog a = new EDM.tbl_Op_DailyLogsCallLog(); { a.DailyLogID = dailyLogID; a.Time = time; a.Reports = reports; a.SupCheckLocation = supCheckLocation; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogsCallLog.Add(a); model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dailyLogID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Created Call Log for Daily Log (" + logNumber + ") " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
//Update employee public void update_Employee(Int16 employeeID, string firstName, string lastName, string otherName, DateTime dateHired, byte areaID, Int16 locationID, byte departmentID, byte positionID, byte shiftID, bool isStandbyEmployee, bool isActive, string employeeNumber, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var a = (from y in model.tbl_Sup_Employees where y.EmployeeID == employeeID select y).First(); a.FirstName = firstName == "" ? null : firstCharToUpper(firstName); a.LastName = firstCharToUpper(lastName); a.OtherName = otherName == "" ? null : firstCharToUpper(otherName); a.DateHired = dateHired; a.AreaID = areaID == 0 ? null : (byte?)areaID; a.LocationID = locationID == 0 ? null : (Int16?)locationID; a.DepartmentID = departmentID == 0 ? null : (byte?)departmentID; a.PositionID = positionID == 0 ? null : (byte?)positionID; a.ShiftID = shiftID == 0 ? null : (byte?)shiftID; a.IsStandbyStaff = isStandbyEmployee; a.IsActive = isActive; a.EmployeeNumber = employeeNumber; a.LastModifiedBy = userID; a.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = employeeID; z.TableName = "tbl_Sup_Employees"; z.AuditProcess = "Modified Employee Record - " + employeeNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
//Update employee public void update_SO(int specialOperationsID, byte areaID, Int16 locationID, DateTime date, bool escortService, bool cashInGT, bool cashOutGT, bool extraOfficers, byte amountOfficers, string reportNumber, string comments, byte userID, byte shiftID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var a = (from y in model.tbl_Mgr_SpecialOperations where y.SpecialOperationsID == specialOperationsID select y).First(); a.AreaID = areaID == 0 ? null : (byte?)areaID; a.LocationID = locationID == 0 ? null : (byte?)locationID; a.Date = date; a.EscortService = escortService; a.CashInGT = cashInGT; a.CashOutGT = cashOutGT; a.ExtraOfficers = extraOfficers; a.AmountOfficers = amountOfficers == 0 ? null : (byte?)amountOfficers; a.ReportNumber = reportNumber; a.Comments = comments == "" ? null : comments; a.ShiftID = shiftID == 0 ? null : (byte?)shiftID; a.LastModifiedBy = userID; a.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = specialOperationsID; z.TableName = "tbl_Mgr_SpecialOperations"; z.AuditProcess = "Modified Special Operations Log - " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_Incident(int incidentID, byte areaID, Int16 locationID, DateTime dateOccured, TimeSpan timeOccured, byte incidentTypeID, string otherTypeDescription, string description, string incidentNumber, byte userID, byte shiftID, string actionTaken) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var recordToUpdate = (from a in model.tbl_Op_Incidents where a.IncidentID == incidentID select a).First(); recordToUpdate.AreaID = areaID; recordToUpdate.LocationID = locationID; recordToUpdate.DateOccured = dateOccured; recordToUpdate.TimeOccured = timeOccured; recordToUpdate.IncidentTypeID = incidentTypeID; recordToUpdate.OtherTypeDescription = otherTypeDescription.Length > 0 ? firstCharToUpper(otherTypeDescription) : null; recordToUpdate.Description = firstCharToUpper(description); recordToUpdate.ActionTaken = firstCharToUpper(actionTaken); recordToUpdate.IncidentNumber = incidentNumber; recordToUpdate.ShiftID = shiftID == 0 ? null : (byte?)shiftID; recordToUpdate.LastModifiedBy = userID; recordToUpdate.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = incidentID; z.TableName = "tbl_Op_Incidents"; z.AuditProcess = "Modified Incident Report - " + incidentNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_PersonAffected(int personAffectedID, byte affectedTypeID, string firstName, string lastName, string description, string address, string otherTypeDescription, string phoneNumber, byte userID, string incidentNumber, int incidentID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the record to update var recordToUpdate = (from a in model.tbl_Op_IncidentPersonsAffected where a.PersonAffectedID == personAffectedID select a).First(); recordToUpdate.AffectedTypeID = affectedTypeID; recordToUpdate.FirstName = firstName.Length > 0 ? firstCharToUpper(firstName) : null; recordToUpdate.LastName = firstCharToUpper(lastName); recordToUpdate.Description = firstCharToUpper(description); recordToUpdate.Address = address.Length > 0 ? firstCharToUpper(address) : null; recordToUpdate.PhoneNumber = phoneNumber.Length > 0 ? phoneNumber : null; recordToUpdate.OtherTypeDescription = otherTypeDescription.Length > 0 ? firstCharToUpper(otherTypeDescription) : null; recordToUpdate.LastModifiedBy = userID; recordToUpdate.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = incidentID; z.TableName = "tbl_Op_Incidents"; z.AuditProcess = "Modified Person Affected - " + incidentNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_Shift(byte shiftID, byte positionID, TimeSpan fromTime, TimeSpan toTime, string shiftName, string hrsInShift, bool isActive, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { var record = (from a in model.tbl_Ref_Shifts where a.ShiftID == shiftID select a).First(); record.PositionID = positionID; record.FromTime = fromTime; record.ToTime = toTime; record.IsActive = isActive; record.HoursInShift = hrsInShift; record.LastModifiedBy = userID; record.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = shiftID; z.TableName = "tbl_Ref_Shifts"; z.AuditProcess = "Updated Shift (" + shiftName + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_ShiftReport(int shiftReportID, byte areaID, byte shiftID, Int16 supervisorID, string reportNumber, 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.SupervisorID = supervisorID; dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = shiftReportID; x.TableName = "tbl_Sup_ShiftReport"; x.AuditProcess = "Modified 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 update_Location(byte areaID, Int16 locationID, string Location, bool isActive, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { var record = (from a in model.tbl_Ref_Locations where a.LocationID == locationID select a).First(); record.AreaID = areaID; record.LocationName = firstCharToUpper(Location); record.IsActive = isActive; record.LastModifiedBy = userID; record.LastModifiedOn = DateTime.Now; model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = locationID; z.TableName = "tbl_Ref_Locations"; z.AuditProcess = "Updated Location (" + Location + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_DailyLog(int dailyLogID, DateTime date, byte areaID, Int16 locationID, byte shiftID, GridView personsWorking, string areaName, string locationName, string shiftTime, string logNumber, byte userID, int workScheduleID, GridView switches, GridView doubles) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var dl = (from a in model.tbl_Op_DailyLogs where a.DailyLogID == dailyLogID select a).First(); dl.LastModifiedBy = userID; dl.LastModifiedOn = DateTime.Now; model.SaveChanges(); //update employees for (int i = 0; i < personsWorking.Rows.Count; i++) { Label lblEmployeeID = (Label)personsWorking.Rows[i].FindControl("lblEmployeeID"); Label lblPersonWorkingID = (Label)personsWorking.Rows[i].FindControl("lblPersonWorkingID"); Label lblIsPresent = (Label)personsWorking.Rows[i].FindControl("lblIsPresent"); Label lblFullName = (Label)personsWorking.Rows[i].FindControl("lblFullName"); CheckBox cbPresent = (CheckBox)personsWorking.Rows[i].FindControl("cbPresent"); Int64 personWorkingID = new Int64(); if (lblPersonWorkingID.Text != "") { //Update employee if already exist personWorkingID = Convert.ToInt64(lblPersonWorkingID.Text); //Get the record to update var recordToUpdate = (from b in model.tbl_Op_DailyLogsPersonWorking where b.PersonWorkingID == personWorkingID select b).First(); recordToUpdate.IsPresent = cbPresent.Checked; recordToUpdate.LastModifiedBy = userID; recordToUpdate.LastModifiedOn = DateTime.Now; model.SaveChanges(); } else { //Insert employee if they do not exist Int16 empID = new Int16(); empID = Convert.ToInt16(lblEmployeeID.Text); EDM.tbl_Op_DailyLogsPersonWorking c = new EDM.tbl_Op_DailyLogsPersonWorking(); { c.DailyLogID = dailyLogID; c.EmployeeID = empID; c.IsPresent = cbPresent.Checked ? true : false; c.TimeClocked = DateTime.Now; c.IsDouble = false; c.IsSwitch = false; c.CreatedBy = userID; c.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogsPersonWorking.Add(c); model.SaveChanges(); } //Check if employee was checked and is no unchecked and vice versa and save in audit trail if (((lblIsPresent.Text == "1") || (lblIsPresent.Text == "True")) && (cbPresent.Checked == false)) { //Insert AuditTrail EDM.tbl_AuditLog xx = new EDM.tbl_AuditLog(); { xx.SourceID = dailyLogID; xx.TableName = "tbl_Op_DailyLogs"; xx.AuditProcess = "Unchecked " + lblFullName.Text + " as Present from Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; xx.DateTime = DateTime.Now; xx.UserID = userID; }; model.tbl_AuditLog.Add(xx); model.SaveChanges(); } else if (((lblIsPresent.Text == "0") || (lblIsPresent.Text == "False")) && (cbPresent.Checked == true)) { //Insert AuditTrail EDM.tbl_AuditLog xx = new EDM.tbl_AuditLog(); { xx.SourceID = dailyLogID; xx.TableName = "tbl_Op_DailyLogs"; xx.AuditProcess = "Checked " + lblFullName.Text + " as Present for Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; xx.DateTime = DateTime.Now; xx.UserID = userID; }; model.tbl_AuditLog.Add(xx); model.SaveChanges(); } } //insert/delete switches for (int i = 0; i < switches.Rows.Count; i++) { Label lblSwitchID = (Label)switches.Rows[i].FindControl("lblSwitchID"); Label lblEmployeeID = (Label)switches.Rows[i].FindControl("lblEmployeeID"); Label lblFullName = (Label)switches.Rows[i].FindControl("lblFullName"); CheckBox cbPresent = (CheckBox)switches.Rows[i].FindControl("cbPresent"); if ((lblSwitchID.Text == "") && (cbPresent.Checked)) { Int16 empID = new Int16(); empID = Convert.ToInt16(lblEmployeeID.Text); //insert EDM.tbl_Op_DailyLogsPersonWorking c = new EDM.tbl_Op_DailyLogsPersonWorking(); { c.DailyLogID = dailyLogID; c.EmployeeID = empID; c.IsPresent = cbPresent.Checked; c.TimeClocked = DateTime.Now; c.IsDouble = false; c.IsSwitch = true; c.CreatedBy = userID; c.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogsPersonWorking.Add(c); model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dailyLogID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Inserted Switch (" + lblFullName.Text + ") to Daily Log (" + logNumber + ") " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else if ((lblSwitchID.Text != "") && (!cbPresent.Checked)) { //delete int switchID = new int(); switchID = Convert.ToInt32(lblSwitchID.Text); var swEmp = (from a in model.tbl_Op_DailyLogsPersonWorking where a.PersonWorkingID == switchID && a.IsSwitch == true select a).SingleOrDefault(); if (swEmp != null) { model.tbl_Op_DailyLogsPersonWorking.Remove(swEmp); model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dailyLogID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Removed Switch (" + lblFullName.Text + ") from Daily Log (" + logNumber + ") " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } } } //delete doubles for (int i = 0; i < doubles.Rows.Count; i++) { Label lblDoubleID = (Label)doubles.Rows[i].FindControl("lblDoubleID"); Label lblEmployeeID = (Label)doubles.Rows[i].FindControl("lblEmployeeID"); Label lblFullName = (Label)doubles.Rows[i].FindControl("lblFullName"); CheckBox cbPresent = (CheckBox)doubles.Rows[i].FindControl("cbPresent"); if (!cbPresent.Checked) { //delete int doubleID = new int(); doubleID = Convert.ToInt32(lblDoubleID.Text); var swEmp = (from a in model.tbl_Op_DailyLogsPersonWorking where a.PersonWorkingID == doubleID && a.IsDouble == true select a).SingleOrDefault(); if (swEmp != null) { model.tbl_Op_DailyLogsPersonWorking.Remove(swEmp); model.SaveChanges(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dailyLogID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Removed Double (" + lblFullName.Text + ") from Daily Log (" + logNumber + ") " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } } } //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = dailyLogID; x.TableName = "tbl_Op_DailyLogs"; x.AuditProcess = "Modified Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; 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()); } }
//insert employee public int insert_SO(byte areaID, Int16 locationID, DateTime date, bool escortService, bool cashInGT, bool cashOutGT, bool extraOfficers, byte amountOfficers, string reportNumber, string comments, byte userID, byte shiftID) { int soID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert transaction EDM.tbl_Mgr_SpecialOperations a = new EDM.tbl_Mgr_SpecialOperations(); { a.AreaID = areaID == 0 ? null : (byte?)areaID; a.LocationID = locationID == 0 ? null : (byte?)locationID; a.Date = date; a.EscortService = escortService; a.CashInGT = cashInGT; a.CashOutGT = cashOutGT; a.ExtraOfficers = extraOfficers; a.AmountOfficers = amountOfficers == 0 ? null : (byte?)amountOfficers; a.ReportNumber = reportNumber; a.Comments = comments == "" ? null : comments; a.ShiftID = shiftID == 0 ? null : (byte?)shiftID; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Mgr_SpecialOperations.Add(a); model.SaveChanges(); //Get the absenceid soID = (from b in model.tbl_Mgr_SpecialOperations where b.ReportNumber == reportNumber select b.SpecialOperationsID ).FirstOrDefault(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = soID; z.TableName = "tbl_Mgr_SpecialOperations"; z.AuditProcess = "Created SO Report - " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { soID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(soID); }
public int insert_ShiftReport(DateTime date, byte areaID, byte shiftID, Int16 supervisorID, string reportNumber, byte userID) { int shiftReportID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert header EDM.tbl_Sup_ShiftReport a = new EDM.tbl_Sup_ShiftReport(); { a.Date = date; a.AreaID = areaID; a.ShiftID = shiftID; a.ReportNumber = reportNumber; a.SupervisorID = supervisorID; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Sup_ShiftReport.Add(a); model.SaveChanges(); //Get the id shiftReportID = (from b in model.tbl_Sup_ShiftReport where b.ReportNumber == reportNumber select b.ShiftReportID ).FirstOrDefault(); if (shiftReportID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = shiftReportID; z.TableName = "tbl_Sup_ShiftReport"; z.AuditProcess = "Created Shift Report " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { shiftReportID = 0; successfulCommit = false; MISC.writetoAlertLog("No shift report ID returned after insert!!"); } } if (shiftReportID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { shiftReportID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(shiftReportID); }
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()); } }
public void insert_Area(string area, bool isActive, byte userID) { int areaID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Get the row count int ct = (from n in model.tbl_Ref_Areas select n ).Count(); ct = ct + 1; byte seq = Convert.ToByte(ct); EDM.tbl_Ref_Areas a = new EDM.tbl_Ref_Areas(); { a.Area = firstCharToUpper(area); a.Seq = seq; a.IsActive = isActive; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Ref_Areas.Add(a); model.SaveChanges(); //Get the id areaID = a.AreaID; if (areaID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = areaID; z.TableName = "tbl_Ref_Areas"; z.AuditProcess = "Created Area (" + area + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { successfulCommit = false; MISC.writetoAlertLog("No area ID returned after insert!!"); } } if (areaID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public void update_WeeklySecurityReport(int securityReportID, string reportNumber, DateTime weekStart, DateTime weekEnd, byte areaID, string comments, GridView gvShiftReport, byte userID) { try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Update header table var wsr = (from a in model.tbl_Mgr_WeeklySecurityReport where a.SecurityReportID == securityReportID select a).First(); wsr.WeekStart = weekStart; wsr.WeekEnd = weekEnd; wsr.Comments = comments; wsr.LastModifiedBy = userID; wsr.LastModifiedOn = DateTime.Now; model.SaveChanges(); ////Delete all shifts saved //for (int j = 0; j < gvShiftReport.Rows.Count; j++) //{ // Label lblShiftID = (Label)gvShiftReport.Rows[j].FindControl("lblShiftID"); // Label lblType = (Label)gvShiftReport.Rows[j].FindControl("lblType"); // bool isScheduled = lblType.Text == "Scheduled" ? true : false; // byte shiftID = Convert.ToByte(lblShiftID.Text); // var wsrc = (from f in model.tbl_Mgr_WeeklySecurityReportComparison // where f.SecurityReportID == securityReportID && f.ShiftID == shiftID && f.IsScheduled == isScheduled // select f).SingleOrDefault(); // if (wsrc != null) // { // model.tbl_Mgr_WeeklySecurityReportComparison.Remove(wsrc); // model.SaveChanges(); // successfulCommit = true; // } //} for (int i = 0; i < gvShiftReport.Rows.Count; i++) { Label lblShiftID = (Label)gvShiftReport.Rows[i].FindControl("lblShiftID"); Label lblType = (Label)gvShiftReport.Rows[i].FindControl("lblType"); Label lblComparisonID = (Label)gvShiftReport.Rows[i].FindControl("lblComparisonID"); //Update shift if it has an ID if (lblComparisonID.Text != "0") { Int32 comparisonID = Convert.ToInt32(lblComparisonID.Text); //insert shift comparison data if (lblType.Text == "Scheduled") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); Label lblMonday = (Label)gvShiftReport.Rows[i].FindControl("lblMonday"); Label lblTuesday = (Label)gvShiftReport.Rows[i].FindControl("lblTuesday"); Label lblWednesday = (Label)gvShiftReport.Rows[i].FindControl("lblWednesday"); Label lblThursday = (Label)gvShiftReport.Rows[i].FindControl("lblThursday"); Label lblFriday = (Label)gvShiftReport.Rows[i].FindControl("lblFriday"); Label lblSaturday = (Label)gvShiftReport.Rows[i].FindControl("lblSaturday"); Label lblSunday = (Label)gvShiftReport.Rows[i].FindControl("lblSunday"); Label lblPresent = (Label)gvShiftReport.Rows[i].FindControl("lblPresent"); Label lblAbsent = (Label)gvShiftReport.Rows[i].FindControl("lblAbsent"); Label lblIncidentsComplaints = (Label)gvShiftReport.Rows[i].FindControl("lblIncidentsComplaints"); Label lblSwitches = (Label)gvShiftReport.Rows[i].FindControl("lblSwitches"); var shi = (from h in model.tbl_Mgr_WeeklySecurityReportComparison where h.ComparisonID == comparisonID select h).First(); shi.CashInGT = lblCashInGT.Text; shi.CashOutGT = lblCashOutGT.Text; shi.Other = lblOther.Text; shi.Monday = lblMonday.Text; shi.Tuesday = lblTuesday.Text; shi.Wednesday = lblWednesday.Text; shi.Thursday = lblThursday.Text; shi.Friday = lblFriday.Text; shi.Saturday = lblSaturday.Text; shi.Sunday = lblSunday.Text; shi.Present = lblPresent.Text; shi.Absent = lblAbsent.Text; shi.IncidentComplaints = lblIncidentsComplaints.Text; shi.Switches = lblSwitches.Text; shi.LastModifiedBy = userID; shi.LastModifiedOn = DateTime.Now; model.SaveChanges(); } else if (lblType.Text == "Actual") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); TextBox tbMonday = (TextBox)gvShiftReport.Rows[i].FindControl("tbMonday"); TextBox tbTuesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbTuesday"); TextBox tbWednesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbWednesday"); TextBox tbThursday = (TextBox)gvShiftReport.Rows[i].FindControl("tbThursday"); TextBox tbFriday = (TextBox)gvShiftReport.Rows[i].FindControl("tbFriday"); TextBox tbSaturday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSaturday"); TextBox tbSunday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSunday"); TextBox tbPresent = (TextBox)gvShiftReport.Rows[i].FindControl("tbPresent"); TextBox tbAbsent = (TextBox)gvShiftReport.Rows[i].FindControl("tbAbsent"); TextBox tbIncidentsComplaints = (TextBox)gvShiftReport.Rows[i].FindControl("tbIncidentsComplaints"); TextBox tbSwitches = (TextBox)gvShiftReport.Rows[i].FindControl("tbSwitches"); var shi = (from h in model.tbl_Mgr_WeeklySecurityReportComparison where h.ComparisonID == comparisonID select h).First(); shi.CashInGT = lblCashInGT.Text; shi.CashOutGT = lblCashOutGT.Text; shi.Other = lblOther.Text; shi.Monday = tbMonday.Text; shi.Tuesday = tbTuesday.Text; shi.Wednesday = tbWednesday.Text; shi.Thursday = tbThursday.Text; shi.Friday = tbFriday.Text; shi.Saturday = tbSaturday.Text; shi.Sunday = tbSunday.Text; shi.Present = tbPresent.Text; shi.Absent = tbAbsent.Text; shi.IncidentComplaints = tbIncidentsComplaints.Text; shi.Switches = tbSwitches.Text; shi.LastModifiedBy = userID; shi.LastModifiedOn = DateTime.Now; model.SaveChanges(); } } //insert shift comparison data else { if (lblType.Text == "Scheduled") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); Label lblMonday = (Label)gvShiftReport.Rows[i].FindControl("lblMonday"); Label lblTuesday = (Label)gvShiftReport.Rows[i].FindControl("lblTuesday"); Label lblWednesday = (Label)gvShiftReport.Rows[i].FindControl("lblWednesday"); Label lblThursday = (Label)gvShiftReport.Rows[i].FindControl("lblThursday"); Label lblFriday = (Label)gvShiftReport.Rows[i].FindControl("lblFriday"); Label lblSaturday = (Label)gvShiftReport.Rows[i].FindControl("lblSaturday"); Label lblSunday = (Label)gvShiftReport.Rows[i].FindControl("lblSunday"); Label lblPresent = (Label)gvShiftReport.Rows[i].FindControl("lblPresent"); Label lblAbsent = (Label)gvShiftReport.Rows[i].FindControl("lblAbsent"); Label lblIncidentsComplaints = (Label)gvShiftReport.Rows[i].FindControl("lblIncidentsComplaints"); Label lblSwitches = (Label)gvShiftReport.Rows[i].FindControl("lblSwitches"); EDM.tbl_Mgr_WeeklySecurityReportComparison b = new EDM.tbl_Mgr_WeeklySecurityReportComparison(); { b.ShiftID = Convert.ToByte(lblShiftID.Text); b.SecurityReportID = securityReportID; b.CashInGT = lblCashInGT.Text; b.CashOutGT = lblCashOutGT.Text; b.Other = lblOther.Text; b.Monday = lblMonday.Text; b.Tuesday = lblTuesday.Text; b.Wednesday = lblWednesday.Text; b.Thursday = lblThursday.Text; b.Friday = lblFriday.Text; b.Saturday = lblSaturday.Text; b.Sunday = lblSunday.Text; b.Present = lblPresent.Text; b.Absent = lblAbsent.Text; b.IncidentComplaints = lblIncidentsComplaints.Text; b.Switches = lblSwitches.Text; b.IsScheduled = true; b.CreatedBy = userID; b.CreatedOn = DateTime.Now; }; model.tbl_Mgr_WeeklySecurityReportComparison.Add(b); model.SaveChanges(); } else if (lblType.Text == "Actual") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); TextBox tbMonday = (TextBox)gvShiftReport.Rows[i].FindControl("tbMonday"); TextBox tbTuesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbTuesday"); TextBox tbWednesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbWednesday"); TextBox tbThursday = (TextBox)gvShiftReport.Rows[i].FindControl("tbThursday"); TextBox tbFriday = (TextBox)gvShiftReport.Rows[i].FindControl("tbFriday"); TextBox tbSaturday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSaturday"); TextBox tbSunday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSunday"); TextBox tbPresent = (TextBox)gvShiftReport.Rows[i].FindControl("tbPresent"); TextBox tbAbsent = (TextBox)gvShiftReport.Rows[i].FindControl("tbAbsent"); TextBox tbIncidentsComplaints = (TextBox)gvShiftReport.Rows[i].FindControl("tbIncidentsComplaints"); TextBox tbSwitches = (TextBox)gvShiftReport.Rows[i].FindControl("tbSwitches"); //insert shift comparison data EDM.tbl_Mgr_WeeklySecurityReportComparison b = new EDM.tbl_Mgr_WeeklySecurityReportComparison(); { b.ShiftID = Convert.ToByte(lblShiftID.Text); b.SecurityReportID = securityReportID; b.CashInGT = lblCashInGT.Text; b.CashOutGT = lblCashOutGT.Text; b.Other = lblOther.Text; b.Monday = tbMonday.Text; b.Tuesday = tbTuesday.Text; b.Wednesday = tbWednesday.Text; b.Thursday = tbThursday.Text; b.Friday = tbFriday.Text; b.Saturday = tbSaturday.Text; b.Sunday = tbSunday.Text; b.Present = tbPresent.Text; b.Absent = tbAbsent.Text; b.IncidentComplaints = tbIncidentsComplaints.Text; b.Switches = tbSwitches.Text; b.IsScheduled = false; b.CreatedBy = userID; b.CreatedOn = DateTime.Now; }; model.tbl_Mgr_WeeklySecurityReportComparison.Add(b); model.SaveChanges(); } } } //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = securityReportID; z.TableName = "tbl_Mgr_WeeklySecurityReport"; z.AuditProcess = "Updated Weekly Security Report for period " + weekStart + " to " + weekEnd + " (" + reportNumber + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } }
public int insert_WeeklySecurityReport(string reportNumber, DateTime weekStart, DateTime weekEnd, byte areaID, string comments, GridView gvShiftReport, byte userID) { int securityReportID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert header EDM.tbl_Mgr_WeeklySecurityReport a = new EDM.tbl_Mgr_WeeklySecurityReport(); { a.ReportNumber = reportNumber; a.AreaID = areaID; a.WeekStart = weekStart; a.WeekEnd = weekEnd; a.Comments = comments == "" ? null : comments; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Mgr_WeeklySecurityReport.Add(a); model.SaveChanges(); //Get the id securityReportID = a.SecurityReportID; if (securityReportID != 0) { for (int i = 0; i < gvShiftReport.Rows.Count; i++) { Label lblShiftID = (Label)gvShiftReport.Rows[i].FindControl("lblShiftID"); Label lblType = (Label)gvShiftReport.Rows[i].FindControl("lblType"); if (lblType.Text == "Scheduled") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); Label lblMonday = (Label)gvShiftReport.Rows[i].FindControl("lblMonday"); Label lblTuesday = (Label)gvShiftReport.Rows[i].FindControl("lblTuesday"); Label lblWednesday = (Label)gvShiftReport.Rows[i].FindControl("lblWednesday"); Label lblThursday = (Label)gvShiftReport.Rows[i].FindControl("lblThursday"); Label lblFriday = (Label)gvShiftReport.Rows[i].FindControl("lblFriday"); Label lblSaturday = (Label)gvShiftReport.Rows[i].FindControl("lblSaturday"); Label lblSunday = (Label)gvShiftReport.Rows[i].FindControl("lblSunday"); Label lblPresent = (Label)gvShiftReport.Rows[i].FindControl("lblPresent"); Label lblAbsent = (Label)gvShiftReport.Rows[i].FindControl("lblAbsent"); Label lblIncidentsComplaints = (Label)gvShiftReport.Rows[i].FindControl("lblIncidentsComplaints"); Label lblSwitches = (Label)gvShiftReport.Rows[i].FindControl("lblSwitches"); //insert shift comparison data EDM.tbl_Mgr_WeeklySecurityReportComparison b = new EDM.tbl_Mgr_WeeklySecurityReportComparison(); { b.ShiftID = Convert.ToByte(lblShiftID.Text); b.SecurityReportID = securityReportID; b.CashInGT = lblCashInGT.Text; b.CashOutGT = lblCashOutGT.Text; b.Other = lblOther.Text; b.Monday = lblMonday.Text; b.Tuesday = lblTuesday.Text; b.Wednesday = lblWednesday.Text; b.Thursday = lblThursday.Text; b.Friday = lblFriday.Text; b.Saturday = lblSaturday.Text; b.Sunday = lblSunday.Text; b.Present = lblPresent.Text; b.Absent = lblAbsent.Text; b.IncidentComplaints = lblIncidentsComplaints.Text; b.Switches = lblSwitches.Text; b.IsScheduled = true; b.CreatedBy = userID; b.CreatedOn = DateTime.Now; }; model.tbl_Mgr_WeeklySecurityReportComparison.Add(b); model.SaveChanges(); } else if (lblType.Text == "Actual") { Label lblCashInGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashInGT"); Label lblCashOutGT = (Label)gvShiftReport.Rows[i].FindControl("lblCashOutGT"); Label lblOther = (Label)gvShiftReport.Rows[i].FindControl("lblOther"); TextBox tbMonday = (TextBox)gvShiftReport.Rows[i].FindControl("tbMonday"); TextBox tbTuesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbTuesday"); TextBox tbWednesday = (TextBox)gvShiftReport.Rows[i].FindControl("tbWednesday"); TextBox tbThursday = (TextBox)gvShiftReport.Rows[i].FindControl("tbThursday"); TextBox tbFriday = (TextBox)gvShiftReport.Rows[i].FindControl("tbFriday"); TextBox tbSaturday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSaturday"); TextBox tbSunday = (TextBox)gvShiftReport.Rows[i].FindControl("tbSunday"); TextBox tbPresent = (TextBox)gvShiftReport.Rows[i].FindControl("tbPresent"); TextBox tbAbsent = (TextBox)gvShiftReport.Rows[i].FindControl("tbAbsent"); TextBox tbIncidentsComplaints = (TextBox)gvShiftReport.Rows[i].FindControl("tbIncidentsComplaints"); TextBox tbSwitches = (TextBox)gvShiftReport.Rows[i].FindControl("tbSwitches"); //insert shift comparison data EDM.tbl_Mgr_WeeklySecurityReportComparison b = new EDM.tbl_Mgr_WeeklySecurityReportComparison(); { b.ShiftID = Convert.ToByte(lblShiftID.Text); b.SecurityReportID = securityReportID; b.CashInGT = lblCashInGT.Text; b.CashOutGT = lblCashOutGT.Text; b.Other = lblOther.Text; b.Monday = tbMonday.Text; b.Tuesday = tbTuesday.Text; b.Wednesday = tbWednesday.Text; b.Thursday = tbThursday.Text; b.Friday = tbFriday.Text; b.Saturday = tbSaturday.Text; b.Sunday = tbSunday.Text; b.Present = tbPresent.Text; b.Absent = tbAbsent.Text; b.IncidentComplaints = tbIncidentsComplaints.Text; b.Switches = tbSwitches.Text; b.IsScheduled = false; b.CreatedBy = userID; b.CreatedOn = DateTime.Now; }; model.tbl_Mgr_WeeklySecurityReportComparison.Add(b); model.SaveChanges(); } } //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = securityReportID; z.TableName = "tbl_Mgr_WeeklySecurityReport"; z.AuditProcess = "Created Weekly Security Report for period " + weekStart + " to " + weekEnd + " (" + reportNumber + ")"; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { securityReportID = 0; successfulCommit = false; MISC.writetoAlertLog("No security report ID returned after insert!!"); } } if (securityReportID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { securityReportID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(securityReportID); }
//insert DAILYlOG public int insert_dailyLog(DateTime date, byte areaID, Int16 locationID, byte shiftID, GridView personsWorking, string areaName, string locationName, string shiftTime, string logNumber, byte userID, int workScheduleID) { int dlID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert dailylog header EDM.tbl_Op_DailyLogs a = new EDM.tbl_Op_DailyLogs(); { a.Date = date; a.AreaID = areaID; a.LocationID = locationID; a.ShiftID = shiftID; a.LogNumber = logNumber; a.WorkScheduleID = workScheduleID; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogs.Add(a); model.SaveChanges(); //Get the id dlID = (from b in model.tbl_Op_DailyLogs where b.LogNumber == logNumber select b.DailyLogID ).FirstOrDefault(); if (dlID != 0) { //insert persons working for (int i = 0; i < personsWorking.Rows.Count; i++) { Label lblEmployeeID = (Label)personsWorking.Rows[i].FindControl("lblEmployeeID"); Label lblIsPresent = (Label)personsWorking.Rows[i].FindControl("lblIsPresent"); Label lblFullName = (Label)personsWorking.Rows[i].FindControl("lblFullName"); CheckBox cbPresent = (CheckBox)personsWorking.Rows[i].FindControl("cbPresent"); Int16 empID = new Int16(); empID = Convert.ToInt16(lblEmployeeID.Text); EDM.tbl_Op_DailyLogsPersonWorking c = new EDM.tbl_Op_DailyLogsPersonWorking(); { c.DailyLogID = dlID; c.EmployeeID = empID; c.IsPresent = cbPresent.Checked ? true : false; c.TimeClocked = DateTime.Now; c.IsDouble = false; c.IsSwitch = false; c.CreatedBy = userID; c.CreatedOn = DateTime.Now; }; model.tbl_Op_DailyLogsPersonWorking.Add(c); model.SaveChanges(); if (((lblIsPresent.Text == "1") || (lblIsPresent.Text == "True")) && (cbPresent.Checked == false)) { //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = dlID; x.TableName = "tbl_Op_DailyLogs"; x.AuditProcess = "Checked " + lblFullName.Text + " as Present on Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; x.DateTime = DateTime.Now; x.UserID = userID; }; model.tbl_AuditLog.Add(x); model.SaveChanges(); } else if (((lblIsPresent.Text == "0") || (lblIsPresent.Text == "False")) && (cbPresent.Checked == true)) { //Insert AuditTrail EDM.tbl_AuditLog x = new EDM.tbl_AuditLog(); { x.SourceID = dlID; x.TableName = "tbl_Op_DailyLogs"; x.AuditProcess = "Unchecked " + lblFullName.Text + " as Present from Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; x.DateTime = DateTime.Now; x.UserID = userID; }; model.tbl_AuditLog.Add(x); model.SaveChanges(); } } //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = dlID; z.TableName = "tbl_Op_DailyLogs"; z.AuditProcess = "Created Daily Log (" + logNumber + ") for " + date.Date.ToString("dd/MM/yyyy") + ", " + areaName + " - " + locationName + " -- " + shiftTime; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { dlID = 0; successfulCommit = false; MISC.writetoAlertLog("No daily log ID returned after insert!!"); } } if (dlID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { dlID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(dlID); }
//Insert new absence public int insert_Absence(string reportNumber, bool isCallIn, Int16 employeeID, DateTime date, TimeSpan time, Int16 callTakenByID, Int16 callForwardedToID, string workSchedule, string phoneNumber, byte absentType, string otherTypeDescription, byte sickLeaveForID, string otherSickLeaveForDescription, string comments, byte userID, DateTime startDate, DateTime endDate) { int absenceID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert transaction EDM.tbl_Op_CallIn_Absent a = new EDM.tbl_Op_CallIn_Absent(); { a.ReportNumber = reportNumber; a.IsCallIn = isCallIn; a.EmployeeID = employeeID; a.Date = date; a.Time = time; a.CallTakenByID = callTakenByID == 0 ? null : (Int16?)callTakenByID; a.ForwardedToID = callForwardedToID == 0 ? null : (Int16?)callForwardedToID; a.WorkSchedule = workSchedule == "" ? null : firstCharToUpper(workSchedule); a.PhoneNumber = phoneNumber == "" ? null : phoneNumber; a.AbsentTypeID = absentType; a.OtherTypeDescription = otherTypeDescription == "" ? null : firstCharToUpper(otherTypeDescription); a.SickLeaveForID = sickLeaveForID == 0 ? null : (byte?)sickLeaveForID; a.OtherSickLeaveForTypeDescription = otherSickLeaveForDescription == "" ? null : firstCharToUpper(otherSickLeaveForDescription); a.Comments = comments == "" ? null : firstCharToUpper(comments); a.StartDate = startDate.Date; a.EndDate = endDate.Date; //a.ShiftID = shiftID; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Op_CallIn_Absent.Add(a); model.SaveChanges(); //Get the absenceid absenceID = (from b in model.tbl_Op_CallIn_Absent where b.ReportNumber == reportNumber select b.CallInOffID ).FirstOrDefault(); //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = absenceID; z.TableName = "tbl_Op_CallIn_Absent"; z.AuditProcess = "Created Call In/Absent Report - " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } //commit transaction ts.Complete(); successfulCommit = true; } } catch (Exception exec) { absenceID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(absenceID); }
//Insert dailyPost public int insert_DailyPostAssignment(DateTime date, byte shiftID, Int16 lateArrivals, Int16 callsForAssistance, Int16 officersPresent, Int16 officersAbsent, Int16 officersAssigned, Int16 officersCalledOut, Int16 officersCallInForDayOff, Int16 officersOnDayOff, Int16 notDressedProperly, string shiftSummary, string shiftBriefingNotes, string PassedOnFrom, string passedOnTo, string summaryOfIncidents, string reportNumber, byte userID, Int16 sleeping) { int postAssignmentID = 0; try { using (TransactionScope ts = new TransactionScope()) { using (EDM.DataSource model = new EDM.DataSource()) { //Insert header EDM.tbl_Sup_DailyPostAssignment a = new EDM.tbl_Sup_DailyPostAssignment(); { a.Date = date; a.ShiftID = shiftID; a.LateArrivals = lateArrivals; a.CallsForAssistance = callsForAssistance; a.OfficersPresent = officersPresent; a.OfficersAbsent = officersAbsent; a.OfficersAssigned = officersAssigned; a.OfficersCalledOut = officersCalledOut; a.OfficersCallInForDayOff = officersCallInForDayOff; a.OfficersOnDayOff = officersOnDayOff; a.NotDressedProperly = notDressedProperly; a.ShiftSummary = shiftSummary; a.ShiftBriefingNotes = shiftBriefingNotes; a.PassedOnFrom = PassedOnFrom; a.PassedOnTo = passedOnTo; a.SummaryOfIncidents = summaryOfIncidents; a.ReportNumber = reportNumber; a.Sleeping = sleeping; a.CreatedBy = userID; a.CreatedOn = DateTime.Now; }; model.tbl_Sup_DailyPostAssignment.Add(a); model.SaveChanges(); //Get the id postAssignmentID = a.PostAssignmentID; if (postAssignmentID != 0) { //Insert AuditTrail EDM.tbl_AuditLog z = new EDM.tbl_AuditLog(); { z.SourceID = postAssignmentID; z.TableName = "tbl_Sup_DailyPostAssignment"; z.AuditProcess = "Created Daily Post Assignment for " + reportNumber; z.DateTime = DateTime.Now; z.UserID = userID; }; model.tbl_AuditLog.Add(z); model.SaveChanges(); } else { postAssignmentID = 0; successfulCommit = false; MISC.writetoAlertLog("No post assignment ID returned after insert!!"); } } if (postAssignmentID != 0) { //commit transaction ts.Complete(); successfulCommit = true; } } } catch (Exception exec) { postAssignmentID = 0; successfulCommit = false; MISC.writetoAlertLog(exec.ToString()); } return(postAssignmentID); }
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()); } }