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

📄 edittaskform.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.Threading

Public Class EditTaskForm
    Inherits System.Windows.Forms.Form


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

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

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

    Public Sub New(ByVal dl As DataLayer, ByVal e As Common.TaskEventArgs, ByVal historyIndex 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_TaskRow = e.Task

        'show the individual history item
        TabControl1.SelectedIndex = c_HistoryTabIndex
        lvHistory.Items(historyIndex).Selected = True
    End Sub

    Private m_DataLayer As DataLayer
    Private m_TaskRow As Business.Task
    Private m_ImageList As New ImageList()
    Private m_TextList As New ArrayList()
    Private m_ProgressList As ArrayList
    Private Const c_HistoryTabIndex As Integer = 1
    Private Const c_PriorityImagesPath As String = "Images\"
    Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())

    Private Sub TaskForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'bind the dropdowns to their respective datatables
        cbStatus.DataSource = m_DataLayer.States
        cbStatus.DisplayMember = Database.Columns.State.Text
        cbStatus.ValueMember = Database.Columns.State.StateID

        cbPriority.DataSource = m_DataLayer.Priorities
        cbPriority.DisplayMember = Database.Columns.Priority.Text
        cbPriority.ValueMember = Database.Columns.Priority.PriorityID

        cbAssignedTo.DataSource = m_DataLayer.Users
        cbAssignedTo.DisplayMember = Database.Columns.User.Name
        cbAssignedTo.ValueMember = Database.Columns.User.UserID

        m_ProgressList = TaskProgress.GetValues()
        cbProgress.DataSource = m_ProgressList
        cbProgress.DisplayMember = "Text"
        cbProgress.ValueMember = "Value"

        'grab the priority images
        Try
            m_ImageList.Images.Add(My.Resources.Major)
            m_ImageList.Images.Add(My.Resources.Medium)
            m_ImageList.Images.Add(My.Resources.Minor)
            m_TextList.Add("Major")
            m_TextList.Add("Medium")
            m_TextList.Add("Minor")

        Catch
            MessageBox.Show(m_ResourceManager.GetString("gif_was_not_found"), m_ResourceManager.GetString("File_Not_Found"))
            LogError.Write(m_ResourceManager.GetString("gif_was_not_found"))
            Me.Close()
            Return
        End Try

        'fill the text boxes with the task data
        lblTaskNumber.Text = m_TaskRow.TaskID.ToString
        lblChangedBy.Text = m_TaskRow.User.Name
        'globalize for german
        If Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName = "de" Then
            lblChangedOn.Text = String.Format("{0:d}", Convert.ToDateTime(m_TaskRow.DateCreated.ToString("dd/MM/yy")))
        Else
            lblChangedOn.Text = String.Format("{0:d}", m_TaskRow.DateCreated)
        End If
        txtSummary.Text = m_TaskRow.Summary
        txtDescription.Text = m_TaskRow.Description
        cbStatus.SelectedValue = m_TaskRow.StateID
        cbProgress.SelectedValue = m_TaskRow.Progress
        cbAssignedTo.SelectedValue = m_TaskRow.AssignedID
        cbPriority.SelectedValue = m_TaskRow.PriorityID
        dtDueDate.Value = m_TaskRow.DateDue

        'enable the update button if data is changed by the user
        AddHandler txtSummary.TextChanged, AddressOf EnableUpdate
        AddHandler txtDescription.TextChanged, AddressOf EnableUpdate
        AddHandler cbPriority.SelectedValueChanged, AddressOf EnableUpdate
        AddHandler cbProgress.SelectedValueChanged, AddressOf EnableUpdate
        AddHandler cbAssignedTo.SelectedValueChanged, AddressOf EnableUpdate
        AddHandler cbStatus.SelectedValueChanged, AddressOf EnableUpdate
        AddHandler dtDueDate.ValueChanged, AddressOf EnableUpdate
    End Sub

    Private Sub EnableUpdate(ByVal sender As Object, ByVal e As System.EventArgs)
        btnOK.Enabled = True
    End Sub

    Private Function SaveTask() As Boolean
        If txtSummary.Text.Trim().Length > 0 Then

            'copy the information from the form fields back to the DataRow
            With m_TaskRow
                .Summary = txtSummary.Text.Trim()
                .Description = txtDescription.Text.Trim()
                .PriorityID = cbPriority.SelectedValue
                .StateID = cbStatus.SelectedValue
                .AssignedID = cbAssignedTo.SelectedValue
                .UserID = m_DataLayer.CurrentUser.UserID
                .Progress = cbProgress.SelectedValue
                .IsDeleted = False
                .DateDue = dtDueDate.Value
                .DateModified = DateTime.Now
                .DateCreated = DateTime.Now
            End With

            Dim facade As New Database.TaskFacade
            facade.UpdateTask(m_TaskRow)

            Return True
        Else
            MessageBox.Show("Please enter a Summary for this change.")
            txtSummary.Focus()
            Return False
        End If
    End Function

    Private Sub cbPriority_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cbPriority.DrawItem
        e.DrawBackground()
        e.DrawFocusRectangle()
        e.Graphics.DrawImage(m_ImageList.Images(e.Index), New Point(e.Bounds.X, e.Bounds.Y))
        e.Graphics.DrawString(CType(m_TextList(e.Index), String), e.Font, New SolidBrush(Color.Black), _
        m_ImageList.Images(e.Index).Width + 4, e.Bounds.Top + 1)
    End Sub


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If SaveTask() Then
            Me.Close()
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.None
        End If
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        'if the history tab is selected
        If TabControl1.SelectedIndex = c_HistoryTabIndex Then

            'clear the fields
            lvHistory.Items.Clear()
            txtHistorySummary.Text = String.Empty
            txtHistoryDescription.Text = String.Empty
            txtHistoryStatus.Text = String.Empty
            txtHistoryProgress.Text = String.Empty
            txtHistoryPriority.Text = String.Empty
            txtHistoryDueDate.Text = String.Empty

            Dim project As Business.Project = m_TaskRow.Project
            Dim lvItem As ListViewItem

            For Each item As Business.Task In project.Tasks
                Dim AssignedUser As Business.User = m_DataLayer.GetAssignment(item.AssignedID).User
                lvItem = New ListViewItem(New String() {(CType(item.DateModified, DateTime).ToShortDateString()), item.User.Name, AssignedUser.Name})
                lvHistory.Items.Add(lvItem)
            Next
        End If
    End Sub

    Private Sub lvHistory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvHistory.SelectedIndexChanged
        If lvHistory.SelectedItems.Count > 0 Then
            Dim TaskID As Integer = lvHistory.SelectedIndices.Item(0)
            Dim SelectedItem As Business.Task
            Dim facade As New Database.TaskFacade

            SelectedItem = facade.GetTask(TaskID)
            If SelectedItem Is Nothing Then Exit Sub

            txtHistorySummary.Text = SelectedItem.Summary
            txtHistoryDescription.Text = SelectedItem.Description
            txtHistoryStatus.Text = SelectedItem.State.Text
            txtHistoryProgress.Text = SelectedItem.Progress & "%"
            txtHistoryPriority.Text = SelectedItem.Priority.Text
            txtHistoryDueDate.Text = String.Format("{0:d}", SelectedItem.DateDue)
        End If
    End Sub

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

    Private Sub txtDescription_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDescription.Enter
        Me.AcceptButton = Nothing
    End Sub

    Private Sub txtDescription_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDescription.Leave
        Me.AcceptButton = Me.btnOK
    End Sub
End Class



⌨️ 快捷键说明

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