Exemplo n.º 1
0
        //public static VIDEO_FILE SelectVideoFileById(decimal videoId)
        //{
        //	var entities = new PSsqmEntities();
        //	return (from i in entities.VIDEO_FILE where i.VIDEO_ID == videoId select i).FirstOrDefault();
        //}

        /// <summary>
        /// Delete all information for a specific video.
        /// </summary>
        /// <param name="videoId"></param>
        /// <param name="fileName"></param> Filename specified on the video record. Must be provided for file extension info.
        /// <returns></returns>
        public static int DeleteVideo(decimal videoId, string fileName)
        {
            int    status = 0;
            string delCmd = " IN (" + videoId + ") ";

            using (PSsqmEntities ctx = new PSsqmEntities())
            {
                try
                {
                    // delete all attachments
                    List <decimal> attachmentIds = (from a in ctx.VIDEO_ATTACHMENT
                                                    where a.VIDEO_ID == videoId
                                                    select a.VIDEO_ATTACH_ID).ToList();

                    if (attachmentIds != null && attachmentIds.Count > 0)
                    {
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO_ATTACHMENT_FILE WHERE VIDEO_ATTACH_ID IN (" + String.Join(",", attachmentIds) + ")");
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO_ATTACHMENT WHERE VIDEO_ATTACH_ID IN (" + String.Join(",", attachmentIds) + ")");
                    }

                    // delete the video from the Azure blob
                    // Retrieve storage account from connection string.
                    List <SETTINGS> sets               = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", "");
                    string          storageContainer   = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString();
                    string          storageURL         = sets.Find(x => x.SETTING_CD == "STORAGE_URL").VALUE.ToString();
                    string          storageQueryString = sets.Find(x => x.SETTING_CD == "STORAGE_QUERY").VALUE.ToString();
                    string          fileType           = Path.GetExtension(fileName);
                    try
                    {
                        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                            CloudConfigurationManager.GetSetting("StorageConnectionString"));

                        // Create the blob client.
                        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                        // Retrieve reference to a previously created container.
                        CloudBlobContainer container = blobClient.GetContainerReference(storageContainer);

                        // Retrieve reference to a blob named "myblob.txt".
                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(videoId.ToString() + fileType);

                        // Delete the blob.
                        blockBlob.Delete();
                    }
                    catch (Exception videoEx)
                    {
                        // what to do if there is an exception? Just log the exception for now
                        SQMLogger.LogException(videoEx);
                    }
                    // delete the video header
                    status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO WHERE VIDEO_ID" + delCmd);
                }
                catch (Exception ex)
                {
                    SQMLogger.LogException(ex);
                }
            }

            return(status);
        }
        public void GetUploadedFiles()
        {
            List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", "");

            storageContainer   = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString();
            storageURL         = sets.Find(x => x.SETTING_CD == "STORAGE_URL").VALUE.ToString();
            storageQueryString = sets.Find(x => x.SETTING_CD == "STORAGE_QUERY").VALUE.ToString();

            var entities = new PSsqmEntities();

            var files = (from a in entities.VIDEO
                         where a.SOURCE_TYPE == _recordType && a.SOURCE_ID == _recordId
                         orderby a.FILE_NAME
                         select new
            {
                VideoId = a.VIDEO_ID,
                RecordStep = a.SOURCE_STEP,
                FileName = a.FILE_NAME,
                Description = a.DESCRIPTION,
                Title = a.TITLE,
                Size = a.FILE_SIZE
            }).ToList();

            if (!string.IsNullOrEmpty(_recordStep))
            {
                if (_recordType == 40 && _recordStep == "2")                 // Special case to cover second page incident attachments originally entered with no recordstep
                {
                    rgFiles.DataSource = files.Where(f => (f.RecordStep == "2" || f.RecordStep == ""));
                }
                else
                {
                    rgFiles.DataSource = files.Where(f => f.RecordStep == _recordStep);
                }
            }
            else
            {
                rgFiles.DataSource = files;
            }
            rgFiles.DataBind();

            if (files.Count > 0 && (_recordType == (int)TaskRecordType.Audit || _recordType == (int)TaskRecordType.HealthSafetyIncident))
            {
                pnlListVideo.Visible      = true;
                rgFiles.Visible           = true;
                pnlNoVideosClosed.Visible = false;
            }
            else
            {
                pnlListVideo.Visible = false;
                rgFiles.Visible      = false;
            }
            //rgFiles.Visible = (files.Count > 0);
        }
        protected void PreviewFile(object sender, EventArgs e)
        {
            byte[] fileContent;
            if (ddlDataType.SelectedValue.Equals(""))
            {
                SetStatusMessage("You must select a file type from the drop down list");
            }
            else if (ddlPlantSelect.SelectedIndex == 0 && ddlDataType.SelectedValue.Equals("RECEIPT"))
            {
                SetStatusMessage("You must select a Receiving Location to upload a receipt record");
            }
            else
            {
                // validate the date in the select control
                periodYear  = 0;
                periodMonth = 0;

                List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("FILE_UPLOAD", ""); // ABW 20140805

                string        fileName       = ddlDataType.SelectedValue.ToString() + ".TXT";
                int           primaryCompany = Convert.ToInt32(sets.Find(x => x.SETTING_CD == "CompanyID").VALUE);
                PSsqmEntities Entities       = new PSsqmEntities();
                BUSINESS_ORG  busOrg         = SQMModelMgr.LookupBusOrg(Entities, primaryCompany, "", true, false);
                selectedFile = tbFileSelected.Text = flUpload.FileName;
                int fileLen = flUpload.PostedFile.ContentLength;

                fileContent = new byte[Convert.ToInt32(fileLen)];
                int nBytes = flUpload.PostedFile.InputStream.Read(fileContent, 0, Convert.ToInt32(fileLen));
                fileDelimiter       = sets.Find(x => x.SETTING_CD == "FileDelimiter1").VALUE.ToCharArray();
                plantDataMultiplier = 1;

                //fileReader = new SQMFileReader().InitializeCSV(1, flUpload.PostedFile.FileName, fileContent, fileDelimiter, plantDataMultiplier);
                fileReader = new SQMFileReader().InitializeCSV(primaryCompany, fileName, fileContent, fileDelimiter, plantDataMultiplier, periodYear, periodMonth, busOrg.PREFERRED_CURRENCY_CODE);
                using (StreamReader sr = new StreamReader(fileReader.FileStream))
                {
                    string line;
                    int    lineNo = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        fileReader.PreviewList.Add(line);
                    }
                    gvPreview.DataSource = fileReader.PreviewList;
                    gvPreview.DataBind();
                    gvPreview.Visible      = true;
                    gvExcelPreview.Visible = false;
                }
            }
            if (ddlDataType.SelectedValue.Equals("RECEIPT"))
            {
                dvPlantSelect.Style.Add("display", "inline");
            }
        }
        protected void rgPrivList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                if (defaultPrivs == null)
                {
                    defaultPrivs = SQMSettings.SelectSettingsGroup("DEFAULT_PRIVS", "");
                }

                GridDataItem item = (GridDataItem)e.Item;
                Label        lbl;
                LinkButton   lnk;

                PRIVLIST data = (PRIVLIST)item.DataItem;

                if (data.PRIV_GROUP != null)
                {
                    lbl      = (Label)item.FindControl("lblPrivDesc");
                    lbl.Text = XLATList.Where(x => x.XLAT_GROUP == "PRIV_PRIV" && x.XLAT_CODE == data.PRIV.ToString()).FirstOrDefault().DESCRIPTION_SHORT;

                    lbl      = (Label)item.FindControl("lblScope");
                    lbl.Text = XLATList.Where(x => x.XLAT_GROUP == "PRIV_SCOPE" && x.XLAT_CODE == data.SCOPE.ToString()).FirstOrDefault().DESCRIPTION_SHORT;

                    lnk = (LinkButton)item.FindControl("lnkDeletePriv");
                    lnk.CommandArgument = data.PRIV_GROUP.ToString() + "~" + data.PRIV.ToString() + "~" + data.SCOPE.ToString();
                    // hide the link for the default privs that can't be removed
                    if (defaultPrivs.Count > 0)
                    {
                        foreach (SETTINGS setting in defaultPrivs)
                        {
                            try
                            {
                                priv   = Convert.ToInt16(setting.SETTING_CD.ToString());
                                scopes = setting.VALUE.ToString().Split(',');
                                for (int i = 0; i < scopes.Count(); i++)
                                {
                                    if (data.PRIV == Convert.ToInt16(setting.SETTING_CD.Trim()) && data.SCOPE == scopes[i].Trim())
                                    {
                                        lnk.Visible = false;
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
        }
        public void BindPrivGroups(List <PRIVGROUP> privGroupList, BusinessLocation businessLocation, string context)
        {
            hfPrivGroupContext.Value = context;

            if (ddlPrivGroupStatus.Items.Count == 0)
            {
                XLATList = SQMBasePage.SelectXLATList(new string[3] {
                    "ACTIVE_STATUS", "PRIV_PRIV", "PRIV_SCOPE"
                });

                ddlPrivGroupStatus.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "ACTIVE_STATUS").ToList();
                ddlPrivGroupStatus.DataValueField = "XLAT_CODE";
                ddlPrivGroupStatus.DataTextField  = "DESCRIPTION";
                ddlPrivGroupStatus.DataBind();
            }

            if (ddlScope.Items.Count == 0)
            {
                ddlScope.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "PRIV_SCOPE").ToList();
                ddlScope.DataValueField = "XLAT_CODE";
                ddlScope.DataTextField  = "DESCRIPTION";
                ddlScope.DataBind();
            }

            if (ddlPriviledge.Items.Count == 0)
            {
                ddlPriviledge.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "PRIV_PRIV").ToList();
                ddlPriviledge.DataValueField = "XLAT_CODE";
                ddlPriviledge.DataTextField  = "DESCRIPTION";
                ddlPriviledge.DataBind();
                RadComboBoxItem item = new RadComboBoxItem("", "select a priviledge level");
                ddlPriviledge.Items.Insert(0, item);
                try
                {
                    item         = ddlPriviledge.FindItemByValue("100");
                    item.Enabled = false;
                }
                catch { }
            }

            defaultPrivs = SQMSettings.SelectSettingsGroup("DEFAULT_PRIVS", "");

            pnlPrivGroups.Visible = true;

            rgPrivGroup.DataSource = privGroupList;
            rgPrivGroup.DataBind();
        }
        //protected void btnReceiptsSearchClick(object sender, EventArgs e)
        //{
        //	if (OnSearchReceiptsClick != null)
        //	{
        //		Button btn = (Button)sender;
        //		OnSearchReceiptsClick(btn.CommandArgument);
        //	}
        //}

        #endregion


        #region ehsaudit

        public void BindAuditListRepeater(object theList, string appContext)
        {
            pnlAuditListRepeater.Visible = true;
            staticAppContext             = appContext;

            // first check settings to see if the company allows ReAudits
            List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("AUDIT", "");            // ABW 20140805

            allowReAudits = "";
            try
            {
                allowReAudits = sets.Find(x => x.SETTING_CD == "AllowReAudit").VALUE;
            }
            catch { }


            rgAuditList.DataSource = theList;
            rgAuditList.DataBind();
        }
        public void BindAuditListRepeater(object theList, string appContext)
        {
            pnlAuditListRepeater.Visible = true;
            staticAppContext             = appContext;

            List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("AUDIT", "");

            string expandDetails = sets.Find(x => x.SETTING_CD == "AuditExceptionExpanded").VALUE.ToString();

            if (expandDetails != null && expandDetails.ToUpper().Equals("Y"))
            {
                rgAuditList.MasterTableView.GroupsDefaultExpanded = true;
            }
            else
            {
                rgAuditList.MasterTableView.GroupsDefaultExpanded = false;
            }

            rgAuditList.DataSource = theList;
            rgAuditList.DataBind();
        }
        protected void rgAuditAnswers_ItemCommand(object sender, GridCommandEventArgs e)
        {
            // add this back to the grid to hit this code... OnItemCommand="rgAuditAnswers_ItemCommand"
            // only close if the company setting AuditExceptionExpanded = "N"
            List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("AUDIT", "");

            string expandDetails = sets.Find(x => x.SETTING_CD == "AuditExceptionExpanded").VALUE.ToString();

            if (expandDetails == null || !expandDetails.ToUpper().Equals("Y"))
            {
                if (e.CommandName == RadGrid.ExpandCollapseCommandName)
                {
                    foreach (GridItem item in e.Item.OwnerTableView.Items)
                    {
                        if (item.Expanded && item != e.Item && item.Parent.ID != e.Item.Parent.ID)
                        {
                            item.Expanded = false;
                        }
                    }
                }
            }
        }
        private void SavePrivGroupItem()
        {
            PSsqmEntities ctx       = new PSsqmEntities();
            PRIVGROUP     privGroup = null;
            bool          isNew     = false;

            if (string.IsNullOrEmpty(hfPrivGroupID.Value))              // add new item
            {
                privGroup = new PRIVGROUP();

                isNew = true;
            }
            else
            {
                privGroup = SQMModelMgr.LookupPrivGroup(ctx, hfPrivGroupID.Value.ToString(), false);
            }

            privGroup.PRIV_GROUP  = tbEditPrivGroup.Text.ToString().Trim();
            privGroup.DESCRIPTION = tbEditDescription.Text.ToString().Trim();
            privGroup.STATUS      = ddlPrivGroupStatus.SelectedValue.ToString().Trim();

            if ((privGroup = SQMModelMgr.UpdatePrivGroup(ctx, privGroup)) != null)
            {
                if (isNew)
                {
                    // We need to add the default privs
                    PRIVLIST privList = null;
                    if (defaultPrivs == null)
                    {
                        defaultPrivs = SQMSettings.SelectSettingsGroup("DEFAULT_PRIVS", "");
                    }
                    if (defaultPrivs.Count > 0)
                    {
                        foreach (SETTINGS setting in defaultPrivs)
                        {
                            try
                            {
                                priv   = Convert.ToInt16(setting.SETTING_CD.ToString());
                                scopes = setting.VALUE.ToString().Split(',');
                                for (int i = 0; i < scopes.Count(); i++)
                                {
                                    privList            = SQMModelMgr.LookupPrivList(privGroup.PRIV_GROUP, priv, scopes[i], true);
                                    privList.PRIV_GROUP = privGroup.PRIV_GROUP;
                                    privList.PRIV       = priv;
                                    privList.SCOPE      = scopes[i].Trim();
                                    privList            = SQMModelMgr.UpdatePrivList(ctx, privList);
                                }
                            }
                            catch
                            { }
                        }
                    }
                    else
                    {
                        // if there are no defult settings, we are going to force dashboard, inbox and incident
                    }
                    if (OnPrivGroupCommand != null)
                    {
                        OnPrivGroupCommand("add");
                    }
                }
                else
                {
                    foreach (GridDataItem item in rgPrivGroup.Items)
                    {
                        LinkButton lnk = (LinkButton)item.FindControl("lnkPrivGroupItem");
                        if (lnk.CommandArgument == hfPrivGroupID.Value)
                        {
                            // update the list item without doing a complete refresh of the list
                            Label lbl = new Label();
                            lbl      = (Label)item.FindControl("lblDescription");
                            lbl.Text = privGroup.DESCRIPTION;

                            lbl      = (Label)item.FindControl("lblGroupStatus");
                            lbl.Text = XLATList.Where(x => x.XLAT_GROUP == "ACTIVE_STATUS" && x.XLAT_CODE == privGroup.STATUS.ToString()).FirstOrDefault().DESCRIPTION_SHORT;
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        protected bool SaveUser(bool updateUser)
        {
            bool  bErrors = false;
            bool  success;
            Label lblErrorMessage = null;

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

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

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

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

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

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

            person.OLD_LOCATION_CD = "";

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

            person.STATUS = ddlUserStatus.SelectedValue;

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

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

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

            SetLocalPerson(person);

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

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

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

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

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

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

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

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

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

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

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

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

            PSsqmEntities entities = new PSsqmEntities();

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

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

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

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

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

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


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

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

            // Send email(s)

            List <SETTINGS> mailSettings = SQMSettings.SelectSettingsGroup("MAIL", "");

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

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

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

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

                string emailBody    = sb.ToString();
                string emailAddress = emailPerson.EMAIL;
                string rtn          = "";        // WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "");
                Thread thread       = new Thread(() => WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "", "", null, mailSettings));
                thread.IsBackground = true;
                thread.Start();
                EHSNotificationMgr.WriteEmailLog(entities, emailAddress, mailSettings.Find(x => x.SETTING_CD == "MailFrom").VALUE, emailSubject, emailBody, (int)TaskRecordType.HealthSafetyIncident, v.INCIDENT_ID, "prevention notification verification", rtn, "");
            }

            Response.Redirect("EHS_Incidents.aspx");
        }
        protected void btnUploadFile_Click(object sender, EventArgs e)
        {
            byte[] fileContent;
            if (ddlDataType.SelectedValue.Equals(""))
            {
                SetStatusMessage("You must select a data type from the drop down list");
            }
            else
            {
                // validate the date in the select control
                periodYear  = 0;
                periodMonth = 0;

                List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("FILE_UPLOAD", ""); // ABW 20140805

                int           primaryCompany = Convert.ToInt32(sets.Find(x => x.SETTING_CD == "CompanyID").VALUE);
                PSsqmEntities Entities       = new PSsqmEntities();
                string        fileName       = "";
                lblSummaryList.Visible = false;

                if (flUpload.HasFile)
                {
                    btnUpload.Enabled = false;

                    selectedFile = tbFileSelected.Text = flUpload.FileName;
                    int fileLen = flUpload.PostedFile.ContentLength;

                    if (fileLen < 5)
                    {
                        SetStatusMessage("The file does not contain relevant data: " + flUpload.FileName);
                        return;
                    }
                    fileDelimiter       = sets.Find(x => x.SETTING_CD == "FileDelimiter1").VALUE.ToCharArray();
                    plantDataMultiplier = 1;

                    fileName = ddlDataType.SelectedValue.ToString() + ".TXT";
                    try
                    {
                        string fileType = flUpload.PostedFile.ContentType;
                        fileContent = new byte[Convert.ToInt32(fileLen)];
                        int nBytes = flUpload.PostedFile.InputStream.Read(fileContent, 0, Convert.ToInt32(fileLen));
                    }
                    catch
                    {
                        SetStatusMessage("Error encountered opening or acquiring the file: " + flUpload.FileName);
                        return;
                    }
                    //fileReader = new SQMFileReader().InitializeCSV(1, flUpload.PostedFile.FileName, fileContent, fileDelimiter, plantDataMultiplier);
                    fileReader = new SQMFileReader().InitializeCSV(primaryCompany, fileName, fileContent, fileDelimiter, plantDataMultiplier, periodYear, periodMonth, "USD");

                    if (fileReader.Status < 0)
                    {
                        SetStatusMessage("Error encountered loading the file: " + flUpload.FileName);
                        return;
                    }

                    ProcessFile();
                }
                else
                {
                    SetStatusMessage("The selected file is empty: " + flUpload.FileName);
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///  Delete a ALL Video and attachment records for a specific source (Incident/Audit)
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="sourceType"></param>
        /// <param name="sourceStep"></param> This is the question Id for Audit videos. If left blank, all videos for a specific audit will be deleted
        /// <returns></returns>
        public static int DeleteAllSourceVideos(decimal sourceId, int sourceType, string sourceStep)
        {
            int status = 0;
            var videos = new List <VIDEO>();

            using (PSsqmEntities ctx = new PSsqmEntities())
            {
                try
                {
                    // select all videos for a source Id & source type
                    if (sourceStep.Trim().Length > 0)
                    {
                        videos = (from i in ctx.VIDEO
                                  where (i.SOURCE_ID == sourceId && i.SOURCE_TYPE == sourceType && i.SOURCE_STEP == sourceStep.Trim())
                                  orderby i.VIDEO_ID descending
                                  select i).ToList();
                    }
                    else
                    {
                        videos = (from i in ctx.VIDEO
                                  where (i.SOURCE_ID == sourceId && i.SOURCE_TYPE == sourceType)
                                  orderby i.VIDEO_ID descending
                                  select i).ToList();
                    }
                    decimal[] ids = videos.Select(v => v.VIDEO_ID).Distinct().ToArray();

                    // delete all attachments for all the videos
                    List <decimal> attachmentIds = (from a in ctx.VIDEO_ATTACHMENT
                                                    where ids.Contains(a.VIDEO_ID)
                                                    select a.VIDEO_ATTACH_ID).ToList();

                    if (attachmentIds != null && attachmentIds.Count > 0)
                    {
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO_ATTACHMENT_FILE WHERE VIDEO_ATTACH_ID IN (" + String.Join(",", attachmentIds) + ")");
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO_ATTACHMENT WHERE VIDEO_ATTACH_ID IN (" + String.Join(",", attachmentIds) + ")");
                    }


                    // delete the videos from the Azure blob
                    // Retrieve storage account from connection string.
                    List <SETTINGS> sets               = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", "");
                    string          storageContainer   = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString();
                    string          storageURL         = sets.Find(x => x.SETTING_CD == "STORAGE_URL").VALUE.ToString();
                    string          storageQueryString = sets.Find(x => x.SETTING_CD == "STORAGE_QUERY").VALUE.ToString();
                    foreach (VIDEO video in videos)
                    {
                        string fileType = Path.GetExtension(video.FILE_NAME);
                        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                            CloudConfigurationManager.GetSetting("StorageConnectionString"));

                        // Create the blob client.
                        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                        // Retrieve reference to a previously created container.
                        CloudBlobContainer container = blobClient.GetContainerReference(storageContainer);

                        // Retrieve reference to a blob named "myblob.txt".
                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(video.VIDEO_ID.ToString() + fileType);

                        // Delete the blob.
                        blockBlob.Delete();
                    }

                    // delete the video headers
                    if (sourceStep.Trim().Length > 0)
                    {
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO WHERE SOURCE_ID = " + sourceId + " AND SOURCE_TYPE = " + sourceType + " AND SOURCE_STEP = '" + sourceStep.Trim() + "'");
                    }
                    else
                    {
                        status = ctx.ExecuteStoreCommand("DELETE FROM VIDEO WHERE SOURCE_ID = " + sourceId + " AND SOURCE_TYPE = " + sourceType);
                    }
                }
                catch (Exception ex)
                {
                    SQMLogger.LogException(ex);
                }
            }

            return(status);
        }
        protected void btnUploadFile_Click(object sender, EventArgs e)
        {
            byte[] fileContent;
            if (ddlDataType.SelectedValue.Equals(""))
            {
                SetStatusMessage("You must select a data type from the drop down list");
            }
            else if (ddlPlantSelect.SelectedIndex == 0 && ddlDataType.SelectedValue.Equals("RECEIPT"))
            {
                SetStatusMessage("You must select a Receiving Location to upload a receipt record");
            }
            else
            {
                // validate the date in the select control
                periodYear  = 0;
                periodMonth = 0;

                List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("FILE_UPLOAD", ""); // ABW 20140805

                int           primaryCompany = Convert.ToInt32(sets.Find(x => x.SETTING_CD == "CompanyID").VALUE);
                PSsqmEntities Entities       = new PSsqmEntities();
                BUSINESS_ORG  busOrg         = SQMModelMgr.LookupBusOrg(Entities, primaryCompany, "", true, false);
                string        fileName       = "";
                lblSummaryList.Visible = false;

                if (flUpload.HasFile)
                {
                    btnUpload.Enabled = false;

                    selectedFile = tbFileSelected.Text = flUpload.FileName;
                    int fileLen = flUpload.PostedFile.ContentLength;

                    if (fileLen < 5)
                    {
                        SetStatusMessage("The file does not contain relevant data: " + flUpload.FileName);
                        return;
                    }
                    fileDelimiter       = sets.Find(x => x.SETTING_CD == "FileDelimiter1").VALUE.ToCharArray();
                    plantDataMultiplier = 1;

                    fileName = ddlDataType.SelectedValue.ToString() + ".TXT";
                    try
                    {
                        string fileType = flUpload.PostedFile.ContentType;
                        fileContent = new byte[Convert.ToInt32(fileLen)];
                        int nBytes = flUpload.PostedFile.InputStream.Read(fileContent, 0, Convert.ToInt32(fileLen));
                    }
                    catch
                    {
                        SetStatusMessage("Error encountered opening or acquiring the file: " + flUpload.FileName);
                        return;
                    }
                    //fileReader = new SQMFileReader().InitializeCSV(1, flUpload.PostedFile.FileName, fileContent, fileDelimiter, plantDataMultiplier);
                    fileReader = new SQMFileReader().InitializeCSV(primaryCompany, fileName, fileContent, fileDelimiter, plantDataMultiplier, periodYear, periodMonth, busOrg.PREFERRED_CURRENCY_CODE);
                    if (ddlDataType.SelectedValue.Equals("RECEIPT"))
                    {
                        fileReader.LocationCode = SQMModelMgr.LookupPlant(Convert.ToDecimal(ddlPlantSelect.SelectedValue)).DUNS_CODE;
                    }


                    if (fileReader.Status < 0)
                    {
                        SetStatusMessage("Error encountered loading the file: " + flUpload.FileName);
                        return;
                    }

                    ProcessFile();

                    if (ddlDataType.SelectedValue.Equals("RECEIPT"))
                    {
                        dvPlantSelect.Style.Add("display", "inline");
                    }
                }
                else
                {
                    SetStatusMessage("The selected file is empty: " + flUpload.FileName);
                }
            }
        }
        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);
        }
Exemplo n.º 16
0
        public void BindNotfyPlan(List <NOTIFYACTION> notifyItemList, BusinessLocation businessLocation, string context)
        {
            hfNotifyActionContext.Value = context;
            if (context != "company")
            {
                hfNotifyActionBusLoc.Value = context == "plant" ? businessLocation.Plant.PLANT_ID.ToString() : businessLocation.BusinessOrg.BUS_ORG_ID.ToString();
            }

            if (ddlNotifyScope.Items.Count == 0)
            {
                XLATList = SQMBasePage.SelectXLATList(new string[4] {
                    "NOTIFY_SCOPE", "NOTIFY_SCOPE_TASK", "NOTIFY_TASK_STATUS", "NOTIFY_TIMING"
                });

                // filter out non-installed or authorized modules from the notify-scope list
                List <SETTINGS> settingList = SQMSettings.SelectSettingsGroup("MODULE", "");

                if (settingList.Where(l => l.SETTING_CD == "PREVACTION" && l.VALUE == "A").Count() < 1)
                {
                    XLATList = XLATList.Where(x => !x.XLAT_CODE.Contains("RM-")).ToList();
                }

                ddlNotifyScope.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "NOTIFY_SCOPE").ToList();
                ddlNotifyScope.DataValueField = "XLAT_CODE";
                ddlNotifyScope.DataTextField  = "DESCRIPTION";
                ddlNotifyScope.DataBind();

                ddlScopeTask.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "NOTIFY_SCOPE_TASK").ToList();
                ddlScopeTask.DataValueField = "XLAT_CODE";
                ddlScopeTask.DataTextField  = "DESCRIPTION";
                ddlScopeTask.DataBind();

                ddlScopeStatus.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "NOTIFY_TASK_STATUS").ToList();
                ddlScopeStatus.DataValueField = "XLAT_CODE";
                ddlScopeStatus.DataTextField  = "DESCRIPTION";
                ddlScopeStatus.DataBind();

                ddlScopeTiming.DataSource     = XLATList.Where(x => x.XLAT_GROUP == "NOTIFY_TIMING").ToList();
                ddlScopeTiming.DataValueField = "XLAT_CODE";
                ddlScopeTiming.DataTextField  = "DESCRIPTION";
                ddlScopeTiming.DataBind();

                /*
                 * foreach (PRIVGROUP pg in SQMModelMgr.SelectPrivGroupList(new SysPriv[2] { SysPriv.admin, SysPriv.notify }, SysScope.incident, "A").ToList())
                 * {
                 *      ddlNotifyPrivGroup.Items.Add(new RadComboBoxItem(SQMModelMgr.FormatPrivGroup(pg), pg.PRIV_GROUP));
                 * }
                 */
                foreach (PRIVGROUP pg in SQMModelMgr.SelectPrivGroupList("A", false).ToList())
                {
                    if (pg.PRIV_GROUP.ToUpper() != "COMMON")
                    {
                        ddlNotifyPrivGroup.Items.Add(new RadComboBoxItem(SQMModelMgr.FormatPrivGroup(pg), pg.PRIV_GROUP));
                    }
                }
            }

            pnlNotifyAction.Visible = true;

            rgNotifyAction.DataSource = notifyItemList;
            rgNotifyAction.DataBind();
        }
Exemplo n.º 17
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);
        }