PdfPTable HeaderSection(AlertData pageData)
        {
            PdfPTable tableHeader = new PdfPTable(new float[] { 220f, 160f, 160f });

            tableHeader.TotalWidth  = 540f;
            tableHeader.LockedWidth = true;
            PdfPCell        cell;
            INCIDENT_ANSWER answer = null;

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "PLANT").DESCRIPTION_SHORT + ":  {0}", pageData.incidentLocation), detailTxtFont));
            tableHeader.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.Colspan        = 2;
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "LOCATION").DESCRIPTION_SHORT + ":  {0}", pageData.incidentDept), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(String.Format("Date" + ":  {0}", pageData.incidentDate), detailTxtFont));
            tableHeader.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(String.Format("Time" + ":  {0}", pageData.incidentTime), detailTxtFont));
            tableHeader.AddCell(cell);
            cell = FormatHeaderCell(pageData, (decimal)EHSQuestionId.Shift);
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthBottom = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "SUPERVISOR").DESCRIPTION_SHORT + ":  {0}", pageData.supervisorPerson == null ? "" : SQMModelMgr.FormatPersonListItem(pageData.supervisorPerson)), detailTxtFont));
            tableHeader.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.Colspan        = 2;
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight = cell.BorderWidthBottom = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "CONTACT_NO").DESCRIPTION_SHORT + ":  {0}", pageData.supervisorPerson == null ? "" : pageData.supervisorPerson.PHONE), detailTxtFont));
            tableHeader.AddCell(cell);
            return(tableHeader);
        }
        PdfPCell FormatHeaderCell(AlertData pageData, decimal questionID)
        {
            PdfPCell cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };

            if (questionID == 0)
            {
                cell.AddElement(new Paragraph(" ", detailTxtFont));
            }
            else
            {
                INCIDENT_ANSWER answer = pageData.answerList.Where(a => a.INCIDENT_QUESTION_ID == questionID).FirstOrDefault();
                if (answer != null)
                {
                    cell.AddElement(new Paragraph(String.Format(answer.ORIGINAL_QUESTION_TEXT + ": {0}", answer.ANSWER_VALUE), detailTxtFont));
                }
                else
                {
                    cell.AddElement(new Paragraph(" ", detailTxtFont));
                }
            }

            return(cell);
        }
        PdfPTable HeaderSection(AuditData pageData)
        {
            PdfPTable tableHeader = new PdfPTable(new float[] { 540f });

            tableHeader.TotalWidth  = 540f;
            tableHeader.LockedWidth = true;
            PdfPCell        cell;
            INCIDENT_ANSWER answer = null;

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "PLANT").DESCRIPTION_SHORT + ":  {0}", pageData.auditLocation), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight =.25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "DEPARTMENT").DESCRIPTION_SHORT + ":  {0}", pageData.auditDepartment), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight =.25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "DESCRIPTION").DESCRIPTION_SHORT + ":  {0}", pageData.auditDescription), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight =.25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "DATE").DESCRIPTION_SHORT + ":  {0}", pageData.auditDate), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight =.25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "CLOSE_DATE").DESCRIPTION_SHORT + ":  {0}", pageData.auditCloseDate), detailTxtFont));
            tableHeader.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 2f, Border = 0
            };
            //cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight =.25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "AUDIT_PRINT", "AUDIT_PERSON").DESCRIPTION_SHORT + ":  {0}", pageData.auditPerson == null ? "" : SQMModelMgr.FormatPersonListItem(pageData.auditPerson)), detailTxtFont));
            tableHeader.AddCell(cell);

            return(tableHeader);
        }
        protected void rgIncidentActionList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HiddenField  hf;
                Label        lbl;

                EHSIncidentData data = (EHSIncidentData)e.Item.DataItem;

                try
                {
                    lbl      = (Label)e.Item.FindControl("lblIncidentId");
                    lbl.Text = WebSiteCommon.FormatID(data.Incident.INCIDENT_ID, 6);


                    if (data.Incident.DESCRIPTION.Length > 200)
                    {
                        lbl      = (Label)e.Item.FindControl("lblDescription");
                        lbl.Text = data.Incident.DESCRIPTION.Substring(0, 200) + "...";
                    }

                    lbl = (Label)e.Item.FindControl("lblDueDT");
                    INCIDENT_ANSWER entry = data.Incident.INCIDENT_ANSWER.Where(l => l.INCIDENT_QUESTION_ID == 65).FirstOrDefault();  // due date
                    if (entry != null && !string.IsNullOrEmpty(entry.ANSWER_VALUE))
                    {
                        lbl.Text = SQMBasePage.FormatDate(Convert.ToDateTime(entry.ANSWER_VALUE), "d", false);
                        entry    = data.Incident.INCIDENT_ANSWER.Where(l => l.INCIDENT_QUESTION_ID == 64).FirstOrDefault(); // responsible person
                        if (entry != null && !string.IsNullOrEmpty(entry.ANSWER_VALUE))
                        {
                            lbl      = (Label)e.Item.FindControl("lblResponsible");
                            lbl.Text = entry.ANSWER_VALUE;
                        }
                    }

                    RadGrid gv = (RadGrid)e.Item.FindControl("rgIncidentActions");
                    List <INCIDENT_ANSWER> incidentActionList = new List <INCIDENT_ANSWER>();
                    incidentActionList.AddRange(data.Incident.INCIDENT_ANSWER.Where(l => l.INCIDENT_QUESTION_ID == 24 || l.INCIDENT_QUESTION_ID == 27).ToList());
                    if (incidentActionList.Count > 0)
                    {
                        baseRowIndex  = e.Item.RowIndex;
                        gv.DataSource = incidentActionList;
                        gv.DataBind();
                        gv.Visible = true;
                    }

                    LinkButton lb8d = (LinkButton)e.Item.FindControl("lb8d");
                    if (lb8d != null && UserContext.RoleAccess() <= AccessMode.Partner)
                    {
                        lb8d.Visible = false;
                    }
                }

                catch
                {
                }
            }
        }
        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);
        }
        PdfPTable HeaderSection(AlertData pageData)
        {
            PdfPTable tableHeader = new PdfPTable(new float[] { 270f, 270f });

            tableHeader.TotalWidth  = 540f;
            tableHeader.LockedWidth = true;
            PdfPCell        cell;
            INCIDENT_ANSWER answer = null;

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "PLANT").DESCRIPTION_SHORT + ":  {0}", pageData.incidentLocation), detailLblFont));
            tableHeader.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
            cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "LOCATION").DESCRIPTION_SHORT + ":  {0}", pageData.incidentDept), detailLblFont));
            tableHeader.AddCell(cell);

            if (exportOption == "xls")
            {
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = ""
                });
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "PLANT").DESCRIPTION_SHORT
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = pageData.incidentLocation
                });
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "LOCATION").DESCRIPTION_SHORT
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = pageData.incidentDept
                });
            }

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthBottom = cell.BorderWidthRight = .25f;
            cell.AddElement(new Paragraph(String.Format("{0}" + ":  {1}", SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "DATE").DESCRIPTION_SHORT, pageData.incidentDate), detailLblFont));
            tableHeader.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthRight = .25f;
            cell.AddElement(new Paragraph(String.Format("{0}" + ":  {1}", SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "TIME").DESCRIPTION_SHORT, pageData.incidentTime), detailLblFont));
            tableHeader.AddCell(cell);

            if (exportOption == "xls")
            {
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "DATE").DESCRIPTION_SHORT
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = pageData.incidentDate
                });
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "TIME").DESCRIPTION_SHORT
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = pageData.incidentTime
                });
            }

            return(tableHeader);
        }
        protected void btnConversion_Click(object sender, EventArgs e)
        {
            int             status   = 0;
            INCIDENT_ANSWER answer   = null;
            List <XLAT>     xlatList = SQMBasePage.SelectXLATList(new string[6] {
                "SHIFT", "INJURY_CAUSE", "INJURY_TYPE", "INJURY_PART", "INJURY_TENURE", "IQ_10"
            });

            foreach (EHSIncidentData eda in HSCalcs().ehsCtl.IncidentHst.Where(i => i.Incident.INCFORM_LAST_STEP_COMPLETED < 1 && i.Incident.INCIDENT_ID > 0))
            {
                INCIDENT incident = (from i in entities.INCIDENT where i.INCIDENT_ID == eda.Incident.INCIDENT_ID select i).SingleOrDefault();
                incident.INCIDENT_ANSWER.Load();

                // clear any prior conversion reecords
                string delCmd = " = " + incident.INCIDENT_ID.ToString();
                status = entities.ExecuteStoreCommand("DELETE FROM TASK_STATUS WHERE RECORD_TYPE = 40 AND RECORD_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_LOSTTIME_HIST WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_CONTAIN WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_ACTION WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_ROOT5Y WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_CAUSATION WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_APPROVAL WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_WITNESS WHERE INCIDENT_ID" + delCmd);
                status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_INJURYILLNESS WHERE INCIDENT_ID" + delCmd);

                EHSIncidentTypeId issueType = (EHSIncidentTypeId)incident.ISSUE_TYPE_ID;
                try
                {
                    switch (issueType)
                    {
                    case EHSIncidentTypeId.PropertyDamage:
                    case EHSIncidentTypeId.PowerOutage:
                    case EHSIncidentTypeId.Fire:
                    case EHSIncidentTypeId.Explosion:
                    case EHSIncidentTypeId.ImsAudit:
                    case EHSIncidentTypeId.RegulatoryContact:
                    case EHSIncidentTypeId.FireSystemImpairment:
                    case EHSIncidentTypeId.SpillRelease:
                    case EHSIncidentTypeId.EhsWalk:
                    case EHSIncidentTypeId.NearMiss:
                    case EHSIncidentTypeId.InjuryIllness:
                        incident.INCFORM_LAST_STEP_COMPLETED = 100;                                                  // assume new status
                        answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 69).FirstOrDefault(); // containment
                        if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                        {
                            incident.INCFORM_LAST_STEP_COMPLETED = 110;                                      // containment
                            INCFORM_CONTAIN contain = new INCFORM_CONTAIN();
                            contain.INCIDENT_ID        = incident.INCIDENT_ID;
                            contain.ITEM_SEQ           = 1;
                            contain.ITEM_DESCRIPTION   = answer.ANSWER_VALUE;
                            contain.ASSIGNED_PERSON_ID = incident.CREATE_PERSON;
                            contain.START_DATE         = contain.COMPLETION_DATE = incident.CREATE_DT;
                            contain.IsCompleted        = true;
                            contain.LAST_UPD_BY        = SessionManager.UserContext.UserName();
                            contain.LAST_UPD_DT        = DateTime.UtcNow;

                            entities.AddToINCFORM_CONTAIN(contain);
                        }

                        answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 24).FirstOrDefault();                                  // root cause
                        if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                        {
                            incident.INCFORM_LAST_STEP_COMPLETED = 120;                                      // root cause
                            INCFORM_ROOT5Y rootc = new INCFORM_ROOT5Y();
                            rootc.INCIDENT_ID      = incident.INCIDENT_ID;
                            rootc.ITEM_SEQ         = 1;
                            rootc.ITEM_DESCRIPTION = answer.ANSWER_VALUE;
                            rootc.LAST_UPD_BY      = SessionManager.UserContext.UserName();
                            rootc.LAST_UPD_DT      = DateTime.UtcNow;

                            entities.AddToINCFORM_ROOT5Y(rootc);
                        }

                        answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 78).FirstOrDefault();                                  // causation
                        if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                        {
                            incident.INCFORM_LAST_STEP_COMPLETED = 125;                                      // causation
                            INCFORM_CAUSATION cause = new INCFORM_CAUSATION();
                            cause.INCIDENT_ID   = incident.INCIDENT_ID;
                            cause.CAUSEATION_CD = xlatList.Where(l => l.XLAT_GROUP == "INJURY_CAUSE" && l.DESCRIPTION == answer.ANSWER_VALUE).FirstOrDefault() == null ? "1000" : xlatList.Where(l => l.XLAT_GROUP == "INJURY_CAUSE" && l.DESCRIPTION == answer.ANSWER_VALUE).FirstOrDefault().XLAT_CODE;
                            cause.LAST_UPD_BY   = SessionManager.UserContext.UserName();
                            cause.LAST_UPD_DT   = DateTime.UtcNow;

                            entities.AddToINCFORM_CAUSATION(cause);
                        }

                        answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 27).FirstOrDefault();                                  // corrective action
                        if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                        {
                            incident.INCFORM_LAST_STEP_COMPLETED = 130;                                      // corrective action
                            TASK_STATUS action = new TASK_STATUS();
                            action.RECORD_TYPE  = (int)TaskRecordType.HealthSafetyIncident;
                            action.RECORD_ID    = incident.INCIDENT_ID;
                            action.TASK_STEP    = ((int)SysPriv.action).ToString();
                            action.TASK_SEQ     = 0;
                            action.RECORD_SUBID = 0;
                            action.TASK_TYPE    = "T";
                            action.TASK_SEQ     = 0;
                            action.DESCRIPTION  = answer.ANSWER_VALUE;
                            action.DETAIL       = incident.DESCRIPTION;
                            action.STATUS       = "1";
                            action.CREATE_ID    = action.RESPONSIBLE_ID = action.COMPLETE_ID = incident.CREATE_PERSON;                                   // default action values
                            action.CREATE_DT    = action.DUE_DT = action.COMPLETE_DT = incident.CREATE_DT;
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 79).FirstOrDefault();                                 // responsible
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                action.RESPONSIBLE_ID = action.COMPLETE_ID = decimal.Parse(answer.ANSWER_VALUE);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 65).FirstOrDefault();                                      // action due date
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                action.DUE_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 66).FirstOrDefault();                                      // action complete date
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                action.COMPLETE_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 70).FirstOrDefault();                                      // verification ?
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                action.COMMENTS = answer.ANSWER_VALUE;
                            }

                            entities.AddToTASK_STATUS(action);
                        }

                        if (incident.CLOSE_DATE_DATA_COMPLETE.HasValue || incident.CLOSE_DATE.HasValue)
                        {
                            incident.INCFORM_LAST_STEP_COMPLETED = 151;                                      // signoff
                            INCFORM_APPROVAL approval = new INCFORM_APPROVAL();
                            approval.INCIDENT_ID        = incident.INCIDENT_ID;
                            approval.ITEM_SEQ           = (int)SysPriv.approve1;
                            approval.APPROVAL_DATE      = incident.CLOSE_DATE.HasValue ? incident.CLOSE_DATE : incident.CLOSE_DATE_DATA_COMPLETE;
                            approval.IsAccepted         = true;
                            approval.APPROVER_PERSON_ID = incident.CLOSE_PERSON.HasValue ? incident.CLOSE_PERSON : incident.CREATE_PERSON;
                            PERSON person = (from p in entities.PERSON where p.PERSON_ID == approval.APPROVER_PERSON_ID select p).FirstOrDefault();
                            approval.APPROVAL_MESSAGE = approval.APPROVER_PERSON = (person.FIRST_NAME + " " + person.LAST_NAME);
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 67).FirstOrDefault();                                      // completed by
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                approval.APPROVAL_MESSAGE = approval.APPROVER_PERSON = answer.ANSWER_VALUE;
                                string[] names = answer.ANSWER_VALUE.ToLower().Split(' ');
                                if (names.Length > 1)
                                {
                                    string firstName = names[0];
                                    string lastnamne = names[1];
                                    person = (from p in entities.PERSON where p.FIRST_NAME.ToLower() == firstName && p.LAST_NAME.ToLower() == lastnamne select p).FirstOrDefault();
                                }
                            }
                            if (person != null)
                            {
                                approval.APPROVER_PERSON_ID = person.PERSON_ID;
                                approval.APPROVER_TITLE     = person.JOB_TITLE;
                            }

                            entities.AddToINCFORM_APPROVAL(approval);
                        }

                        if (issueType == EHSIncidentTypeId.InjuryIllness)
                        {
                            INCFORM_INJURYILLNESS inRec   = new INCFORM_INJURYILLNESS();
                            INCFORM_WITNESS       witness = new INCFORM_WITNESS();
                            INCFORM_LOSTTIME_HIST hist    = new INCFORM_LOSTTIME_HIST();

                            inRec.INCIDENT_ID = incident.INCIDENT_ID;
                            answer            = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 6).FirstOrDefault();                          // shift

                            inRec.SHIFT = GetXLATCode(xlatList, "SHIFT", answer.ANSWER_VALUE);
                            answer      = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 7).FirstOrDefault();                                // department
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.DEPARTMENT = answer.ANSWER_VALUE;
                                DEPARTMENT dept = (from d in entities.DEPARTMENT where d.DEPT_NAME.ToLower() == answer.ANSWER_VALUE.ToLower() select d).SingleOrDefault();
                                if (dept != null)
                                {
                                    inRec.DEPT_ID = dept.DEPT_ID;
                                }
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 8).FirstOrDefault();                                     // involved person
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.INVOLVED_PERSON_NAME = answer.ANSWER_VALUE;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 4).FirstOrDefault();                                     // supervisor inform date
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.SUPERVISOR_INFORMED_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 5).FirstOrDefault();                                     // time of incident
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.INCIDENT_TIME = TimeSpan.Parse(answer.ANSWER_VALUE);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 9).FirstOrDefault();                                     // witness
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE) && answer.ANSWER_VALUE.Split(' ').Length > 1)
                            {
                                witness.INCIDENT_ID  = incident.INCIDENT_ID;
                                witness.WITNESS_NO   = 1;
                                witness.WITNESS_NAME = answer.ANSWER_VALUE;
                                witness.LAST_UPD_BY  = SessionManager.UserContext.UserName();
                                witness.LAST_UPD_DT  = DateTime.UtcNow;

                                entities.AddToINCFORM_WITNESS(witness);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 10).FirstOrDefault();                                     // inside/outside
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.INSIDE_OUTSIDE_BLDNG = GetXLATCode(xlatList, "IQ_10", answer.ANSWER_VALUE);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 11).FirstOrDefault();                                     // weather
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                ;                                                                                        // NO FIELD
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 12).FirstOrDefault(); // injury type
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.INJURY_TYPE = GetXLATCode(xlatList, "INJURY_TYPE", answer.ANSWER_VALUE);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 13).FirstOrDefault();                                     // body part
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.INJURY_BODY_PART = GetXLATCode(xlatList, "INJURY_PART", answer.ANSWER_VALUE);
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 15).FirstOrDefault();                                     // reocurrance
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.REOCCUR = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 16).FirstOrDefault();                                     // first aid case
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.FIRST_AID = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 37).FirstOrDefault();                                     // employee
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.COMPANY_SUPERVISED = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 58).FirstOrDefault();                                     // specific description
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.DESCRIPTION_LOCAL = answer.ANSWER_VALUE;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 62).FirstOrDefault();                                     // recordable
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.RECORDABLE = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 63).FirstOrDefault();                                     // lost time case
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.LOST_TIME = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;
                                if (inRec.LOST_TIME)
                                {
                                    hist.INCIDENT_ID      = incident.INCIDENT_ID;
                                    hist.WORK_STATUS      = "03";
                                    hist.ITEM_DESCRIPTION = "Lost Time";
                                    hist.BEGIN_DT         = incident.INCIDENT_DT;
                                    answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 3).FirstOrDefault();                                             // expected return date
                                    if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                                    {
                                        hist.RETURN_EXPECTED_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null);
                                    }
                                    answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 55).FirstOrDefault();                                             // actual return date
                                    if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                                    {
                                        hist.RETURN_TOWORK_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null);
                                    }
                                    hist.LAST_UPD_BY = SessionManager.UserContext.UserName();
                                    hist.LAST_UPD_DT = DateTime.UtcNow;

                                    entities.AddToINCFORM_LOSTTIME_HIST(hist);
                                }
                            }
                            answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 74).FirstOrDefault();                                     // occupational event ?
                            if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE))
                            {
                                inRec.STD_PROCS_FOLLOWED = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false;                                          // map to std procedures ?
                            }

                            entities.AddToINCFORM_INJURYILLNESS(inRec);
                        }

                        status = entities.SaveChanges();

                        break;

                    case EHSIncidentTypeId.PreventativeAction:
                        break;

                    default:
                        break;
                    }
                }
                catch
                {
                    decimal id;
                    id = incident.INCIDENT_ID;
                }
            }
        }
        protected void rgIncidentList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HiddenField  hf;
                Label        lbl;

                EHSIncidentData data = (EHSIncidentData)e.Item.DataItem;

                lbl      = (Label)e.Item.FindControl("lblIncidentId");
                lbl.Text = WebSiteCommon.FormatID(data.Incident.INCIDENT_ID, 6);

                if (data.Incident.DESCRIPTION.Length > 120)
                {
                    lbl      = (Label)e.Item.FindControl("lblDescription");
                    lbl.Text = data.Incident.DESCRIPTION.Substring(0, 117) + "...";
                }

                lbl      = (Label)e.Item.FindControl("lblDescription");
                lbl.Text = HttpUtility.HtmlEncode(lbl.Text);

                if (data.Person != null)
                {
                    lbl      = (Label)e.Item.FindControl("lblReportedBy");
                    lbl.Text = SQMModelMgr.FormatPersonListItem(data.Person);
                }

                lbl = (Label)e.Item.FindControl("lblIncStatus");
                if (data.Status == "C")
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "C") + " " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                }
                else if (data.Status == "C8")
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "C8") + " " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE_8D, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                }
                else if (data.Status == "N")
                {
                    lbl.Text = "<strong>" + WebSiteCommon.GetXlatValue("incidentStatus", "N") + "</strong>";
                }
                else
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "A") + "<br/>(" + data.DaysOpen + ")";
                }

                LinkButton lb8d         = (LinkButton)e.Item.FindControl("lb8d");
                LinkButton lbEditReport = (LinkButton)e.Item.FindControl("lbEditReport");

                HyperLink hlReport = (HyperLink)e.Item.FindControl("hlReport");
                hlReport.Visible = true;

                INCIDENT_ANSWER entry = data.Incident.INCIDENT_ANSWER.Where(l => l.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Create8D).FirstOrDefault();
                if (entry != null && entry.ANSWER_VALUE == "Yes")
                {
                    if (UserContext.RoleAccess() > AccessMode.View)
                    {
                        lb8d.Visible = true;
                    }
                    else
                    {
                        lb8d.Visible = false;
                    }

                    lbEditReport.Visible = false;

                    var problemCaseId = EHSIncidentMgr.SelectProblemCaseIdByIncidentId(data.Incident.INCIDENT_ID);
                    if (problemCaseId > 0)
                    {
                        hlReport.NavigateUrl = "/EHS/EHS_Alert_PDF.aspx?pcid=" + EncryptionManager.Encrypt(problemCaseId.ToString());

                        LinkButton lbReport = (LinkButton)e.Item.FindControl("lbReport");
                        lbReport.Visible         = true;
                        lbReport.CommandArgument = problemCaseId.ToString();
                        lbReport.Attributes.Add("CaseType", data.Incident.INCIDENT_TYPE);
                    }
                }
                else
                {
                    lb8d.Visible         = false;
                    lbEditReport.Visible = true;

                    hlReport.NavigateUrl = "/EHS/EHS_Alert_PDF.aspx?iid=" + EncryptionManager.Encrypt(data.Incident.INCIDENT_ID.ToString());
                }

                if (data.Incident.ISSUE_TYPE_ID == 10)                 // Prevention Verification
                {
                    lbEditReport.Visible = false;
                    //HtmlImage imgEditReport = (HtmlImage)e.Item.FindControl("imgEditReport");
                    //imgEditReport.Visible = false;
                }

                if (rgIncidentList.MasterTableView.GetColumn("Attach").Visible&& data.AttachList != null)
                {
                    lbl = (Label)e.Item.FindControl("lblAttach");
                    Ucl_Attach attch = (Ucl_Attach)Page.LoadControl("/Include/Ucl_Attach.ascx");
                    lbl.Parent.Controls.AddAt(lbl.Parent.Controls.IndexOf(lbl), attch);
                    attch.BindListAttachment(data.AttachList, "", 1);
                }
            }
        }