protected void btnSubmit_Click(object sender, EventArgs e)
        {
            INCIDENT_VERIFICATION verification = (from iv in entities.INCIDENT_VERIFICATION
                                                  where
                                                  iv.INCIDENT_ID == incidentId &&
                                                  iv.PERSON_ID == personId &&
                                                  iv.PLANT_ID == plantId
                                                  select iv).FirstOrDefault();

            verification.HAS_RESPONDED = true;
            entities.SaveChanges();
            CheckSubmitDisabled();
        }
        protected void CheckSubmitDisabled()
        {
            INCIDENT_VERIFICATION verification = (from iv in entities.INCIDENT_VERIFICATION
                                                  where
                                                  iv.INCIDENT_ID == incidentId &&
                                                  iv.PERSON_ID == personId &&
                                                  iv.PLANT_ID == plantId
                                                  select iv).FirstOrDefault();

            if (verification.HAS_RESPONDED == true)
            {
                btnSubmit.Text    = "Incident Acknowledged.";
                btnSubmit.Enabled = false;
            }
        }
Пример #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var verifications = new List <INCIDENT_VERIFICATION>();

            if (tbInstructions.Text.Trim().Length == 0 || !rdpDueDate.SelectedDate.HasValue)
            {
                lblRequired.Visible = true;
                return;
            }
            lblRequired.Visible = false;

            PSsqmEntities entities = new PSsqmEntities();

            if (IsEditContext == true)
            {
                if (IncidentId != null)
                {
                    // Update description, date
                    INCIDENT incident = (from i in entities.INCIDENT where i.INCIDENT_ID == IncidentId select i).FirstOrDefault();
                    incident.DESCRIPTION = tbInstructions.Text;
                    if (rdpDueDate.SelectedDate.HasValue)
                    {
                        incident.INCIDENT_DT = (DateTime)rdpDueDate.SelectedDate;
                    }
                    if (!string.IsNullOrEmpty(rcbCases.SelectedValue))
                    {
                        incident.VERIFY_PROBCASE_ID = Convert.ToDecimal(rcbCases.SelectedValue);
                    }
                    entities.SaveChanges();

                    // Add notified people and plants to database
                    foreach (GridViewRow gvr in gvPreventLocationsList.Rows)
                    {
                        decimal plantId = (decimal)gvPreventLocationsList.DataKeys[gvr.RowIndex].Value;

                        if (plantId != null)
                        {
                            RadGrid currentGridView = (RadGrid)gvr.FindControl("rgPlantContacts");
                            foreach (GridDataItem item in currentGridView.Items)
                            {
                                decimal personId = (decimal)item.GetDataKeyValue("PERSON_ID");
                                if (personId != null)
                                {
                                    var incidentVerification = (from iv in entities.INCIDENT_VERIFICATION
                                                                where iv.INCIDENT_ID == IncidentId &&
                                                                iv.PLANT_ID == plantId &&
                                                                iv.PERSON_ID == personId
                                                                select iv).FirstOrDefault();

                                    if (item.Selected == true)
                                    {
                                        var newVerification = new INCIDENT_VERIFICATION()
                                        {
                                            INCIDENT_ID   = IncidentId,
                                            PLANT_ID      = plantId,
                                            PERSON_ID     = personId,
                                            DATE_NOTIFIED = DateTime.Now
                                        };
                                        // Add to list to use for emails
                                        verifications.Add(newVerification);

                                        // Add to database if it does not exist
                                        if (incidentVerification == null)
                                        {
                                            entities.INCIDENT_VERIFICATION.AddObject(newVerification);
                                            entities.SaveChanges();
                                        }
                                    }
                                    else
                                    {
                                        // Delete if exists
                                        if (incidentVerification != null)
                                        {
                                            entities.INCIDENT_VERIFICATION.DeleteObject(incidentVerification);
                                            entities.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else             // Is add context
            {
                decimal verifyProbcaseId = 0;
                if (!string.IsNullOrEmpty(rcbCases.SelectedValue))
                {
                    verifyProbcaseId = Convert.ToDecimal(rcbCases.SelectedValue);
                }

                // Add incident to database
                var incident = new INCIDENT()
                {
                    DETECT_COMPANY_ID  = SessionManager.UserContext.WorkingLocation.Company.COMPANY_ID,
                    DETECT_BUS_ORG_ID  = SessionManager.UserContext.WorkingLocation.BusinessOrg.BUS_ORG_ID,
                    DETECT_PLANT_ID    = SessionManager.UserContext.WorkingLocation.Plant.PLANT_ID,
                    INCIDENT_TYPE      = "EHS",
                    CREATE_DT          = DateTime.Now,
                    CREATE_BY          = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME,
                    DESCRIPTION        = tbInstructions.Text,
                    CREATE_PERSON      = SessionManager.UserContext.Person.PERSON_ID,
                    INCIDENT_DT        = rdpDueDate.SelectedDate.Value,
                    ISSUE_TYPE         = "Prevention Verification",
                    ISSUE_TYPE_ID      = 10,
                    VERIFY_PROBCASE_ID = verifyProbcaseId
                };
                entities.INCIDENT.AddObject(incident);
                entities.SaveChanges();
                decimal incidentId = incident.INCIDENT_ID;


                // Add notified people and plants to database
                foreach (GridViewRow gvr in gvPreventLocationsList.Rows)
                {
                    decimal plantId = (decimal)gvPreventLocationsList.DataKeys[gvr.RowIndex].Value;

                    if (plantId != null)
                    {
                        RadGrid currentGridView = (RadGrid)gvr.FindControl("rgPlantContacts");
                        foreach (GridDataItem item in currentGridView.Items)
                        {
                            decimal personId = (decimal)item.GetDataKeyValue("PERSON_ID");
                            if (personId != null)
                            {
                                if (item.Selected == true)
                                {
                                    var incidentVerification = new INCIDENT_VERIFICATION()
                                    {
                                        INCIDENT_ID   = incidentId,
                                        PLANT_ID      = plantId,
                                        PERSON_ID     = personId,
                                        DATE_NOTIFIED = DateTime.Now
                                    };
                                    verifications.Add(incidentVerification);
                                    entities.INCIDENT_VERIFICATION.AddObject(incidentVerification);
                                    entities.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }

            // Send email(s)

            foreach (var v in verifications)
            {
                var    thisVerification = v;
                PERSON emailPerson      = (from p in entities.PERSON where p.PERSON_ID == thisVerification.PERSON_ID select p).FirstOrDefault();

                string emailSubject = SessionManager.PrimaryCompany().COMPANY_NAME + " Issue Acknowledgement Notification";                 // AW20140129 - use company name variable instead of hard coding.

                string path = "http://" + HttpContext.Current.Request.Url.Authority + "/EHS/EHS_Incident_Verification.aspx";

                path += string.Format("?inid={0}&plid={1}&peid={2}", v.INCIDENT_ID, v.PLANT_ID, emailPerson.PERSON_ID);
                var sb = new StringBuilder();
                sb.AppendLine("<p>You have been sent an issue acknowledgement notification from " + SessionManager.PrimaryCompany().COMPANY_NAME + ".</p>");
                sb.AppendLine();
                sb.AppendLine("<p><b>DETAILS</b></p>");
                sb.AppendLine();
                sb.AppendLine("<p>Date: " + rdpDueDate.SelectedDate.Value.ToShortDateString() + "</p>");
                sb.AppendLine();
                sb.AppendLine("<p>Instructions: " + tbInstructions.Text + "</p>");
                sb.AppendLine();
                sb.AppendLine("<p>Please go here to acknowledge receipt of this issue:<br/>");
                sb.AppendLine("<a href=\"" + path + "\">" + path + "</a></p>");
                sb.AppendLine();                                      // AW20140129
                sb.AppendLine();                                      // AW20140129
                sb.AppendLine("Please Do Not Reply To This Message"); // AW20140129

                string emailBody    = sb.ToString();
                string emailAddress = emailPerson.EMAIL;
                WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "");
            }

            Response.Redirect("EHS_Incidents.aspx");
        }