⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edituserform.vb

📁 使用Access数据库演示的任务分配管理程序 一个使用ADO.NET基于Microsoft Access数据库演示的任务分配管理的程序
💻 VB
字号:
'---------------------------------------------------------------------
'  This file is part of the Microsoft .NET Framework SDK Code Samples.
' 
'  Copyright (C) Microsoft Corporation.  All rights reserved.
' 
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation.  See these other
' materials for detailed information regarding Microsoft code samples.
' 
' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'---------------------------------------------------------------------
Imports System.Text.RegularExpressions

Public Class EditUserForm
    Inherits System.Windows.Forms.Form

    Public Sub New(ByVal dl As DataLayer, ByVal e As Common.UserEventArgs)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        m_DataLayer = dl
        m_UserRow = e.User
    End Sub

    Private m_DataLayer As DataLayer
    Private m_UserRow As Business.User
    Private Const c_DefaultPassword As String = "********"
    Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())

    Private Sub EditUserForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not m_UserRow Is Nothing Then
            txtPassword.Text = c_DefaultPassword
            txtConfirmPassword.Text = c_DefaultPassword
            txtUserName.Text = m_UserRow.Name
            txtUserFullName.Text = m_UserRow.FullName
            txtUserEmail.Text = m_UserRow.Email
            cbAdministrator.Checked = m_UserRow.IsAdministrator
            cbLocked.Checked = m_UserRow.IsAccountLocked
        End If
    End Sub

    Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
        'TODO: Remove the code below to enable changes to the 'jdoe' account.
        If m_UserRow.Name = "jdoe" Then
            MessageBox.Show("Changes to the 'jdoe' user account are not allowed.")
            Me.DialogResult = System.Windows.Forms.DialogResult.None
            Return
        End If
        'TODO: Remove the code above to enable changes to the 'jdoe' account.

        If IsFormValid() Then

            Dim editUserInfo As New Business.User
            editUserInfo.UserID = m_UserRow.UserID
            editUserInfo.FullName = txtUserFullName.Text
            editUserInfo.Email = txtUserEmail.Text
            editUserInfo.IsAdministrator = cbAdministrator.Checked
            editUserInfo.IsAccountLocked = cbLocked.Checked

            'if password changed
            If txtPassword.Text <> c_DefaultPassword Then
                editUserInfo.Password = txtPassword.Text
            Else
                editUserInfo.Password = String.Empty
            End If

            Dim dlResult As DataLayerResult = UpdateUser(editUserInfo)

            If dlResult = DataLayerResult.Success Then

                'did we just edit the current user
                If editUserInfo.UserID = m_DataLayer.CurrentUser.UserID Then
                    m_DataLayer.CurrentUser.FullName = txtUserFullName.Text
                    m_DataLayer.CurrentUser.Email = txtUserEmail.Text
                    m_DataLayer.CurrentUser.IsAdministrator = cbAdministrator.Checked
                    m_DataLayer.CurrentUser.IsAccountLocked = cbLocked.Checked

                    If txtPassword.Text <> c_DefaultPassword Then
                        ' Don't forget to protect this with encryption
                        m_DataLayer.CurrentUser.Password = txtPassword.Text
                    End If
                End If

                Me.Close()
            Else
                MessageBox.Show(m_ResourceManager.GetString("Unable_to_edit_user_at_this_time"))
                Me.DialogResult = System.Windows.Forms.DialogResult.None
            End If
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.None
        End If
    End Sub

    Public Function UpdateUser(ByVal user As Business.User) As DataLayerResult
        Try
            Dim facade As New Database.UserFacade
            facade.UpdateUser(user)

        Catch ex As Exception
            Return DataLayerResult.UnknownFailure
        End Try

        Return DataLayerResult.Success
    End Function

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Function IsFormValid() As Boolean
        'check the fields for valid data and
        'display message boxes if neccessary

        If txtPassword.Text.IndexOf(" ") > -1 Then
            MessageBox.Show(m_ResourceManager.GetString("Password_may_not_contain_spaces"))
            Return False
        End If

        If txtPassword.Text.Length < 3 Then
            MessageBox.Show(m_ResourceManager.GetString("Password_must_be_between"))
            Return False
        End If

        If txtPassword.Text <> txtConfirmPassword.Text Then
            MessageBox.Show(m_ResourceManager.GetString("Password_fields_do_not_match"))
            Return False
        End If

        txtUserFullName.Text = txtUserFullName.Text.Trim() 'remove white space from ends
        If txtUserFullName.Text.Length < 3 Then
            MessageBox.Show(m_ResourceManager.GetString("Full_name_must_be_between"))
            Return False
        End If

        Dim r As New Regex("\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase)
        If Not r.IsMatch(txtUserEmail.Text) Then
            MessageBox.Show(m_ResourceManager.GetString("Email_address_is_not_valid"))
            Return False
        End If

        Return True
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -