📄 mainform.vb
字号:
DataGridViewTasks1_CurrentCellChanged(Nothing, Nothing)
Catch
End Try
End Sub
'tries to find the id of the currently selected datagrid row
Private Function GetSelectedTaskID() As Integer
'if our datagrid isn't ready to then return -1
If DataGridViewTasks1.DataSource Is Nothing Then Return -1
'this code will find the id column in the style and together with the current row index
'will return the taskid currently selected.
Try
Dim taskIDColumnIndex As Integer = DataGridViewTasks1.Columns("TaskID").Index
Dim currentRow As Integer = DataGridViewTasks1.CurrentRow.Index
Return CType(DataGridViewTasks1.Item(taskIDColumnIndex, currentRow).Value, Integer)
Catch ex As Exception
Return -1
End Try
End Function
'trys to display the selected task in the task form
Private Sub ShowTaskFormFromDataGrid()
If dsTasks.Tables(0).DefaultView.Count = 0 Then Return
Try
Dim dr As DataRow = dsTasks.Tables(0).Rows.Find(GetSelectedTaskID())
Dim task As New Business.Task
PrepareTask(dr, task)
Dim eForm As New EditTaskForm(m_DataLayer, New Common.TaskEventArgs(task))
tmrGetTasks.Stop()
Dim eFormResult As System.Windows.Forms.DialogResult = eForm.ShowDialog()
Me.Refresh()
If eFormResult <> System.Windows.Forms.DialogResult.Cancel Then UpdateTasks()
tmrGetTasks.Start()
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Sub
'sets a new row filter for the tasks table
Private Sub ResetViewFilter()
Select Case m_SelectedFilter
Case TaskFilterValue.AllTasks
dsTasks.Tables(0).DefaultView.RowFilter = m_ResourceManager.GetString("ProjectID") & m_ProjectID & " and IsDeleted = 0"
Case TaskFilterValue.OpenTasks
'StateID = 1 maps to the database lookup table and means 'open'
dsTasks.Tables(0).DefaultView.RowFilter = m_ResourceManager.GetString("ProjectID") & m_ProjectID & " and IsDeleted = 0 and StateID = 1"
Case TaskFilterValue.MyTasks
dsTasks.Tables(0).DefaultView.RowFilter = m_ResourceManager.GetString("ProjectID") & m_ProjectID & " and IsDeleted = 0 and AssignedTo = " & m_DataLayer.CurrentUser.UserID
End Select
UpdateStatusBarText()
End Sub
Private Sub UpdateStatusBarText()
Try
ToolStripStatusLabel1.Text = dsTasks.Tables(0).DefaultView.Count.ToString() & m_ResourceManager.GetString("sbrPanelLeftText")
Catch ex As Exception
End Try
End Sub
Private Sub LockControls(ByVal Value As Boolean)
m_ControlsLocked = Value
If m_ControlsLocked Then
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
Else
Me.Cursor = Cursors.Arrow
Application.DoEvents()
End If
End Sub
'adjusts the ui to reflect online status
Private Sub ChangeOnlineStatus(ByVal newState As Boolean)
m_IsOnline = newState
If m_IsOnline Then
ChangePasswordToolStripMenuItem.Enabled = True
If m_DataLayer.CurrentUser.IsAdministrator Then
ManageToolStripMenuItem.Visible = True
Else
ManageToolStripMenuItem.Visible = False
End If
ManageToolStripMenuItem.Enabled = True
ToolStripButton2.Text = m_ResourceManager.GetString("TopButtonsOfflineText")
ToolStripButton2.ToolTipText = m_ResourceManager.GetString("TopButtonsOfflineToolTipText")
ToolStripButton2.Image = My.Resources.ToolWorkOffline.ToBitmap()
ToolStripStatusLabelImage.Image = My.Resources.StatusConnected.ToBitmap()
ToolStripStatusLabel2.Text = m_ResourceManager.GetString("sbrPanelRightOnlineText")
trayIcon.Icon = My.Resources.TrayOnline
Else
ChangePasswordToolStripMenuItem.Enabled = False
ManageToolStripMenuItem.Visible = False
ToolStripButton2.Text = m_ResourceManager.GetString("TopButtonsOnlineText")
ToolStripButton2.ToolTipText = m_ResourceManager.GetString("TopButtonsOnlineToolTipText")
ToolStripButton2.Image = My.Resources.ToolWorkOnline.ToBitmap()
ToolStripStatusLabelImage.Image = My.Resources.StatusDisconnected.ToBitmap()
ToolStripStatusLabel2.Text = m_ResourceManager.GetString("sbrPanelRightOfflineText")
trayIcon.Icon = My.Resources.TrayOffline
End If
End Sub
Private Sub SwitchOnlineMode()
If m_IsOnline Then
Dim oForm As New OfflineSelectionForm(m_DataLayer, m_ProjectID)
Dim oFormResult As System.Windows.Forms.DialogResult = oForm.ShowDialog()
If oFormResult <> System.Windows.Forms.DialogResult.Cancel Then
'try to write datasets
Try
dsProjects.WriteXml(m_MyDocumentsPath & c_OfflineProjectsFile, XmlWriteMode.WriteSchema)
dsTasks.WriteXml(m_MyDocumentsPath & c_OfflineTasksFile, XmlWriteMode.WriteSchema)
'make sure there isn't a change file.
Try
File.Delete(m_MyDocumentsPath & c_OfflineTaskChangesFile)
Catch
End Try
ChangeOnlineStatus(False)
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
MessageBox.Show(m_ResourceManager.GetString("MessageBoxShow_Unable_to_write_files"))
GetProjects()
End Try
End If
Else
'try to go online
'if the user did not cancel login
If DisplayLoginForm() <> System.Windows.Forms.DialogResult.Cancel Then
ChangeOnlineStatus(True)
'get a new list of projects
LockControls(True)
GetProjects()
LockControls(False)
'verify the current projectid or try to get the first project
If dsProjects.Tables(0).Rows.Count > 0 Then
'verify the current project id, otherwise choose the first project
If dsProjects.Tables(0).Rows.Find(m_ProjectID) Is Nothing Then
m_ProjectID = CType(dsProjects.Tables(0).Rows(0)("ProjectID"), Integer)
End If
Else
'no projects exist
m_ProjectID = -1
End If
cbProjects.SelectedValue = m_ProjectID
'update or get the latest tasks
If dsTasks.HasChanges() Then
'loop through the rows and update the userid now that we are logged on
Dim dr As DataRow
For Each dr In dsTasks.Tables(0).Rows
If CType(dr.Item("ModifiedBy"), Integer) = -1 Then dr.Item("ModifiedBy") = m_DataLayer.CurrentUser.UserID
Next
UpdateTasks()
Else
GetTasks(m_ProjectID, True)
End If
DeleteOfflineFiles()
End If
End If
End Sub
Private Sub LoadSettings()
Try
' My.Settings replaces the use of the registry
m_ProjectID = My.Settings.ProjectID
MyBase.WindowState = My.Settings.WindowState
MyBase.Height = My.Settings.Height
MyBase.Width = My.Settings.Width
If My.Settings.xpProject Then
xpProject.Expand()
Else
xpProject.Collapse()
End If
If My.Settings.xpPriority Then
xpPriority.Expand()
Else
xpPriority.Collapse()
End If
If My.Settings.xpProgress Then
xpProgress.Expand()
Else
xpProgress.Collapse()
End If
If My.Settings.xpHistory Then
xpHistory.Expand()
Else
xpHistory.Collapse()
End If
If My.Settings.preview Then
PreviewPaneToolStripMenuItem.Checked = True
SplitContainer2.Panel2Collapsed = False
Else
PreviewPaneToolStripMenuItem.Checked = False
SplitContainer2.Panel2Collapsed = True
End If
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Sub
Private Sub SaveSettings()
Try
My.Settings.ProjectID = m_ProjectID
My.Settings.xpProject = xpProject.IsExpanded
My.Settings.xpPriority = xpPriority.IsExpanded
My.Settings.xpProgress = xpProgress.IsExpanded
My.Settings.xpHistory = xpHistory.IsExpanded
My.Settings.preview = PreviewPaneToolStripMenuItem.Checked
If MyBase.WindowState <> FormWindowState.Minimized Then
Dim height = MyBase.Height
Dim width = MyBase.Width
My.Settings.WindowState = MyBase.WindowState
My.Settings.Height = height
My.Settings.Width = width
End If
My.Settings.Save()
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Sub
'trys to delete each offline file
Private Sub DeleteOfflineFiles()
Try
File.Delete(m_MyDocumentsPath & c_OfflineProjectsFile)
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
Try
File.Delete(m_MyDocumentsPath & c_OfflineTasksFile)
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
Try
File.Delete(m_MyDocumentsPath & c_OfflineLookUpTablesFile)
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
Try
File.Delete(m_MyDocumentsPath & c_OfflineTaskChangesFile)
Catch ex As Exception
LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Sub
#End Region
Private Sub AnsichtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnsichtToolStripMenuItem.Click
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -