protected void DisplayUser()
        {
            PERSON           person = LocalPerson();
            BusinessLocation businessLocation;
            SETTINGS         setsPwdReset = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordResetEnable");
            SQM_ACCESS       sysAccess    = SQMModelMgr.LookupCredentials(entities, person.SSO_ID, "", false);

            divPageBody.Visible = true;
            ddlPlantSelect.ClearCheckedItems();

            DisplayErrorMessage(null);

            string addFields = SessionManager.GetUserSetting("COMPANY", "PERSON_ADD_FIELDS") == null ? "" : SessionManager.GetUserSetting("COMPANY", "PERSON_ADD_FIELDS").VALUE;

            if (addFields.Contains("jobcode"))
            {
                trJobCode.Visible = true;
            }
            else
            {
                trJobCode.Visible = false;
            }

            if (addFields.Contains("supv"))
            {
                lblEmpSupv.Visible = tbSupvEmpID.Visible = true;
            }
            else
            {
                lblEmpID.Visible = true;
            }

            if (person == null || string.IsNullOrEmpty(person.STATUS))                 // new user
            {
                winUserEdit.Title        = hfAddUser.Value;
                businessLocation         = new BusinessLocation();
                businessLocation.Company = SessionManager.EffLocation.Company;
                SetStatusList("ddlUserStatus", "A", true);
                tbUserSSOID.Enabled = true;
                tbUserSSOID.Text    = "";
                tbUserSSOID.Focus();
            }
            else
            {
                winUserEdit.Title   = hfUpdateUser.Value;
                tbUserSSOID.Enabled = setsPwdReset != null && setsPwdReset.VALUE.ToUpper() == "Y" ? true : false;
                tbUserFirstName.Focus();

                lblPlantAccess.Text = "";
                if (person.PLANT_ID > 0)
                {
                    ddlHRLocation.SelectedValue = person.PLANT_ID.ToString();
                    if (ddlPlantSelect.Items.FindItemByValue(person.PLANT_ID.ToString()) != null)
                    {
                        ddlPlantSelect.Items.FindItemByValue(person.PLANT_ID.ToString()).Checked = true;
                    }
                }

                if (!string.IsNullOrEmpty(person.NEW_LOCATION_CD))
                {
                    RadComboBoxItem plantItem = null;
                    string[]        locs      = person.NEW_LOCATION_CD.Split(',');
                    foreach (string locid in locs)
                    {
                        if (!string.IsNullOrEmpty(locid))
                        {
                            if ((plantItem = ddlPlantSelect.Items.FindItemByValue(locid)) != null)
                            {
                                ddlPlantSelect.Items.FindItemByValue(locid).Checked = true;
                                if (locs.Length > 2)
                                {
                                    lblPlantAccess.Text += lblPlantAccess.Text.Length == 0 ? plantItem.Text : (", " + plantItem.Text);
                                }
                            }
                        }
                    }
                }
            }

            // AW20131106 - do not want to be able to change a SSO ID once a person has been added
            if (!string.IsNullOrEmpty(person.SSO_ID.Trim()))
            {
                tbUserSSOID.Text = person.SSO_ID;
            }

            tbUserFirstName.Text  = person.FIRST_NAME;
            tbUserLastName.Text   = person.LAST_NAME;
            tbUserMiddleName.Text = !string.IsNullOrEmpty(person.MIDDLE_NAME) ? person.MIDDLE_NAME : "";
            if (ddlJobCode.Items.FindItemByValue(person.JOBCODE_CD) != null)
            {
                ddlJobCode.SelectedValue = person.JOBCODE_CD;
            }
            else
            {
                ddlJobCode.SelectedValue = "";
            }

            if (ddlPrivGroup.Items.FindItemByValue(person.PRIV_GROUP) != null)
            {
                ddlPrivGroup.SelectedValue = person.PRIV_GROUP;
            }
            else
            {
                ddlPrivGroup.SelectedValue = "";
            }

            tbUserPhone.Text = person.PHONE;
            tbUserEmail.Text = person.EMAIL;
            tbEmpID.Text     = person.EMP_ID;
            tbSupvEmpID.Text = person.SUPV_EMP_ID;
            SetStatusList("ddlUserStatus", person.STATUS, true);
            if (sysAccess != null && sysAccess.LAST_LOGON_DT.HasValue)
            {
                lblUserLoginDate_out.Text = SQMBasePage.FormatDate(WebSiteCommon.LocalTime((DateTime)sysAccess.LAST_LOGON_DT, WebSiteCommon.GetXlatValue("timeZone", person.PREFERRED_TIMEZONE)), "g", true);
            }
            else
            {
                lblUserLoginDate_out.Text = "";
            }
            lblUserLastUpdate.Text = person.LAST_UPD_BY + "  " + SQMBasePage.FormatDate(WebSiteCommon.LocalTime((DateTime)person.LAST_UPD_DT, SessionManager.UserContext.TimeZoneID), "g", true);

            if (ddlUserLanguage.Items.FindByValue(person.PREFERRED_LANG_ID.ToString()) != null)
            {
                ddlUserLanguage.SelectedValue = person.PREFERRED_LANG_ID.ToString();
            }
            if (ddlUserTimezone.Items.FindByValue(person.PREFERRED_TIMEZONE) != null)
            {
                ddlUserTimezone.SelectedValue = person.PREFERRED_TIMEZONE;
            }


            List <SysModule> sysmodList = SQMSettings.SystemModuleItems();
            string           prod = "";
            RadComboBoxItem  item = null; RadComboBoxItem itemSep = null;

            lblPrivScope.Text = "";
            if (person.PRIV_GROUP != null)
            {
                foreach (PRIVLIST jp in SQMModelMgr.SelectPrivList(person.PRIV_GROUP).ToList())
                {
                    lblPrivScope.Text += (" " + ((SysPriv)jp.PRIV).ToString() + ": " + jp.SCOPE + ",");
                }
            }
            lblPrivScope.Text = lblPrivScope.Text.TrimEnd(',');

            if (setsPwdReset != null && setsPwdReset.VALUE.ToUpper() == "Y")
            {
                trResetPassword.Visible = true;
            }

            cbUserEmailLock.Checked    = SQMModelMgr.PersonFieldLocked(person, LockField.email);
            cbPrivGroupLock.Checked    = SQMModelMgr.PersonFieldLocked(person, LockField.priv);
            cbHRLocationLock.Checked   = SQMModelMgr.PersonFieldLocked(person, LockField.plant);
            cbUserLanguageLock.Checked = SQMModelMgr.PersonFieldLocked(person, LockField.lang);

            string script = "function f(){OpenUserEditWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
        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.MIDDLE_NAME = string.IsNullOrEmpty(tbUserMiddleName.Text) ? "" : tbUserMiddleName.Text;
            person.JOBCODE_CD  = ddlJobCode.SelectedValue;
            if (string.IsNullOrEmpty(ddlPrivGroup.SelectedValue))
            {
                person.PRIV_GROUP = null;
            }
            else
            {
                person.PRIV_GROUP = ddlPrivGroup.SelectedValue;
            }
            person.PHONE       = tbUserPhone.Text;
            person.EMAIL       = tbUserEmail.Text;
            person.EMP_ID      = tbEmpID.Text;
            person.SUPV_EMP_ID = tbSupvEmpID.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))
            {
                if (string.IsNullOrEmpty(person.NEW_LOCATION_CD))
                {
                    person.NEW_LOCATION_CD = ",";
                }
                person.NEW_LOCATION_CD += (item.Value + ",");
            }

            person.OLD_LOCATION_CD = "";

            /* quality module reference
             * 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           = 100;   /////
            person.RCV_ESCALATION = true;

            person.LOCKS = "";
            if (cbUserEmailLock.Checked)
            {
                person.LOCKS += (LockField.email.ToString() + ",");
            }
            if (cbPrivGroupLock.Checked)
            {
                person.LOCKS += (LockField.priv.ToString() + ",");
            }
            if (cbHRLocationLock.Checked)
            {
                person.LOCKS += (LockField.plant.ToString() + ",");
            }
            if (cbUserLanguageLock.Checked)
            {
                person.LOCKS += (LockField.lang.ToString() + ",");
            }
            person.LOCKS = person.LOCKS.TrimEnd(',');

            SetLocalPerson(person);

            if (string.IsNullOrEmpty(tbUserSSOID.Text) || string.IsNullOrEmpty(tbUserFirstName.Text) || string.IsNullOrEmpty(tbUserLastName.Text) ||
                ddlJobCode.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)
            {
                string defaultPwd  = "";
                string environment = System.Configuration.ConfigurationManager.AppSettings["environment"].ToString();
                string altEmail    = !string.IsNullOrEmpty(environment) && environment.ToLower() == "dev" ?  System.Configuration.ConfigurationManager.AppSettings["altEmail"].ToString() : "";
                if (isNew)
                {
                    SETTINGS pwdInitial = SQMSettings.SelectSettingByCode(entities, "COMPANY", "TASK", "PasswordDefault");
                    if (pwdInitial != null)
                    {
                        switch (pwdInitial.VALUE.ToUpper())
                        {
                        case "LASTNAME":
                            defaultPwd = person.LAST_NAME;
                            break;

                        case "EMPID":
                            defaultPwd = person.EMP_ID;
                            break;

                        default:
                            break;
                        }
                    }
                }
                SetLocalPerson(SQMModelMgr.UpdatePerson(entities, person, SessionManager.UserContext.UserName(), false, currentSSOID, defaultPwd));
                //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
                List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", ""); // ABW 20140805
                SETTINGS        setting      = new SETTINGS();                              // ABW 20140805
                setting = MailSettings.Find(x => x.SETTING_CD == "MailFromSystem");         // ABW 20140805
                string strEmailCompanyName = "";                                            // ABW 20140805
                if (setting != null)                                                        // ABW 20140805
                {
                    strEmailCompanyName = setting.VALUE;
                }
                bool sendEmail = false;
                setting = MailSettings.Find(x => x.SETTING_CD == "SendNewUserEmail");
                if (setting != null && setting.VALUE.ToLower().Equals("true"))                 // ABW 20140805
                {
                    sendEmail = true;
                }

                List <XLAT> XLATList = SQMBasePage.SelectXLATList(new string[1] {
                    "USER_EMAIL"
                }, 0);
                string         strEmailSubject = "";
                string         strEmailBody    = "";
                LOCAL_LANGUAGE lang            = SQMModelMgr.LookupLanguage(new PSsqmEntities(), "", (int)person.PREFERRED_LANG_ID, false);
                string         strTemp         = "";

                if (isNew && (string.IsNullOrEmpty(defaultPwd) || sendEmail))                  // send email notice only when a default password was not set
                {
                    // 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
                    //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 20160115 - Build the email based on fields in the XLAT table
                    strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSubject", lang.NLS_LANGUAGE).DESCRIPTION;
                    if (strTemp == null || strTemp == "")
                    {
                        strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString();
                    }
                    else
                    {
                        strEmailSubject = strTemp.Trim();
                    }
                    strTemp      = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserWelcome", lang.NLS_LANGUAGE).DESCRIPTION;
                    strEmailBody = "";
                    if (strTemp == null || strTemp == "")
                    {
                        strEmailBody = lblPasswordEmailBody1a.Text.ToString();
                    }
                    else
                    {
                        strEmailBody = strTemp.Trim();
                    }
                    strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUsername", lang.NLS_LANGUAGE).DESCRIPTION;
                    if (strTemp == null || strTemp == "")
                    {
                        strEmailBody += lblPasswordEmailBody1b.Text.ToString();
                    }
                    else
                    {
                        strEmailBody += strTemp.Trim();
                    }
                    strEmailBody += " " + LocalPerson().SSO_ID;
                    strTemp       = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyPassword", lang.NLS_LANGUAGE).DESCRIPTION;
                    if (strTemp == null || strTemp == "")
                    {
                        strEmailBody += lblPasswordEmailBody2.Text.ToString();
                    }
                    else
                    {
                        strEmailBody += strTemp.Trim();
                    }
                    strEmailBody += " " + strPassword;
                    strTemp       = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUrl", lang.NLS_LANGUAGE).DESCRIPTION;
                    string strUrlLabel = "";
                    if (strTemp == null || strTemp == "")
                    {
                        strUrlLabel = lblPasswordEmailBody2b.Text.ToString();
                    }
                    else
                    {
                        strUrlLabel = strTemp.Trim();
                    }
                    setting = MailSettings.Find(x => x.SETTING_CD == "MailURL");
                    if (setting != null)
                    {
                        strEmailBody += strUrlLabel + " <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>";
                    }
                    strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSignature", lang.NLS_LANGUAGE).DESCRIPTION;
                    if (strTemp == null || strTemp == "")
                    {
                        strEmailBody += "<br><br>" + lblPasswordEmailBody3.Text.ToString();
                    }
                    else
                    {
                        strEmailBody += "<br><br>" + strTemp.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();
                     */
                    string mailStatus = WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody.Trim(), "");
                    EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBody, 0, LocalPerson().PERSON_ID, ("user password notification - is new = " + isNew.ToString()), mailStatus, altEmail);
                }
                else
                {
                    bool roleChanged = person.ROLE != currentPerson.ROLE ? true : false;
                    // ABW 20160115 - send an email based on a parameter
                    setting = MailSettings.Find(x => x.SETTING_CD == "SendChangeUserEmail");
                    if (setting != null && setting.VALUE.ToLower().Equals("true"))
                    {
                        sendEmail = true;
                    }
                    else
                    {
                        sendEmail = false;
                    }

                    if (roleChanged && sendEmail)
                    {
                        //ABW 20140805 - Build the email based on fields in the SETTINGS table
                        //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();

                        //ABW 20160115 - Build the email based on fields in the XLAT table
                        strEmailSubject = "";
                        strTemp         = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeSubject", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailSubject = lblUserRoleEmailSubjecta.Text + strEmailCompanyName + lblUserRoleEmailSubjectb.Text;
                        }
                        else
                        {
                            strEmailSubject = strTemp.Trim();
                        }

                        strEmailBody = "";
                        strTemp      = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeWelcome", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBody = lblUserRoleEmailBodya.Text + strEmailCompanyName + lblUserRoleEmailBodyb.Text;
                        }
                        else
                        {
                            strEmailBody = strTemp.Trim();
                        }

                        setting = MailSettings.Find(x => x.SETTING_CD == "AdminRoleChangeSignature");
                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminRoleChangeSignature", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBody += "<br><br>" + lblUserRoleEmailBodyc.Text;
                        }
                        else
                        {
                            strEmailBody += strTemp.Trim();
                        }

                        /*
                         * Thread thread = new Thread(() => WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, ""));
                         * thread.IsBackground = true;
                         * thread.Start();
                         */
                        string mailStatus = WebSiteCommon.SendEmail(person.EMAIL, strEmailSubject, strEmailBody, "");
                        EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBody, 0, LocalPerson().PERSON_ID, "user role changed", mailStatus, altEmail);
                    }

                    if (cbResetPassword.Checked)                     // always send an email when the password changes
                    {
                        // 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;
                        }

                        // ABW 20140805 - Build the email based on fields in the SETTINGS table
                        //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();

                        // ABW 20160115 - Build the email based on fields in the XLAT table
                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminPasswordResetSubject", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailSubject = strEmailCompanyName + " " + lblPasswordEmailSubject.Text.ToString();
                        }
                        else
                        {
                            strEmailSubject = strTemp.Trim();
                        }

                        string strEmailBodya = "";
                        string strEmailBodyb = "";
                        string strEmailBodyc = "";
                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "AdminPasswordResetWelcome", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBodya = lblResetEmailBody1a.Text.ToString();
                        }
                        else
                        {
                            strEmailBodya = strTemp.Trim();
                        }

                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUsername", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBodya += lblPasswordEmailBody1b.Text.ToString();
                        }
                        else
                        {
                            strEmailBodya += strTemp.Trim();
                        }

                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyPassword", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBodyb = lblPasswordEmailBody2.Text.ToString();
                        }
                        else
                        {
                            strEmailBodyb = strTemp.Trim();
                        }

                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserBodyUrl", lang.NLS_LANGUAGE).DESCRIPTION;
                        string strUrlLabel = "";
                        if (strTemp == null || strTemp == "")
                        {
                            strUrlLabel = lblPasswordEmailBody2b.Text.ToString();
                        }
                        else
                        {
                            strUrlLabel = strTemp.Trim();
                        }
                        setting = MailSettings.Find(x => x.SETTING_CD == "MailURL");
                        if (setting != null)
                        {
                            strEmailBodyc += strUrlLabel.Trim() + "<a href='" + setting.VALUE + "'>" + setting.VALUE + "</a>";
                        }
                        complexity = SQMSettings.SelectSettingByCode(entities, "PASSWORDCOMPLEXITY", "TASK", strength);
                        if (complexity != null)
                        {
                            strEmailBodyc += "<br><br>" + complexity.VALUE + "<br><br>";
                        }

                        strTemp = SQMBasePage.GetXLAT(XLATList, "USER_EMAIL", "NewUserSignature", lang.NLS_LANGUAGE).DESCRIPTION;
                        if (strTemp == null || strTemp == "")
                        {
                            strEmailBodyc += "<br><br>" + lblPasswordEmailBody3.Text.ToString();
                        }
                        else
                        {
                            strEmailBodyc += "<br><br>" + strTemp.Trim();
                        }

                        int msg = WebSiteCommon.RecoverPassword(person.EMAIL, person.SSO_ID, strEmailSubject, strEmailBodya, strEmailBodyb, strEmailBodyc);
                        EHSNotificationMgr.WriteEmailLog(entities, person.EMAIL, "", strEmailSubject, strEmailBodya, 0, LocalPerson().PERSON_ID, "recover password", msg.ToString(), altEmail);
                    }
                }
                isNew = false;
                if (SQMModelMgr.updateStatus < 0)  // report error
                {
                    AlertUpdateResult(SQMModelMgr.updateStatus);
                }
            }
            else
            {
                SetLocalPerson(person);
            }
            return(true);
        }
Beispiel #3
0
        public PROB_DEFINE UpdateProblemDefinition(PROB_DEFINE prDefine)
        {
            foreach (INCIDENT incident in this.IncidentList)
            {
                if (this.ProbCase.PROBCASE_TYPE == "QI")
                {
                    QualityIssue qualityIssue = new QualityIssue().Load(incident.INCIDENT_ID);
                    string       str          = "";

                    // who reported the problem
                    str = incident.CREATE_BY;
                    if (incident.CREATE_PERSON != null && incident.CREATE_PERSON > 0)
                    {
                        PERSON  person  = SQMModelMgr.LookupPerson((decimal)incident.CREATE_PERSON, "");
                        COMPANY company = SQMModelMgr.LookupCompany(person.COMPANY_ID);
                        str += " (" + company.COMPANY_NAME + ")";
                    }
                    if (string.IsNullOrEmpty(prDefine.WHO_IS) || !prDefine.WHO_IS.Contains(str))
                    {
                        if (!string.IsNullOrEmpty(prDefine.WHO_IS))
                        {
                            prDefine.WHO_IS += ", ";
                        }
                        prDefine.WHO_IS += str;
                    }

                    // where did the problem occur
                    str = qualityIssue.DetectedLocation.Company.COMPANY_NAME;
                    if (incident.DETECT_BUS_ORG_ID != null && incident.DETECT_BUS_ORG_ID > 0)
                    {
                        str += (" /  " + qualityIssue.DetectedLocation.BusinessOrg.ORG_NAME);
                    }
                    if (incident.DETECT_PLANT_ID != null && incident.DETECT_PLANT_ID > 0)
                    {
                        str += (" / " + qualityIssue.DetectedLocation.Plant.PLANT_NAME);
                    }
                    if (string.IsNullOrEmpty(prDefine.WHERE_IS) || !prDefine.WHERE_IS.Contains(str))
                    {
                        if (!string.IsNullOrEmpty(prDefine.WHERE_IS))
                        {
                            prDefine.WHERE_IS += ", ";
                        }
                        prDefine.WHERE_IS += str;
                    }


                    // where detected
                    str = WebSiteCommon.GetXlatValueLong("issueResponsible", qualityIssue.IssueOccur.SOURCE);
                    if (string.IsNullOrEmpty(prDefine.DETECTED_IS) || !prDefine.DETECTED_IS.Contains(str))
                    {
                        if (!string.IsNullOrEmpty(prDefine.DETECTED_IS))
                        {
                            prDefine.DETECTED_IS += ", ";
                        }
                        prDefine.DETECTED_IS += str;
                    }

                    // who or where is impacted
                    if (!string.IsNullOrEmpty(prDefine.IMPACT_IS))
                    {
                        prDefine.IMPACT_IS += ", ";
                    }

                    prDefine.IMPACT_IS += WebSiteCommon.GetXlatValueLong("issueResponsible", qualityIssue.IssueOccur.SOURCE);

                    // when did the problem occur
                    str = WebSiteCommon.FormatDateString(WebSiteCommon.LocalTime(incident.INCIDENT_DT, SessionManager.UserContext.TimeZoneID), false);
                    if (string.IsNullOrEmpty(prDefine.WHEN_IS) || !prDefine.WHEN_IS.Contains(str))
                    {
                        if (!string.IsNullOrEmpty(prDefine.WHEN_IS))
                        {
                            prDefine.WHEN_IS += ", ";
                        }
                        prDefine.WHEN_IS += str;
                    }

                    // what is the problem
                    if (!string.IsNullOrEmpty(prDefine.WHAT_IS))
                    {
                        prDefine.WHAT_IS += ", ";
                    }
                    prDefine.WHAT_IS += (" " + qualityIssue.Partdata.Part.PART_NUM + "(" + qualityIssue.Partdata.Part.PART_NAME + ")");

                    // how many how often detected
                    double qty = 0;
                    if (!string.IsNullOrEmpty(prDefine.HOW_MANY))
                    {
                        qty = double.Parse(prDefine.HOW_MANY);
                    }
                    foreach (QI_OCCUR_ITEM item in qualityIssue.IssueOccur.QI_OCCUR_ITEM)
                    {
                        qty += Convert.ToDouble(item.INSPECT_NC_QTY);
                        foreach (QI_OCCUR_NC sample in item.QI_OCCUR_NC)
                        {
                            if (!string.IsNullOrEmpty(prDefine.NC_IS))
                            {
                                prDefine.NC_IS += ", ";
                            }
                            NONCONFORMANCE nc = SQMResourcesMgr.LookupNonconf(this.Entities, (decimal)sample.NONCONF_ID, "");
                            if (nc != null)
                            {
                                prDefine.NC_IS += (qualityIssue.IssueOccur.OCCUR_DESC + ": " + nc.NONCONF_DESC);
                            }
                        }
                    }
                    prDefine.HOW_MANY = qty.ToString();

                    str = qualityIssue.IssueOccur.OCCUR_DESC;
                    if (string.IsNullOrEmpty(prDefine.WHY_IS) || !prDefine.WHY_IS.Contains(str))
                    {
                        if (!string.IsNullOrEmpty(prDefine.WHY_IS))
                        {
                            prDefine.WHY_IS += ", ";
                        }
                        prDefine.WHY_IS += str;
                    }

                    prDefine.URGENT_IS = prDefine.MEASURE_IS = prDefine.OFTEN_IS = "TBD";
                }
            }

            return(prDefine);
        }
Beispiel #4
0
        public UserContext Initialize(string SSOID, string pwd, bool activeOnly)
        {
            SQM.Website.PSsqmEntities ctx = new PSsqmEntities();
            this.LoginStatus = LoginStatus.SSOUndefined;
            SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctx, SSOID, pwd, true);

            if (access != null)
            {
                string key = SQMModelMgr.GetPasswordKey();
                // AW - for now, we want to allow if the password = the password OR the encrypted password
                string password = WebSiteCommon.Decrypt(access.PASSWORD, key);
                //string encrypt = WebSiteCommon.Encrypt(pwd, key);
                //string ss = encrypt;

                /*
                 * if ((string.IsNullOrEmpty(pwd) && (SSOID.ToLower() != "admin")) || (pwd != password && pwd != access.PASSWORD))
                 *      this.LoginStatus = LoginStatus.PasswordMismatch;
                 */
                //if (!string.IsNullOrEmpty(access.PASSWORD)  && (pwd != password && pwd != access.PASSWORD))

                if (pwd != password && pwd != access.PASSWORD)
                {
                    this.LoginStatus = LoginStatus.PasswordMismatch;
                }
                else if (activeOnly && access.STATUS == "I")
                {
                    this.LoginStatus = LoginStatus.Inactive;
                }
                else if (access.STATUS == "L")
                {
                    this.LoginStatus = LoginStatus.Locked;
                }
                else
                {
                    if ((this.Person = SQMModelMgr.LookupPerson(ctx, 0, access.SSO_ID, false)) == null)
                    {
                        this.LoginStatus = LoginStatus.PersonUndefined;
                    }
                    else
                    {
                        this.LoginStatus = LoginStatus.Success;
                        this.HRLocation  = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID));

                        if (this.HRLocation.Company == null)
                        {
                            this.LoginStatus = LoginStatus.CompanyUndefined;
                        }
                        else
                        {
                            //this.PrivList = SQMModelMgr.SelectPrivGroupJobcode(this.Person.JOBCODE_CD, "COMMON");
                            this.PrivList = SQMModelMgr.SelectPrivGroupPerson(this.Person.PRIV_GROUP, "COMMON");

                            SessionManager.EffLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID));

                            if (this.Person.PERSON_RESP.ALT_COMPANY_ID > 0)
                            {
                                this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.PERSON_RESP.ALT_COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.PERSON_RESP.ALT_BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PERSON_RESP.ALT_PLANT_ID));
                            }
                            else
                            {
                                this.WorkingLocation = new BusinessLocation();
                                this.WorkingLocation = SessionManager.EffLocation;
                            }
                            //this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID));

                            this.PlantAccessList = new List <decimal>();
                            this.PlantAccessList.Add(this.WorkingLocation.Plant.PLANT_ID);
                            if (!string.IsNullOrEmpty(Person.NEW_LOCATION_CD))
                            {
                                decimal  plantID;
                                string[] locs = Person.NEW_LOCATION_CD.Split(',');
                                foreach (string locid in locs)
                                {
                                    if (decimal.TryParse(locid, out plantID) && plantID != this.WorkingLocation.Plant.PLANT_ID)
                                    {
                                        this.PlantAccessList.Add(plantID);
                                    }
                                }
                            }

                            access.LAST_LOGON_DT = WebSiteCommon.CurrentUTCTime();
                            int ctxstatus = 0;
                            SQMModelMgr.UpdateCredentials(ctx, access, "", out ctxstatus);
                            this.Credentials = access;
                            this.TimeZoneID  = WebSiteCommon.GetXlatValue("timeZone", this.Person.PREFERRED_TIMEZONE);

                            //this.DelegateList = new List<decimal>();
                            //this.DelegateList = SQMModelMgr.SelectDelegateList(ctx, this.Person.PERSON_ID).Select(l => l.PERSON_ID).ToList();

                            if (SessionManager.CreateSessionContext(this) == null)
                            {
                                this.LoginStatus = LoginStatus.SessionError;
                            }

                            this.InboxReviews = 0;
                            this.TaskList     = new List <TaskItem>();
                        }
                    }
                }
            }
            return(this);
        }
        protected void rgIncidentList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HiddenField  hf;
                Label        lbl;

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

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

                if (data.Incident.DESCRIPTION.Length > 120)
                {
                    lbl      = (Label)e.Item.FindControl("lblDescription");
                    lbl.Text = data.Incident.DESCRIPTION.Substring(0, 117) + "...";
                }

                lbl      = (Label)e.Item.FindControl("lblDescription");
                lbl.Text = HttpUtility.HtmlEncode(lbl.Text);

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

                lbl = (Label)e.Item.FindControl("lblIncStatus");
                if (data.Status == "C")
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "C") + " " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                }
                else if (data.Status == "C8")
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "C8") + " " + SQMBasePage.FormatDate((DateTime)data.Incident.CLOSE_DATE_8D, "d", false) + "<br/>(" + data.DaysToClose.ToString() + ")";
                }
                else if (data.Status == "N")
                {
                    lbl.Text = "<strong>" + WebSiteCommon.GetXlatValue("incidentStatus", "N") + "</strong>";
                }
                else
                {
                    lbl.Text = WebSiteCommon.GetXlatValue("incidentStatus", "A") + "<br/>(" + data.DaysOpen + ")";
                }

                LinkButton lb8d         = (LinkButton)e.Item.FindControl("lb8d");
                LinkButton lbEditReport = (LinkButton)e.Item.FindControl("lbEditReport");

                HyperLink hlReport = (HyperLink)e.Item.FindControl("hlReport");
                hlReport.Visible = true;

                INCIDENT_ANSWER entry = data.Incident.INCIDENT_ANSWER.Where(l => l.INCIDENT_QUESTION_ID == (decimal)EHSQuestionId.Create8D).FirstOrDefault();
                if (entry != null && entry.ANSWER_VALUE == "Yes")
                {
                    if (UserContext.RoleAccess() > AccessMode.View)
                    {
                        lb8d.Visible = true;
                    }
                    else
                    {
                        lb8d.Visible = false;
                    }

                    lbEditReport.Visible = false;

                    var problemCaseId = EHSIncidentMgr.SelectProblemCaseIdByIncidentId(data.Incident.INCIDENT_ID);
                    if (problemCaseId > 0)
                    {
                        hlReport.NavigateUrl = "/EHS/EHS_Alert_PDF.aspx?pcid=" + EncryptionManager.Encrypt(problemCaseId.ToString());

                        LinkButton lbReport = (LinkButton)e.Item.FindControl("lbReport");
                        lbReport.Visible         = true;
                        lbReport.CommandArgument = problemCaseId.ToString();
                        lbReport.Attributes.Add("CaseType", data.Incident.INCIDENT_TYPE);
                    }
                }
                else
                {
                    lb8d.Visible         = false;
                    lbEditReport.Visible = true;

                    hlReport.NavigateUrl = "/EHS/EHS_Alert_PDF.aspx?iid=" + EncryptionManager.Encrypt(data.Incident.INCIDENT_ID.ToString());
                }

                if (data.Incident.ISSUE_TYPE_ID == 10)                 // Prevention Verification
                {
                    lbEditReport.Visible = false;
                    //HtmlImage imgEditReport = (HtmlImage)e.Item.FindControl("imgEditReport");
                    //imgEditReport.Visible = false;
                }

                if (rgIncidentList.MasterTableView.GetColumn("Attach").Visible&& data.AttachList != null)
                {
                    lbl = (Label)e.Item.FindControl("lblAttach");
                    Ucl_Attach attch = (Ucl_Attach)Page.LoadControl("/Include/Ucl_Attach.ascx");
                    lbl.Parent.Controls.AddAt(lbl.Parent.Controls.IndexOf(lbl), attch);
                    attch.BindListAttachment(data.AttachList, "", 1);
                }
            }
        }
        protected void rgPreventativeList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                HiddenField hf;
                Label       lbl;
                string      val = "";

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

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

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

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

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

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

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

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

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

                if (rgPreventativeList.MasterTableView.GetColumn("Attach").Visible&&  data.AttachList != null)
                {
                    lbl = (Label)e.Item.FindControl("lblAttach");
                    Ucl_Attach attch = (Ucl_Attach)Page.LoadControl("/Include/Ucl_Attach.ascx");
                    lbl.Parent.Controls.AddAt(lbl.Parent.Controls.IndexOf(lbl), attch);
                    attch.BindListAttachment(data.AttachList, "1", 1);
                }
            }
        }
 public string GetFullIncidentName(string typeCode)
 {
     return(WebSiteCommon.GetXlatValue("incidentType", typeCode));
 }
        private void SetupProfilePanel()
        {
            if (ddlMetricDisposalCode.Items.Count == 0)
            {
                ddlDayDue.Items.AddRange(WebSiteCommon.PopulateDropDownListNums(1, 31));

                ddlMetricDue.Items.AddRange(WebSiteCommon.PopulateDropDownListNums(1, 31));

                ddlWarningDays.Items.AddRange(WebSiteCommon.PopulateDropDownListNums(0, 11));

                ddlMetricDisposalCode.DataSource     = SessionManager.DisposalCodeList;
                ddlMetricDisposalCode.DataValueField = "UN_CODE";
                ddlMetricDisposalCode.DataTextField  = "UN_CODE";
                ddlMetricDisposalCode.DataBind();
                ddlMetricDisposalCode.Items.Insert(0, new ListItem(""));

                ddlMetricRegStatus.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("regulatoryStatus"));
                ddlMetricRegStatus.Items.Insert(0, new ListItem(""));

                SQMBasePage.FillCurrencyDDL(ddlMetricCurrency, "EUR");
                ddlMetricCurrency.Items.Insert(0, "");

                ddlMetricCost.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("costType", "long"));
                ddlMetricCost.Items.Insert(0, "");

                if (UserContext.CheckUserPrivilege(SysPriv.config, SysScope.envdata))
                {
                    ddlMetricStatus.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("statusCodeDelete"));
                }
                else
                {
                    ddlMetricStatus.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("statusCode"));
                }

                ddlMetricCategory.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("measureCategoryEHS", 2, ""));
                ddlMetricCategory.Items.Insert(0, "");

                measureList = EHSModel.SelectEHSMeasureList("", true).OrderBy(l => l.MEASURE_NAME).ToList();
                foreach (EHS_MEASURE measure in measureList)
                {
                    ddlMetricID.Items.Add(new ListItem(measure.MEASURE_NAME.Trim(), WebSiteCommon.PackItemValue(measure.MEASURE_CATEGORY, measure.EFM_TYPE, measure.MEASURE_ID.ToString())));
                    if (measure.MEASURE_CATEGORY == "FACT")
                    {
                        ListItem item = new ListItem(measure.MEASURE_NAME.Trim(), measure.MEASURE_ID.ToString());
                        item.Attributes.Add("title", measure.MEASURE_DESC);
                        ddlNormFact.Items.Add(item);
                    }
                }
                ddlMetricID.Items.Insert(0, "");
                ddlNormFact.Items.Insert(0, "");

                if (ddlNormFact.Items.Count == 1)       // don't display normalize selects if no factors defined
                {
                    phNormFact.Visible = false;
                }

                foreach (UOM uom in SessionManager.UOMList.Where(l => l.OWNER_ID == null).OrderBy(l => l.UOM_NAME).ToList())
                {
                    ddlMetricUOM.Items.Add(new ListItem(uom.UOM_NAME, WebSiteCommon.PackItemValue(uom.UOM_CATEGORY, uom.EFM_TYPE, uom.UOM_ID.ToString())));
                }
                ddlMetricUOM.Items.Insert(0, "");
                ddlMetricUOM.SelectedIndex = 0;
            }
            divEHSProfile.Visible  = true;
            pnlCopyProfile.Visible = false;
            UpdateListTitles();
        }
Beispiel #9
0
        public static VIDEO Add(String fileName, String fileExtention, String description, string videoTitle, int sourceType, decimal sourceId, string sourceStep, string injuryType, string bodyPart, string videoType, DateTime videoDate, DateTime incidentDate, Stream file, decimal plantId)
        {
            VIDEO ret = null;

            try
            {
                using (PSsqmEntities entities = new PSsqmEntities())
                {
                    VIDEO video = new VIDEO();
                    //video.FILE_NAME = filename;
                    video.DESCRIPTION = description;
                    video.TITLE       = videoTitle;
                    video.SOURCE_TYPE = sourceType;
                    video.SOURCE_ID   = sourceId;
                    video.SOURCE_STEP = sourceStep;

                    if (plantId > 0)
                    {
                        PLANT plant = SQMModelMgr.LookupPlant(plantId);
                        video.COMPANY_ID = (decimal)plant.COMPANY_ID;
                        video.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID;
                        video.PLANT_ID   = plantId;
                    }
                    else
                    {
                        video.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID;
                        video.BUS_ORG_ID = SessionManager.UserContext.Person.BUS_ORG_ID;
                        video.PLANT_ID   = SessionManager.UserContext.Person.PLANT_ID;
                    }

                    video.VIDEO_PERSON = SessionManager.UserContext.Person.PERSON_ID;
                    video.CREATE_DT    = WebSiteCommon.CurrentUTCTime();
                    video.VIDEO_TYPE   = videoType;                   // this is the injury/incident type.  Default to 0 for Media & audit
                    video.VIDEO_DT     = videoDate;
                    video.INCIDENT_DT  = incidentDate;
                    video.INJURY_TYPES = injuryType;
                    video.BODY_PARTS   = bodyPart;
                    video.VIDEO_STATUS = "";
                    //video.FILE_NAME = fileName;
                    video.FILE_SIZE = file.Length;

                    entities.AddToVIDEO(video);
                    entities.SaveChanges();

                    // use the video id, but have to save video
                    video.FILE_NAME = video.VIDEO_ID.ToString() + fileExtention;
                    entities.SaveChanges();

                    // this is the code for saving the file in the Azure cloud
                    if (video != null)
                    {
                        // get the container from the settings table
                        List <SETTINGS> sets             = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", "");
                        string          storageContainer = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString();

                        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                            CloudConfigurationManager.GetSetting("StorageConnectionString"));
                        CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                        CloudBlobContainer container  = blobClient.GetContainerReference(storageContainer);
                        CloudBlockBlob     blockBlob  = container.GetBlockBlobReference(video.VIDEO_ID.ToString() + fileExtention);
                        blockBlob.UploadFromStream(file);
                    }

                    ret = video;
                }
            }
            catch (Exception e)
            {
                //SQMLogger.LogException(e);
                ret = null;
            }

            return(ret);
        }
        protected void tab_Click(string tabID, string cmdArg)
        {
            if (tabID != null)
            {
                // setup for ps_admin.js to toggle the tab active/inactive display
                SetActiveTab(SessionManager.CurrentSecondaryTab = hfActiveTab.Value = tabID);

                pnlDetails.Visible = uclDocMgr.DocMgrPnl.Visible = pnlTargetList.Visible = pnlUomStd.Visible = false;
                COMPANY company = SQMModelMgr.LookupCompany(entities, SessionManager.EffLocation.Company.COMPANY_ID, "", false);

                switch (tabID)
                {
                case "lbCompanyDetail_tab":
                    pnlDetails.Visible   = true;
                    cbIsCustomer.Checked = (bool)company.IS_CUSTOMER;
                    cbIsSupplier.Checked = (bool)company.IS_SUPPLIER;
                    if (ddlStatus.Items.FindByValue(company.STATUS) != null)
                    {
                        ddlStatus.SelectedValue = company.STATUS;
                    }
                    if (SessionManager.IsEffLocationPrimary() == true)
                    {
                        phUpdateCompany.Visible = false;
                        cbIsCustomer.Enabled    = cbIsSupplier.Enabled = ddlStatus.Enabled = false;
                    }
                    break;

                case "lbUomStds_tab":
                    pnlUomStd.Visible = true;
                    BindStdUnits(SessionManager.EffLocation.Company);
                    break;

                case "lbCompanyTargets_tab":
                    pnlTargetList.Visible = true;
                    targetList            = ViewModel.SelectTargets(entities, company.COMPANY_ID, 0);
                    BindTargetList(targetList);
                    if (ddlEffYear.Items.Count == 0)
                    {
                        ddlEffYear.Items.AddRange(WebSiteCommon.PopulateDropDownListNums(2005, 15));
                        ddlTargetStatus.Items.AddRange(WebSiteCommon.PopulateDropDownListItems("statusCodeDelete", "short"));
                        string[] targs = { "statScopeE", "statScopeHS", "statScopeQS" };
                        foreach (string scopelist in targs)
                        {
                            foreach (WebSiteCommon.SelectItem si in WebSiteCommon.PopulateListItems(scopelist))
                            {
                                if (string.IsNullOrEmpty(si.Value))
                                {
                                    RadComboBoxItem li = new RadComboBoxItem(si.Text, si.Text);
                                    li.IsSeparator = true;
                                    ddlTarget.Items.Add(li);
                                }
                                else
                                {
                                    ddlTarget.Items.Add(new RadComboBoxItem(si.Text, (si.Value + "|" + scopelist.Substring(9))));
                                }
                            }
                        }
                    }

                    break;

                default:
                    if (SessionManager.IsEffLocationPrimary())
                    {
                        uclDocMgr.BindDocMgr("SYS", 0, 0);
                    }
                    break;
                }
            }
        }
        protected void btnMetricSave_Click(object sender, EventArgs e)
        {
            bool success;
            bool measureChanged    = false;
            bool reqdError         = false;
            EHS_PROFILE_MEASURE pm = null;

            if (hfOper.Value == "add")
            {
                pm = new EHS_PROFILE_MEASURE();
                pm.EHS_PROFILE_MEASURE_EXT = new EHS_PROFILE_MEASURE_EXT();
            }
            else
            {
                pm = LocalProfile().Profile.EHS_PROFILE_MEASURE.FirstOrDefault(l => l.PRMR_ID == LocalProfile().CurrentProfileMeasure.PRMR_ID);
                if (pm.EHS_PROFILE_MEASURE_EXT == null)
                {
                    pm.EHS_PROFILE_MEASURE_EXT         = new EHS_PROFILE_MEASURE_EXT();
                    pm.EHS_PROFILE_MEASURE_EXT.PRMR_ID = pm.PRMR_ID;
                }
            }

            pm.PLANT_ID = LocalProfile().Profile.PLANT_ID;

            decimal measureID = 0;

            if (!string.IsNullOrEmpty(ddlMetricID.SelectedValue))
            {
                measureID = Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue));
                if (pm.MEASURE_ID != measureID)
                {
                    measureChanged = true;
                }
            }

            pm.MEASURE_ID     = measureID;
            pm.MEASURE_PROMPT = tbMetricPrompt.Text;
            pm.REG_STATUS     = ddlMetricRegStatus.SelectedValue;
            pm.UN_CODE        = ddlMetricDisposalCode.SelectedValue;
            pm.WASTE_CODE     = tbWasteCode.Text;

            if (trMetricDue.Visible == true && ddlMetricDue.SelectedIndex != null && ddlMetricDue.SelectedIndex > -1)
            {
                pm.DAY_DUE = Convert.ToInt32(ddlMetricDue.SelectedValue);
            }
            else
            {
                pm.DAY_DUE = Convert.ToInt32(ddlDayDue.SelectedValue);
            }

            pm.DEFAULT_CURRENCY_CODE = ddlMetricCurrency.SelectedValue;
            if (ddlMetricResponsible.SelectedIndex > 0)
            {
                decimal personID = Convert.ToDecimal(ddlMetricResponsible.SelectedValue);
                if (personID != pm.RESPONSIBLE_ID)
                {
                    pm = LocalProfile().UpdateMeasureResponsible(pm, personID);
                }
                pm.RESPONSIBLE_ID = personID;
            }
            else
            {
                pm.RESPONSIBLE_ID = Convert.ToDecimal(null);
            }

            if (ddlMetricCost.SelectedValue == "CREDIT")
            {
                pm.NEG_VALUE_ALLOWED = true;
            }
            else
            {
                pm.NEG_VALUE_ALLOWED = false;
            }

            pm.STATUS = ddlMetricStatus.SelectedValue;

            pm.IS_REQUIRED = cbMetricRequired.Checked;

            decimal uomID = 0;

            if (ddlMetricCategory.SelectedValue == "FACT")
            {
                pm.DEFAULT_UOM = EHSModel.LookupEHSMeasure(new PSsqmEntities(), pm.MEASURE_ID, "").STD_UOM;
            }
            else
            {
                if (SQMBasePage.ParseToDecimal(WebSiteCommon.ParseItemValue(ddlMetricUOM.SelectedValue), out uomID))
                {
                    pm.DEFAULT_UOM = uomID;
                }

                decimal UOMFactor = 0;
                if (decimal.TryParse(tbUOMFactor.Text, out UOMFactor))
                {
                    pm.UOM_FACTOR = UOMFactor;
                }
                else
                {
                    pm.UOM_FACTOR = null;
                }
            }

            if (phMetricExt.Visible)
            {
                decimal decimalValue;
                if (SQMBasePage.ParseToDecimal(tbValueDflt.Text, out decimalValue))
                {
                    pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT = decimalValue;
                }
                else
                {
                    pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT = null;
                }

                if (SQMBasePage.ParseToDecimal(tbCostDflt.Text, out decimalValue))
                {
                    pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT = decimalValue;
                }
                else
                {
                    pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT = null;
                }

                if ((pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue || pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue))
                {
                    pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED = cbEnableOverride.Checked;
                }
                else
                {
                    pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED = false;
                }

                /*
                 * if ((pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue || pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue) && radEffEndDate.SelectedDate != null)
                 *  pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT = (DateTime)radEffEndDate.SelectedDate;
                 * else
                 *  pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT = null;
                 */
            }

            // validate

            switch (ddlMetricCategory.SelectedValue)
            {
            case "ENGY":
            case "EUTL":
                if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricUOM.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue))
                {
                    reqdError = true;
                }
                break;

            case "PROD":
            case "FACT":
                if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue))
                {
                    reqdError = true;
                }
                break;

            case "SAFE":
                if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue))
                {
                    reqdError = true;
                }
                break;

            default:
                if (tdDisposal.Attributes["Class"] == null || tdDisposal.Attributes["Class"] != "required")                          // UN disposal code not required
                {
                    if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricUOM.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue) ||
                        string.IsNullOrEmpty(ddlMetricRegStatus.SelectedValue))
                    {
                        reqdError = true;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(ddlMetricCategory.SelectedValue) || string.IsNullOrEmpty(ddlMetricID.SelectedValue) || string.IsNullOrEmpty(ddlMetricUOM.SelectedValue) || string.IsNullOrEmpty(ddlMetricResponsible.SelectedValue) ||
                        string.IsNullOrEmpty(ddlMetricDisposalCode.SelectedValue) || string.IsNullOrEmpty(ddlMetricRegStatus.SelectedValue))
                    {
                        reqdError = true;
                    }
                }
                if (tbUOMFactor.Visible && string.IsNullOrEmpty(tbUOMFactor.Text))
                {
                    reqdError = true;
                }
                break;
            }

            // AW01/2016 - if trying to delete, verify that there is no historical data associated with the Metric by checking for a EHS_PROFILE_INPUT
            if (pm.STATUS.Equals("D"))
            {
                if (EHSProfile.ValidateProfileMeasureForDelete(LocalProfile(), pm.PRMR_ID) > 0)
                {
                    reqdError = true;
                    BindProfileMeasure(pm);
                    DisplayErrorMessage(hfErrMetricHasHistory);
                    return;
                }
                else
                {
                }
            }
            if (reqdError && !pm.STATUS.Equals("D"))             // AW 01/2016 - don't show the errors if we are deleting the record
            {
                BindProfileMeasure(pm);
                DisplayErrorMessage(hfErrRequiredInputs);
                hfOper.Value = "";
                return;
            }

            if (hfOper.Value == "add")  // add measure to list
            {
                pm = LocalProfile().AddMeasure(pm, Convert.ToDecimal(WebSiteCommon.ParseItemValue(ddlMetricID.SelectedValue)));
            }

            EHSProfile.UpdateProfile(LocalProfile());

            if (pm.STATUS == "D")
            {
                EHSProfile.DeleteProfileMeasureNoHistory(LocalProfile(), pm.PRMR_ID);                 // AW 01/2016 - Delete record by PRMR_ID, not MEASURE_ID
                measureChanged = true;
            }

            if (measureChanged)
            {
                SetLocalProfile(new EHSProfile().Load(LocalProfile().Plant.PLANT_ID, true, false));
            }

            btnMetricClear_Click(null, null);
            BindProfile(LocalProfile());
        }
        protected void btnProfileSave_Click(object sender, EventArgs e)
        {
            LocalProfile().Profile.DAY_DUE        = Convert.ToInt32(ddlDayDue.SelectedValue);
            LocalProfile().Profile.REMINDER_DAYS  = Convert.ToInt32(ddlWarningDays.SelectedValue);
            LocalProfile().Profile.APPROVER_ID    = Convert.ToInt32(ddlFinalApprover.SelectedValue);
            LocalProfile().Profile.DISPLAY_OPTION = ddlDisplayOrder.SelectedIndex;

            if (LocalProfile().Profile.EHS_PROFILE_FACT != null)
            {
                LocalProfile().Profile.EHS_PROFILE_FACT.Clear();
            }

            if (ddlNormFact.SelectedIndex > 0)
            {
                LocalProfile().Profile.EHS_PROFILE_FACT.Add(LocalProfile().AddFactor("norm", "", Convert.ToDecimal(ddlNormFact.SelectedValue)));
                LocalProfile().Profile.EHS_PROFILE_FACT.Add(LocalProfile().AddFactor("normCost", "", Convert.ToDecimal(ddlNormFact.SelectedValue)));
            }

            LocalProfile().Profile.UTIL_MONTH_SPAN = LocalProfile().Profile.WASTE_MONTH_SPAN = Convert.ToInt32(WebSiteCommon.GetXlatValue("invoiceSpan", "MINDATE"));

            if (EHSProfile.UpdateProfile(LocalProfile()) >= 0)
            {
                string script = string.Format("alert('{0}');", Resources.LocalizedText.SaveSuccess);
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", script, true);
                //ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alertResult('hfAlertSaveSuccess');", true);
            }
            BindProfile(LocalProfile());
        }
        public int BindProfileMeasure(EHS_PROFILE_MEASURE pm)
        {
            int status = 0;

            pnlMetricEdit.Visible   = true;
            spUOMFactor.Visible     = false;
            pnlMetricEdit.Visible   = true;
            btnMetricCancel.Enabled = true;
            DisplayErrorMessage(null);

            if (SessionManager.GetUserSetting("EHS", "PROFILE_METRIC_DAYDUE") != null && SessionManager.GetUserSetting("EHS", "PROFILE_METRIC_DAYDUE").VALUE.ToUpper() == "Y")
            {
                trMetricDue.Visible = true;
            }
            else
            {
                trMetricDue.Visible = false;
            }

            try
            {
                if (pm == null)
                {
                    ddlMetricID.Enabled             = ddlMetricCost.Enabled = ddlMetricDisposalCode.Enabled = ddlMetricRegStatus.Enabled = ddlMetricUOM.Enabled = ddlMetricCurrency.Enabled = ddlMetricResponsible.Enabled = false;
                    ddlMetricCategory.SelectedIndex = ddlMetricID.SelectedIndex = ddlMetricDisposalCode.SelectedIndex = ddlMetricRegStatus.SelectedIndex = ddlMetricUOM.SelectedIndex = ddlMetricCost.SelectedIndex = ddlMetricResponsible.SelectedIndex = 0;
                    if (ddlMetricCurrency.Items.FindByValue(LocalProfile().Plant.CURRENCY_CODE) != null)
                    {
                        ddlMetricCurrency.SelectedValue = LocalProfile().Plant.CURRENCY_CODE;
                    }
                    lblMetricName.Text         = lblDisposalDesc.Text = "";
                    tbMetricPrompt.Text        = tbUOMFactor.Text = tbWasteCode.Text = "";
                    winMetricEdit.Title        = hfAddMetric.Value;
                    tbValueDflt.Text           = tbCostDflt.Text = "";
                    cbEnableOverride.Checked   = false;
                    cbMetricRequired.Checked   = true;
                    ddlMetricDue.SelectedValue = ddlDayDue.SelectedValue;
                }
                else
                {
                    winMetricEdit.Title = hfUpdateMetric.Value;
                    LocalProfile().CurrentProfileMeasure = pm;
                    LocalProfile().CurrentEHSMeasure     = pm.EHS_MEASURE;

                    if (pm.EHS_MEASURE != null && ddlMetricCategory.Items.FindByValue(pm.EHS_MEASURE.MEASURE_CATEGORY) != null)
                    {
                        ddlMetricCategory.SelectedValue = pm.EHS_MEASURE.MEASURE_CATEGORY;
                        ddlCategoryChanged(ddlMetricCategory, null);
                        ddlMetricID.SelectedValue = WebSiteCommon.PackItemValue(pm.EHS_MEASURE.MEASURE_CATEGORY, pm.EHS_MEASURE.EFM_TYPE, pm.EHS_MEASURE.MEASURE_ID.ToString());
                        lblMetricName.Text        = pm.EHS_MEASURE.MEASURE_CD;

                        if (pm.DAY_DUE.HasValue)
                        {
                            ddlMetricDue.SelectedValue = pm.DAY_DUE.ToString();
                        }
                        else
                        {
                            ddlMetricDue.SelectedValue = ddlDayDue.SelectedValue;
                        }

                        if (pm.EHS_MEASURE.MEASURE_CATEGORY != "PROD" && pm.EHS_MEASURE.MEASURE_CATEGORY != "SAFE" && pm.EHS_MEASURE.MEASURE_CATEGORY != "FACT" && ddlMetricCurrency.Items.FindByValue(pm.DEFAULT_CURRENCY_CODE) != null)
                        {
                            ddlMetricCurrency.SelectedValue = pm.DEFAULT_CURRENCY_CODE;
                        }

                        if (pm.EHS_MEASURE.MEASURE_CATEGORY != "PROD" && pm.EHS_MEASURE.MEASURE_CATEGORY != "SAFE" && pm.EHS_MEASURE.MEASURE_CATEGORY != "FACT" && pm.DEFAULT_UOM > 0)
                        {
                            UOM uom = SessionManager.UOMList.FirstOrDefault(l => l.UOM_ID == pm.DEFAULT_UOM);
                            if (uom != null)
                            {
                                if (ddlMetricUOM.Items.FindByValue(WebSiteCommon.PackItemValue(uom.UOM_CATEGORY, uom.EFM_TYPE, uom.UOM_ID.ToString())) != null)
                                {
                                    ddlMetricUOM.SelectedValue = WebSiteCommon.PackItemValue(uom.UOM_CATEGORY, uom.EFM_TYPE, uom.UOM_ID.ToString());
                                }
                                else
                                {
                                    ddlMetricUOM.SelectedIndex = 0;
                                }

                                if (uom.UOM_CATEGORY == "CUST")
                                {
                                    spUOMFactor.Visible = true;
                                }
                            }

                            if (pm.UOM_FACTOR.HasValue)
                            {
                                tbUOMFactor.Text = SQMBasePage.FormatValue((decimal)pm.UOM_FACTOR, 5);
                            }
                        }

                        if (pm.EHS_MEASURE.MEASURE_CATEGORY != "PROD" && pm.EHS_MEASURE.MEASURE_CATEGORY != "SAFE" && pm.EHS_MEASURE.MEASURE_CATEGORY != "FACT")
                        {
                            if (pm.NEG_VALUE_ALLOWED.HasValue && (bool)pm.NEG_VALUE_ALLOWED)
                            {
                                ddlMetricCost.SelectedValue = "CREDIT";
                            }
                            else
                            {
                                ddlMetricCost.SelectedValue = "COST";
                            }
                        }
                    }

                    tbMetricPrompt.Text = pm.MEASURE_PROMPT;
                    ddlMetricRegStatus.SelectedValue    = pm.REG_STATUS;
                    ddlMetricDisposalCode.SelectedValue = pm.UN_CODE;
                    if (!string.IsNullOrEmpty(pm.UN_CODE))
                    {
                        lblDisposalDesc.Text = SessionManager.DisposalCodeList.FirstOrDefault(l => l.UN_CODE == pm.UN_CODE).DESCRIPTION;
                    }
                    else
                    {
                        lblDisposalDesc.Text = "";
                    }

                    tbWasteCode.Text = pm.WASTE_CODE;

                    if (pm.RESPONSIBLE_ID > 0 && ddlMetricResponsible.Items.FindByValue(pm.RESPONSIBLE_ID.ToString()) != null)
                    {
                        ddlMetricResponsible.SelectedValue = pm.RESPONSIBLE_ID.ToString();
                    }
                    else
                    {
                        ddlMetricResponsible.SelectedIndex = 0;
                    }

                    ddlUOMChanged(ddlMetricUOM, null);
                    ddlMetricStatus.SelectedValue = pm.STATUS;
                    cbMetricRequired.Checked      = (bool)pm.IS_REQUIRED;

                    tbValueDflt.Text         = tbCostDflt.Text = "";
                    cbEnableOverride.Checked = false;
                    // radEffEndDate.ShowPopupOnFocus = true;
                    //radEffEndDate.SelectedDate = null;
                    if (pm.EHS_PROFILE_MEASURE_EXT != null && pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT.HasValue)
                    {
                        tbValueDflt.Text = SQMBasePage.FormatValue((decimal)pm.EHS_PROFILE_MEASURE_EXT.VALUE_DEFAULT, 2);
                    }
                    if (pm.EHS_PROFILE_MEASURE_EXT != null && pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT.HasValue)
                    {
                        tbCostDflt.Text = SQMBasePage.FormatValue((decimal)pm.EHS_PROFILE_MEASURE_EXT.COST_DEFAULT, 2);
                    }
                    if (pm.EHS_PROFILE_MEASURE_EXT != null && pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED.HasValue)
                    {
                        cbEnableOverride.Checked = (bool)pm.EHS_PROFILE_MEASURE_EXT.OVERRIDE_ALLOWED;
                    }
                    //if (pm.EHS_PROFILE_MEASURE_EXT != null && pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT.HasValue)
                    //    radEffEndDate.SelectedDate = pm.EHS_PROFILE_MEASURE_EXT.EFF_END_DT;
                }

                UpdateListTitles();
                pnlMetricEdit.Enabled = btnMetricCancel.Enabled = btnMetricSave.Enabled = UserContext.CheckUserPrivilege(SysPriv.config, SysScope.envdata);

                string script = "function f(){OpenMetricEditWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
            }

            catch
            {
            }

            return(status);
        }
        protected void rgAuditList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HiddenField  hf;
                Label        lbl;

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

                LinkButton lnk = (LinkButton)e.Item.FindControl("lbAuditId");
                lnk.Text = WebSiteCommon.FormatID(data.Audit.AUDIT_ID, 6);

                /*
                 * if (data.Audit.DESCRIPTION.Length > 120)
                 * {
                 *      lbl = (Label)e.Item.FindControl("lblDescription");
                 *      lbl.Text = data.Audit.DESCRIPTION.Substring(0, 117) + "...";
                 * }
                 */
                //lbl = (Label)e.Item.FindControl("lblDescription");
                //lbl.Text = HttpUtility.HtmlEncode(lbl.Text);

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

                lbl = (Label)e.Item.FindControl("lblAuditStatus");

                List <XLAT> TaskXLATList = SQMBasePage.SelectXLATList(new string[1] {
                    "AUDIT_STATUS"
                });

                if (data.Audit.CURRENT_STATUS == "C")
                {
                    // TODO: This throws a null reference error when the database field is NULL (which is valid)
                    DateTime clsDate = (DateTime)data.Audit.CLOSE_DATE_DATA_COMPLETE;
                    lbl.Text = TaskXLATList.Where(l => l.XLAT_GROUP == "AUDIT_STATUS" && l.XLAT_CODE == "C").FirstOrDefault().DESCRIPTION + " " + SQMBasePage.FormatDate(clsDate, "d", false);

                    // TODO: Possible fix
                    //DateTime? clsDate = data.Audit.CLOSE_DATE;
                    //if (data.Audit.CLOSE_DATE_DATA_COMPLETE.HasValue)
                    //{
                    //	clsDate = data.Audit.CLOSE_DATE_DATA_COMPLETE;
                    //}

                    //if (clsDate.HasValue)
                    //{
                    //	lbl.Text = TaskXLATList.Where(l => l.XLAT_GROUP == "AUDIT_STATUS" && l.XLAT_CODE == "C").FirstOrDefault().DESCRIPTION + " " + SQMBasePage.FormatDate(clsDate.Value, "d", false);
                    //}
                }
                else
                {
                    if (data.DaysToClose == 0)
                    {
                        DateTime tmp = ((DateTime)data.Audit.AUDIT_DT).AddDays(data.AuditType.DAYS_TO_COMPLETE);
                        lbl.Text = TaskXLATList.Where(l => l.XLAT_GROUP == "AUDIT_STATUS" && l.XLAT_CODE == "X").FirstOrDefault().DESCRIPTION + "<br/>(" + SQMBasePage.FormatDate(tmp, "d", false) + ")";
                    }
                    else if (data.Audit.PERCENT_COMPLETE > 0)
                    {
                        lbl.Text = TaskXLATList.Where(l => l.XLAT_GROUP == "AUDIT_STATUS" && l.XLAT_CODE == "I").FirstOrDefault().DESCRIPTION + "<br/>(" + data.DaysToClose + ")";
                    }
                    else
                    {
                        lbl.Text = TaskXLATList.Where(l => l.XLAT_GROUP == "AUDIT_STATUS" && l.XLAT_CODE == "A").FirstOrDefault().DESCRIPTION + "<br/>(" + data.DaysToClose + ")";
                    }
                }

                lnk = (LinkButton)e.Item.FindControl("lbAuditId");
                LinkButton  lnkReAudit    = (LinkButton)e.Item.FindControl("lbReAudit");
                Label       lblAuditingId = (Label)e.Item.FindControl("lblAuditingId");
                HiddenField hdnId         = (HiddenField)e.Item.FindControl("hdnAuditingId");

                if (allowReAudits.ToUpper().Equals("Y"))
                {
                    if (SessionManager.CheckUserPrivilege(SysPriv.admin, SysScope.audit))
                    {
                        if (hdnId.Value.ToString().Trim().Equals("0") || hdnId.Value.ToString().Trim().Equals(""))
                        {
                            lblAuditingId.Visible = false;
                        }
                        else
                        {
                            lnkReAudit.Visible = false;
                            lblAuditingId.Text = Resources.LocalizedText.ReAuditing + " " + hdnId.Value.ToString();
                        }
                    }
                    else
                    {
                        lnkReAudit.Visible    = false;
                        lblAuditingId.Visible = false;
                    }
                }
                else
                {
                    lnkReAudit.Visible    = false;
                    lblAuditingId.Visible = false;
                }

                if (SessionManager.UserContext.Person.PERSON_ID == data.Person.PERSON_ID)
                {
                    lnk.CommandArgument = data.Audit.AUDIT_ID.ToString() + "~" + data.Status;
                    lnkReAudit.Visible  = false;
                    //lblAuditingId.Visible = false;
                }
                else if (!data.Status.Equals("C"))
                {
                    lnk.CommandArgument = data.Audit.AUDIT_ID.ToString() + "~D";
                }
                else
                {
                    lnk.CommandArgument = data.Audit.AUDIT_ID.ToString() + "~C";
                }
            }
        }
        protected void rgCaseList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                GridHeaderItem gh = e.Item as GridHeaderItem;
                if (staticAppContext == "QI")
                {
                    //gh.Cells[4].Text = "";
                    //gh.Cells[4].Visible = false;
                    ;
                }
                else
                {
                    ;
                }
            }

            if (e.Item is GridDataItem)
            {
                try
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    HiddenField  hf   = (HiddenField)item["Reports"].FindControl("hfProblemCaseType");

                    LinkButton lbReportQi  = (LinkButton)item["Reports"].FindControl("lbReport");
                    HyperLink  hlReportEhs = (HyperLink)item["Reports"].FindControl("hlReport");

                    lbReportQi.Attributes.Add("CaseType", hf.Value);

                    //lbReportQi.Visible = (hf.Value != "EHS");
                    lbReportQi.Visible  = true;
                    hlReportEhs.Visible = (hf.Value == "EHS");

                    ProblemCase probCase = (ProblemCase)e.Item.DataItem;

                    Label lbl = (Label)e.Item.FindControl("lblCaseID");
                    lbl.Text = WebSiteCommon.FormatID(probCase.ProbCase.PROBCASE_ID, 6);
                    LinkButton lnk = (LinkButton)e.Item.FindControl("lbCaseId");
                    if (lnk != null && UserContext.RoleAccess() < AccessMode.Partner)
                    {
                        lnk.Enabled = false;
                    }


                    lbl = (Label)e.Item.FindControl("lblIncidentID");
                    if (probCase.IncidentList != null && probCase.IncidentList.Count > 0)
                    {
                        lbl.Text = WebSiteCommon.FormatID(probCase.IncidentList[0].INCIDENT_ID, 6);
                    }

                    lbl = (Label)e.Item.FindControl("lblStatus");
                    if (probCase.ProbCase.CLOSE_DT.HasValue)
                    {
                        lbl.Text = WebSiteCommon.GetXlatValue("recordStatus", "C") + ": " + SQMBasePage.FormatDate((DateTime)probCase.ProbCase.CLOSE_DT, "d", false);
                    }
                    else
                    {
                        lbl.Text = WebSiteCommon.GetXlatValue("caseStep", (Math.Max((decimal)probCase.ProbCase.PROGRESS, 1) - 1).ToString());
                        hf       = (HiddenField)e.Item.FindControl("hfStatus");
                        if (hf.Value == "I")
                        {
                            Image img = (Image)e.Item.FindControl("imgStatus");
                            img.ImageUrl = "/images/defaulticon/16x16/no.png";
                            img.Visible  = true;
                        }
                    }
                }
                catch
                {
                }
            }
        }
 public string GetFullAuditName(string typeCode)
 {
     return(WebSiteCommon.GetXlatValue("auditType", typeCode));
 }
        public void gvOnProfileRowDataBound(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
                {
                    CheckBox    cb;
                    Label       lbl;
                    Image       img = (Image)e.Row.Cells[0].FindControl("imgHazardType");
                    HiddenField hf  = (HiddenField)e.Row.Cells[0].FindControl("hfMetricPrompt");

                    if (!string.IsNullOrEmpty(hf.Value))
                    {
                        lbl         = (Label)e.Row.Cells[0].FindControl("lblMetricPrompt");
                        lbl.Visible = true;
                        lbl.Text    = "<br>" + hf.Value;
                    }

                    hf = (HiddenField)e.Row.Cells[0].FindControl("hfMetricCategory");
                    if (hf.Value == "ENGY" || hf.Value == "EUTL")
                    {
                        e.Row.Cells[0].CssClass = e.Row.Cells[1].CssClass = "energyColor";
                        img.ImageUrl            = "~/images/status/energy.png";
                    }
                    else if (hf.Value == "PROD" || hf.Value == "SAFE" || hf.Value == "FACT")
                    {
                        img.ImageUrl = "~/images/status/inputs.png";
                        img.ToolTip  = WebSiteCommon.GetXlatValueLong("measureCategoryEHS", hf.Value);
                    }
                    else
                    {
                        e.Row.Cells[0].CssClass = e.Row.Cells[1].CssClass = "wasteColor";
                        hf = (HiddenField)e.Row.Cells[0].FindControl("hfMetricRegStatus");

                        if (hf.Value == "HZ")
                        {
                            img.ImageUrl = "~/images/status/hazardous.png";
                        }
                        else
                        {
                            img.ImageUrl = "~/images/status/waste.png";
                        }
                        img.ToolTip = WebSiteCommon.GetXlatValueLong("regulatoryStatus", hf.Value);
                        hf          = (HiddenField)e.Row.Cells[0].FindControl("hfDisposalCode");
                        if (!string.IsNullOrEmpty(hf.Value))
                        {
                            img.ToolTip += (".  " + SessionManager.DisposalCodeList.FirstOrDefault(l => l.UN_CODE == hf.Value).DESCRIPTION);
                        }
                    }
                    //      e.Row.Cells[0].Attributes.Add("Style", "background: wheat;");

                    hf = (HiddenField)e.Row.Cells[0].FindControl("hfMetricStatus");
                    if (hf.Value == "I")
                    {
                        img          = (Image)e.Row.Cells[0].FindControl("imgStatus");
                        img.ImageUrl = "/images/defaulticon/16x16/no.png";
                        img.Visible  = true;
                        cb           = (CheckBox)e.Row.Cells[0].FindControl("cbMetricRequired");
                        cb.Visible   = false;
                    }

                    LinkButton lnk  = (LinkButton)e.Row.Cells[0].FindControl("lnkMetricCD");
                    LinkButton lnk2 = (LinkButton)e.Row.Cells[0].FindControl("lnkMetricName");
                    lnk.ToolTip = lnk2.ToolTip = WebSiteCommon.GetXlatValue("measureCategoryEHS", hf.Value);

                    cb = (CheckBox)e.Row.Cells[0].FindControl("cbMetricRequired");
                    hf = (HiddenField)e.Row.Cells[0].FindControl("hfMetricRequired");
                    if (!string.IsNullOrEmpty(hf.Value))
                    {
                        try
                        {
                            cb.Checked = Convert.ToBoolean(hf.Value);
                        }
                        catch
                        { }
                    }

                    lbl = (Label)e.Row.Cells[0].FindControl("lblInvoiceType");
                    hf  = (HiddenField)e.Row.Cells[0].FindControl("hfMetricCategory");
                    if (hf.Value == "SAFE" || hf.Value == "PROD" || hf.Value == "FACT")
                    {
                        lbl.Text = "";
                    }
                    else
                    {
                        if (lbl.Text == "True")
                        {
                            lbl.Text = WebSiteCommon.GetXlatValue("costType", "CREDIT", "short");
                        }
                        else
                        {
                            lbl.Text = WebSiteCommon.GetXlatValue("costType", "COST", "short");
                        }
                    }

                    lbl = (Label)e.Row.Cells[0].FindControl("lblInvoiceUOM");
                    if (!string.IsNullOrEmpty(lbl.Text))
                    {
                        decimal uomID = Convert.ToDecimal(lbl.Text);
                        lbl.Text = SessionManager.UOMList.Where(l => l.UOM_ID == uomID).Select(u => u.UOM_NAME).FirstOrDefault().ToString();
                    }
                }
                catch
                {
                }
            }
        }