AlertData PopulateByIncidentId(decimal iid) { AlertData d = new AlertData(); var entities = new PSsqmEntities(); d.incident = EHSIncidentMgr.SelectIncidentById(entities, iid); if (d.incident != null) { try { string plantName = EHSIncidentMgr.SelectPlantNameById((decimal)d.incident.DETECT_PLANT_ID); d.incidentLocation = plantName; d.incidentNumber = WebSiteCommon.FormatID(iid, 6); string incidentType = EHSIncidentMgr.SelectIncidentTypeByIncidentId(iid); decimal incidentTypeId = EHSIncidentMgr.SelectIncidentTypeIdByIncidentId(iid); decimal companyId = d.incident.DETECT_COMPANY_ID; var questions = EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 0); questions.AddRange(EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 1)); d.answerList = EHSIncidentMgr.GetIncidentAnswerList(d.incident.INCIDENT_ID); INCIDENT_ANSWER answer = null; // Date/Time d.incidentDate = d.incident.INCIDENT_DT.ToShortDateString(); if ((answer = d.answerList.Where(a => a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.TimeOfDay).SingleOrDefault()) != null) { if (!string.IsNullOrEmpty(answer.ANSWER_VALUE)) { d.incidentTime = Convert.ToDateTime(answer.ANSWER_VALUE).ToShortTimeString(); } } if ((answer = d.answerList.Where(a => a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Shift).SingleOrDefault()) != null) { if (!string.IsNullOrEmpty(SQMBasePage.GetXLAT(reportXLAT, "SHIFT", answer.ANSWER_VALUE).DESCRIPTION)) { answer.ANSWER_VALUE = SQMBasePage.GetXLAT(reportXLAT, "SHIFT", answer.ANSWER_VALUE).DESCRIPTION; } } if ((answer = d.answerList.Where(a => a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Department).SingleOrDefault()) != null) { d.incidentDept = answer.ANSWER_VALUE; decimal deptID = 0; if (decimal.TryParse(answer.ANSWER_VALUE, out deptID)) { DEPARTMENT dept = SQMModelMgr.LookupDepartment(entities, deptID); if (dept != null) { d.incidentDept = dept.DEPT_NAME; } } } // Incident Type d.incidentType = incidentType; // Description d.incidentDescription = d.incident.DESCRIPTION; d.detectPerson = SQMModelMgr.LookupPerson(entities, (decimal)d.incident.CREATE_PERSON, "", false); if (d.detectPerson != null) { d.supervisorPerson = SQMModelMgr.LookupPersonByEmpID(entities, d.detectPerson.SUPV_EMP_ID); } if (d.incident.ISSUE_TYPE_ID == (decimal)EHSIncidentTypeId.InjuryIllness) { if (d.incident.INCFORM_INJURYILLNESS.INVOLVED_PERSON_ID.HasValue) { d.involvedPerson = SQMModelMgr.LookupPerson(entities, (decimal)d.incident.INCFORM_INJURYILLNESS.INVOLVED_PERSON_ID, "", false); if (d.involvedPerson != null) { if (d.incident.INCFORM_INJURYILLNESS.SUPERVISOR_PERSON_ID.HasValue) // supervisor was known { d.supervisorPerson = SQMModelMgr.LookupPerson(entities, (decimal)d.incident.INCFORM_INJURYILLNESS.SUPERVISOR_PERSON_ID, "", false); } else { // get current supervisor d.supervisorPerson = SQMModelMgr.LookupPersonByEmpID(entities, d.involvedPerson.SUPV_EMP_ID); } } } else { d.involvedPerson = new PERSON(); d.involvedPerson.FIRST_NAME = d.incident.INCFORM_INJURYILLNESS.INVOLVED_PERSON_NAME; } if (d.incident.INCFORM_INJURYILLNESS.DEPT_ID.HasValue) { DEPARTMENT dept = SQMModelMgr.LookupDepartment(entities, (decimal)d.incident.INCFORM_INJURYILLNESS.DEPT_ID); if (dept != null) { d.incidentDept = dept.DEPT_NAME; } } else { d.incidentDept = d.incident.INCFORM_INJURYILLNESS.DEPARTMENT; } } // Containment foreach (INCFORM_CONTAIN cc in EHSIncidentMgr.GetContainmentList(iid, null, false)) { if (cc.ASSIGNED_PERSON_ID.HasValue) { cc.ASSIGNED_PERSON = SQMModelMgr.FormatPersonListItem(SQMModelMgr.LookupPerson((decimal)cc.ASSIGNED_PERSON_ID, "")); } d.containList.Add(cc); } // Root Cause(s) d.root5YList = EHSIncidentMgr.GetRootCauseList(iid).Where(l => !string.IsNullOrEmpty(l.ITEM_DESCRIPTION)).ToList(); if (d.root5YList != null && d.root5YList.Count > 0) { d.incident.INCFORM_CAUSATION.Load(); if (d.incident.INCFORM_CAUSATION != null && d.incident.INCFORM_CAUSATION.Count > 0) { d.causation = d.incident.INCFORM_CAUSATION.ElementAt(0); } } // Corrective Actions foreach (TASK_STATUS ac in EHSIncidentMgr.GetCorrectiveActionList(iid, null, false)) { if (ac.RESPONSIBLE_ID.HasValue) { ac.COMMENTS = SQMModelMgr.FormatPersonListItem(SQMModelMgr.LookupPerson((decimal)ac.RESPONSIBLE_ID, "")); } d.actionList.Add(ac); } var files = (from a in entities.ATTACHMENT where (a.RECORD_ID == iid && a.RECORD_TYPE == 40 && a.DISPLAY_TYPE > 0) && (a.FILE_NAME.ToLower().Contains(".jpg") || a.FILE_NAME.ToLower().Contains(".jpeg") || a.FILE_NAME.ToLower().Contains(".gif") || a.FILE_NAME.ToLower().Contains(".png") || a.FILE_NAME.ToLower().Contains(".bmp")) orderby a.RECORD_TYPE, a.FILE_NAME select new { Data = (from f in entities.ATTACHMENT_FILE where f.ATTACHMENT_ID == a.ATTACHMENT_ID select f.ATTACHMENT_DATA).FirstOrDefault(), Description = (string.IsNullOrEmpty(a.FILE_DESC)) ? "" : a.FILE_DESC, }).ToList(); d.approvalList = EHSIncidentMgr.GetApprovalList(entities, (decimal)d.incident.ISSUE_TYPE_ID, 10.0m, iid, null, 0); if (files.Count > 0) { d.photoData = new List <byte[]>(); d.photoCaptions = new List <string>(); foreach (var f in files) { d.photoData.Add(f.Data); d.photoCaptions.Add(f.Description); } } } catch { } } return(d); }