예제 #1
0
        bool validate()
        {
            bool isValid = true;

            try
            {
                foreach (var control in requiredControlList)
                {
                    TextBox textBox = FindControls.FindVisualChildren <TextBox>(this).Where(x => x.Name == "tb_" + control)
                                      .FirstOrDefault();
                    System.Windows.Shapes.Path path = FindControls.FindVisualChildren <System.Windows.Shapes.Path>(this).Where(x => x.Name == "p_error_" + control)
                                                      .FirstOrDefault();
                    Border border = FindControls.FindVisualChildren <Border>(this).Where(x => x.Name == "brd_" + control)
                                    .FirstOrDefault();
                    if (textBox != null && path != null)
                    {
                        if (!HelpClass.validateEmpty(textBox.Text, path))
                        {
                            isValid = false;
                        }
                    }
                }
                foreach (var control in requiredControlList)
                {
                    ComboBox comboBox = FindControls.FindVisualChildren <ComboBox>(this).Where(x => x.Name == "cb_" + control)
                                        .FirstOrDefault();
                    System.Windows.Shapes.Path path = FindControls.FindVisualChildren <System.Windows.Shapes.Path>(this).Where(x => x.Name == "p_error_" + control)
                                                      .FirstOrDefault();
                    Border border = FindControls.FindVisualChildren <Border>(this).Where(x => x.Name == "brd_" + control)
                                    .FirstOrDefault();
                    if (comboBox != null && path != null)
                    {
                        if (!HelpClass.validateEmpty(comboBox.Text, path))
                        {
                            isValid = false;
                        }
                    }
                }
            }
            catch { }
            return(isValid);
        }
예제 #2
0
        private async void Btn_save_Click(object sender, RoutedEventArgs e)
        {//save
            try
            {
                HelpClass.StartAwait(grid_main);

                #region validate
                bool wrongOldPasswordLength = false, wrongNewPasswordLength = false, wrongConfirmPasswordLength = false;
                //chk empty old password
                if (pb_oldPassword.Password.Equals(""))
                {
                    HelpClass.validateEmpty(pb_oldPassword.Password, p_errorOldPassword);
                }
                else
                {
                    //chk password length
                    wrongOldPasswordLength = chkPasswordLength(pb_oldPassword.Password);
                    if (wrongOldPasswordLength)
                    {
                        HelpClass.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trErrorPasswordLengthToolTip");
                    }
                    else
                    {
                        HelpClass.clearPasswordValidate(pb_oldPassword, p_errorOldPassword);
                    }
                }
                //chk empty new password
                if (pb_newPassword.Password.Equals(""))
                {
                    HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trEmptyPasswordToolTip");
                }
                else
                {
                    //chk password length
                    wrongNewPasswordLength = chkPasswordLength(pb_newPassword.Password);
                    if (wrongNewPasswordLength)
                    {
                        HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorPasswordLengthToolTip");
                    }
                    else
                    {
                        HelpClass.clearPasswordValidate(pb_newPassword, p_errorNewPassword);
                    }
                }
                //chk empty confirm password
                if (pb_confirmPassword.Password.Equals(""))
                {
                    HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trEmptyPasswordToolTip");
                }
                else
                {
                    //chk password length
                    wrongConfirmPasswordLength = chkPasswordLength(pb_confirmPassword.Password);
                    if (wrongConfirmPasswordLength)
                    {
                        HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorPasswordLengthToolTip");
                    }
                    else
                    {
                        HelpClass.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword);
                    }
                }
                #endregion

                #region save
                if ((!pb_oldPassword.Password.Equals("")) && (!wrongOldPasswordLength) &&
                    (!pb_newPassword.Password.Equals("")) && (!wrongNewPasswordLength) &&
                    (!pb_confirmPassword.Password.Equals("")) && (!wrongConfirmPasswordLength))
                {
                    //get password for logined user
                    string loginPassword = MainWindow.userLogin.password;

                    string enteredPassword = Md5Encription.MD5Hash("Inc-m" + pb_oldPassword.Password);

                    if (!loginPassword.Equals(enteredPassword))
                    {
                        HelpClass.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trWrongPassword");
                    }
                    else
                    {
                        HelpClass.clearPasswordValidate(pb_oldPassword, p_errorOldPassword);
                        bool isNewEqualConfirmed = true;
                        if (pb_newPassword.Password.Equals(pb_confirmPassword.Password))
                        {
                            isNewEqualConfirmed = true;
                        }
                        else
                        {
                            isNewEqualConfirmed = false;
                        }

                        if (!isNewEqualConfirmed)
                        {
                            HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorNewPasswordNotEqualConfirmed");
                            HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorNewPasswordNotEqualConfirmed");
                        }
                        else
                        {
                            HelpClass.clearPasswordValidate(pb_newPassword, p_errorNewPassword);
                            HelpClass.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword);
                            //change password
                            string newPassword = Md5Encription.MD5Hash("Inc-m" + pb_newPassword.Password);
                            MainWindow.userLogin.password = newPassword;
                            int s = await userModel.Save(MainWindow.userLogin);

                            if (s > 0)
                            {
                                if (!Properties.Settings.Default.password.Equals(""))
                                {
                                    Properties.Settings.Default.password = pb_newPassword.Password;
                                    Properties.Settings.Default.Save();
                                }
                                Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopPasswordChanged"), animation: ToasterAnimation.FadeIn);
                                this.Close();
                            }
                            else
                            {
                                Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);
                            }
                        }
                    }
                }
                #endregion

                HelpClass.EndAwait(grid_main);
            }
            catch (Exception ex)
            {
                HelpClass.EndAwait(grid_main);
                HelpClass.ExceptionMessage(ex, this);
            }
        }