private int SaveActions(decimal incidentId, List <TASK_STATUS> actionList)
        {
            PSsqmEntities entities = new PSsqmEntities();
            int           status   = 0;

            foreach (TASK_STATUS action in actionList)
            {
                if (!string.IsNullOrEmpty(action.DESCRIPTION) && action.DUE_DT.HasValue && action.RESPONSIBLE_ID.HasValue)
                {
                    EHSIncidentMgr.CreateOrUpdateTask(ActionIncident, action, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ));
                }
            }

            if (status > -1)
            {
                EHSNotificationMgr.NotifyIncidentStatus(ActionIncident, ((int)SysPriv.update).ToString(), "Corrective action specified");
            }

            EHSIncidentMgr.UpdateIncidentStatus(incidentId, IncidentStepStatus.correctiveaction, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ));

            return(status);
        }
Ejemplo n.º 2
0
        public int AddUpdateINCFORM_APPROVAL(decimal incidentId, string option)
        {
            //To get approvertype from usercontext. -NIHARIKA SAXENA
            var approveerType = (SessionManager.UserContext.PrivList.Where(p => p.PRIV <= 100).FirstOrDefault()).PRIV_GROUP.ToString();
            //Check status of severityLevel of Global Safety Group
            bool severityLevel = false;

            var  itemList      = new List <INCFORM_APPROVAL>();
            int  status        = 0;
            int  numRequired   = 0;
            int  requiredCount = 0;
            int  approvalCount = 0;
            bool isRequired;
            bool isChanged = false;



            List <INCFORM_APPROVAL> approvalList = new List <INCFORM_APPROVAL>();

            using (PSsqmEntities ctx = new PSsqmEntities())
            {
                foreach (RepeaterItem item in rptApprovals.Items)
                {
                    isRequired = false;
                    HiddenField hfreq = (HiddenField)item.FindControl("hfReqdComplete");
                    if (hfreq.Value.ToLower() == "true")
                    {
                        ++numRequired;
                        isRequired = true;
                    }

                    INCFORM_APPROVAL approval = new INCFORM_APPROVAL();
                    approval.INCIDENT_ID    = incidentId;
                    approval.APPROVAL_LEVEL = 0;
                    approval.STEP           = ApprovalStep.STEP;
                    Label         lba    = (Label)item.FindControl("lbApprover");
                    Label         lb     = (Label)item.FindControl("lbItemSeq");
                    CheckBox      cba    = (CheckBox)item.FindControl("cbIsAccepted");
                    RadDatePicker rda    = (RadDatePicker)item.FindControl("rdpAcceptDate");
                    HiddenField   hfrole = (HiddenField)item.FindControl("hfRoleDesc");
                    HiddenField   hf     = (HiddenField)item.FindControl("hfItemSeq");
                    HiddenField   hfINCFORM_APPROVER_LIST_ID = (HiddenField)item.FindControl("hfINCFORM_APPROVER_LIST_ID");
                    approval.ITEM_SEQ       = Convert.ToInt32(hf.Value);
                    approval.APPROVER_TITLE = hfrole.Value;
                    if (IncidentId > MaxIncidentForNewFeature && ApprovalStep.STEP < 6)
                    {
                        approval.INCFORM_APPROVER_LIST_ID = Convert.ToDecimal(hfINCFORM_APPROVER_LIST_ID.Value);
                    }

                    //Update SEVERITY_LEVEL value. -
                    if (chkSeverityLevel00.Checked && chkSeverityLevel00.Visible == true)
                    {
                        severityLevel           = chkSeverityLevel00.Checked;
                        approval.SEVERITY_LEVEL = SysPriv.first_add.ToString();
                    }
                    else if (chkSeverityLevel01.Checked && chkSeverityLevel01.Visible == true)
                    {
                        severityLevel           = chkSeverityLevel01.Checked;
                        approval.SEVERITY_LEVEL = SysPriv.l1.ToString();
                    }

                    else if (chkSeverityLevel02.Checked && chkSeverityLevel02.Visible == true)
                    {
                        severityLevel           = chkSeverityLevel02.Checked;
                        approval.SEVERITY_LEVEL = SysPriv.l2.ToString();
                    }
                    else if (chkSeverityLevel03.Checked && chkSeverityLevel03.Visible == true)
                    {
                        severityLevel           = chkSeverityLevel03.Checked;
                        approval.SEVERITY_LEVEL = SysPriv.l3.ToString();
                    }
                    else if (chkSeverityLevel04.Checked && chkSeverityLevel04.Visible == true)
                    {
                        severityLevel           = chkSeverityLevel04.Checked;
                        approval.SEVERITY_LEVEL = SysPriv.l4.ToString();
                    }

                    approvalList.Add(approval);

                    if (cba.Checked == true)    // is approved
                    {
                        ++approvalCount;

                        if (isRequired)
                        {
                            ++requiredCount;
                        }

                        hf = (HiddenField)item.FindControl("hfApprovalID");
                        if (string.IsNullOrEmpty(hf.Value) || hf.Value == "0")
                        {
                            // save new approval to db
                            isChanged = true;
                            approval.APPROVAL_DATE = rda.SelectedDate;
                            approval.IsAccepted    = true;
                            hf = (HiddenField)item.FindControl("hfPersonID");
                            if (string.IsNullOrEmpty(hf.Value) || hf.Value == "0")
                            {
                                approval.APPROVER_PERSON_ID = SessionManager.UserContext.Person.PERSON_ID;
                                approval.APPROVER_PERSON    = SessionManager.UserContext.UserName();
                            }
                            else
                            {
                                approval.APPROVER_PERSON_ID = Convert.ToDecimal(hf.Value);
                                approval.APPROVER_PERSON    = lba.Text;
                            }

                            ctx.AddToINCFORM_APPROVAL(approval);
                        }
                    }
                }

                if (approveerType == "Global Safety Group")
                {
                    if (severityLevel)
                    {
                        lblResponseMsg.Text        = "";
                        chkSeverityLevel00.Enabled = false;

                        chkSeverityLevel01.Enabled = false;

                        chkSeverityLevel02.Enabled = false;

                        chkSeverityLevel03.Enabled = false;

                        chkSeverityLevel04.Enabled = false;

                        //status = ctx.ExecuteStoreCommand("DELETE FROM INCFORM_APPROVAL WHERE INCIDENT_ID = " + incidentId.ToString() + " AND STEP = " + ApprovalStep.ToString());
                        status = ctx.SaveChanges();
                    }
                    else
                    {
                        status = -1;
                    }
                }
                else
                {
                    status = ctx.SaveChanges();
                }

                bool   notifyStepComplete = false;
                string incidentStep       = "";

                // determine step status
                if (approvalCount > 0)
                {
                    if (ApprovalStep.STEP == 10.0m)
                    {
                        incidentStep = "Approvals";
                        IncidentStepStatus stat;
                        if ((numRequired > 0 && requiredCount == numRequired) || approvalCount == rptApprovals.Items.Count)
                        {
                            stat = (IncidentStepStatus)Math.Min(rptApprovals.Items.Count + 150, 155);
                            EHSIncidentMgr.UpdateIncidentStatus(incidentId, stat, true, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ));
                            notifyStepComplete = true;
                        }
                        else
                        {
                            incidentStep = ApprovalStep.STEP == 5.5m ? "CorrectiveActionApproval" : "InitialActionApproval";
                            stat         = (IncidentStepStatus)Math.Min(approvalCount + 150, 154);
                            EHSIncidentMgr.UpdateIncidentStatus(incidentId, stat, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ));
                        }
                    }
                    else
                    {
                        if ((numRequired > 0 && requiredCount == numRequired) || approvalCount == rptApprovals.Items.Count)
                        {
                            EHSIncidentMgr.UpdateIncidentApprovalStatus(incidentId, ApprovalStep.STEP);
                            notifyStepComplete = true;
                        }
                    }
                }

                // only send notifications when approvals are added
                if (isChanged)
                {
                    NotifyCycle notifyCycle;
                    try
                    {
                        notifyCycle = ApprovalStep.NOTIFY_CYCLE.HasValue ? (NotifyCycle)ApprovalStep.NOTIFY_CYCLE : NotifyCycle.None;
                    }
                    catch
                    {
                        notifyCycle = NotifyCycle.None;
                    }

                    if (notifyStepComplete && ApprovalStep.STEP == 10.0m)
                    {
                        EHSNotificationMgr.NotifyIncidentStatus(LocalIncident, ((int)SysPriv.approve).ToString(), "");
                    }

                    if (notifyCycle == NotifyCycle.notifyNext)
                    {
                        INCFORM_APPROVAL priorApproval = new INCFORM_APPROVAL();
                        foreach (INCFORM_APPROVAL approval in approvalList)
                        {
                            // notify missing approvers when prior roles approved or the step was completed by 380 or 390 priv
                            if (!approval.APPROVAL_DATE.HasValue && (priorApproval.APPROVAL_DATE.HasValue || notifyStepComplete))
                            {
                                List <string> infoList = new List <string>();
                                infoList.Add(approval.APPROVER_TITLE);
                                infoList.Add(priorApproval.APPROVER_TITLE);
                                EHSNotificationMgr.NotifyIncidentSignoffRequired(LocalIncident, approval, ApprovalStep.STEP_HEADING_TEXT, approval.ITEM_SEQ >= 390 ? "SIGNOFF" : "APPROVAL", infoList);
                            }
                            priorApproval = approval;
                        }
                    }
                }
            }
            if (IncidentId > MaxIncidentForNewFeature && ApprovalStep.STEP < 6)
            {
                bool isNotify = false;
                if (isChanged)
                {
                    using (PSsqmEntities ctx = new PSsqmEntities())
                    {
                        //foreach (RepeaterItem item in rptApprovals.Items)
                        //{
                        //    CheckBox cba = (CheckBox)item.FindControl("cbIsAccepted");
                        //    HiddenField hfINCFORM_APPROVER_LIST_ID = (HiddenField)item.FindControl("hfINCFORM_APPROVER_LIST_ID");
                        //    HiddenField hfAPPROVERType = (HiddenField)item.FindControl("hfAPPROVERType");
                        //    if (cba.Checked && (hfAPPROVERType.Value == "A" || hfAPPROVERType.Value == "N"))
                        //    {
                        //        isNotify = true;
                        //    }
                        //    else if (!cba.Checked && (hfAPPROVERType.Value == "A" || hfAPPROVERType.Value == "N"))
                        //    {
                        //        isNotify = false;
                        //        break;
                        //    }
                        //}
                        //if (isNotify)
                        //{

                        foreach (RepeaterItem item in rptApprovals.Items)
                        {
                            HiddenField   hfrole = (HiddenField)item.FindControl("hfRoleDesc");
                            CheckBox      cba    = (CheckBox)item.FindControl("cbIsAccepted");
                            HiddenField   hfINCFORM_APPROVER_LIST_ID = (HiddenField)item.FindControl("hfINCFORM_APPROVER_LIST_ID");
                            List <string> infoList = new List <string>();
                            infoList.Add(hfrole.Value);
                            decimal?applistid             = Convert.ToDecimal(hfINCFORM_APPROVER_LIST_ID.Value);
                            INCFORM_APPROVER_LIST appList = (from i in ctx.INCFORM_APPROVER_LIST where i.INCFORM_APPROVER_LIST_ID == applistid select i).FirstOrDefault();
                            PERSON person = (from i in ctx.PERSON where i.PERSON_ID == appList.PERSON_ID select i).FirstOrDefault();
                            if (!cba.Checked)
                            {
                                if (person != null)
                                {
                                    EHSNotificationMgr.NotifyApprover(LocalIncident, person.PERSON_ID, ApprovalStep.STEP_HEADING_TEXT, appList.PRIV >= 390 ? "SIGNOFF" : "APPROVAL", infoList);
                                }
                            }
                        }
                        //CheckBox cba = (CheckBox)item.FindControl("cbIsAccepted");
                        //HiddenField hfINCFORM_APPROVER_LIST_ID = (HiddenField)item.FindControl("hfINCFORM_APPROVER_LIST_ID");
                        //HiddenField hfAPPROVERType = (HiddenField)item.FindControl("hfAPPROVERType");
                        //if (!cba.Checked && (hfAPPROVERType.Value == "R"))
                        //{
                        //    decimal? applistid = Convert.ToDecimal(hfINCFORM_APPROVER_LIST_ID.Value);
                        //    INCFORM_APPROVER_LIST appList = (from i in ctx.INCFORM_APPROVER_LIST where i.INCFORM_APPROVER_LIST_ID == applistid select i).FirstOrDefault();
                        //    if (appList.PERSON_ID != null)
                        //    {
                        //        PERSON person = (from i in ctx.PERSON where i.PERSON_ID == appList.PERSON_ID select i).FirstOrDefault();
                        //        EHSNotificationMgr.NotifyRegionalApprover(person.PERSON_ID, "Notify Regional Approver");
                        //    }
                        //}

                        //}
                    }
                }
            }
            return(status);
        }