📄 frmtimetracker.vb
字号:
' -----------------------------------------------------------------------------
' Code from _Programming the .NET Compact Framework with VB_
' and _Programming the .NET Compact Framework with C#_
' (c) Copyright 2002-2004 Paul Yao and David Durant.
' All rights reserved.
' -----------------------------------------------------------------------------
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Collections
Public Class frmTimeTracker
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
#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
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'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.
Friend WithEvents lblProjName As System.Windows.Forms.Label
Friend WithEvents txtTaskEnd As System.Windows.Forms.TextBox
Friend WithEvents txtTaskStart As System.Windows.Forms.TextBox
Friend WithEvents lblProjStart As System.Windows.Forms.Label
Friend WithEvents lblProjEnd As System.Windows.Forms.Label
Friend WithEvents cboxTasks As System.Windows.Forms.ComboBox
Friend WithEvents txtTaskNo As System.Windows.Forms.TextBox
Friend WithEvents txtTaskName As System.Windows.Forms.TextBox
Friend WithEvents txtTaskEstimated As System.Windows.Forms.TextBox
Friend WithEvents txtTaskActual As System.Windows.Forms.TextBox
Friend WithEvents btnNewTask As System.Windows.Forms.Button
Friend WithEvents btnAddTask As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.lblProjStart = New System.Windows.Forms.Label
Me.btnNewTask = New System.Windows.Forms.Button
Me.lblProjName = New System.Windows.Forms.Label
Me.lblProjEnd = New System.Windows.Forms.Label
Me.txtTaskNo = New System.Windows.Forms.TextBox
Me.txtTaskEnd = New System.Windows.Forms.TextBox
Me.txtTaskStart = New System.Windows.Forms.TextBox
Me.txtTaskName = New System.Windows.Forms.TextBox
Me.txtTaskEstimated = New System.Windows.Forms.TextBox
Me.txtTaskActual = New System.Windows.Forms.TextBox
Me.cboxTasks = New System.Windows.Forms.ComboBox
Me.btnAddTask = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
'
'lblProjStart
'
Me.lblProjStart.Location = New System.Drawing.Point(144, 16)
Me.lblProjStart.Size = New System.Drawing.Size(40, 20)
'
'btnNewTask
'
Me.btnNewTask.Location = New System.Drawing.Point(80, 240)
Me.btnNewTask.Text = "New &Task"
'
'lblProjName
'
Me.lblProjName.Location = New System.Drawing.Point(16, 16)
Me.lblProjName.Size = New System.Drawing.Size(120, 20)
'
'lblProjEnd
'
Me.lblProjEnd.Location = New System.Drawing.Point(192, 16)
Me.lblProjEnd.Size = New System.Drawing.Size(40, 20)
'
'txtTaskNo
'
Me.txtTaskNo.Location = New System.Drawing.Point(8, 136)
Me.txtTaskNo.Size = New System.Drawing.Size(40, 22)
Me.txtTaskNo.Text = ""
'
'txtTaskEnd
'
Me.txtTaskEnd.Location = New System.Drawing.Point(168, 136)
Me.txtTaskEnd.Size = New System.Drawing.Size(64, 22)
Me.txtTaskEnd.Text = ""
'
'txtTaskStart
'
Me.txtTaskStart.Location = New System.Drawing.Point(96, 136)
Me.txtTaskStart.Size = New System.Drawing.Size(64, 22)
Me.txtTaskStart.Text = ""
'
'txtTaskName
'
Me.txtTaskName.Location = New System.Drawing.Point(8, 168)
Me.txtTaskName.Size = New System.Drawing.Size(144, 22)
Me.txtTaskName.Text = ""
'
'txtTaskEstimated
'
Me.txtTaskEstimated.Location = New System.Drawing.Point(160, 168)
Me.txtTaskEstimated.Size = New System.Drawing.Size(32, 22)
Me.txtTaskEstimated.Text = ""
'
'txtTaskActual
'
Me.txtTaskActual.Location = New System.Drawing.Point(200, 168)
Me.txtTaskActual.Size = New System.Drawing.Size(32, 22)
Me.txtTaskActual.Text = ""
'
'cboxTasks
'
Me.cboxTasks.Location = New System.Drawing.Point(8, 200)
Me.cboxTasks.Size = New System.Drawing.Size(224, 22)
'
'btnAddTask
'
Me.btnAddTask.Location = New System.Drawing.Point(0, 240)
Me.btnAddTask.Text = "Add &Task"
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(160, 240)
Me.btnCancel.Text = "&Cancel"
'
'frmTimeTracker
'
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnAddTask)
Me.Controls.Add(Me.cboxTasks)
Me.Controls.Add(Me.txtTaskActual)
Me.Controls.Add(Me.txtTaskEstimated)
Me.Controls.Add(Me.txtTaskName)
Me.Controls.Add(Me.txtTaskStart)
Me.Controls.Add(Me.txtTaskEnd)
Me.Controls.Add(Me.txtTaskNo)
Me.Controls.Add(Me.lblProjEnd)
Me.Controls.Add(Me.lblProjName)
Me.Controls.Add(Me.btnNewTask)
Me.Controls.Add(Me.lblProjStart)
Me.Menu = Me.MainMenu1
Me.Text = "Time Tracker"
End Sub
#End Region
#Region " Database Structure Simulated "
Private Structure Project
Public strProjNo As String
Public strProjName As String
Public dateProjStart As Date
Public dateProjEnd As Date
Public ctProjTasks As Integer
Public strProjComments As String
Public Sub New(ByVal strNo As String, _
ByVal strName As String, _
ByVal dateStart As Date, _
ByVal dateEnd As Date, _
ByVal ctTasks As Integer, _
ByVal strComments As String)
strProjNo = strNo
strProjName = strName
dateProjStart = dateStart
dateProjEnd = dateEnd
ctProjTasks = ctTasks
strProjComments = strComments
End Sub
End Structure
Private Structure Task
Public strTaskIdent As String
Public strTaskName As String
Public dateTaskStart As Date
Public dateTaskEnd As Date
Public durTaskEstimated As Integer ' In hours
Public durTaskActual As Integer ' In hours
Public strTaskComments As String
Public Sub New(ByVal strNo As String, _
ByVal strName As String, _
ByVal dateStart As Date, _
ByVal dateEnd As Date, _
ByVal durEstimated As Integer, _
ByVal durActual As Integer, _
ByVal strComments As String)
strTaskIdent = strNo
strTaskName = strName
dateTaskStart = dateStart
dateTaskEnd = dateEnd
durTaskEstimated = durEstimated
durTaskActual = durActual
strTaskComments = strComments
End Sub
End Structure
#End Region
Private theProject As Project
Private theTasks As New ArrayList
' A text box that we will create later in the program.
Private txtTaskComments As Windows.Forms.TextBox
' The index number of the previous task. We will
' need to know it in case the users cancels out
' `during task creation.
Private ixTaskPrev As Integer
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles MyBase.Load
' Set the initial state of the controls.
InitControlState()
' Load and display a project.
If LoadProject(42) Then
DisplayProject()
Else
Me.Close()
End If
End Sub
Private Sub lbldateProjEnd_TextChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles lblProjEnd.TextChanged
' If this project is due or
' overdue, use red ink.
'With lblProjEnd
' If CDate(.Text) <= DateTime.Today Then
' .ForeColor = Color.Red
' End If
'End With
' If this project is due or overdue,
' make the background light red.
SetBkColor(lblProjEnd, Color.LightPink)
End Sub
Private Sub txtTaskDates_Validating( _
ByVal sender As System.Object, _
ByVal e As CancelEventArgs _
) _
Handles txtTaskStart.Validating, _
txtTaskEnd.Validating
' If the date entered is not within one year
' of today, make the background light red.
Dim txtSender As TextBox = sender
With txtSender
If CDate(.Text) <= DateTime.Today.AddYears(-1) _
Or CDate(.Text) >= DateTime.Today.AddYears(1) Then
.BackColor = Color.LightPink
End If
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -