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

📄 manageusersform.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.
'---------------------------------------------------------------------

Public Class ManageUsersForm
    Inherits System.Windows.Forms.Form


    Public Sub New(ByVal dl As DataLayer)
        MyBase.New()

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

        'Add any initialization after the InitializeComponent() call
        m_DataLayer = dl
    End Sub

    Private m_DataLayer As DataLayer

#Region " Private Classes "
    'this is the object we use for the ListBox
    Private Class UserFullNameAndID

        Private m_UserID As Integer
        Private m_UserFullName As String

        Public Sub New(ByVal uID As Integer, ByVal uFullName As String)
            m_UserID = uID
            m_UserFullName = uFullName
        End Sub

        Public Property UserID() As Integer
            Get
                Return m_UserID
            End Get
            Set(ByVal Value As Integer)
                m_UserID = Value
            End Set
        End Property

        Public Property UserFullName() As String
            Get
                Return m_UserFullName
            End Get
            Set(ByVal Value As String)
                m_UserFullName = Value
            End Set
        End Property
    End Class
#End Region

    Private Sub ManageUsersForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PopulateListBox()
    End Sub

    Private Sub PopulateListBox()
        If Not m_DataLayer.Users Is Nothing Then
            lbUsers.Items.Clear()
            lbUsers.DisplayMember = "UserFullName"

            Dim user As Business.User
            For Each user In m_DataLayer.Users
                lbUsers.Items.Add(New UserFullNameAndID(user.UserID, user.Name))
            Next
        End If
    End Sub

    Private Sub lbUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbUsers.SelectedIndexChanged
        If Not lbUsers.SelectedItem Is Nothing Then
            btnEdit.Enabled = True
        End If
    End Sub

    Private Sub lbUsers_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUsers.DoubleClick
        DisplayEditForm()
    End Sub

    Private Sub DisplayEditForm()
        If Not lbUsers.SelectedItem Is Nothing Then
            Dim SelectedItem As UserFullNameAndID = CType(lbUsers.SelectedItem, UserFullNameAndID)
            Dim userRow As Business.User = FindUser(SelectedItem.UserFullName, SelectedItem.UserID)
            If userRow Is Nothing Then Exit Sub

            Dim eForm As New EditUserForm(m_DataLayer, New Common.UserEventArgs(userRow))
            Dim eFormResult As System.Windows.Forms.DialogResult = eForm.ShowDialog()
            If eFormResult = System.Windows.Forms.DialogResult.OK Then
                PopulateListBox()
            End If
        End If
    End Sub

    Private Function FindUser(ByVal UserName As String, ByVal UserID As Integer) As Business.User
        For Each user As Business.User In m_DataLayer.Users
            If user.Name.ToLower = UserName AndAlso user.UserID = UserID Then
                Return user
            End If
        Next

        Return Nothing
    End Function

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim aForm As New AddUserForm(m_DataLayer)
        Dim aFormResult As System.Windows.Forms.DialogResult = aForm.ShowDialog()

        If aFormResult = System.Windows.Forms.DialogResult.OK Then
            PopulateListBox()
        End If
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        DisplayEditForm()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class

⌨️ 快捷键说明

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