机房重构 之 修改密码

前言

  憋屈了几天,终于将这个功能实现了。理清了思路,一切都那么容易了

内容

  下面我们来看一下机房重构修改密码的代码吧

UI层

  
<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层

Imports Model
Imports BLL
Imports System.Reflection

Public Class ChangePasswordFacade
    Public Function ChangePwd(ByVal UserPwd As Model.UserModel) As Boolean
        Dim cUser As New BLL.Changepassword
        Dim flag As New Boolean
        flag = cUser.ChangePwd(UserPwd)
        Return flag
    End Function
End Class

BLL层

Imports Factory
Imports IDAL

Public Class Changepassword
    Public Function ChangePwd(ByVal Userpwd As Model.UserModel) As Boolean
        Dim fac As New Factory.ChangePwdFactory
        Dim iChangepwd As IDAL.IChangePassword
        iChangepwd = fac.Changepwd

        Dim dt As Boolean
        dt = iChangepwd.ChangePassword(Userpwd)
        Return dt
    End Function
End Class

DAL层

Imports SQLHelper

Public Class ChangePasswordDAL : Implements IDAL.IChangePassword
    Private shelper As New SQLHelper.SqlHelper
    Public Function ChangePassword(ByVal UserPwd As UserModel) As Boolean Implements IChangePassword.ChangePassword
        ' Dim shelper As New SQLHelper.SqlHelper
        Dim paras As SqlParameter() = {New SqlParameter("@Password", UserPwd.Password), New SqlParameter("@UserID", UserPwd.UserID)}
        Dim cmdText As String
        cmdText = "update  User_info set Password=@Password where UserID=@UserID"
        Dim dt As Boolean
        dt = shelper.ExecAddDelUpdate(cmdText, CommandType.Text, paras)
        Return dt
    End Function
End Class


IDAL层

Imports System.Reflection

Public Interface IChangePassword
    Function ChangePassword(ByVal UserPwd As Model.UserModel) As Boolean
End Interface

Factory层

Imports System.Reflection
Imports System.Configuration
Imports IDAL

Public Class ChangePwdFactory  '修改密码
    Dim strDB As String = System.Configuration.ConfigurationManager.AppSettings("DB")
    Public Function Changepwd() As IDAL.IChangePassword
        'CType函数将返回表达式显示地转换为指定的数据类型、对象、结构、类或接口的结果
        Return CType(Assembly.Load("DAL").CreateInstance("DAL.ChangePasswordDAL"), IDAL.IChangePassword)
    End Function
End Class

Model层

Public Class UserModel
    Private _UserID As String
    Private _Password As String
    Private _Level As String
    Private _UserName As String
    Private _Head As String

    Public Property UserName() As String
        Get
            Return _UserName
        End Get
        Set(value As String)
            _UserName = value
        End Set
    End Property

    Public Property UserID() As String
        Get
            Return _UserID
        End Get
        Set(value As String)
            _UserID = value
        End Set
    End Property
    Public Property Password() As String
        Get
            Return _Password
        End Get
        Set(value As String)
            _Password = value
        End Set
    End Property
    Public Property Level() As String
        Get
            Return _Level
        End Get
        Set(value As String)
            _Level = value
        End Set
    End Property
    Public Property Head() As String
        Get
            Return _Head
        End Get
        Set(value As String)
            _Head = value
        End Set
    End Property

End Class


总结:

  原来师傅让用数据库的表作为一个实体还有点不理解,现在终于明白了,一个数据表作为一个实体,那样层次就更加清楚了。祝愿自己在这条路上越走越顺

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 32
    评论
这个问题比较宽泛,需要具体情况具体分析。如果你是想实现一个计算机机房用户管理系统,以下是一个简单的示例代码,供参考: ```python class User: def __init__(self, username, password): self.username = username self.password = password class Computer: def __init__(self, name, ip_address): self.name = name self.ip_address = ip_address self.users = [] def add_user(self, user): self.users.append(user) def remove_user(self, user): self.users.remove(user) def modify_user(self, old_user, new_user): index = self.users.index(old_user) self.users[index] = new_user class ComputerLab: def __init__(self, name): self.name = name self.computers = [] def add_computer(self, computer): self.computers.append(computer) def remove_computer(self, computer): self.computers.remove(computer) def modify_computer(self, old_computer, new_computer): index = self.computers.index(old_computer) self.computers[index] = new_computer def add_user_to_computer(self, computer, user): computer.add_user(user) def remove_user_from_computer(self, computer, user): computer.remove_user(user) def modify_user_on_computer(self, computer, old_user, new_user): computer.modify_user(old_user, new_user) ``` 以上代码定义了三个类:User、Computer和ComputerLab。User类表示一个计算机机房用户,包括用户名和密码。Computer类表示一台计算机,包括名称、IP地址和当前连接的用户列表。ComputerLab类表示一个计算机机房,包括名称和所包含的计算机列表。 其中,Computer类有三个方法,分别用于添加、删除和修改计算机当前连接的用户。ComputerLab类有四个方法,分别用于添加、删除和修改计算机,以及在某台计算机上添加、删除和修改用户。 当然,以上代码只是一个简单的示例,实际情况需要根据具体需求进行适当的修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 32
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值