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 IncidentSection(AlertData pageData)
        {
            PdfPTable tableIncident = new PdfPTable(new float[] { 540f });

            tableIncident.TotalWidth    = 540f;
            tableIncident.LockedWidth   = true;
            tableIncident.SpacingBefore = 5f;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph("Description:", detailHdrFont));
            tableIncident.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(pageData.incidentDescription, detailTxtFont));
            tableIncident.AddCell(cell);

            if (pageData.incident.ISSUE_TYPE_ID == (decimal)EHSIncidentTypeId.InjuryIllness && pageData.incident.INCFORM_INJURYILLNESS != null)
            {
                string val = SQMBasePage.GetXLAT(reportXLAT, "TRUEFALSE", pageData.incident.INCFORM_INJURYILLNESS.ERGONOMIC_CONCERN == true ? "1" : "0").DESCRIPTION_SHORT;
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(string.Format("Ergonomic Concerns" + " ? {0}", val), labelTxtFont));
                tableIncident.AddCell(cell);

                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                val = SQMBasePage.GetXLAT(reportXLAT, "TRUEFALSE", pageData.incident.INCFORM_INJURYILLNESS.STD_PROCS_FOLLOWED == true ? "1" : "0").DESCRIPTION_SHORT;
                cell.AddElement(new Paragraph(string.Format("Standardized Work Procedure Followed" + " ? {0}", val), labelTxtFont));
                tableIncident.AddCell(cell);

                val  = SQMBasePage.GetXLAT(reportXLAT, "TRUEFALSE", pageData.incident.INCFORM_INJURYILLNESS.TRAINING_PROVIDED == true ? "1" : "0").DESCRIPTION_SHORT;
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(string.Format("Was training for this task provided" + " ? {0}", val), labelTxtFont));
                tableIncident.AddCell(cell);

                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(string.Format("How long has associcate been doing this job/specific task" + " ? {0}", SQMBasePage.GetXLAT(reportXLAT, "INJURY_TENURE", pageData.incident.INCFORM_INJURYILLNESS.JOB_TENURE).DESCRIPTION), labelTxtFont));
                tableIncident.AddCell(cell);
            }

            return(tableIncident);
        }
        PdfPTable ActionSection(AlertData pageData)
        {
            PdfPTable tableAction = new PdfPTable(new float[] { 540f });

            tableAction.TotalWidth    = 540f;
            tableAction.LockedWidth   = true;
            tableAction.SpacingBefore = 15f;
            tableAction.SpacingAfter  = 15f;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "ACTION").DESCRIPTION, detailHdrFont));
            tableAction.AddCell(cell);

            if (exportOption == "xls")
            {
                exportList.Add(new ReportCell()
                {
                    Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "ACTION").DESCRIPTION
                });
            }

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "ACTION").DESCRIPTION_SHORT, colHdrFont));
            tableAction.AddCell(cell);

            int n = 0;

            foreach (var ac in pageData.actionList)
            {
                List <string> descList = ac.DESCRIPTION.Split('\r').ToList();
                foreach (string desc in descList)
                {
                    cell = new PdfPCell()
                    {
                        Padding = 1f, Border = 0
                    };
                    cell.AddElement(new Paragraph(desc.Replace("\n", ""), detailTxtFont));
                    tableAction.AddCell(cell);

                    if (exportOption == "xls")
                    {
                        exportList.Add(new ReportCell()
                        {
                            Row = ++n == 1 ? exportRow : ++exportRow, Col = 2, Text = desc.Replace("\n", "")
                        });
                    }
                }
            }

            return(tableAction);
        }
        PdfPTable IncidentSection(AlertData pageData)
        {
            PdfPTable tableIncident = new PdfPTable(new float[] { 540f });

            tableIncident.TotalWidth    = 540f;
            tableIncident.LockedWidth   = true;
            tableIncident.SpacingBefore = 5f;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "DESCRIPTION").DESCRIPTION, detailHdrFont));
            tableIncident.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(pageData.incidentDescription, detailTxtFont));
            tableIncident.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", "DESCRIPTION").DESCRIPTION
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = pageData.incidentDescription
                });
            }

            return(tableIncident);
        }
        PdfPTable IDSection(AlertData pageData)
        {
            PdfPTable tableIncident = new PdfPTable(new float[] { 90f, 450f, });

            tableIncident.TotalWidth  = 540f;
            tableIncident.LockedWidth = true;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 6, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "INCIDENTTYPE").DESCRIPTION_SHORT + ":", detailHdrFont));
            tableIncident.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 4, Border = 0
            };
            cell.AddElement(new Paragraph(string.Format(pageData.incidentType + "   ( # {0} )", pageData.incidentNumber), labelTxtFont));
            tableIncident.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", "INCIDENTTYPE").DESCRIPTION_SHORT
                });
                exportList.Add(new ReportCell()
                {
                    Row = exportRow, Col = 2, Text = string.Format(pageData.incidentType + "   ( # {0} )", pageData.incidentNumber)
                });
            }

            return(tableIncident);
        }
Example #7
0
        AlertData PopulateAlertDataTest()
        {
            AlertData d = new AlertData();

            d.incidentDateTime = "Tuesday, Mar 19, 2014 4:00 PM";
            d.incidentLocation = "Location: Clamart";
            d.incidentNumber   = "Incident #: 135";
            d.incidentType     = "Near Miss";

            d.incidentDescription = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet lacinia sapien. Ut nec luctus leo. Mauris a lacus tellus. Nunc quis ultricies eros, ac molestie justo. Ut pellentesque libero commodo tempus aliquet. Vivamus molestie venenatis elit sed imperdiet.";
            d.incidentRootCause   = new List <string> {
                "The root cause for the incident described above."
            };
            d.incidentContainment = new List <string> {
                "Here is a description of the various steps we used to contain the incident that is listed."
            };
            d.incidentCorrectiveActions = new List <string> {
                "Step 1: stop this from happening again.  Step 2: Make sure it never happens at a later date."
            };

            return(d);
        }
        PdfPTable IDSection(AlertData pageData)
        {
            PdfPTable tableIncident = new PdfPTable(new float[] { 90f, 450f, });

            tableIncident.TotalWidth  = 540f;
            tableIncident.LockedWidth = true;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 6, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "INCIDENTTYPE").DESCRIPTION_SHORT + ":", detailHdrFont));
            tableIncident.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 4, Border = 0
            };
            cell.AddElement(new Paragraph(string.Format(pageData.incidentType + "   ( # {0} )", pageData.incidentNumber), labelTxtFont));
            tableIncident.AddCell(cell);

            return(tableIncident);
        }
        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 ActionSection(AlertData pageData)
        {
            PdfPTable tableAction = new PdfPTable(new float[] { 420f, 110f, 110f });

            tableAction.TotalWidth    = 540f;
            tableAction.LockedWidth   = true;
            tableAction.SpacingBefore = 15f;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.Colspan        = 3;
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ACTION").DESCRIPTION, detailHdrFont));
            tableAction.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ACTION").DESCRIPTION_SHORT, colHdrFont));
            tableAction.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "RESPONSIBLE").DESCRIPTION_SHORT, colHdrFont));
            tableAction.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ACTION_DT").DESCRIPTION_SHORT, colHdrFont));
            tableAction.AddCell(cell);

            foreach (var ac in pageData.actionList)
            {
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(ac.DESCRIPTION, detailTxtFont));
                tableAction.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(ac.COMMENTS, detailTxtFont));
                tableAction.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                if (ac.COMPLETE_DT.HasValue)
                {
                    cell.AddElement(new Paragraph(SQMBasePage.FormatDate((DateTime)ac.COMPLETE_DT, "d", false), detailTxtFont));
                }
                else
                {
                    cell.AddElement(new Paragraph(" ", detailTxtFont));
                }
                tableAction.AddCell(cell);
            }

            return(tableAction);
        }
        PdfPTable ReviewSection(AlertData pageData)
        {
            PdfPTable tableReview = new PdfPTable(new float[] { 170f, 210f, 160f });

            tableReview.TotalWidth    = 540f;
            tableReview.LockedWidth   = true;
            tableReview.SpacingBefore = 15f;
            PdfPCell cell;

            INCFORM_APPROVAL reviewer = null;

            cell = new PdfPCell()
            {
                Padding = 1f, PaddingBottom = 4f, Border = 0
            };
            cell.Colspan        = 3;
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "REVIEW").DESCRIPTION_SHORT, detailHdrFont));
            tableReview.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, PaddingBottom = 4f, Border = 0
            };
            cell.Colspan = 3;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "REVIEW").DESCRIPTION, detailTxtItalicFont));
            tableReview.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "REVIEW_1").DESCRIPTION_SHORT, detailTxtFont));
            tableReview.AddCell(cell);

            if ((reviewer = pageData.approvalList.Where(l => l.approval.ITEM_SEQ == (int)SysPriv.approve1).Select(l => l.approval).FirstOrDefault()) == null)
            {
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
                cell.AddElement(new Paragraph("", detailTxtFont));
                tableReview.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
                cell.AddElement(new Paragraph(string.Format(""), detailTxtFont));
                tableReview.AddCell(cell);
            }
            else
            {
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthLeft = .25f;
                cell.AddElement(new Paragraph(reviewer.APPROVER_PERSON, detailTxtFont));
                tableReview.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_5PHASE", "DATED").DESCRIPTION_SHORT + ":  {0}", SQMBasePage.FormatDate((DateTime)reviewer.APPROVAL_DATE, "d", false)), detailTxtFont));
                tableReview.AddCell(cell);
            }

            cell = new PdfPCell()
            {
                Padding = 2f, PaddingBottom = 5f, Border = 0
            };
            cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthLeft = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "REVIEW_2").DESCRIPTION_SHORT, detailTxtFont));
            tableReview.AddCell(cell);
            if ((reviewer = pageData.approvalList.Where(l => l.approval.ITEM_SEQ == (int)SysPriv.approve2).Select(l => l.approval).FirstOrDefault()) == null)
            {
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthLeft = .25f;
                cell.AddElement(new Paragraph("", detailTxtFont));
                tableReview.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
                cell.AddElement(new Paragraph(string.Format(""), detailTxtFont));
                tableReview.AddCell(cell);
            }
            else
            {
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthLeft = .25f;
                cell.AddElement(new Paragraph(reviewer.APPROVER_PERSON, detailTxtFont));
                tableReview.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 2f, PaddingBottom = 5f, Border = 0
                };
                cell.BorderWidthTop = cell.BorderWidthBottom = cell.BorderWidthLeft = cell.BorderWidthRight = .25f;
                cell.AddElement(new Paragraph(string.Format(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "DATED").DESCRIPTION_SHORT + ":  {0}", SQMBasePage.FormatDate((DateTime)reviewer.APPROVAL_DATE, "d", false)), detailTxtFont));
                tableReview.AddCell(cell);
            }

            return(tableReview);
        }
        PdfPTable ContainmentSection(AlertData pageData)
        {
            PdfPTable tableContain = new PdfPTable(new float[] { 420f, 110f, 110f });

            tableContain.TotalWidth    = 540f;
            tableContain.LockedWidth   = true;
            tableContain.SpacingBefore = 15f;
            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.Colspan        = 3;
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "CONTAINMENT").DESCRIPTION, detailHdrFont));
            tableContain.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "CONTAINMENT").DESCRIPTION_SHORT, colHdrFont));
            tableContain.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "RESPONSIBLE").DESCRIPTION_SHORT, colHdrFont));
            tableContain.AddCell(cell);
            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ACTION_DT").DESCRIPTION_SHORT, colHdrFont));
            tableContain.AddCell(cell);

            foreach (var cc in pageData.containList)
            {
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(cc.ITEM_DESCRIPTION, detailTxtFont));
                tableContain.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(cc.ASSIGNED_PERSON, detailTxtFont));
                tableContain.AddCell(cell);
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                if (cc.START_DATE.HasValue)
                {
                    cell.AddElement(new Paragraph(SQMBasePage.FormatDate((DateTime)cc.START_DATE, "d", false), detailTxtFont));
                }
                else
                {
                    cell.AddElement(new Paragraph(" ", detailTxtFont));
                }
                tableContain.AddCell(cell);
            }

            return(tableContain);
        }
        PdfPTable CauseSection(AlertData pageData)
        {
            PdfPTable tableCause = new PdfPTable(new float[] { 540f });

            tableCause.TotalWidth    = 540f;
            tableCause.LockedWidth   = true;
            tableCause.SpacingBefore = 15f;

            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ROOTCAUSE").DESCRIPTION, detailHdrFont));
            tableCause.AddCell(cell);

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.AddElement(new Paragraph(pageData.incidentDescription, detailTxtItalicFont));
            tableCause.AddCell(cell);

            iTextSharp.text.List lst = new List();
            lst.SetListSymbol("\u2022");
            lst.IndentationLeft = 3f;
            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            foreach (var rc in pageData.root5YList)
            {
                iTextSharp.text.ListItem li = new ListItem(String.Format(" {0}  {1}", SQMBasePage.GetXLAT(reportXLAT, "HS_5PHASE", "ROOTCAUSE").DESCRIPTION_SHORT, rc.ITEM_DESCRIPTION), detailTxtFont);
                lst.Add(li);
            }
            cell.AddElement(lst);
            tableCause.AddCell(cell);

            /*
             * foreach (var rc in pageData.root5YList)
             * {
             *      cell = new PdfPCell() { Padding = 1f, Border = 0 };
             *      cell.AddElement(new Paragraph(String.Format(SQMBasePage.GetXLAT(reportXLAT,"HS_5PHASE", "ROOTCAUSE").DESCRIPTION_SHORT + "  {0}", rc.ITEM_DESCRIPTION), detailTxtFont));
             *      tableCause.AddCell(cell);
             * }
             */
            if (pageData.causation != null)
            {
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0, PaddingTop = 3f
                };
                cell.AddElement(new Paragraph("Causation", detailHdrFont));
                cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "INJURY_CAUSE", pageData.causation.CAUSEATION_CD).DESCRIPTION, detailTxtFont));
                tableCause.AddCell(cell);
            }

            return(tableCause);
        }
Example #14
0
        AlertData PopulateByIncidentId(decimal iid)
        {
            AlertData d        = new AlertData();
            var       entities = new PSsqmEntities();

            var incident = EHSIncidentMgr.SelectIncidentById(entities, iid);

            if (incident != null)
            {
                string plantName = EHSIncidentMgr.SelectPlantNameById((decimal)incident.DETECT_PLANT_ID);
                d.incidentLocation = String.Format("Location: {0}", plantName);
                d.incidentNumber   = String.Format("Incident #: {0}", iid);

                string  incidentType   = EHSIncidentMgr.SelectIncidentTypeByIncidentId(iid);
                decimal incidentTypeId = EHSIncidentMgr.SelectIncidentTypeIdByIncidentId(iid);
                decimal companyId      = incident.DETECT_COMPANY_ID;
                var     questions      = EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 0);
                questions.AddRange(EHSIncidentMgr.SelectIncidentQuestionList(incidentTypeId, companyId, 1));

                // Date/Time

                d.incidentDateTime = 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))
                    {
                        d.incidentDateTime += " " + Convert.ToDateTime(timeAnswer).ToShortTimeString();
                    }
                }

                // Incident Type

                d.incidentType = incidentType;

                // Description

                d.incidentDescription = incident.DESCRIPTION;

                // 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 == iid &&
                                              a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.RootCause
                                              select a.ANSWER_VALUE).FirstOrDefault();

                    if (!string.IsNullOrEmpty(rootCauseAnswer))
                    {
                        d.incidentRootCause = new List <string> {
                            rootCauseAnswer
                        }
                    }
                    ;
                }


                // 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 == iid &&
                                                a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Containment
                                                select a.ANSWER_VALUE).FirstOrDefault();

                    if (!string.IsNullOrEmpty(containmentAnswer))
                    {
                        d.incidentContainment = new List <string> {
                            containmentAnswer
                        }
                    }
                    ;
                }

                // 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 == iid &&
                                               a.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.CorrectiveActions
                                               select a.ANSWER_VALUE).FirstOrDefault();

                    if (!string.IsNullOrEmpty(correctiveAnswer))
                    {
                        d.incidentCorrectiveActions = new List <string> {
                            correctiveAnswer
                        }
                    }
                    ;
                }


                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();


                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);
                    }
                }
            }

            return(d);
        }
        private byte[] BuildPdf()
        {
            reportXLAT = SQMBasePage.SelectXLATList(new string[5] {
                "HS_ALERT", "TRUEFALSE", "SHIFT", "INJURY_TENURE", "INJURY_CAUSE"
            }, 1);

            AlertData pageData = new AlertData()
            {
                incidentDate        = "N/A",
                incidentTime        = "N/A",
                incidentLocation    = "N/A",
                locationNLS         = "en",
                incidentDept        = "N/A",
                incidentNumber      = "N/A",
                incidentType        = "N/A",
                incidentDescription = "N/A",
                detectPerson        = null,
                involvedPerson      = null,
                supervisorPerson    = null,
                incident            = null,
                answerList          = new List <INCIDENT_ANSWER>(),
                containList         = new List <INCFORM_CONTAIN>(),
                root5YList          = new List <INCFORM_ROOT5Y>(),
                causation           = null,
                actionList          = new List <TASK_STATUS>(),
                approvalList        = new List <EHSIncidentApproval>()
            };

            baseApplicationUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + ResolveUrl("~/");

            if (Request.QueryString["iid"] != null)
            {
                string query = Request.QueryString["iid"];
                query = query.Replace(" ", "+");
                iid   = EncryptionManager.Decrypt(query);

                if (Request.QueryString["opt"] != null)
                {
                    exportOption = Request.QueryString["opt"];
                }

                pageData = PopulateByIncidentId(Convert.ToDecimal(iid));
            }
            else
            {
                return(null);
            }

            string customerLogo = "";

            if (System.Configuration.ConfigurationManager.AppSettings["CustomerLogoLarge"] != null)
            {
                customerLogo = System.Configuration.ConfigurationManager.AppSettings["CustomerLogoLarge"].ToString();
            }
            if (string.IsNullOrEmpty(customerLogo))
            {
                if (System.Configuration.ConfigurationManager.AppSettings["CustomerLogo"] != null)
                {
                    customerLogo = System.Configuration.ConfigurationManager.AppSettings["CustomerLogo"].ToString();
                }
            }
            if (string.IsNullOrEmpty(customerLogo))
            {
                customerLogo = "MetricsoftLogo.png";
            }

            string logoUrl = baseApplicationUrl + "images/company/" + customerLogo;

            BaseColor darkGrayColor  = new BaseColor(0.25f, 0.25f, 0.25f);
            BaseColor lightGrayColor = new BaseColor(0.5f, 0.5f, 0.5f);
            BaseColor whiteColor     = new BaseColor(1.0f, 1.0f, 1.0f);
            BaseColor blackColor     = new BaseColor(0.0f, 0.0f, 0.0f);

            iTextSharp.text.Font textFont       = GetTextFont();
            iTextSharp.text.Font headerFont     = GetHeaderFont();
            iTextSharp.text.Font labelFont      = GetLabelFont();
            iTextSharp.text.Font colHeaderFont  = GetTextFont();
            iTextSharp.text.Font textItalicFont = GetTextFont();

            // Chinese text font
            iTextSharp.text.Font textFontZH = GetZHFont();

            detailHdrFont = new iTextSharp.text.Font(headerFont.BaseFont, 13, 0, lightGrayColor);
            detailLblFont = new iTextSharp.text.Font(textFont.BaseFont, 10, 0, blackColor);
            labelTxtFont  = new iTextSharp.text.Font(labelFont.BaseFont, 12, 0, blackColor);
            colHdrFont    = new iTextSharp.text.Font(colHeaderFont.BaseFont, 10, iTextSharp.text.Font.UNDERLINE, blackColor);

            detailTxtBoldFont = new iTextSharp.text.Font(colHeaderFont.BaseFont, 10, iTextSharp.text.Font.BOLD, blackColor);

            switch (pageData.locationNLS)
            {
            case "zh":
                detailTxtFont       = new iTextSharp.text.Font(textFontZH.BaseFont, 10, 0, blackColor);
                detailTxtItalicFont = new iTextSharp.text.Font(textFontZH.BaseFont, 10, iTextSharp.text.Font.ITALIC, blackColor);
                break;

            default:
                detailTxtFont       = new iTextSharp.text.Font(textFont.BaseFont, 10, 0, blackColor);
                detailTxtItalicFont = new iTextSharp.text.Font(colHeaderFont.BaseFont, 10, iTextSharp.text.Font.ITALIC, blackColor);
                break;
            }

            // Create new PDF document
            Document document = new Document(PageSize.A4, 35f, 35f, 35f, 35f);

            using (MemoryStream output = new MemoryStream())
            {
                PdfWriter.GetInstance(document, output);

                try
                {
                    document.Open();

                    //
                    // Table 1 - Header
                    //

                    var table1 = new PdfPTable(new float[] { 162f, 378f });
                    table1.TotalWidth         = 540f;
                    table1.LockedWidth        = true;
                    table1.DefaultCell.Border = 0;
                    table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    table1.DefaultCell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                    table1.SpacingAfter = 10f;

                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(logoUrl);
                    img.ScaleToFit(102f, 51f);
                    var imgCell = new PdfPCell()
                    {
                        Border = 0
                    };
                    imgCell.AddElement(img);
                    table1.AddCell(imgCell);

                    var hdrFont = new iTextSharp.text.Font(headerFont.BaseFont, 24, 0, darkGrayColor);
                    table1.AddCell(new PdfPCell(new Phrase(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "TITLE").DESCRIPTION, hdrFont))
                    {
                        HorizontalAlignment = Element.ALIGN_LEFT,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                        Border = 0
                    });


                    // export to Excel
                    if (exportOption == "xls")
                    {
                        exportList = new List <ReportCell>();
                        exportRow  = 1;
                        exportList.Add(new ReportCell()
                        {
                            Row = 1, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "TITLE").DESCRIPTION
                        });
                    }

                    document.Add(table1);
                    document.Add(IDSection(pageData));
                    document.Add(HeaderSection(pageData));
                    document.Add(IncidentSection(pageData));
                    document.Add(ContainmentSection(pageData));
                    document.Add(CauseSection(pageData));
                    document.Add(ActionSection(pageData));

                    //
                    // Table 4 - Photos
                    //
                    var table4 = new PdfPTable(new float[] { 220f, 220f });
                    table4.TotalWidth    = 540f;
                    table4.LockedWidth   = true;
                    table4.SpacingBefore = 15f;

                    try
                    {
                        if (pageData.photoData != null && pageData.photoData.Count() > 0)
                        {
                            PdfPCell cell = new PdfPCell(new Phrase("Photos", detailHdrFont))
                            {
                                Padding = 5f, Border = 0, Colspan = 2
                            };
                            cell.BorderWidthTop = .25f;
                            table4.AddCell(cell);
                            table4.SpacingBefore = 5f;
                            var captionFont = new iTextSharp.text.Font(textFont.BaseFont, 11, 0, darkGrayColor);

                            if (exportOption == "xls")
                            {
                                exportList.Add(new ReportCell()
                                {
                                    Row = ++exportRow, Col = 1, Text = ""
                                });
                                exportList.Add(new ReportCell()
                                {
                                    Row = ++exportRow, Col = 1, Text = "Photos"
                                });
                            }

                            int i = 0;
                            for (i = 0; i < pageData.photoData.Count; i++)
                            {
                                var photoCell = new PdfPCell()
                                {
                                    PaddingLeft = 0, PaddingRight = 4, PaddingTop = 8, PaddingBottom = 8, Border = 0
                                };

                                iTextSharp.text.Image photo = iTextSharp.text.Image.GetInstance(pageData.photoData[i]);
                                photo.ScaleToFit(176f, 132f);
                                //photo.ScaleToFit(264f, 198f);
                                photoCell.AddElement(photo);

                                photoCell.AddElement(new Phrase(pageData.photoCaptions[i], captionFont));
                                table4.AddCell(photoCell);

                                if (exportOption == "xls")
                                {
                                    MemoryStream ms = new MemoryStream(pageData.photoData[i]);
                                    exportList.Add(new ReportCell()
                                    {
                                        Row = ++exportRow, Col = 1, Type = "img", Text = pageData.photoCaptions[i], Obj = ms
                                    });
                                }
                            }
                            // pad remaining cells in row or else table will be corrupt
                            int currentCol = i % 3;
                            for (int j = 0; j < 3 - currentCol; j++)
                            {
                                table4.AddCell(new PdfPCell()
                                {
                                    PaddingLeft = 0, PaddingRight = 4, PaddingTop = 8, PaddingBottom = 8, Border = 0
                                });
                            }
                        }
                    }
                    catch { }

                    document.Add(table4);

                    document.Close();
                }
                catch
                {
                }

                return(output.ToArray());
            }
        }
        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);
        }
Example #17
0
        AlertData PopulateByProblemCaseId(decimal pcid)
        {
            AlertData d        = new AlertData();
            var       entities = new PSsqmEntities();

            PROB_CASE probCase = ProblemCase.LookupCase(entities, pcid);

            if (probCase != null)
            {
                List <INCIDENT> incidentList = ProblemCase.LookupProbIncidentList(entities, probCase);

                if (incidentList.Count > 0)
                {
                    var incident = incidentList[0];

                    string plantName = EHSIncidentMgr.SelectPlantNameById((decimal)incident.DETECT_PLANT_ID);
                    d.incidentLocation = String.Format("Location: {0}", plantName);
                    d.incidentNumber   = String.Format("Incident #: {0}", incident.INCIDENT_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));

                    d.incidentDateTime = 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))
                        {
                            d.incidentDateTime += " " + Convert.ToDateTime(timeAnswer).ToShortTimeString();
                        }
                    }

                    d.incidentType        = incidentType;
                    d.incidentDescription = probCase.DESC_LONG;


                    // Root Cause(s)

                    List <PROB_CAUSE_STEP> probCauses = (from i in entities.PROB_CAUSE_STEP
                                                         where
                                                         i.PROBCASE_ID == pcid &&
                                                         i.IS_ROOTCAUSE == true
                                                         select i).ToList();

                    if (probCauses.Count > 0)
                    {
                        d.incidentRootCause = (from rc in probCauses select rc.HOW_CONFIRMED).ToList();
                    }

                    // Containment

                    var containment = (from i in entities.PROB_CONTAIN
                                       where i.PROBCASE_ID == pcid
                                       select new
                    {
                        Recommendation = i.CONTAINMENT_DESC,
                        Action = i.INITIAL_ACTION,
                        Results = i.INITIAL_RESULTS
                    }).FirstOrDefault();

                    var actions = (from i in entities.PROB_CONTAIN_ACTION
                                   where i.PROBCASE_ID == pcid
                                   select i.ACTION_ITEM).ToList();

                    if (containment != null)
                    {
                        d.incidentContainment = new List <string> ();

                        //if (!string.IsNullOrEmpty(containment.Recommendation))
                        //{
                        //	d.incidentContainment.Add("RECOMMENDATION: " + containment.Recommendation);
                        //	d.incidentContainment.Add(" ");
                        //}

                        if (actions != null)
                        {
                            string strActions;
                            int    i = 1;
                            foreach (var actionItem in actions)
                            {
                                strActions = i++ + ") " + actionItem;
                                d.incidentContainment.Add(strActions);
                            }
                        }

                        if (!string.IsNullOrEmpty(containment.Results))
                        {
                            d.incidentContainment.Add(" ");
                            d.incidentContainment.Add("RESULTS: " + containment.Results);
                        }
                    }

                    // Corrective Actions

                    var correctiveActions = (from i in entities.PROB_CAUSE_ACTION
                                             where i.PROBCASE_ID == pcid
                                             select i.ACTION_DESC).ToList();

                    if (correctiveActions.Count() > 0)
                    {
                        d.incidentCorrectiveActions = new List <string>();
                        int i = 1;
                        foreach (var ca in correctiveActions)
                        {
                            d.incidentCorrectiveActions.Add(i++ + ") " + ca);
                        }
                    }

                    // Photos

                    var files = (from a in entities.ATTACHMENT
                                 where
                                 ((a.RECORD_ID == incident.INCIDENT_ID && a.RECORD_TYPE == 40) || (a.RECORD_ID == pcid && a.RECORD_TYPE == 21)) &&
                                 (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();

                    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);
                        }
                    }
                }
            }

            return(d);
        }
        PdfPTable CauseSection(AlertData pageData)
        {
            PdfPTable tableCause = new PdfPTable(new float[] { 540f });

            tableCause.TotalWidth    = 540f;
            tableCause.LockedWidth   = true;
            tableCause.SpacingBefore = 15f;

            PdfPCell cell;

            cell = new PdfPCell()
            {
                Padding = 1f, Border = 0
            };
            cell.BorderWidthTop = .25f;
            cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "ROOTCAUSE").DESCRIPTION, detailHdrFont));
            tableCause.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", "ROOTCAUSE").DESCRIPTION
                });
            }

            if (pageData.root5YList != null && pageData.root5YList.Count > 0)
            {
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0
                };
                cell.AddElement(new Paragraph(pageData.root5YList.Last().ITEM_DESCRIPTION, detailTxtItalicFont));
                tableCause.AddCell(cell);

                if (exportOption == "xls")
                {
                    exportList.Add(new ReportCell()
                    {
                        Row = exportRow, Col = 2, Text = pageData.root5YList.Last().ITEM_DESCRIPTION
                    });
                }
            }

            if (pageData.causation != null && !string.IsNullOrEmpty(pageData.causation.CAUSEATION_CD))
            {
                cell = new PdfPCell()
                {
                    Padding = 1f, Border = 0, PaddingTop = 3f
                };
                cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "CAUSATION").DESCRIPTION, detailHdrFont));
                cell.AddElement(new Paragraph(SQMBasePage.GetXLAT(reportXLAT, "INJURY_CAUSE", pageData.causation.CAUSEATION_CD).DESCRIPTION, detailTxtFont));
                tableCause.AddCell(cell);

                if (exportOption == "xls")
                {
                    exportList.Add(new ReportCell()
                    {
                        Row = ++exportRow, Col = 1, Text = SQMBasePage.GetXLAT(reportXLAT, "HS_ALERT", "CAUSATION").DESCRIPTION
                    });
                    exportList.Add(new ReportCell()
                    {
                        Row = exportRow, Col = 2, Text = SQMBasePage.GetXLAT(reportXLAT, "INJURY_CAUSE", pageData.causation.CAUSEATION_CD).DESCRIPTION
                    });
                }
            }

            return(tableCause);
        }