protected void btnChange_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnChange_Click";

            try {
                // Did page load already throw an error?
                if (((HtmlGenericControl)Master.FindControl("divWarning")).InnerHtml.Length > 0)
                {
                    return;
                }

                if (SHID.ToString() != txtSHID.Text)
                {
                    Common.CWarning wex = new Common.CWarning("Please press the Find button to ensure you're editing the correct Shareholder before trying to Save.");
                    throw (wex);
                }

                if (SHID == 0)
                {
                    Common.CWarning wex = new Common.CWarning("Please enter a SHID and press the Find button.");
                    throw (wex);
                }

                WSCSecurity auth = Globals.SecurityState;
                if (auth.AuthorizeShid(SHID, CropYear) < WSCSecurity.ShsPermission.shsReadWrite)
                {
                    Common.CWarning warn = new Common.CWarning("Sorry, you are not authorized to update this information");
                    throw (warn);
                }

                if (EmailAddress.Length == 0)
                {
                    Common.CWarning warn = new Common.CWarning("Please create an email address for this member.");
                    throw (warn);
                }

                string warnMsg = null;
                WSCMember.ResetPassword(SHID.ToString(), EmailAddress, ref warnMsg);
                if (warnMsg == null)
                {
                    Common.AppHelper.ShowConfirmation((HtmlGenericControl)Master.FindControl("divWarning"), "Password has been reset and sent to you via email.");
                }
                else
                {
                    Common.CWarning warn = new Common.CWarning(warnMsg);
                    throw (warn);
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ((PrimaryTemplate)Page.Master).ShowWarning(ex);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnSave_Click";

            try {
                int currentCropYear = Convert.ToInt32(WSCField.GetCropYears()[0].ToString());

                if (currentCropYear != CropYear)
                {
                    Common.CWarning wex = new Common.CWarning("Sorry, you cannot update information for a prior crop year.");
                    throw (wex);
                }

                if (!Common.CodeLib.IsValidSHID(txtSHID.Text))
                {
                    Common.CWarning wex = new Common.CWarning("Please enter a valid SHID.");
                    throw (wex);
                }

                if (SHID.ToString() != txtSHID.Text)
                {
                    Common.CWarning wex = new Common.CWarning("Please press the Find button to ensure you're editing the correct Shareholder before trying to Save.");
                    throw (wex);
                }

                if (SHID == 0)
                {
                    Common.CWarning wex = new Common.CWarning("Please enter a SHID and press the Find button.");
                    throw (wex);
                }

                WSCSecurity auth = Globals.SecurityState;
                if (auth.AuthorizeShid(SHID, CropYear) < WSCSecurity.ShsPermission.shsReadWrite)
                {
                    Common.CWarning wex = new Common.CWarning("Sorry, you are not authorized to update this information");
                    throw (wex);
                }

                // Validate Email or fax when needed.
                string sendRptOption = GetSendRptOption();

                if (txtEmail.Text.Length > 0 || sendRptOption == SEND_RPT_OPT_EMAIL)
                {
                    if (!Common.CodeLib.ValidateEmail(txtEmail.Text))
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Please enter the information in the correct format");
                        Common.AppHelper.ShowWarning(lblEmail, "Required to receive reports by email.");
                        return;
                    }
                }

                if (txtFax.Text.Length > 0 || sendRptOption == SEND_RPT_OPT_FAX)
                {
                    if (!Common.CodeLib.ValidateFax(txtFax.Text))
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Please enter the information in the correct format");
                        Common.AppHelper.ShowWarning(lblFax, "Required to receive reports by fax.");
                        return;
                    }
                }

                try {
                    WSCMember.UpdateSendRptOption(MemberID, sendRptOption);
                    Common.AppHelper.ShowConfirmation((HtmlGenericControl)Master.FindControl("divWarning"), "Your changes have been successfully updated!");
                }
                catch (System.Exception ex) {
                    if (Common.AppHelper.IsDebugBuild())
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), ex);
                    }
                    else
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Unable to save your changes at this time.", ex);
                        Common.AppHelper.LogException(ex, HttpContext.Current);
                    }
                    return;
                }


                try {
                    WSCMember.UpdateAddress(MemberID, txtEmail.Text, txtFax.Text, Globals.SecurityState.UserName);
                    Common.AppHelper.ShowConfirmation((HtmlGenericControl)Master.FindControl("divWarning"), "Your changes have been successfully updated!");
                }
                catch (System.Exception ex) {
                    if (Common.AppHelper.IsDebugBuild())
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), ex);
                    }
                    else
                    {
                        Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Unable to save your changes at this time.", ex);
                        Common.AppHelper.LogException(ex, HttpContext.Current);
                    }
                }

                if (((HtmlGenericControl)Master.FindControl("divWarning")).InnerHtml.Length == 0)
                {
                    Common.AppHelper.ShowConfirmation((HtmlGenericControl)Master.FindControl("divWarning"), "Your information has been updated!");
                }
            }
            catch (Exception ex) {
                ResetShareholder();
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ((PrimaryTemplate)Page.Master).ShowWarning(ex);
            }
        }
Exemple #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnSave_Click";

            string email = "";
            string fax   = "";

            try {
                if (!Common.CodeLib.IsValidSHID(txtSHID.Text))
                {
                    Common.CWarning warn = new WSCIEMP.Common.CWarning("Please enter a valid SHID");
                    throw (warn);
                }

                if (SHID.ToString() != txtSHID.Text)
                {
                    Common.CWarning wex = new Common.CWarning("Please press the Find button to ensure you're editing the correct Shareholder before trying to Save.");
                    throw (wex);
                }

                if (SHID == 0)
                {
                    Common.CWarning wex = new Common.CWarning("Please enter a SHID and press the Find button.");
                    throw (wex);
                }

                WSCSecurity auth = Globals.SecurityState;
                if (auth.AuthorizeShid(SHID, CropYear) < WSCSecurity.ShsPermission.shsReadWrite)
                {
                    Common.CWarning wex = new Common.CWarning("Sorry, you are not authorized to update this information");
                    throw (wex);
                }
                string userName = auth.UserName;
                email = txtEmail.Text;
                fax   = txtFax.Text;

                if (email.Length > 0 && !Common.CodeLib.ValidateEmail(email))
                {
                    Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Please enter the information in the correct format");
                    Common.AppHelper.ShowWarning(lblEmail, "Required to receive reports by email.");
                    return;
                }

                if (fax.Length > 0 && !Common.CodeLib.ValidateFax(fax))
                {
                    Common.AppHelper.ShowWarning((HtmlGenericControl)Master.FindControl("divWarning"), "Please enter the information in the correct format");
                    Common.AppHelper.ShowWarning(lblFax, "Required to receive reports by fax.");
                    return;
                }

                // Update the email address or fax number when necessary.
                try {
                    WSCMember.UpdateAddress(MemberID, email, fax, userName);
                    Common.AppHelper.ShowConfirmation((HtmlGenericControl)Master.FindControl("divWarning"), "Your changes have been successfully updated!");
                }
                catch (System.Exception ex) {
                    ResetShareholder();
                    throw(ex);
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ((PrimaryTemplate)Page.Master).ShowWarning(ex);
            }
        }