public static void NotifyOnCreate(decimal incidentId, decimal plantId) { var entities = new PSsqmEntities(); decimal companyId = SessionManager.UserContext.HRLocation.Company.COMPANY_ID; decimal busOrgId = SessionManager.UserContext.HRLocation.BusinessOrg.BUS_ORG_ID; var emailIds = new HashSet <decimal>(); INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, incidentId); string incidentLocation = EHSIncidentMgr.SelectIncidentLocationNameByIncidentId(incidentId); string incidentType = EHSIncidentMgr.SelectIncidentTypeByIncidentId(incidentId); List <ATTACHMENT> attachList = SQM.Website.Classes.SQMDocumentMgr.SelectAttachmentListByRecord(40, incidentId, "", ""); List <NOTIFY> notifications = SQMModelMgr.SelectNotifyHierarchy(companyId, busOrgId, plantId, 0, TaskRecordType.HealthSafetyIncident); foreach (NOTIFY n in notifications) { if (n.NOTIFY_PERSON1 != null) { emailIds.Add((decimal)n.NOTIFY_PERSON1); } if (n.NOTIFY_PERSON2 != null) { emailIds.Add((decimal)n.NOTIFY_PERSON2); } } if (emailIds.Count > 0) { string appUrl = SQMSettings.SelectSettingByCode(entities, "MAIL", "TASK", "MailURL").VALUE; if (string.IsNullOrEmpty(appUrl)) { appUrl = "the website"; } string emailSubject = "Incident Created: " + incidentType + " (" + incidentLocation + ")"; string emailBody = "A new incident has been created:<br/>" + "<br/>" + incidentLocation + "<br/>" + incidentType + "<br/>" + "<br/>" + incident.DESCRIPTION + "<br/>" + "<br/>" + "Please log in to " + appUrl + " to view the incident."; foreach (decimal eid in emailIds) { string emailAddress = (from p in entities.PERSON where p.PERSON_ID == eid select p.EMAIL).FirstOrDefault(); Thread thread = new Thread(() => WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "", "web", attachList)); thread.IsBackground = true; thread.Start(); //WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, ""); } } }
void PopulateByProblemCaseId(decimal problemCaseId) { PROB_CASE probCase = ProblemCase.LookupCase(entities, problemCaseId); if (probCase != null) { List <INCIDENT> incidentList = ProblemCase.LookupProbIncidentList(entities, probCase); ltrDate.Text = probCase.CREATE_DT.ToString(); if (incidentList.Count > 0) { var incident = incidentList[0]; string plantName = EHSIncidentMgr.SelectPlantNameById((decimal)incident.DETECT_PLANT_ID); lblPlantName.Text = String.Format("Location: {0}", plantName); lblIncidentId.Text = String.Format("Incident ID: {0}", incident.INCIDENT_ID); //lblCaseId.Text = String.Format("Problem Case ID: {0}", probCase.PROBCASE_ID); string incidentType = EHSIncidentMgr.SelectIncidentTypeByIncidentId(incident.INCIDENT_ID); decimal incidentTypeId = EHSIncidentMgr.SelectIncidentTypeIdByIncidentId(incident.INCIDENT_ID); decimal companyId = incident.DETECT_COMPANY_ID; var questions = EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 0); questions.AddRange(EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 1)); // Date/Time ltrDate.Text = incidentList[0].INCIDENT_DT.ToLongDateString(); var timeQuestion = questions.FirstOrDefault(q => q.QuestionId == 5); if (timeQuestion != null) { string timeAnswer = (from a in entities.INCIDENT_ANSWER where a.INCIDENT_ID == incident.INCIDENT_ID && a.INCIDENT_QUESTION_ID == 5 select a.ANSWER_VALUE).FirstOrDefault(); if (!string.IsNullOrEmpty(timeAnswer)) { ltrTime.Text = Convert.ToDateTime(timeAnswer).ToShortTimeString(); } } // Incident Type ltrIncidentType.Text = incidentType; // Description ltrDescription.Text = "<div style=\"width: 600px; word-wrap: break-word;\">" + Server.HtmlEncode(probCase.DESC_LONG) + "</div>"; // Root Cause(s) List <PROB_CAUSE_STEP> probCauses = (from i in entities.PROB_CAUSE_STEP where i.PROBCASE_ID == problemCaseId && i.IS_ROOTCAUSE == true select i).ToList(); if (probCauses.Count > 0) { ltrRootCause.Text = "<ul>"; foreach (var pc in probCauses) { ltrRootCause.Text += "<li>" + Server.HtmlEncode(pc.WHY_OCCUR) + "</li>"; } ltrRootCause.Text += "</ul>"; } // Containment var containment = (from i in entities.PROB_CONTAIN where i.PROBCASE_ID == problemCaseId select new { Disposition = i.INITIAL_DISPOSITION, Action = i.INITIAL_ACTION, Results = i.INITIAL_RESULTS }).FirstOrDefault(); if (containment != null) { ltrContainment.Text = "<ul><li>Initial Disposition: " + Server.HtmlEncode(containment.Disposition) + "</li>" + "<li>Action: " + Server.HtmlEncode(containment.Action) + "</li>" + "<li>Results: " + Server.HtmlEncode(containment.Results) + "</li>" + "</ul>"; } // Corrective Actions var correctiveActions = (from i in entities.PROB_CAUSE_ACTION where i.PROBCASE_ID == problemCaseId select i.ACTION_DESC).ToList(); if (correctiveActions.Count > 0) { ltrCorrectiveActions.Text = "<ul>"; foreach (var caDesc in correctiveActions) { ltrCorrectiveActions.Text += "<li>" + Server.HtmlEncode(caDesc) + "</li>"; } ltrCorrectiveActions.Text += "</ul>"; } // Photos BindAttachmentsProbCase(incident.INCIDENT_ID, probCase.PROBCASE_ID); } else { pnlContent.Visible = false; pnlError.Visible = true; } } }
void PopulateByIncidentId(decimal incidentId) { var entities = new PSsqmEntities(); var incident = EHSIncidentMgr.SelectIncidentById(entities, incidentId); string plantName = EHSIncidentMgr.SelectPlantNameById((decimal)incident.DETECT_PLANT_ID); lblPlantName.Text = String.Format("Location: {0}", plantName); lblIncidentId.Text = String.Format("Incident ID: {0}", incidentId); //lblCaseId.Text = String.Format("Incident ID: {0}", incidentId); string incidentType = EHSIncidentMgr.SelectIncidentTypeByIncidentId(incidentId); decimal incidentTypeId = EHSIncidentMgr.SelectIncidentTypeIdByIncidentId(incidentId); decimal companyId = incident.DETECT_COMPANY_ID; var questions = EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 0); questions.AddRange(EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 1)); // Date/Time ltrDate.Text = incident.INCIDENT_DT.ToLongDateString(); var timeQuestion = questions.FirstOrDefault(q => q.QuestionId == (decimal)EHSQuestionId.TimeOfDay); if (timeQuestion != null) { string timeAnswer = (from a in entities.INCIDENT_ANSWER where a.INCIDENT_ID == incident.INCIDENT_ID && a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.TimeOfDay select a.ANSWER_VALUE).FirstOrDefault(); if (!string.IsNullOrEmpty(timeAnswer)) { ltrTime.Text = Convert.ToDateTime(timeAnswer).ToShortTimeString(); } } // Incident Type ltrIncidentType.Text = incidentType; // Description ltrDescription.Text = "<div style=\"width: 600px; word-wrap: break-word;\">" + Server.HtmlEncode(incident.DESCRIPTION) + "</div>"; // Root Cause(s) var rootCauseQuestion = questions.FirstOrDefault(q => q.QuestionId == (decimal)EHSQuestionId.RootCause); if (rootCauseQuestion != null) { string rootCauseAnswer = (from a in entities.INCIDENT_ANSWER where a.INCIDENT_ID == incidentId && a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.RootCause select a.ANSWER_VALUE).FirstOrDefault(); if (!string.IsNullOrEmpty(rootCauseAnswer)) { ltrRootCause.Text = "<div style=\"width: 600px; word-wrap: break-word;\">" + Server.HtmlEncode(rootCauseAnswer) + "</div>"; } } // Containment var containmentQuestion = questions.FirstOrDefault(q => q.QuestionId == (decimal)EHSQuestionId.Containment); if (containmentQuestion != null) { string containmentAnswer = (from a in entities.INCIDENT_ANSWER where a.INCIDENT_ID == incidentId && a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Containment select a.ANSWER_VALUE).FirstOrDefault(); if (!string.IsNullOrEmpty(containmentAnswer)) { ltrContainment.Text = "<div style=\"width: 600px; word-wrap: break-word;\">" + Server.HtmlEncode(containmentAnswer) + "</div>"; } } // Corrective Actions var correctiveQuestion = questions.FirstOrDefault(q => q.QuestionId == (decimal)EHSQuestionId.CorrectiveActions); if (correctiveQuestion != null) { string correctiveAnswer = (from a in entities.INCIDENT_ANSWER where a.INCIDENT_ID == incidentId && a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.CorrectiveActions select a.ANSWER_VALUE).FirstOrDefault(); if (!string.IsNullOrEmpty(correctiveAnswer)) { ltrCorrectiveActions.Text = "<div style=\"width: 600px; word-wrap: break-word;\">" + Server.HtmlEncode(correctiveAnswer) + "</div>"; } } // Photos BindAttachmentsIncident(incident.INCIDENT_ID); }