📄 addtaskform.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 Common
Public Class AddTaskForm
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
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_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 datatables to their respective dropdowns
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
'add the value from a drag and drop task
If m_TaskRow.Description Is DBNull.Value Then
txtDescription.Text = String.Empty
Else
txtDescription.Text = m_TaskRow.Description
End If
'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
lblHeader.Text = m_ResourceManager.GetString("Add_new_task_to") & " " & m_TaskRow.Project.Name
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
Return True
Else
MessageBox.Show(m_ResourceManager.GetString("Please_enter_a_Summary"))
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 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 + -