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
                {
                }
            }
        }
        protected void rgPreventativeList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                HiddenField hf;
                Label       lbl;
                string      val = "";

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

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

                lbl      = (Label)e.Item.FindControl("lblDescription");
                lbl.Text = StringHtmlExtensions.TruncateHtml(data.Incident.DESCRIPTION, 100, "...");
                lbl.Text = lbl.Text.Replace("<a href", "<a target=\"blank\" href");

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

                lbl      = (Label)e.Item.FindControl("lblCategory");
                lbl.Text = EHSIncidentMgr.SelectIncidentAnswer(data.Incident, (decimal)EHSQuestionId.InspectionCategory) + "<br/>" +
                           EHSIncidentMgr.SelectIncidentAnswer(data.Incident, (decimal)EHSQuestionId.RecommendationType);

                lbl = (Label)e.Item.FindControl("lblIncStatus");
                try
                {
                    if (data.Status == "U")
                    {
                        lbl.Text = "Audited " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE_DATA_COMPLETE, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                    }
                    else if (data.Status == "F")
                    {
                        lbl.Text = "Awaiting Funding " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE_DATA_COMPLETE, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                    }
                    else if (data.Status == "C")
                    {
                        lbl.Text = "Closed  " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE, "d", false) + "<br/><strong>Not Audited</strong>";
                    }
                    else
                    {
                        lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", data.Status) + "<br/>(" + data.DaysOpen + ")";
                    }
                }
                catch
                {
                    ;
                }

                LinkButton lbEditReport = (LinkButton)e.Item.FindControl("lbEditReport");
                lbEditReport.Visible = true;

                try
                {
                    lbl      = (Label)e.Item.FindControl("lblIncidentDT");
                    lbl.Text = SQMBasePage.FormatDate(data.Incident.INCIDENT_DT, "d", false);
                    if ((val = data.EntryList.Where(l => l.INCIDENT_QUESTION_ID == 80).Select(l => l.ANSWER_VALUE).FirstOrDefault()) != null && !string.IsNullOrEmpty(val))
                    {
                        val = val.Substring(0, val.IndexOf(' '));
                        DateTime parseDate;
                        if (DateTime.TryParse(val, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out parseDate))
                        {
                            lbl.Text = parseDate.ToShortDateString();
                        }
                    }
                }
                catch {}
                try {
                    if ((val = data.EntryList.Where(l => l.INCIDENT_QUESTION_ID == 92).Select(l => l.ANSWER_VALUE).FirstOrDefault()) != null && !string.IsNullOrEmpty(val))
                    {
                        val = val.Substring(0, val.IndexOf(' '));
                        DateTime parseDate;
                        if (DateTime.TryParse(val, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out parseDate))
                        {
                            lbl      = (Label)e.Item.FindControl("lblDueDT");
                            lbl.Text = parseDate.ToShortDateString();
                        }
                    }
                }
                catch  {; }

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

                if (rgPreventativeList.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", 1);
                }
            }
        }
        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");
                lb8d.Visible = lbEditReport.Visible = false;                  // mt - for AAM

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

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