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

📄 offlineselectionform.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 OfflineSelectionForm
    Inherits System.Windows.Forms.Form


    Public Sub New(ByVal dl As DataLayer, ByVal projectID As Integer)
        MyBase.New()

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

        'Add any initialization after the InitializeComponent() call
        m_DataLayer = dl
        m_ProjectID = projectID
        AddHandler btnOK.Click, AddressOf btnOK_Click
    End Sub

    Private m_DataLayer As DataLayer
    Private m_ProjectID As Integer
    Private Const c_AllProjects As String = "(All)"

#Region " Private Classes "
    'this is the object class we use as items in the CheckedListBox 
    Private Class ProjectNameAndID
        Private m_Name As String
        Private m_ID As Integer

        Public Sub New(ByVal projectName As String, ByVal projectID As Integer)
            m_Name = projectName
            m_ID = projectID
        End Sub

        Public Property Name() As String
            Get
                Return m_Name
            End Get
            Set(ByVal Value As String)
                m_Name = Value
            End Set
        End Property

        Public Property ID() As Integer
            Get
                Return m_ID
            End Get
            Set(ByVal Value As Integer)
                m_ID = Value
            End Set
        End Property
    End Class
#End Region

    Private Sub OfflineSelectionForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        clbProjects.DisplayMember = "Name"
        clbProjects.Items.Add(New ProjectNameAndID(c_AllProjects, -1), False)

        Dim item As Business.Project
        For Each item In m_DataLayer.Projects
            If item.ProjectID = m_ProjectID Then
                clbProjects.Items.Add(New ProjectNameAndID(item.Name, item.ProjectID), True)
            Else
                clbProjects.Items.Add(New ProjectNameAndID(item.Name, item.ProjectID), False)
            End If
        Next
    End Sub

    'this event handler creates some custom behavior,
    'when "(All)" is clicked all other items are unchecked,
    'and when an item is checked that "(All)" is unchecked
    Private Sub clbProjects_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clbProjects.ItemCheck
        'if all is checked true
        If e.Index = 0 AndAlso e.NewValue = CheckState.Checked Then
            'uncheck the others (which will cause this to run again)
            Dim item As Integer
            For Each item In clbProjects.CheckedIndices
                If item <> 0 Then
                    clbProjects.SetItemCheckState(item, CheckState.Unchecked)
                End If
            Next
            'now enable the ok button
            btnOK.Enabled = True
        ElseIf e.Index <> 0 AndAlso e.NewValue = CheckState.Checked Then
            'something other than "(All)" is checked true
            'set "(All)" to unchecked
            clbProjects.SetItemCheckState(0, CheckState.Unchecked)
            btnOK.Enabled = True
        Else
            'any item is checked false
            'Note: this event occurs before the clbProjects.CheckedItems.Count
            'property is updated so we check for 1 instead of 0
            If clbProjects.CheckedItems.Count = 1 Then
                btnOK.Enabled = False
            End If
        End If
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If clbProjects.CheckedItems.Count > 0 Then

            Dim firstTime As Boolean = True
            Dim facade As New Database.ProjectFacade
            Dim i As Integer

            '"(All)" is not a real project, so start with 1 and skip item 0
            For i = 1 To (clbProjects.Items.Count - 1)

                'this item is checked, or all is checked
                'then we want to fetch the data
                If CType(clbProjects.GetItemCheckState(i), Boolean) Or CType(clbProjects.GetItemCheckState(0), Boolean) Then

                    'if this is the first fetch, then clear the current data
                    If firstTime Then
                        firstTime = False
                    Else
                        ' leave the current data in place
                        Dim ProjectID As Integer = CType(clbProjects.Items.Item(i), ProjectNameAndID).ID
                        Dim project As Business.Project = facade.GetProject(ProjectID)

                        project.IsDeleted = True
                        facade.UpdateProject(project)
                    End If
                End If
            Next
        End If
        Me.Close()
    End Sub

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

⌨️ 快捷键说明

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