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

📄 taskhistorypanel.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.ComponentModel

'<DefaultEvent("ClickItem")> _
Public Class TaskHistoryPanel
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

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

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

    Private m_DataView As DataView = Nothing
    Private m_TaskIDMember As String = String.Empty
    Private m_OptionalDateMember As String = String.Empty
    Private m_DisplayMember As String = String.Empty
    Private m_SelectedTaskID As Integer = -1 'magic number for nothing
    Private m_MaxListItems As Integer = 0

    Private Const c_LinkLabelStartingX As Integer = 5
    Private Const c_LinkLabelStartingY As Integer = 5
    Private Const c_LinkLabelHeight As Integer = 16

    Delegate Sub HistoryLinkClickedHandler(ByVal taskID As Integer, ByVal index As Integer)
    Public Event HistoryLinkClicked As HistoryLinkClickedHandler
    Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())

    <Browsable(False), Description("DataView used for data binding.")> _
    Public WriteOnly Property DataSource() As DataView
        Set(ByVal Value As DataView)
            If Value Is Nothing Then
                m_DataView = Nothing
            Else
                m_DataView = Value
            End If
        End Set
    End Property

    <Browsable(False), _
    Description("Column name of date last modified.")> _
    Public WriteOnly Property OptionalDateMember() As String
        Set(ByVal Value As String)
            m_OptionalDateMember = Value
        End Set
    End Property

    <Browsable(False), _
    Description("Column name of ID key.")> _
    Public WriteOnly Property TaskIDMember() As String
        Set(ByVal Value As String)
            m_TaskIDMember = Value
        End Set
    End Property

    <Browsable(False), _
    Description("Column name to display as text.")> _
    Public WriteOnly Property DisplayMember() As String
        Set(ByVal Value As String)
            m_DisplayMember = Value
        End Set
    End Property

    <Browsable(False), _
    Description("Selected ID key.")> _
    Public Property SelectedTaskID() As Integer
        Set(ByVal Value As Integer)
            m_SelectedTaskID = Value
            DataBind()
        End Set
        Get
            Return m_SelectedTaskID
        End Get
    End Property

    <Browsable(False), _
    Description("Maximum items to list.")> _
    Public WriteOnly Property MaxListItems() As Integer
        Set(ByVal Value As Integer)
            m_MaxListItems = Value
        End Set
    End Property

    Private Sub DataBind()
        'clear all controls
        Me.Controls.Clear()

        'if data binding is not setup, create a label and return
        If m_DataView Is Nothing Or m_TaskIDMember = String.Empty Or m_SelectedTaskID = -1 Or m_MaxListItems = 0 Then
            Dim newLabel As New Label()
            newLabel.Text = m_ResourceManager.GetString("history_unavailable")
            newLabel.Location = New System.Drawing.Point(c_LinkLabelStartingX, c_LinkLabelStartingY)
            newLabel.Size = New System.Drawing.Size((Me.Width - (c_LinkLabelStartingX * 2)), c_LinkLabelHeight)
            newLabel.Name = "Label"
            newLabel.TabIndex = 0
            newLabel.TabStop = True
            newLabel.FlatStyle = FlatStyle.System

            'add the label
            Me.Controls.Add(newLabel)
        Else
            'we have a dataview, member value, task id, and are allow to display more than 0 items
            Dim numLinks As Integer = 0
            Dim row As DataRowView
            For Each row In m_DataView
                If CType(row.Item(m_TaskIDMember), Integer) = m_SelectedTaskID Then
                    Dim datePrefix As String = String.Empty

                    If m_OptionalDateMember <> String.Empty Then
                        Dim dateModified As DateTime = CType(row.Item(m_OptionalDateMember), DateTime)
                        'globalize for german
                        If Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName = "de" Then
                            datePrefix = dateModified.ToString("dd/MM ")
                        Else
                            datePrefix = dateModified.ToString("MM/dd b\y ")
                        End If

                    End If

                    'create a linklabel
                    Dim newLinkLabel As New LinkLabel()
                    newLinkLabel.Text = datePrefix & CType(row.Item(m_DisplayMember), String)
                    newLinkLabel.Location = New System.Drawing.Point(c_LinkLabelStartingX, (c_LinkLabelStartingY + (numLinks * c_LinkLabelHeight)))
                    newLinkLabel.Size = New System.Drawing.Size((Me.Width - (c_LinkLabelStartingX * 2)), c_LinkLabelHeight)
                    newLinkLabel.Name = "LinkLabel" & numLinks
                    newLinkLabel.Tag = (numLinks)
                    newLinkLabel.TabStop = True
                    newLinkLabel.FlatStyle = FlatStyle.System

                    'add the link label
                    Me.Controls.Add(newLinkLabel)
                    AddHandler newLinkLabel.Click, AddressOf LinkLabel_Click

                    'increment the number of matching links
                    numLinks += 1
                End If

                'if we hit the max items
                If numLinks = m_MaxListItems Then
                    Exit For
                End If
            Next

            'if we didn't have any matching history items
            If (numLinks = 0) Then
                'create a label
                Dim newLabel As New Label()
                newLabel.Text = m_ResourceManager.GetString("no_history")
                newLabel.Location = New System.Drawing.Point(c_LinkLabelStartingX, c_LinkLabelStartingY)
                newLabel.Size = New System.Drawing.Size((Me.Width - (c_LinkLabelStartingX * 2)), c_LinkLabelHeight)
                newLabel.Name = "Label"
                newLabel.TabIndex = 0
                newLabel.TabStop = True
                newLabel.FlatStyle = FlatStyle.System

                'add the label
                Me.Controls.Add(newLabel)
            End If
        End If
    End Sub

    Private Sub LinkLabel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        're-raise the click event with our own parameter
        Dim link As LinkLabel = CType(sender, LinkLabel)
        RaiseEvent HistoryLinkClicked(m_SelectedTaskID, CType(link.Tag, Integer))
    End Sub
End Class

⌨️ 快捷键说明

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