private bool IsFormValid()
        {
            if (OldPasswordTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Old password is Required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                OldPasswordTextBox.Focus();
                return(false);
            }

            if (NewPasswordTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("New password is Required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NewPasswordTextBox.Focus();
                return(false);
            }

            if (ConfirmPasswordTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Confirm password is Required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ConfirmPasswordTextBox.Focus();
                return(false);
            }

            if (NewPasswordTextBox.Text.Trim() != ConfirmPasswordTextBox.Text.Trim())
            {
                MessageBox.Show("New and Confirm password does not match.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ConfirmPasswordTextBox.Focus();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            if (NameTextBox.Text == "")
            {
                MessageBox.Show("이름을 입력하세요!!");
                NameTextBox.Focus();
                return;
            }
            else if (AgeTextBox.Text == "")
            {
                MessageBox.Show("나이를 입력하세요!!");
                AgeTextBox.Focus();
                return;
            }
            else if (NewIDTextBox.Text == "")
            {
                MessageBox.Show("ID를 입력하세요!!");
                NewIDTextBox.Focus();
                return;
            }
            else if (NewPasswordTextBox.Password == "")
            {
                MessageBox.Show("PWD를 입력하세요!!");
                NewPasswordTextBox.Focus();
                return;
            }
            string insertQuery = "INSERT INTO info(id,password,name,age) VALUES('" + NewIDTextBox.Text + "','" + NewPasswordTextBox.Password + "','" + NameTextBox.Text + "','" + AgeTextBox.Text + "')";

            conn.Open();
            MySqlCommand cmd = new MySqlCommand(insertQuery, conn);

            try
            {
                if (cmd.ExecuteNonQuery() == 1)//내가 처리한 mysql에 정상적으로 들어감
                {
                    MessageBox.Show("회원가입 완료!!");
                    Window.GetWindow(this).Close();
                }
                else
                {
                    MessageBox.Show("오류");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("같은 아이디가 있습니다ㅜ-ㅜ");
            }
            conn.Close();
        }
Ejemplo n.º 3
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     CanClose = false;
     try
     {
         if (NewPasswordTextBox.Text == "")
         {
             MessageBox.Show("新密碼不可空白!", "錯誤",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
             NewPasswordTextBox.Focus();
             return;
         }
         if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text)
         {
             MessageBox.Show("新密碼與確認新密碼不一致!", "錯誤",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
             NewPasswordTextBox.Focus();
             return;
         }
         using (var context = new XINEntities())
         {
             var qry = (from U in context.XINUsers
                        where U.EmployeeNo == fmMain.FEmployeeNo &&
                        U.PasswordCode == OrignalPasswordTextBox.Text
                        select U).FirstOrDefault();
             if (qry == null)
             {
                 MessageBox.Show("原來的密碼輸入錯誤!", "錯誤",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                 OrignalPasswordTextBox.Focus();
                 return;
             }
             //開始更新使用者的密碼
             qry.PasswordCode = NewPasswordTextBox.Text;
             context.SaveChanges();
             MessageBox.Show("密碼變更完成", "變更密碼",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     //成功完成密碼變更,允許關閉視窗
     CanClose = true;
 }
Ejemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //開始密碼變更,禁止關閉視窗
            CanClose = false;

            //驗證程序
            try
            {
                if (NewPasswordTextBox.Text == "")
                {
                    MessageBox.Show("新密碼不可空白!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text)
                {
                    MessageBox.Show("新密碼與確認密碼不一致!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                using (var SSEntities = new SmartShoppingEntities())
                {
                    var qry = (from U in SSEntities.SSUsers
                               where U.Employee_ID == frmMain.FUserID && U.Password == OrignalPasswordTextBox.Text
                               select U).FirstOrDefault();
                    if (qry == null)
                    {
                        MessageBox.Show("原來密碼錯誤!", "錯誤",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OrignalPasswordTextBox.Focus();
                        return;
                    }

                    //開始更新使用者的密碼
                    qry.Password = NewPasswordTextBox.Text;
                    SSEntities.SaveChanges();
                    MessageBox.Show("密碼變更完成,下次登入請使用新密碼", "變更密碼", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //完成密碼變更,允許關閉視窗
            CanClose = true;
        }
Ejemplo n.º 5
0
        private void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            User user = new User()
            {
                UserName = UserNameTextBox.Text.Trim(),
                Password = OriginalPasswordTextBox.Text.Trim()
            };
            Response response = new Response();

            if (string.IsNullOrEmpty(UserNameTextBox.Text.Trim()))
            {
                UserNameTextBox.Focus();
                UserNameErrorProvider.SetError(UserNameTextBox, "UserName can't be vacant!");
            }
            else
            {
                UserNameErrorProvider.SetError(UserNameTextBox, "");
                if (string.IsNullOrEmpty(OriginalPasswordTextBox.Text.Trim()))
                {
                    OriginalPasswordTextBox.Focus();
                    OriginalPasswordErrorProvider.SetError(OriginalPasswordTextBox, "OriginalPassword can't be vacant!");
                }
                else
                {
                    OriginalPasswordErrorProvider.SetError(OriginalPasswordTextBox, "");
                    if (string.IsNullOrEmpty(NewPasswordTextBox.Text.Trim()))
                    {
                        NewPasswordTextBox.Focus();
                        NewPasswordErrorProvider.SetError(NewPasswordTextBox, "NewPassword can't be vacant!");
                    }
                    else
                    {
                        NewPasswordErrorProvider.SetError(NewPasswordTextBox, "");
                        if (string.IsNullOrEmpty(ConfirmPasswordTextBox.Text.Trim()))
                        {
                            ConfirmPasswordTextBox.Focus();
                            ConfirmPasswordErrorProvider.SetError(ConfirmPasswordTextBox, "ConfirmPassword can't be vacant!");
                        }
                        else
                        {
                            try
                            {
                                response = new UserService().Authentication(user);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            if (string.IsNullOrEmpty(response.Message))
                            {
                                if (NewPasswordTextBox.Text.Trim() != OriginalPasswordTextBox.Text.Trim())
                                {
                                    if (ConfirmPasswordTextBox.Text.Trim() == NewPasswordTextBox.Text.Trim())
                                    {
                                        try
                                        {
                                            user.UserId   = new UserService().GetUserIdByUserName(user.UserName);
                                            user.Password = ConfirmPasswordTextBox.Text.Trim();
                                            response      = new UserService().ChangePassword(user);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.ToString());
                                        }
                                        if (response.IsFailed)
                                        {
                                            MessageBox.Show("Changing password fails", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            UserNameTextBox.Focus();
                                            UserNameTextBox.Text         = string.Empty;
                                            OriginalPasswordTextBox.Text = string.Empty;
                                            NewPasswordTextBox.Text      = string.Empty;
                                            ConfirmPasswordTextBox.Text  = string.Empty;
                                        }
                                        else
                                        {
                                            MessageBox.Show("Changing password succeeds", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Please repeat new password again.", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        NewPasswordTextBox.Text     = string.Empty;
                                        ConfirmPasswordTextBox.Text = string.Empty;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("New password and current password are same.", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    NewPasswordTextBox.Text     = string.Empty;
                                    ConfirmPasswordTextBox.Text = string.Empty;
                                }
                            }
                            else
                            {
                                MessageBox.Show(response.Message, "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                UserNameTextBox.Focus();
                                UserNameTextBox.Text         = string.Empty;
                                OriginalPasswordTextBox.Text = string.Empty;
                                NewPasswordTextBox.Text      = string.Empty;
                                ConfirmPasswordTextBox.Text  = string.Empty;
                            }
                        }
                    }
                }
            }
        }