📄 offlineselectionform.vb
字号:
Me.AutoScrollMinSize = CType(resources.GetObject("$this.AutoScrollMinSize"), System.Drawing.Size)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.CancelButton = Me.btnCancel
Me.ClientSize = CType(resources.GetObject("$this.ClientSize"), System.Drawing.Size)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblHeader, Me.btnOK, Me.btnCancel, Me.clbProjects})
Me.Dock = CType(resources.GetObject("$this.Dock"), System.Windows.Forms.DockStyle)
Me.Enabled = CType(resources.GetObject("$this.Enabled"), Boolean)
Me.Font = CType(resources.GetObject("$this.Font"), System.Drawing.Font)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.ImeMode = CType(resources.GetObject("$this.ImeMode"), System.Windows.Forms.ImeMode)
Me.Location = CType(resources.GetObject("$this.Location"), System.Drawing.Point)
Me.MaximizeBox = False
Me.MaximumSize = CType(resources.GetObject("$this.MaximumSize"), System.Drawing.Size)
Me.MinimumSize = CType(resources.GetObject("$this.MinimumSize"), System.Drawing.Size)
Me.Name = "OfflineSelectionForm"
Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"), System.Windows.Forms.RightToLeft)
Me.ShowInTaskbar = False
Me.StartPosition = CType(resources.GetObject("$this.StartPosition"), System.Windows.Forms.FormStartPosition)
Me.Text = resources.GetString("$this.Text")
Me.Visible = CType(resources.GetObject("$this.Visible"), Boolean)
Me.ResumeLayout(False)
End Sub
#End Region
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 dr As DataRow
For Each dr In m_DataLayer.DsProjects.Projects.Rows
If CType(dr.Item("ProjectID"), Integer) = m_ProjectID Then
clbProjects.Items.Add(New ProjectNameAndID(CType(dr.Item("ProjectName"), String), CType(dr.Item("ProjectID"), Integer)), True)
Else
clbProjects.Items.Add(New ProjectNameAndID(CType(dr.Item("ProjectName"), String), CType(dr.Item("ProjectID"), Integer)), 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) Handles btnOK.Click
If clbProjects.CheckedItems.Count > 0 Then
Dim firstTime As Boolean = True
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
m_DataLayer.GetTasks(CType(clbProjects.Items.Item(i), ProjectNameAndID).ID, True)
Else
'leave the current data in place
m_DataLayer.GetTasks(CType(clbProjects.Items.Item(i), ProjectNameAndID).ID, False)
End If
Else
'this item is not checked, remove it from the project dataset
Dim dr As DataRow
For Each dr In m_DataLayer.DsProjects.Projects.Rows
If Convert.ToInt32(dr.Item("ProjectID")) = CType(clbProjects.Items.Item(i), ProjectNameAndID).ID Then
dr.Delete()
End If
Next
m_DataLayer.DsProjects.Projects.AcceptChanges()
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 + -