Пример #1
0
        public BusinessLocation ProblemBusinessLocation()
        {
            BusinessLocation problemLocation = new BusinessLocation();

            if (this.IncidentList != null && this.IncidentList.Count > 0)
            {
                INCIDENT incident = this.IncidentList[0];
                if (incident.INCIDENT_TYPE == "QI")
                {
                    problemLocation.Company     = SQMModelMgr.LookupCompany((decimal)incident.RESP_COMPANY_ID);
                    problemLocation.BusinessOrg = SQMModelMgr.LookupBusOrg((decimal)incident.RESP_BUS_ORG_ID);
                    problemLocation.Plant       = SQMModelMgr.LookupPlant((decimal)incident.RESP_PLANT_ID);
                }
                else
                {
                    problemLocation.Company     = SQMModelMgr.LookupCompany((decimal)incident.DETECT_COMPANY_ID);
                    problemLocation.BusinessOrg = SQMModelMgr.LookupBusOrg((decimal)incident.DETECT_BUS_ORG_ID);
                    problemLocation.Plant       = SQMModelMgr.LookupPlant((decimal)incident.DETECT_PLANT_ID);
                }
            }
            else
            {
                problemLocation.Company = this.ProbCase.COMPANY;
            }

            return(problemLocation);
        }
Пример #2
0
        static void UpdatePastDueAuditStatus()
        {
            string status = "";
            // get a list of all audits that do not have a close date
            List <AUDIT> openAudits = EHSAuditMgr.SelectOpenAudits(0, null);

            foreach (AUDIT audit in openAudits)
            {
                AUDIT_TYPE type      = EHSAuditMgr.SelectAuditTypeById(entities, audit.AUDIT_TYPE_ID);
                PLANT      plant     = SQMModelMgr.LookupPlant((decimal)audit.DETECT_PLANT_ID);
                DateTime   closeDT   = Convert.ToDateTime(audit.AUDIT_DT.AddDays(type.DAYS_TO_COMPLETE + 1));              // add one to the date and it will default to the next day at 00:00:00, which means midnight
                DateTime   localTime = WebSiteCommon.LocalTime(DateTime.UtcNow, plant.LOCAL_TIMEZONE);
                if (closeDT.CompareTo(localTime) < 0)
                {
                    // close the audit
                    // valid status codes... A = active, C = complete, I = incomplete/in-process, E = Expired. We are closing audits that are past due, so Expired.
                    try
                    {
                        status = audit.CURRENT_STATUS;
                        if (status != "C")
                        {
                            status = "E";
                        }
                    }
                    catch
                    {
                        status = "E";
                    }
                    EHSAuditMgr.CloseAudit(audit.AUDIT_ID, status, closeDT.AddDays(-1));                     // now take the one day back off so that the close date sets correctly
                    // now mark the Task as expired too!
                    EHSAuditMgr.CreateOrUpdateTask(audit.AUDIT_ID, (decimal)audit.AUDIT_PERSON, 50, closeDT.AddDays(-1), status, 0);
                }
            }
        }
        void InitializeForm()
        {
            lblStatusMsg.Visible = false;
            pnlContain.Visible   = true;

            LocalIncident = EHSIncidentMgr.SelectIncidentById(new PSsqmEntities(), IncidentId);
            if (LocalIncident == null)
            {
                return;
            }

            PLANT plant = SQMModelMgr.LookupPlant(entities, (decimal)LocalIncident.DETECT_PLANT_ID, "");

            if (plant != null)
            {
                IncidentLocationTZ = plant.LOCAL_TIMEZONE;
            }

            pnlContain.Visible = true;
            if (PageMode == PageUseMode.ViewOnly)
            {
                divTitle.Visible  = true;
                lblFormTitle.Text = Resources.LocalizedText.InitialAction;
            }

            rptContain.DataSource = EHSIncidentMgr.GetContainmentList(IncidentId, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ), PageMode == PageUseMode.ViewOnly ? false : true);
            rptContain.DataBind();

            pnlContain.Enabled = PageMode == PageUseMode.ViewOnly ? false : EHSIncidentMgr.CanUpdateIncident(LocalIncident, IsEditContext, SysPriv.originate, LocalIncident.INCFORM_LAST_STEP_COMPLETED);
        }
        public void PopulateInitialForm()
        {
            PSsqmEntities entities = new PSsqmEntities();

            IncidentId = (IsEditContext) ? IncidentId : NewIncidentId;

            if (IncidentId > 0)
            {
                try
                {
                    ActionIncident = (from i in entities.INCIDENT where i.INCIDENT_ID == IncidentId select i).Single();
                    PLANT plant = SQMModelMgr.LookupPlant(entities, (decimal)ActionIncident.DETECT_PLANT_ID, "");
                    if (plant != null)
                    {
                        IncidentLocationTZ = plant.LOCAL_TIMEZONE;
                    }
                }
                catch { }

                XLATList = SQMBasePage.SelectXLATList(new string[1] {
                    "ACTION_CATEGORY"
                }, SessionManager.UserContext.Person.PREFERRED_LANG_ID.HasValue ? (int)SessionManager.UserContext.Person.PREFERRED_LANG_ID : 1);

                decimal typeId = (IsEditContext) ? EditIncidentTypeId : SelectedTypeId;

                // what the f**k does this do ?
                //formSteps = EHSIncidentMgr.GetStepsForincidentTypeId(typeId);
                //totalFormSteps = formSteps.Count();

                InitializeForm();
            }
        }
        protected void btnStatusSave_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn == null || string.IsNullOrEmpty(btn.CommandArgument))
            {
                return;
            }

            string[] cmd = btn.CommandArgument.Split('~');             // recordType, recordID, recordSubID, taskStep, taskType

            EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(Convert.ToInt32(cmd[0]), Convert.ToDecimal(cmd[1]));

            if (auditQuestion != null)
            {
                auditQuestion.Status            = ddlAnswerStatus.SelectedValue.ToString();
                auditQuestion.ResolutionComment = tbResolutionComment.Text.ToString();
                if (auditQuestion.Status.Equals("03"))
                {
                    // update the complete date with the local date/time of the plant
                    AUDIT    audit     = EHSAuditMgr.SelectAuditById(entities, auditQuestion.AuditId);
                    PLANT    plant     = SQMModelMgr.LookupPlant((decimal)audit.DETECT_PLANT_ID);
                    DateTime localTime = WebSiteCommon.LocalTime(DateTime.UtcNow, plant.LOCAL_TIMEZONE);
                    auditQuestion.CompleteDate = localTime;
                }
                EHSAuditMgr.UpdateAnswer(auditQuestion);
            }
            UpdateTaskList("update");
        }
        public void PopulateInitialForm()
        {
            PSsqmEntities entities = new PSsqmEntities();
            decimal       typeId   = (IsEditContext) ? EditIncidentTypeId : SelectedTypeId;

            if (IncidentId > 0)
            {
                try
                {
                    LocalIncident = (from i in entities.INCIDENT where i.INCIDENT_ID == IncidentId select i).SingleOrDefault();
                    PLANT plant = SQMModelMgr.LookupPlant(entities, (decimal)LocalIncident.DETECT_PLANT_ID, "");
                    if (plant != null)
                    {
                        IncidentLocationTZ = plant.LOCAL_TIMEZONE;
                    }


                    if (PageMode == PageUseMode.ViewOnly)
                    {
                        divTitle.Visible  = true;
                        lblFormTitle.Text = Resources.LocalizedText.RootCause;
                    }

                    pnlRoot5Y.Enabled = PageMode == PageUseMode.ViewOnly ? false : EHSIncidentMgr.CanUpdateIncident(LocalIncident, IsEditContext, SysPriv.originate, LocalIncident.INCFORM_LAST_STEP_COMPLETED);
                }
                catch { }
            }

            InitializeForm();
        }
Пример #7
0
        public void rptProgramPart_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                try
                {
                    PartData partData = (PartData)e.Item.DataItem;
                    PLANT    plant    = null;
                    Label    lbl1     = (Label)e.Item.FindControl("lblPartSource");
                    Label    lbl2     = (Label)e.Item.FindControl("lblPartSourceCode");

                    if (partData.Used.SUPP_PLANT_ID.HasValue)
                    {
                        if ((plant = staticPlantList.Where(l => l.PLANT_ID == partData.Used.SUPP_PLANT_ID).SingleOrDefault()) == null)
                        {
                            staticPlantList.Add((plant = SQMModelMgr.LookupPlant((decimal)partData.Used.SUPP_PLANT_ID)));
                        }
                        lbl1.Text = plant.PLANT_NAME;
                        lbl2.Text = plant.ADDRESS.FirstOrDefault().CITY;
                    }
                    else
                    {
                        if ((plant = staticPlantList.Where(l => l.PLANT_ID == partData.Used.PLANT_ID).SingleOrDefault()) == null)
                        {
                            staticPlantList.Add((plant = SQMModelMgr.LookupPlant((decimal)partData.Used.PLANT_ID)));
                        }
                        lbl1.Text = plant.PLANT_NAME;
                        lbl2.Text = plant.DUNS_CODE;
                    }

                    lbl1 = (Label)e.Item.FindControl("lblPartUsed");
                    lbl2 = (Label)e.Item.FindControl("lblPartUsedCode");
                    if (partData.Used.CUST_PLANT_ID.HasValue)
                    {
                        if ((plant = staticPlantList.Where(l => l.PLANT_ID == partData.Used.CUST_PLANT_ID).SingleOrDefault()) == null)
                        {
                            staticPlantList.Add((plant = SQMModelMgr.LookupPlant((decimal)partData.Used.CUST_PLANT_ID)));
                        }
                        lbl1.Text = plant.PLANT_NAME;
                        lbl2.Text = plant.ADDRESS.FirstOrDefault().CITY;
                    }
                    else
                    {
                        if ((plant = staticPlantList.Where(l => l.PLANT_ID == partData.Used.PLANT_ID).SingleOrDefault()) == null)
                        {
                            staticPlantList.Add((plant = SQMModelMgr.LookupPlant((decimal)partData.Used.PLANT_ID)));
                        }
                        lbl1.Text = plant.PLANT_NAME;
                        lbl2.Text = plant.DUNS_CODE;
                    }

                    GridView gv = (GridView)e.Item.FindControl("gvProgramPartList");
                    gv.DataSource = staticPartList.Where(l => l.Used.PLANT_ID == partData.Used.PLANT_ID && l.Used.SUPP_PLANT_ID == partData.Used.SUPP_PLANT_ID && l.Used.CUST_PLANT_ID == partData.Used.CUST_PLANT_ID).ToList();
                    gv.DataBind();
                }
                catch { }
            }
        }
        protected void lnkPlantView_Click(object sender, EventArgs e)
        {
            LinkButton lnk     = (LinkButton)sender;
            decimal    plantID = Convert.ToDecimal(lnk.CommandArgument.ToString().Trim());

            SessionManager.Plant = SQMModelMgr.LookupPlant(entities, SessionManager.SessionContext.ActiveCompany().COMPANY_ID, 0, plantID, "", false);

            Response.Redirect("/Admin/Administrate_ViewPlant.aspx");
        }
Пример #9
0
        protected decimal CreateReAudit(decimal auditId)
        {
            decimal       reauditId = 0;
            PSsqmEntities entities  = new PSsqmEntities();

            AUDIT oldAudit = EHSAuditMgr.SelectAuditById(entities, auditId);

            if (oldAudit != null)
            {
                // create the copy
                PLANT    auditPlant = SQMModelMgr.LookupPlant((decimal)oldAudit.DETECT_PLANT_ID);
                DateTime localTime  = WebSiteCommon.LocalTime(DateTime.UtcNow, auditPlant.LOCAL_TIMEZONE);
                AUDIT    reAudit    = new AUDIT()
                {
                    DETECT_COMPANY_ID = Convert.ToDecimal(oldAudit.DETECT_COMPANY_ID),
                    DETECT_BUS_ORG_ID = oldAudit.DETECT_BUS_ORG_ID,
                    DETECT_PLANT_ID   = oldAudit.DETECT_PLANT_ID,
                    DEPT_ID           = oldAudit.DEPT_ID,
                    AUDIT_TYPE        = oldAudit.AUDIT_TYPE,
                    CREATE_DT         = localTime,
                    CREATE_BY         = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME,
                    DESCRIPTION       = oldAudit.DESCRIPTION,
                    CREATE_PERSON     = SessionManager.UserContext.Person.PERSON_ID,                 // do we want to set this to admin?
                    AUDIT_DT          = localTime,
                    AUDIT_TYPE_ID     = oldAudit.AUDIT_TYPE_ID,
                    AUDIT_PERSON      = SessionManager.UserContext.Person.PERSON_ID,
                    CURRENT_STATUS    = "A",
                    PERCENT_COMPLETE  = 0,
                    TOTAL_SCORE       = 0,
                    AUDITING_ID       = auditId
                };

                entities.AddToAUDIT(reAudit);
                entities.SaveChanges();
                reauditId = reAudit.AUDIT_ID;

                AUDIT_ANSWER            answer    = null;
                List <EHSAuditQuestion> questions = EHSAuditMgr.SelectAuditQuestionList(reAudit.AUDIT_TYPE_ID, 0, auditId);
                foreach (var q in questions)
                {
                    answer = new AUDIT_ANSWER()
                    {
                        AUDIT_ID               = reauditId,
                        AUDIT_QUESTION_ID      = q.QuestionId,
                        ANSWER_VALUE           = "",
                        ORIGINAL_QUESTION_TEXT = q.QuestionText,
                        //COMMENT = q.AnswerComment
                    };
                    entities.AddToAUDIT_ANSWER(answer);
                }
                entities.SaveChanges();
            }

            return(reauditId);
        }
Пример #10
0
        public PLANT GetPlant(decimal plantID)
        {
            PLANT plant;

            plant = this.RecordList.Where(l => l.Plant.PLANT_ID == plantID).Select(l => l.Plant).FirstOrDefault();
            if (plant == null)
            {
                plant = SQMModelMgr.LookupPlant(plantID);
            }
            return(plant);
        }
Пример #11
0
        protected void SelectPlant(decimal plantID)
        {
            newLocation.Plant = SQMModelMgr.LookupPlant(plantID);
            if (newLocation.BusinessOrg == null || (newLocation.BusinessOrg.BUS_ORG_ID != newLocation.Plant.BUS_ORG_ID))
            {
                newLocation.BusinessOrg = SQMModelMgr.LookupBusOrg((decimal)newLocation.Plant.BUS_ORG_ID);
                lblSelBusOrg.Text       = newLocation.BusinessOrg.ORG_NAME;
            }

            lblSelPlant.Text = newLocation.Plant.PLANT_NAME;

            pnlSelectCompany.Visible = false;
            if (OnBusinessLocationChange != null)
            {
                OnBusinessLocationChange(newLocation);
            }
        }
Пример #12
0
        protected void ddlLocationChange(object sender, EventArgs e)
        {
            decimal plantID;

            try
            {
                if (decimal.TryParse(ddlHRLocation.SelectedValue, out plantID))
                {
                    ddlUserTimezone.SelectedValue = SQMModelMgr.LookupPlant(plantID).LOCAL_TIMEZONE;
                    // if (accessLevel >= changeLocationAccessLevel)
                    if (ddlPlantSelect.Items.FindItemByValue(plantID.ToString()) != null)
                    {
                        ddlPlantSelect.Items.FindItemByValue(plantID.ToString()).Checked = true;
                    }
                }
            }
            catch { }
        }
        protected AUDIT_SCHEDULER UpdateAuditScheduler(decimal auditScheduleId)
        {
            AUDIT_SCHEDULER scheduler  = (from i in entities.AUDIT_SCHEDULER where i.AUDIT_SCHEDULER_ID == auditScheduleId select i).FirstOrDefault();
            PLANT           auditPlant = SQMModelMgr.LookupPlant(Convert.ToDecimal(hdnAuditLocation.Value.ToString()));

            if (scheduler != null)
            {
                scheduler.PLANT_ID      = auditPlant.PLANT_ID;
                scheduler.AUDIT_TYPE_ID = Convert.ToDecimal(rddlAuditType.SelectedValue.ToString());
                scheduler.DAY_OF_WEEK   = Convert.ToInt32(rddlDayOfWeek.SelectedValue.ToString());
                scheduler.JOBCODE_CD    = rddlAuditJobcodes.SelectedValue.ToString();
                scheduler.INACTIVE      = cbInactive.Checked;
                scheduler.UPDATE_DT     = DateTime.Now;
                scheduler.UPDATE_PERSON = SessionManager.UserContext.Person.PERSON_ID;
                entities.SaveChanges();
            }

            return(scheduler);
        }
Пример #14
0
        private void OnLocationSelect(decimal plantID)
        {
            PLANT plant = SQMModelMgr.LookupPlant(plantID);

            if (plant == null)
            {
                DisplayProfileMessage(lblProfileNotExist);
            }
            else
            {
                List <BusinessLocation> locationList = new List <BusinessLocation>();
                locationList.Add(new BusinessLocation().Initialize(plantID));
                List <PERSON> responsibleList = SQMModelMgr.SelectPlantPersonList(locationList, "311", AccessMode.Update);

                SQMBasePage.SetPersonList(ddlMetricResponsible, responsibleList, "");
                SQMBasePage.SetPersonList(ddlFinalApprover, responsibleList.Where(l => l.ROLE < SessionManager.AccessModeRoleXREF(AccessMode.Update)).ToList(), "");

                LoadPlantProfile(plant);

                if (LocalProfile() != null && (LocalProfile().Profile.EHS_PROFILE_MEASURE == null || LocalProfile().Profile.EHS_PROFILE_MEASURE.Count == 0))
                {
                    if (UserContext.RoleAccess() > AccessMode.Plant)
                    {
                        List <EHS_PROFILE> profileList = EHSModel.SelectPlantProfileList(SessionManager.UserContext.HRLocation.Company.COMPANY_ID);
                        SQMBasePage.SetLocationList(ddlCopyProfile, SQMModelMgr.SelectBusinessLocationList(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, 0, true).Where(l => profileList.Select(p => p.PLANT_ID).ToArray().Contains(l.Plant.PLANT_ID)).ToList(), 0);
                        ddlCopyProfile.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("", ""));
                        responsibleList = SQMModelMgr.SelectPersonList((decimal)plant.COMPANY_ID, (decimal)plant.BUS_ORG_ID, true, false).Where(p => p.ROLE >= SessionManager.AccessModeRoleXREF(AccessMode.Admin) && p.ROLE < SessionManager.AccessModeRoleXREF(AccessMode.View)).OrderBy(l => l.LAST_NAME).ToList();
                        ddlDefaultResponsible.Items.Clear();
                        foreach (PERSON person in responsibleList)
                        {
                            if (SQMModelMgr.PersonPlantAccess(person, plant.PLANT_ID))
                            {
                                ddlDefaultResponsible.Items.Add(new Telerik.Web.UI.RadComboBoxItem(SQMModelMgr.FormatPersonListItem(person), person.PERSON_ID.ToString()));
                            }
                        }
                        ddlDefaultResponsible.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("", ""));
                        pnlCopyProfile.Visible = true;
                    }
                }

                pnlProfileEdit.Style.Add("display", "none");
            }
        }
Пример #15
0
        public CalcsResult DaysElapsedLTC(COMPANY company, decimal[] plantArray)
        {
            CalcsResult results = new CalcsResult().Initialize();

            SQMMetricMgr metricMgr = new SQMMetricMgr().CreateNew(company, "HS", DateTime.Now, DateTime.Now, plantArray).Load(DateIntervalType.fuzzy, DateSpanOption.SelectRange);

            metricMgr.CalcsMethods(plantArray, "HS", "63", SStat.deltaDy.ToString(), 5, 1);
            results = metricMgr.ehsCtl.Results;
            if (!results.ValidResult)
            {
                PLANT plant = SQMModelMgr.LookupPlant(plantArray[0]);
                if (plant != null && plant.PLANT_START_DT.HasValue)
                {
                    results.Result      = (decimal)Math.Truncate(DateTime.Now.Subtract((DateTime)plant.PLANT_START_DT).TotalDays);
                    results.ValidResult = true;
                }
            }
            return(results);
        }
Пример #16
0
        public static int NotifyIncidentTaskAssigment(INCIDENT incident, TASK_STATUS theTask, string scopeAction)
        {
            int    status = 0;
            PLANT  plant  = SQMModelMgr.LookupPlant((decimal)incident.DETECT_PLANT_ID);
            PERSON person = SQMModelMgr.LookupPerson((decimal)theTask.RESPONSIBLE_ID, "");

            if (person != null && !string.IsNullOrEmpty(person.EMAIL))
            {
                List <XLAT> XLATList = SQMBasePage.SelectXLATList(new string[3] {
                    "NOTIFY_SCOPE", "NOTIFY_SCOPE_TASK", "NOTIFY_TASK_STATUS"
                });
                string appUrl = SQMSettings.SelectSettingByCode(new PSsqmEntities(), "MAIL", "TASK", "MailURL").VALUE;
                if (string.IsNullOrEmpty(appUrl))
                {
                    appUrl = "the website";
                }

                string emailTo      = person.EMAIL;
                string actionText   = XLATList.Where(x => x.XLAT_GROUP == "NOTIFY_SCOPE_TASK" && x.XLAT_CODE == scopeAction).FirstOrDefault().DESCRIPTION;
                string emailSubject = "Health/Safety Incident " + actionText + ": " + incident.ISSUE_TYPE + " (" + plant.PLANT_NAME + ")";
                string emailBody    = "You have been assigned to one or more tasks regarding the following Incident: <br/>" +
                                      "<br/>" +
                                      "Incident ID: " + WebSiteCommon.FormatID(incident.INCIDENT_ID, 6) + "<br/>" +
                                      plant.PLANT_NAME + "<br/>" +
                                      incident.ISSUE_TYPE + "<br/>" +
                                      "<br/>" +
                                      incident.DESCRIPTION + "<br/>" +
                                      "<br/>" +
                                      theTask.DESCRIPTION + "<br/>" +
                                      "<br/>" +
                                      "Due : " + theTask.DUE_DT.ToString() + "<br/>" +
                                      "<br/>" +
                                      "Please log in to " + (appUrl + incidentPath) + " to view this incident.";

                Thread thread = new Thread(() => WebSiteCommon.SendEmail(emailTo, emailSubject, emailBody, "", "web", null));
                thread.IsBackground = true;
                thread.Start();
            }

            return(status);
        }
        protected AUDIT_SCHEDULER CreateNewAuditScheduler()
        {
            decimal auditScheduleId   = 0;
            PLANT   auditPlant        = SQMModelMgr.LookupPlant(Convert.ToDecimal(hdnAuditLocation.Value.ToString()));
            var     newAuditScheduler = new AUDIT_SCHEDULER()
            {
                DAY_OF_WEEK   = Convert.ToInt32(rddlDayOfWeek.SelectedValue.ToString()),
                INACTIVE      = false,
                JOBCODE_CD    = rddlAuditJobcodes.SelectedValue.ToString(),
                PLANT_ID      = auditPlant.PLANT_ID,
                CREATE_DT     = DateTime.Now,
                CREATE_PERSON = SessionManager.UserContext.Person.PERSON_ID,
                AUDIT_TYPE_ID = auditTypeId
            };

            entities.AddToAUDIT_SCHEDULER(newAuditScheduler);
            entities.SaveChanges();
            auditScheduleId = newAuditScheduler.AUDIT_SCHEDULER_ID;

            return(newAuditScheduler);
        }
Пример #18
0
        public int PopulateInitialForm(PSsqmEntities ctx)
        {
            int status = 0;

            INCIDENT incident = EHSIncidentMgr.SelectIncidentById(ctx, IncidentId, true);

            //if incident is not null populate the form
            if (incident != null)
            {
                PLANT plant = SQMModelMgr.LookupPlant(ctx, (decimal)incident.DETECT_PLANT_ID, "");
                if (plant != null)
                {
                    IncidentLocationTZ = plant.LOCAL_TIMEZONE;
                }

                BindCausation(incident);

                pnlCausation.Enabled = PageMode == PageUseMode.ViewOnly ? false : EHSIncidentMgr.CanUpdateIncident(incident, IsEditContext, SysPriv.originate, incident.INCFORM_LAST_STEP_COMPLETED);
            }

            return(status);
        }
Пример #19
0
        public static List <ProblemCase> QualifyCaseList(List <PROB_CASE> problemCaseList, decimal[] plantIDS)
        {
            var   qualCaseList = new List <ProblemCase>();
            PLANT plant        = null;

            using (PSsqmEntities entities = new PSsqmEntities())
            {
                try
                {
                    foreach (PROB_CASE probCase in problemCaseList)
                    {
                        INCIDENT incident = ProblemCase.LookupProbIncidentList(entities, probCase).FirstOrDefault();
                        if (incident != null && ((incident.DETECT_PLANT_ID.HasValue && plantIDS.Contains((decimal)incident.DETECT_PLANT_ID)) || (incident.RESP_PLANT_ID.HasValue && plantIDS.Contains((decimal)incident.RESP_PLANT_ID))))
                        {
                            if (plant == null || plant.PLANT_ID != incident.DETECT_PLANT_ID)
                            {
                                plant = SQMModelMgr.LookupPlant((decimal)incident.DETECT_PLANT_ID);
                            }
                            ProblemCase problemCase = new ProblemCase();
                            problemCase.IncidentList = new List <INCIDENT>();
                            problemCase.ProbCase     = probCase;
                            problemCase.IncidentList.Add(incident);
                            problemCase.Plant = plant;
                            if (incident.INCIDENT_TYPE == "QI")
                            {
                                ;  // todo get qi_occur and part number
                            }
                            qualCaseList.Add(problemCase);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //  SQMLogger.LogException(ex);
                }
            }

            return(qualCaseList);
        }
        public void PopulateInitialForm(string context)
        {
            lblStatusMsg.Visible = false;
            PSsqmEntities entities = new PSsqmEntities();

            hfContext.Value = context;

            IncidentId = (IsEditContext) ? IncidentId : NewIncidentId;

            companyId = SessionManager.UserContext.WorkingLocation.Company.COMPANY_ID;

            if (IncidentId > 0)
            {
                try
                {
                    WorkStatusIncident = (from i in entities.INCIDENT where i.INCIDENT_ID == IncidentId select i).Single();
                    PLANT plant = SQMModelMgr.LookupPlant(entities, (decimal)WorkStatusIncident.DETECT_PLANT_ID, "");
                    if (plant != null)
                    {
                        IncidentLocationTZ = plant.LOCAL_TIMEZONE;
                    }
                }
                catch { return; }
            }
            else
            {
                WorkStatusIncident = new INCIDENT();
                WorkStatusIncident.INCFORM_LAST_STEP_COMPLETED = 100;
            }

            decimal typeId = (IsEditContext) ? EditIncidentTypeId : SelectedTypeId;

            // what the f**k does this do ?
            //formSteps = EHSIncidentMgr.GetStepsForincidentTypeId(typeId);
            //totalFormSteps = formSteps.Count();

            InitializeForm();
        }
Пример #21
0
        public void rptDocList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                try
                {
                    DOCUMENT doc = (DOCUMENT)e.Item.DataItem;
                    Label    lbl = (Label)e.Item.FindControl("lblPosted");
                    lbl.Text = doc.UPLOADED_BY;
                    lbl.Text = lbl.Text + " " + SQMBasePage.FormatDate(WebSiteCommon.LocalTime((DateTime)doc.UPLOADED_DT, SessionManager.UserContext.TimeZoneID), "d", true);  //WebSiteCommon.LocalTime((DateTime)doc.UPLOADED_DT, SessionManager.UserContext.TimeZoneID).ToShortDateString();

                    lbl      = (Label)e.Item.FindControl("lblDisplayArea");
                    lbl.Text = WebSiteCommon.GetXlatValue("docDisplayType", doc.DISPLAY_TYPE.ToString());
                    if (doc.RECORD_ID > 0)
                    {
                        lbl = (Label)e.Item.FindControl("lblDocReference");
                        if (doc.DOCUMENT_SCOPE == "BLI")
                        {
                            PLANT plant = SQMModelMgr.LookupPlant((decimal)doc.RECORD_ID);
                            if (plant != null)
                            {
                                lbl.Text = plant.PLANT_NAME;
                            }
                        }
                    }

                    string ext = doc.FILE_NAME.Substring(doc.FILE_NAME.LastIndexOf('.') + 1).ToLower();
                    if (!string.IsNullOrEmpty(ext))
                    {
                        Image img = (Image)e.Item.FindControl("imgFileType");
                        img.ImageUrl = "~/images/filetype/icon_" + ext + ".gif";
                    }
                }
                catch
                {
                }
            }
        }
Пример #22
0
        private void OnLocationSelect(decimal plantID)
        {
            PLANT plant = SQMModelMgr.LookupPlant(plantID);

            if (plant == null)
            {
                DisplayProfileMessage(lblProfileNotExist);
            }
            else
            {
                List <BusinessLocation> locationList = new List <BusinessLocation>();
                locationList.Add(new BusinessLocation().Initialize(plantID));

                List <PERSON> responsibleList = SQMModelMgr.SelectPrivGroupPersonList(SysPriv.approve, SysScope.envdata, plant.PLANT_ID);
                responsibleList.AddRange(SQMModelMgr.SelectPrivGroupPersonList(SysPriv.admin, SysScope.system, 0));                  // append any system administrators to the approval list
                SQMBasePage.SetPersonList(ddlFinalApprover, responsibleList, "", true);
                SQMBasePage.SetPersonList(ddlMetricResponsible, SQMModelMgr.SelectPrivGroupPersonList(SysPriv.originate, SysScope.envdata, plant.PLANT_ID), "", true);

                LoadPlantProfile(plant);

                if (LocalProfile() != null && (LocalProfile().Profile.EHS_PROFILE_MEASURE == null || LocalProfile().Profile.EHS_PROFILE_MEASURE.Count == 0))
                {
                    if (UserContext.GetMaxScopePrivilege(SysScope.envdata) <= SysPriv.config)
                    {
                        List <EHS_PROFILE> profileList = EHSModel.SelectPlantProfileList(SessionManager.UserContext.HRLocation.Company.COMPANY_ID);
                        SQMBasePage.SetLocationList(ddlCopyProfile, SQMModelMgr.SelectBusinessLocationList(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, 0, true).Where(l => profileList.Select(p => p.PLANT_ID).ToArray().Contains(l.Plant.PLANT_ID)).ToList(), 0);
                        ddlCopyProfile.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("", ""));

                        responsibleList = SQMModelMgr.SelectPrivGroupPersonList(SysPriv.originate, SysScope.envdata, plant.PLANT_ID);
                        SQMBasePage.SetPersonList(ddlDefaultResponsible, responsibleList, "");
                        ddlDefaultResponsible.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("", ""));
                        pnlCopyProfile.Visible = true;
                    }
                }

                pnlProfileEdit.Style.Add("display", "none");
            }
        }
Пример #23
0
        public SQMStream Load(decimal streamID)
        {
            this.Entities = new PSsqmEntities();
            this.isNew    = false;
            this.Stream   = LookupStream(this.Entities, streamID);
            if (this.Stream.PART_ID > 0)
            {
                this.Data.Partdata = SQMModelMgr.LookupPartData(this.Entities, (decimal)this.Stream.COMPANY_ID, (decimal)this.Stream.PART_ID);
            }
            if (this.Stream.SUPP_COMPANY_ID > 0)
            {
                this.Data.Supplier      = SQMModelMgr.LookupCompany((decimal)this.Stream.SUPP_COMPANY_ID);
                this.Data.SupplierPlant = SQMModelMgr.LookupPlant((decimal)this.Stream.SUPP_PLANT_ID);
            }
            if (this.Stream.CUST_COMPANY_ID > 0)
            {
                this.Data.Customer      = SQMModelMgr.LookupCompany((decimal)this.Stream.CUST_COMPANY_ID);
                this.Data.CustomerPlant = SQMModelMgr.LookupPlant((decimal)this.Stream.CUST_PLANT_ID);
            }
            this.RecList = FillHistory(12);

            return(this);
        }
Пример #24
0
        protected bool SaveUser(bool updateUser)
        {
            bool  bErrors = false;
            bool  success;
            Label lblErrorMessage = null;

            PERSON person        = LocalPerson();
            string currentSSOID  = LocalPerson().SSO_ID;
            PERSON currentPerson = new PERSON();

            if (isNew)
            {
                person.SSO_ID = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text.Trim();  // trim traling blanks when creating new user
            }
            else
            {
                person             = SQMModelMgr.LookupPerson(entities, person.PERSON_ID, "", false);
                person.SSO_ID      = string.IsNullOrEmpty(tbUserSSOID.Text) ? "" : tbUserSSOID.Text;
                currentPerson.ROLE = person.ROLE;
            }

            person.FIRST_NAME = string.IsNullOrEmpty(tbUserFirstName.Text) ? "" : tbUserFirstName.Text;
            person.LAST_NAME  = string.IsNullOrEmpty(tbUserLastName.Text) ? "" : tbUserLastName.Text;
            person.JOB_TITLE  = tbUserTitle.Text;
            person.PHONE      = tbUserPhone.Text;
            person.EMAIL      = tbUserEmail.Text;

            if (!string.IsNullOrEmpty(ddlUserLanguage.SelectedValue))
            {
                person.PREFERRED_LANG_ID = Convert.ToInt32(ddlUserLanguage.SelectedValue);
            }
            if (!string.IsNullOrEmpty(ddlUserTimezone.SelectedValue))
            {
                person.PREFERRED_TIMEZONE = ddlUserTimezone.SelectedValue;
            }

            person.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID;
            if (!string.IsNullOrEmpty(ddlHRLocation.SelectedValue))
            {
                PLANT plant = SQMModelMgr.LookupPlant(Convert.ToDecimal(ddlHRLocation.SelectedValue));
                if (plant != null)
                {
                    person.PLANT_ID   = plant.PLANT_ID;
                    person.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID;
                }
            }
            person.NEW_LOCATION_CD = "";

            foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlPlantSelect))
            {
                person.NEW_LOCATION_CD += (item.Value + ",");
            }
            person.NEW_LOCATION_CD = person.NEW_LOCATION_CD.TrimEnd(',');

            person.OLD_LOCATION_CD = "";

            foreach (RadComboBoxItem item in SQMBasePage.GetComboBoxCheckedItems(ddlCustPlantSelect))
            {
                person.OLD_LOCATION_CD += (item.Value + ",");
            }
            person.OLD_LOCATION_CD = person.OLD_LOCATION_CD.TrimEnd(',');

            person.STATUS = ddlUserStatus.SelectedValue;

            // roles were originally a list - let's keep the logic below just in case we need to restore a multi-role strategy
            //person.PERSON_ROLE.Clear();
            person.ROLE           = GetSelectedUserRole();
            person.RCV_ESCALATION = cbUserRcvEscalation.Checked;

            person.PERSON_ACCESS.Clear();
            string prod = "";

            foreach (RadComboBoxItem accessItem in ddlModuleAccess.Items)
            {
                if (accessItem.IsSeparator)
                {
                    prod = accessItem.Value;
                }
                if (accessItem.Checked || person.ROLE <= 100)
                {
                    person = SQMModelMgr.AddPersonAccess(person, prod, accessItem.Value, true);
                }
            }

            SetLocalPerson(person);

            if (string.IsNullOrEmpty(tbUserSSOID.Text) || string.IsNullOrEmpty(tbUserFirstName.Text) || string.IsNullOrEmpty(tbUserLastName.Text) ||
                string.IsNullOrEmpty(tbUserEmail.Text) || ddlUserRole.SelectedIndex < 0 || string.IsNullOrEmpty(ddlHRLocation.SelectedValue) ||
                string.IsNullOrEmpty(ddlHRLocation.SelectedValue))
            {
                lblErrorMessage = lblErrRequiredInputs;
            }

            if (lblErrorMessage == null)
            {
                // AW20131106 - need to verify that the SSO_ID and email address are unique in the system
                lblDuplicateSSOId.Visible = false;
                lblDuplicateEmail.Visible = false;
                string strSSOId = tbUserSSOID.Text;
                string strEmail = tbUserEmail.Text;
                if (isNew) // || !strSSOId.Equals(person.SSO_ID))
                {
                    // verify unique sso_id
                    strSSOId = tbUserSSOID.Text.Trim();
                    SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities();
                    SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctxAccess, strSSOId, "", false);
                    if (access != null && access.SSO_ID.ToLower().Equals(strSSOId.ToLower()))
                    {
                        lblErrorMessage = lblDuplicateSSOId;
                    }
                }
                if (lblErrorMessage == null && (isNew || !strEmail.Equals(person.EMAIL)))
                {
                    // verify unique email
                    SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities();
                    //SQM_ACCESS access = SQMModelMgr.LookupCredentialsByEmail(ctxAccess, strEmail, false);
                    // ABW 20140117 - we want to look up email on person record...
                    PERSON personEmail = SQMModelMgr.LookupPersonByEmail(ctxAccess, strEmail);
                    if (personEmail != null && personEmail.EMAIL.Trim().ToLower().Equals(strEmail.Trim().ToLower()))
                    {
                        lblErrorMessage = lblDuplicateEmail;
                    }
                }
            }
            if (lblErrorMessage != null)
            {
                DisplayUser();
                DisplayErrorMessage(lblErrorMessage);
                return(false);
            }

            if (updateUser)
            {
                List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", ""); // ABW 20140805
                SETTINGS        setting      = new SETTINGS();                              // ABW 20140805
                SetLocalPerson(SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), false, currentSSOID));
                //selectedUser = SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), Convert.ToBoolean(GetFindControlValue("cbIsBuyer", hfBase, out success)), GetFindControlValue("tbBuyerCode", hfBase, out success));
                // AW20131106 - send an email for new users with random password generation

                setting = MailSettings.Find(x => x.SETTING_CD == "MailFromSystem"); // ABW 20140805
                string strEmailCompanyName = "";                                    // ABW 20140805
                if (setting != null)                                                // ABW 20140805
                {
                    strEmailCompanyName = setting.VALUE;
                }

                if (isNew)
                {
                    // send a confirmation email
                    // string strength = WebConfigurationManager.AppSettings["PasswordComplexity"]; // ABW 20140805
                    SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity"); // ABW 20140805
                    string   strength   = "";                                                                                 // ABW 20140805
                    if (complexity == null)
                    {
                        strength = "4";
                    }
                    else
                    {
                        strength = complexity.VALUE;
                    }

                    SQM.Website.PSsqmEntities ctxAccess = new PSsqmEntities();
                    SQM_ACCESS access      = SQMModelMgr.LookupCredentials(ctxAccess, LocalPerson().SSO_ID, "", false);
                    string     key         = SQMModelMgr.GetPasswordKey();
                    string     strPassword = WebSiteCommon.Decrypt(access.PASSWORD, key);

                    // ABW 20140805 - Build the email based on fields in the SETTINGS table
                    // the following is standard email
                    //string strEmailBody = lblPasswordEmailBody1a.Text.ToString() + strEmailCompanyName + lblPasswordEmailBody1b.Text.ToString() + " " + selectedUser.SSO_ID + lblPasswordEmailBody2.Text.ToString() + " " + strPassword;
                    //strEmailBody += "<br><br>" + WebSiteCommon.GetXlatValueLong("passwordComplexity", strength) + "<br><br>" + lblPasswordEmailBody3.Text.ToString().Trim();

                    // the following is for TI only
                    //string strEmailBody = "Risk Management Professional,<br><br>TI Automotive Risk Management is pleased to offer you access to the TI Automotive Risk Management Portal (Portal)<br><br>The Portal will be used to provide tracking for:<br>";
                    //strEmailBody += "<ul><li>Environmental performance tracking</li><li>Insurer Recommendations response</li><li>Internal Risk Quality Index Recommendations Response</li><li>Safety Alerts</li>";
                    //strEmailBody += "<br>A new user account has been created for you in the Portal.<br><br>Access the website by clicking on the link: <a href='http://Ti.qai.luxinteractive.com'>Ti.qai.luxinteractive.com</a><br><br>";
                    //strEmailBody += "Your username has been assigned: <font color='red'>" + selectedUser.SSO_ID + "</font><br>Your temporary password is: <font color='red'>" + strPassword + "</font>";
                    //strEmailBody += "<br>Once you gain access to the Portal you must change your password. " + WebSiteCommon.GetXlatValueLong("passwordComplexity", strength) + "<br><br>" + lblPasswordEmailBody3.Text.ToString().Trim();
                    //strEmailBody += "<br><br><b>Michael D. Wildfong</b><br>Global Director Facilities Risk Management<br>TI Automotive<br>1272 Doris Road<br>Auburn Hills, MI 48326<br>t: +1 248 494 5320<br>m: + 1 810 265 1677<br>f: +1 248 494 5302";
                    //strEmailBody += "<br>e: <a href='mailto:[email protected]'>[email protected]</a>";

                    // ABW 20140805 - Build the email based on fields in the SETTINGS table
                    string strEmailSubject = "";
                    setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSubject");
                    if (setting == null)
                    {
                        strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString();
                    }
                    else
                    {
                        strEmailSubject = setting.VALUE.Trim();
                    }
                    setting = MailSettings.Find(x => x.SETTING_CD == "NewUserWelcome");
                    string strEmailBody = "";
                    if (setting == null)
                    {
                        strEmailBody = lblPasswordEmailBody1a.Text.ToString();
                    }
                    else
                    {
                        strEmailBody = setting.VALUE.Trim();
                    }
                    strEmailBody += lblPasswordEmailBody1b.Text.ToString() + " " + LocalPerson().SSO_ID + lblPasswordEmailBody2.Text.ToString() + " " + strPassword;
                    setting       = MailSettings.Find(x => x.SETTING_CD == "MailURL");
                    if (setting != null)
                    {
                        strEmailBody += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>";
                    }
                    complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength);                     // ABW 20140805
                    if (complexity != null)
                    {
                        strEmailBody += "<br><br>" + complexity.VALUE + "<br><br>";
                    }
                    setting = MailSettings.Find(x => x.SETTING_CD == "NewUserSignature");
                    if (setting == null)
                    {
                        strEmailBody += "<br><br>" + lblPasswordEmailBody3.Text.ToString();
                    }
                    else
                    {
                        strEmailBody += "<br><br>" + setting.VALUE.Trim();
                    }

                    // ABW 20140117 - we are now using the email on the Person record
                    Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody.Trim(), ""));
                    thread.IsBackground = true;
                    thread.Start();
                }
                else
                {
                    bool roleChanged = person.ROLE != currentPerson.ROLE || person.PERSON_ACCESS.Count != currentPerson.PERSON_ACCESS.Count ? true : false;
                    if (roleChanged)
                    {
//						string strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text + "<br><br>" + lblUserRoleEmailBodyc.Text;
                        // ABW 20140805 - Build the email based on fields in the SETTINGS table
                        string strEmailSubject = "";
                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSubject");
                        if (setting == null)
                        {
                            strEmailSubject = lblUserRoleEmailSubjecta.Text + strEmailCompanyName + lblUserRoleEmailSubjectb.Text;
                        }
                        else
                        {
                            strEmailSubject = setting.VALUE.Trim();
                        }
                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeWelcome");
                        string strEmailBody = "";
                        if (setting == null)
                        {
                            strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text;
                        }
                        else
                        {
                            strEmailBody = setting.VALUE.Trim();
                        }

                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSignature");
                        if (setting == null)
                        {
                            strEmailBody += "<br><br>" + lblUserRoleEmailBodyc.Text;
                        }
                        else
                        {
                            strEmailBody += "<br><br>" + setting.VALUE.Trim();
                        }
                        Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, ""));
                        thread.IsBackground = true;
                        thread.Start();
                    }
                    if (cbResetPassword.Checked)
                    {
                        // build the email body in 3 segments
                        SETTINGS complexity = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordComplexity");
                        string   strength   = "";
                        if (complexity == null)
                        {
                            strength = "4";
                        }
                        else
                        {
                            strength = complexity.VALUE;
                        }
                        string strEmailSubject = "";
                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSubject");
                        if (setting == null)
                        {
                            strEmailSubject = strEmailCompanyName + " " + lblResetEmailSubject.Text.ToString();
                        }
                        else
                        {
                            strEmailSubject = setting.VALUE.Trim();
                        }
                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetWelcome");
                        string strEmailBodya = "";
                        string strEmailBodyb = "";
                        string strEmailBodyc = "";
                        if (setting == null)
                        {
                            strEmailBodya = lblPasswordEmailBody1a.Text.ToString();
                        }
                        else
                        {
                            strEmailBodya = setting.VALUE.Trim();
                        }
                        strEmailBodya += lblPasswordEmailBody1b.Text.ToString();
                        strEmailBodyb  = lblPasswordEmailBody2.Text.ToString();
                        setting        = MailSettings.Find(x => x.SETTING_CD == "MailURL");
                        if (setting != null)
                        {
                            strEmailBodyc += lblPasswordEmailBody2b.Text.ToString() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>";
                        }
                        complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength);
                        if (complexity != null)
                        {
                            strEmailBodyc += "<br><br>" + complexity.VALUE + "<br><br>";
                        }
                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminPasswordResetSignature");
                        if (setting == null)
                        {
                            strEmailBodyc += "<br><br>" + lblPasswordEmailBody3.Text.ToString();
                        }
                        else
                        {
                            strEmailBodyc += "<br><br>" + setting.VALUE.Trim();
                        }
                        int msg = WebSiteCommon.RecoverPassword(person.EMAIL, person.SSO_ID, strEmailSubject, strEmailBodya, strEmailBodyb, strEmailBodyc);
                    }
                }
                isNew = false;
                if (SQMModelMgr.updateStatus < 0)  // report error
                {
                    AlertUpdateResult(SQMModelMgr.updateStatus);
                }
            }
            else
            {
                SetLocalPerson(person);
            }
            return(true);
        }
Пример #25
0
        protected void SavePart()
        {
            bool partAdded = false;

            if (string.IsNullOrEmpty(tbPartNumber.Text))
            {
                DisplayPart();
                DisplayErrorMessage(hfRequiredInputs);
                return;
            }

            if (!staticPartData.IsNew)
            {
                staticPartData = SQMModelMgr.LookupPartData(entities, (decimal)staticPartData.Part.COMPANY_ID, staticPartData.Part.PART_ID);
            }

            staticPartData.Part.PART_NUM           = tbPartNumber.Text;
            staticPartData.Part.PART_PREFIX        = tbPartPrefix.Text;
            staticPartData.Part.PART_SUFFIX        = tbPartSuffix.Text;
            staticPartData.Part.PART_NUM_SEPARATOR = tbPartSep.Text;
            staticPartData.Part.PART_NAME          = tbPartName.Text;
            staticPartData.Part.REVISION_LEVEL     = tbPartRevision.Text;
            if (!string.IsNullOrEmpty(ddlPartProgram.SelectedValue))
            {
                staticPartData.Part.PROGRAM_ID = Convert.ToDecimal(ddlPartProgram.SelectedValue);
            }
            else
            {
                staticPartData.Part.PROGRAM_ID = null;
            }

            staticPartData.Part.SERIAL_NUM = tbPartSerialNum.Text;
            staticPartData.Part.STATUS     = ddlPartStatus.SelectedValue;
            staticPartData.Part            = SQMModelMgr.UpdatePart(entities, staticPartData.Part, SessionManager.UserContext.UserName());

            if (staticPartData.IsNew)
            {
                try
                {
                    PLANT  suppPlant = SQMModelMgr.LookupPlant(Convert.ToDecimal(ddlSourceSelect.SelectedValue));
                    string custSel   = ddlUsedSelect.CheckedItems.FirstOrDefault().Value;
                    PLANT  custPlant = SQMModelMgr.LookupPlant(Convert.ToDecimal(custSel));
                    STREAM stream    = SQMModelMgr.CreatePartStream(SessionManager.PrimaryCompany().COMPANY_ID, staticPartData.Part.PART_ID);
                    if (suppPlant.COMPANY_ID == SessionManager.PrimaryCompany().COMPANY_ID)
                    {
                        // primary company is supplier to customer
                        stream.COMPANY_ID      = (decimal)suppPlant.COMPANY_ID;
                        stream.PLANT_ID        = suppPlant.PLANT_ID;
                        stream.CUST_COMPANY_ID = custPlant.COMPANY_ID;
                        stream.CUST_PLANT_ID   = custPlant.PLANT_ID;
                        stream.CUST_PART_NUM   = staticPartData.Part.PART_NUM;
                        stream.SUPP_COMPANY_ID = stream.SUPP_PLANT_ID = null;
                        stream = SQMModelMgr.UpdatePartStream(entities, stream, SessionManager.UserContext.UserName());
                    }
                    else
                    {
                        // primary company is customer
                        stream.COMPANY_ID      = (decimal)custPlant.COMPANY_ID;
                        stream.PLANT_ID        = custPlant.PLANT_ID;
                        stream.SUPP_COMPANY_ID = suppPlant.COMPANY_ID;
                        stream.SUPP_PLANT_ID   = suppPlant.PLANT_ID;
                        stream.SUPP_PART_NUM   = staticPartData.Part.PART_NUM;
                        stream.CUST_COMPANY_ID = stream.CUST_PLANT_ID = null;
                    }
                    partAdded = true;
                }
                catch
                {
                    ;
                }
            }

            staticPartData.IsNew = false;
            editObject           = null;

            if (partAdded)
            {
                uclSearchBar_OnSearchClick();
            }
        }
Пример #26
0
        public void gvCtlPlan_OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if ((!e.Row.RowType.ToString().Trim().Equals(System.Web.UI.WebControls.ListItemType.Header.ToString())) & (!e.Row.RowType.ToString().Trim().Equals(System.Web.UI.WebControls.ListItemType.Footer.ToString())))
            {
                try
                {
                    HiddenField  hf  = (HiddenField)e.Row.Cells[0].FindControl("hfSampleRate");
                    DropDownList ddl = (DropDownList)e.Row.Cells[0].FindControl("ddlSampleRate");
                    ddl.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("sampleRate"));
                    if (!String.IsNullOrEmpty(hf.Value))
                    {
                        ddl.SelectedValue = hf.Value;
                    }

                    hf  = (HiddenField)e.Row.Cells[0].FindControl("hfSampleUnit");
                    ddl = (DropDownList)e.Row.Cells[0].FindControl("ddlSampleUnit");
                    ddl.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("sampleUnit"));
                    if (!String.IsNullOrEmpty(hf.Value))
                    {
                        ddl.SelectedValue = hf.Value;
                    }

                    Label lbl;
                    hf = (HiddenField)e.Row.Cells[0].FindControl("hfStepInstructions");
                    Image img = (Image)e.Row.Cells[0].FindControl("imgStepType");
                    img.ToolTip = hf.Value;

                    hf = (HiddenField)e.Row.Cells[0].FindControl("hfPlanStepLocation");
                    if (!string.IsNullOrEmpty(hf.Value))
                    {
                        decimal plantID = Convert.ToDecimal(hf.Value);
                        PLANT   plant   = SQMModelMgr.LookupPlant(entities, plantID, "");
                        if (plant != null)
                        {
                            img = (Image)e.Row.Cells[0].FindControl("imgPlanStepLocation");
                            if (plant.COMPANY_ID == SessionManager.SessionContext.ActiveCompany().COMPANY_ID)
                            {
                                img.ImageUrl = "~/images/icon_customer2.gif";
                                img.ToolTip  = "";   // mt - todo: remove constant
                            }
                            else
                            {
                                img.ImageUrl = "~/images/icon_supplier2.gif";
                                img.ToolTip  = "Supplier";   // mt - todo: remove constant
                            }
                        }
                    }

                    lbl      = (Label)e.Row.Cells[0].FindControl("lblSampleUnit_out");
                    lbl.Text = WebSiteCommon.GetXlatValueLong("sampleUnit", lbl.Text);
                    lbl      = (Label)e.Row.Cells[0].FindControl("lblSampleRate_out");
                    lbl.Text = WebSiteCommon.GetXlatValueLong("sampleRate", lbl.Text);

                    lbl = (Label)e.Row.Cells[0].FindControl("lblPlanStepID");
                    GridView      gv   = (GridView)e.Row.Cells[0].FindControl("gvMeasureGrid");
                    CTL_PLAN_STEP step = ctlPlanMgr.CtlPlan.CTL_PLAN_STEP.First(s => s.CTLPLANSTEP_ID == Convert.ToInt32(lbl.Text));
                    gv.DataSource = step.CTL_PLAN_MEASURE;
                    gv.DataBind();
                    gv            = (GridView)e.Row.Cells[0].FindControl("gvMethodGrid");
                    gv.DataSource = step.CTL_PLAN_MEASURE;
                    gv.DataBind();
                }
                catch
                {
                }
            }
        }
Пример #27
0
        private void uclCaseEdit_OnSaveClick(string cmdArg)
        {
            bool bNotify;

            CaseCtl().problemCase.UpdateStatus = CaseUpdateStatus.Success;
            switch (cmdArg)
            {
            case "0":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase0(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase0();
                }
                break;

            case "1":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase1(CaseCtl().problemCase, out bNotify);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase1(bNotify);
                    if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success && bNotify)
                    {
                        try
                        {
                            string appUrl = SQMSettings.SelectSettingByCode(entities, "MAIL", "TASK", "MailURL").VALUE;
                            PERSON person = null;
                            PLANT  plant  = SQMModelMgr.LookupPlant((decimal)CaseCtl().problemCase.IncidentList[0].DETECT_PLANT_ID);
                            int    emailStatus;
                            bool   bUpdateTasks = false;
                            foreach (TASK_STATUS task in CaseCtl().problemCase.TeamTask.TaskList.Where(t => t.TASK_TYPE == "C" && t.TASK_SEQ == 0).ToList())
                            {
                                if (task.RESPONSIBLE_ID.HasValue && (person = SQMModelMgr.LookupPerson((decimal)task.RESPONSIBLE_ID, "")) != null && !task.NOTIFY_DT.HasValue)
                                {
                                    task.NOTIFY_DT = DateTime.UtcNow;
                                    List <TaskItem> taskList = new List <TaskItem>();
                                    TaskItem        taskItem = new TaskItem();
                                    taskItem.RecordID    = CaseCtl().problemCase.ProbCase.PROBCASE_ID;
                                    taskItem.RecordKey   = CaseCtl().problemCase.ProbCase.PROBCASE_ID.ToString();
                                    taskItem.RecordType  = 21;
                                    taskItem.NotifyType  = TaskNotification.Owner;
                                    taskItem.Taskstatus  = TaskMgr.CalculateTaskStatus(task);
                                    taskItem.Detail      = SQMModelMgr.FormatPersonListItem(person);
                                    taskItem.Description = WebSiteCommon.FormatID(CaseCtl().problemCase.ProbCase.PROBCASE_ID, 6) + " / " + WebSiteCommon.GetXlatValue("caseStep", task.TASK_STEP);
                                    taskItem.Plant       = plant;
                                    taskItem.Task        = task;
                                    //  taskItem.Task = task;
                                    taskList.Add(taskItem);
                                    Thread thread = new Thread(() => TaskMgr.MailTaskList(taskList, person.EMAIL, "web"));
                                    thread.IsBackground = true;
                                    thread.Start();
                                    bUpdateTasks = true;
                                    //  if ((emailStatus = TaskMgr.MailTaskList(taskList, person.EMAIL, "web")) > 0)
                                    //      bUpdateTasks = true;
                                }
                            }
                            if (bUpdateTasks)
                            {
                                CaseCtl().Update();     // save task notify dates
                            }
                        }
                        catch (Exception ex)
                        {
                            //  SQMLogger.LogException(ex);
                        }
                    }
                }
                break;

            case "2":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase2(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase2();
                }
                break;

            case "3":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase3(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase3();
                }
                break;

            case "4":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase4(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase4();
                }
                break;

            case "5":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase5(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase5();
                }
                break;

            case "6":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase6(CaseCtl().problemCase);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase6();
                }
                break;

            case "7":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase7(CaseCtl().problemCase, true);
                if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
                {
                    CaseCtl().Update();
                    uclCaseEdit.BindCase7();
                }
                break;

            case "8":
                CaseCtl().problemCase = uclCaseEdit.UpdateCase8(CaseCtl().problemCase, out bNotify);
                CaseCtl().Update();
                uclCaseEdit.BindCase8(bNotify);
                if (bNotify && CaseCtl().problemCase != null)
                {
                    List <decimal?> teamList = new List <decimal?>();
                    teamList = CaseCtl().problemCase.TeamTask.TaskList.Where(l => l.TASK_TYPE == "C" && l.RESPONSIBLE_ID > 0).Select(l => l.RESPONSIBLE_ID).Distinct().ToList();
                    PERSON person = null;
                    // string emailStatus;
                    foreach (decimal?personID in teamList)
                    {
                        if ((person = SQMModelMgr.LookupPerson((decimal)personID, "")) != null)
                        {
                            Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, CaseCtl().problemCase.ProbCase.PROB_CLOSE.MESSAGE_TITLE, CaseCtl().problemCase.ProbCase.PROB_CLOSE.MESSAGE, ""));
                            thread.IsBackground = true;
                            thread.Start();
                        }
                    }
                }
                break;

            default:
                break;
            }

            if (CaseCtl().problemCase.UpdateStatus == CaseUpdateStatus.Success)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alertResult('hfAlertSaveSuccess');", true);
                SetupPage();
            }
            else
            {
                ErrorAlert(CaseCtl().problemCase.UpdateStatus);
            }
        }
Пример #28
0
        static void ScheduleAllAudits()
        {
            List <SETTINGS> sets              = SQMSettings.SelectSettingsGroup("AUTOMATE", ""); // ABW 20140805
            int             startRangeHours   = 04;
            int             startRangeMinutes = 45;
            int             endRangeHours     = 05;
            int             endRangeMinutes   = 15;

            try
            {
                startRange        = sets.Find(x => x.SETTING_CD == "AuditScheduleStart").VALUE.ToString();
                startRangeHours   = Convert.ToInt16(startRange.Substring(0, 2));
                startRangeMinutes = Convert.ToInt16(startRange.Substring(3, 2));
            }
            catch { }
            try
            {
                endRange        = sets.Find(x => x.SETTING_CD == "AuditScheduleEnd").VALUE.ToString();
                endRangeHours   = Convert.ToInt16(endRange.Substring(0, 2));
                endRangeMinutes = Convert.ToInt16(endRange.Substring(3, 2));
            }
            catch { }

            List <AUDIT_SCHEDULER> scheduler = EHSAuditMgr.SelectActiveAuditSchedulers(0, null);            // currently, we will select all schedules for all plants
            AUDIT audit = null;
            List <EHSAuditQuestion> questions = null;
            AUDIT_ANSWER            answer    = null;
            decimal  auditId = 0;
            TimeSpan start   = new TimeSpan(startRangeHours, startRangeMinutes, 0);
            TimeSpan end     = new TimeSpan(endRangeHours, endRangeMinutes, 0);

            WriteLine("Audits will be created for locations with a local time of " + startRangeHours + ":" + startRangeMinutes + " through " + endRangeHours + ":" + endRangeMinutes);
            foreach (AUDIT_SCHEDULER schedule in scheduler)
            {
                AUDIT_TYPE audittype = EHSAuditMgr.SelectAuditTypeById(entities, (decimal)schedule.AUDIT_TYPE_ID);
                // check that the audit is still active
                if (audittype != null)
                {
                    if (!audittype.INACTIVE)
                    {
                        // ABW 1/5/16 - changing the scheduler from scheduling one week of audits to creating audits that are to be scheduled that day.
                        //     All audits will be scheduled at 5am local plant time for the day.
                        //WriteLine("");
                        //WriteLine("The following " + type.TITLE + " assessments were created for Assessment Scheduler " + schedule.AUDIT_SCHEDULER_ID + ": ");
                        //// determine the date to schedule, by finding the next occurance of the selected day of the week after the current day
                        //DateTime auditDate = DateTime.Today;
                        //while ((int)auditDate.DayOfWeek != schedule.DAY_OF_WEEK)
                        //{
                        //	auditDate = auditDate.AddDays(1);
                        //}

                        // get the plant
                        PLANT auditPlant = SQMModelMgr.LookupPlant((decimal)schedule.PLANT_ID);
                        // check the local plant time to see if it is almost 5am.  If so, schedule the audit. If not, do nothing.
                        DateTime localTime = WebSiteCommon.LocalTime(DateTime.UtcNow, auditPlant.LOCAL_TIMEZONE);
                        if ((int)localTime.DayOfWeek == schedule.DAY_OF_WEEK && ((localTime.TimeOfDay > start) && (localTime.TimeOfDay < end)))
                        {
                            WriteLine("");
                            WriteLine("The following " + audittype.TITLE + " assessments were created for Assessment Scheduler " + schedule.AUDIT_SCHEDULER_ID + ": ");
                            // for the location, select all people that should get the audit
                            List <PERSON> auditors = SQMModelMgr.SelectPlantPrivgroupPersonList(auditPlant.PLANT_ID, new string[1] {
                                schedule.JOBCODE_CD
                            }, true);
                            foreach (PERSON person in auditors)
                            {
                                // check to see if there is already an audit for this plant/type/date/person
                                audit = EHSAuditMgr.SelectAuditForSchedule(auditPlant.PLANT_ID, audittype.AUDIT_TYPE_ID, person.PERSON_ID, localTime);
                                if (audit == null)
                                {
                                    // create audit header
                                    auditId = 0;
                                    audit   = new AUDIT()
                                    {
                                        DETECT_COMPANY_ID = Convert.ToDecimal(auditPlant.COMPANY_ID),
                                        DETECT_BUS_ORG_ID = auditPlant.BUS_ORG_ID,
                                        DETECT_PLANT_ID   = auditPlant.PLANT_ID,
                                        AUDIT_TYPE        = "EHS",
                                        CREATE_DT         = localTime,
                                        CREATE_BY         = "Automated Scheduler",
                                        DESCRIPTION       = audittype.TITLE,
                                        // CREATE_PERSON = SessionManager.UserContext.Person.PERSON_ID, // do we want to set this to admin?
                                        AUDIT_DT         = localTime,
                                        AUDIT_TYPE_ID    = audittype.AUDIT_TYPE_ID,
                                        AUDIT_PERSON     = person.PERSON_ID,
                                        CURRENT_STATUS   = "A",
                                        PERCENT_COMPLETE = 0,
                                        TOTAL_SCORE      = 0
                                    };

                                    entities.AddToAUDIT(audit);
                                    entities.SaveChanges();
                                    auditId = audit.AUDIT_ID;

                                    // create audit answer records
                                    questions = EHSAuditMgr.SelectAuditQuestionListByType(audittype.AUDIT_TYPE_ID);
                                    foreach (var q in questions)
                                    {
                                        answer = new AUDIT_ANSWER()
                                        {
                                            AUDIT_ID               = auditId,
                                            AUDIT_QUESTION_ID      = q.QuestionId,
                                            ANSWER_VALUE           = "",
                                            ORIGINAL_QUESTION_TEXT = q.QuestionText,
                                            //COMMENT = q.AnswerComment
                                        };
                                        entities.AddToAUDIT_ANSWER(answer);
                                    }
                                    entities.SaveChanges();
                                    // create task record for their calendar
                                    EHSAuditMgr.CreateOrUpdateTask(auditId, person.PERSON_ID, 50, localTime.AddDays(audittype.DAYS_TO_COMPLETE), "A", 0);

                                    // send an email
                                    EHSNotificationMgr.NotifyOnAuditCreate(auditId, person.PERSON_ID);
                                    System.Threading.Thread.Sleep(timer);                                     //will wait for 2 seconds to allow Google Mail to process email requests

                                    WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - assessment added");
                                }
                                else
                                {
                                    // ABW 1/5/16 - Since this will be running once every hour now, we don't want to see this message
                                    //WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - assessment already exists for this date");
                                }
                            }
                        }
                        else
                        {
                            // ABW 1/5/16 - Do we need to write any message out to explaing why the audit wasn't created?  I don't think so
                            //WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " - assessment already exists for this date OR is not scheduled to be created");
                        }
                    }
                    else
                    {
                        WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " inactive. Assessments not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                    }
                }
                else
                {
                    WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " not found. Assessments not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            PSsqmEntities ctx      = new PSsqmEntities();
            string        delimStr = "~";

            char[]   delimiter   = delimStr.ToCharArray();
            string[] exportParms = null;
            string[] plants      = null;
            int      loop1;

            exportParms = SessionManager.ExportCriteria.Split(delimiter);

            delimStr  = ",";
            delimiter = null;
            delimiter = delimStr.ToCharArray();
            plants    = exportParms[1].Split(delimiter);
            decimal[] plantIDs = new decimal[plants.Length];
            for (loop1 = 0; loop1 < plants.Length; loop1++)
            {
                plantIDs[loop1] = Convert.ToDecimal(plants[loop1]);
            }

            DateTime    dtFrom = Convert.ToDateTime(exportParms[2]);
            DateTime    dtTo   = Convert.ToDateTime(exportParms[3]);
            EHSCalcsCtl esMgr  = new EHSCalcsCtl().CreateNew(SessionManager.FYStartDate().Month, DateSpanOption.SelectRange, "E");

            esMgr.LoadMetricHistory(plantIDs, dtFrom, dtTo, DateIntervalType.month, false);
            List <MetricData> metric_history = esMgr.MetricHst.OrderBy(l => l.MetricRec.PLANT_ID).ThenBy(l => l.MetricRec.PERIOD_YEAR).ThenBy(l => l.MetricRec.PERIOD_MONTH).ThenBy(l => l.Measure.MEASURE_CATEGORY).ThenBy(l => l.Measure.MEASURE_CD).ToList();
            string            uom_cd;
            string            uom_input_cd;
            decimal           uom_id = 0;

            // need to cycle thru and populate the UOM and other formatting
            try
            {
                string filename = exportParms[0].Trim() + ".xls";
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename));
                Response.Clear();
                InitializeWorkbook();
                ISheet sheet1 = hssfworkbook.CreateSheet("Metric History");

                //// create the header - Plant Name, DUNS Code, Measure, Measure Name, Period Year, Period Month, Period from Date, Period To Date, Value, UOM, UOM Name, Input Value, Cost, Currency, Input Cost, Input Currency
                IRow row = sheet1.CreateRow(0);

                row.CreateCell(0).SetCellValue("Plant Name");
                row.CreateCell(1).SetCellValue("DUNS Code");
                row.CreateCell(2).SetCellValue("Measure");
                row.CreateCell(3).SetCellValue("Measure Name");
                row.CreateCell(4).SetCellValue("Period Year");
                row.CreateCell(5).SetCellValue("Period Month");
                row.CreateCell(6).SetCellValue(Resources.LocalizedText.Value);
                row.CreateCell(7).SetCellValue("UOM");
                row.CreateCell(8).SetCellValue("Input Value");
                row.CreateCell(9).SetCellValue("Input UOM");
                row.CreateCell(10).SetCellValue(Resources.LocalizedText.Cost);
                row.CreateCell(11).SetCellValue("Currency");
                row.CreateCell(12).SetCellValue("Input Cost");
                row.CreateCell(13).SetCellValue("Input Currency");

                ICell      cellNumeric;
                ICellStyle cellStyleNumeric = hssfworkbook.CreateCellStyle();
                cellStyleNumeric.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00");

                for (int irows = 0; irows < metric_history.Count; irows++)
                {
                    int rownum = irows + 1;
                    UOM uom    = null;
                    uom_id = metric_history[irows].MetricRec.UOM_ID;
                    uom    = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == uom_id);
                    if (uom != null)
                    {
                        uom_cd = uom.UOM_CD;
                    }
                    else
                    {
                        uom_cd = "";
                    }
                    try
                    {
                        uom_id = Convert.ToDecimal(metric_history[irows].MetricRec.INPUT_UOM_ID.ToString());
                        uom    = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == uom_id);
                        if (uom != null)
                        {
                            uom_input_cd = uom.UOM_CD;
                        }
                        else
                        {
                            uom_input_cd = "";
                        }
                    }
                    catch { uom_input_cd = ""; }
                    // create a column for each field we want

                    PLANT       plant   = SQMModelMgr.LookupPlant(ctx, metric_history[irows].MetricRec.PLANT_ID, "");             //metric_history[irows].Plant;
                    EHS_MEASURE measure = metric_history[irows].Measure as EHS_MEASURE;

                    row = sheet1.CreateRow(rownum);
                    try
                    {
                        row.CreateCell(0).SetCellValue(plant.PLANT_NAME);
                    }
                    catch
                    {
                        row.CreateCell(0).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(1).SetCellValue(plant.DUNS_CODE);
                    }
                    catch
                    {
                        row.CreateCell(1).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(2).SetCellValue(measure.MEASURE_CD);
                    }
                    catch
                    {
                        row.CreateCell(2).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(3).SetCellValue(measure.MEASURE_NAME);
                    }
                    catch
                    {
                        row.CreateCell(3).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(4).SetCellValue(metric_history[irows].MetricRec.PERIOD_YEAR);
                    }
                    catch
                    {
                        row.CreateCell(4).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(5).SetCellValue(metric_history[irows].MetricRec.PERIOD_MONTH);
                    }
                    catch
                    {
                        row.CreateCell(5).SetCellValue("");
                    }
                    try
                    {
                        cellNumeric           = row.CreateCell(6);
                        cellNumeric.CellStyle = cellStyleNumeric;
                        cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.MEASURE_VALUE));
                    }
                    catch
                    {
                        row.CreateCell(6).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(7).SetCellValue(uom_cd);
                    }
                    catch
                    {
                        row.CreateCell(7).SetCellValue("");
                    }
                    try
                    {
                        cellNumeric           = row.CreateCell(8);
                        cellNumeric.CellStyle = cellStyleNumeric;
                        cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.INPUT_VALUE));
                    }
                    catch
                    {
                        row.CreateCell(8).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(9).SetCellValue(uom_input_cd);
                    }
                    catch
                    {
                        row.CreateCell(9).SetCellValue("");
                    }
                    try
                    {
                        cellNumeric           = row.CreateCell(10);
                        cellNumeric.CellStyle = cellStyleNumeric;
                        cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.MEASURE_COST));
                    }
                    catch
                    {
                        row.CreateCell(10).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(11).SetCellValue(metric_history[irows].MetricRec.CURRENCY_CODE);
                    }
                    catch
                    {
                        row.CreateCell(11).SetCellValue("");
                    }
                    try
                    {
                        cellNumeric           = row.CreateCell(12);
                        cellNumeric.CellStyle = cellStyleNumeric;
                        cellNumeric.SetCellValue(Convert.ToDouble(metric_history[irows].MetricRec.INPUT_COST));
                    }
                    catch
                    {
                        row.CreateCell(12).SetCellValue("");
                    }
                    try
                    {
                        row.CreateCell(13).SetCellValue(metric_history[irows].MetricRec.INPUT_CURRENCY_CODE);
                    }
                    catch
                    {
                        row.CreateCell(13).SetCellValue("");
                    }
                }
                sheet1.AutoSizeColumn(0);
                sheet1.AutoSizeColumn(1);
                sheet1.AutoSizeColumn(2);
                sheet1.AutoSizeColumn(3);
                sheet1.AutoSizeColumn(4);
                sheet1.AutoSizeColumn(5);
                sheet1.AutoSizeColumn(6);
                sheet1.AutoSizeColumn(7);
                sheet1.AutoSizeColumn(8);
                sheet1.AutoSizeColumn(9);
                sheet1.AutoSizeColumn(10);
                sheet1.AutoSizeColumn(11);
                sheet1.AutoSizeColumn(12);
                sheet1.AutoSizeColumn(13);

                GetExcelStream().WriteTo(Response.OutputStream);
                Response.End();
            }
            catch (Exception ex)
            {
                //Response.Write("Error processing the file:" + ex.Message.ToString());
                Response.End();
            }
        }
        protected void rgAlertTaskList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HiddenField  hf;
                Label        lbl;
                RadComboBox  ddl = null;
                PERSON       responsiblePerson = null;

                try
                {
                    TASK_STATUS task = (TASK_STATUS)e.Item.DataItem;

                    hf       = (HiddenField)e.Item.FindControl("hfTaskID");
                    hf.Value = task.TASK_ID > 0 ? task.TASK_ID.ToString() : "";

                    hf       = (HiddenField)e.Item.FindControl("hfLocation");
                    hf.Value = task.RECORD_SUBID.ToString();

                    lbl = (Label)e.Item.FindControl("lblLocation");
                    PLANT plant = SQMModelMgr.LookupPlant((decimal)task.RECORD_SUBID);
                    if (plant != null)
                    {
                        lbl.Text = plant.PLANT_NAME;
                        hf       = (HiddenField)e.Item.FindControl("hfLocationTZ");
                        hf.Value = plant.LOCAL_TIMEZONE;
                    }
                    else
                    {
                        lbl.Text = task.RECORD_SUBID.ToString();
                    }

                    lbl      = (Label)e.Item.FindControl("lblTaskComments");
                    lbl.Text = task.COMMENTS;

                    if (task.COMPLETE_DT.HasValue)
                    {
                        lbl      = (Label)e.Item.FindControl("lblTaskCompleteDT");
                        lbl.Text = Convert.ToDateTime(task.COMPLETE_DT).ToShortDateString();
                    }

                    ddl = (RadComboBox)e.Item.FindControl("ddlResponsible");
                    List <PERSON> responsibleList = SQMModelMgr.SelectPlantPrivgroupPersonList((decimal)task.RECORD_SUBID, new string[1] {
                        ddlResponsibleGroup.SelectedValue
                    }, false);
                    if (responsibleList.Count > 0)
                    {
                        foreach (PERSON person in responsibleList)
                        {
                            ddl.Items.Add(new RadComboBoxItem(SQMModelMgr.FormatPersonListItem(person), person.PERSON_ID.ToString()));
                        }
                    }
                    if (task.RESPONSIBLE_ID.HasValue)
                    {
                        if ((responsiblePerson = SQMModelMgr.LookupPerson((decimal)task.RESPONSIBLE_ID, "")) != null)
                        {
                            if (ddl.Items.FindItemByValue(responsiblePerson.PERSON_ID.ToString()) != null)
                            {
                                ddl.SelectedValue = responsiblePerson.PERSON_ID.ToString();
                            }
                            else
                            {
                                ddl.Items.Add(new RadComboBoxItem(SQMModelMgr.FormatPersonListItem(responsiblePerson), responsiblePerson.PERSON_ID.ToString()));
                            }
                        }
                    }
                    if (task.COMPLETE_DT.HasValue)
                    {
                        ddl.Enabled = false;
                    }
                }
                catch
                {
                }
            }
        }