1. 程式人生 > >機房重構 之 修改密碼

機房重構 之 修改密碼

<span style="color:#333333;">Imports System.Windows.Forms
Imports System.Drawing
Imports Model

Public Class frmChangePassword
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Hide()
        frmMain.Show()

    End Sub

    Private Sub frmChangePassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtOldPassword.Select()
        txtOldPassword.Focus()
        Label1.Parent = PictureBox1
        Label1.BackColor = Color.Transparent
        Label2.Parent = PictureBox1
        Label2.BackColor = Color.Transparent
        Label3.Parent = PictureBox1
        Label3.BackColor = Color.Transparent


    End Sub

    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        '進行非空判斷  舊密碼不能為空
        If txtOldPassword.Text = "" Then
            MsgBox("請輸入原始密碼", 0, "提示")
            txtOldPassword.Select()
            txtOldPassword.Focus()
        End If
        '新密碼不能為空
        If txtNewPassword.Text = "" Then
            MsgBox("請輸入新密碼", 0, "提示")
            txtNewPassword.Select()
            txtNewPassword.Focus()
        End If
        ' 確認新密碼不能為空
        If txtBeSure.Text = "" Then
            MsgBox("請確認新密碼", 0, "提示")
        End If

        '判斷舊密碼是否正確
        Dim fac As New Facade.LoginFacade   '借用登入窗體的密碼
        Dim userInfo As New Model.UserModel

        userInfo.UserID = frmLogin.txtUserID.Text.Trim()
        userInfo.Password = txtOldPassword.Text.Trim()

        Dim table As New DataTable
        table = fac.CheckPwd(userInfo)
        If txtOldPassword.Text <> Trim(table.Rows(0).Item(1)) Then
            MsgBox("舊密碼不正確,請查證後再輸入", "0", "提示")
            txtOldPassword.Text = ""
            txtNewPassword.Text = ""
            txtBeSure.Text = ""
            txtOldPassword.Focus()
        End If
        '判斷兩次輸入的新密碼是否相同
        If txtNewPassword.Text <> txtBeSure.Text Then
            MsgBox("您兩次輸入的密碼不相同", 0, "提示")
            txtBeSure.Text = ""
            txtNewPassword.Text = ""
            txtNewPassword.Select()
            txtNewPassword.Focus()
        Else
            '進行密碼更新
            Dim Updatefac As New Facade.ChangePasswordFacade
            Dim table1 As New Boolean
            Dim UserPwd As New Model.UserModel
            UserPwd.Password = txtNewPassword.Text.Trim()
            UserPwd.UserID = frmLogin.txtUserID.Text.Trim()
            table1 = Updatefac.ChangePwd(UserPwd)
            If table1 = False Then
                MsgBox("修改失敗", "0", "提示")
            Else
                MsgBox("修改成功", 0, "恭喜哦親")
            End If

        End If

    End Sub
End Class</span>

Facade層