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

📄 mainform.vb

📁 使用Access数据库演示的任务分配管理程序 一个使用ADO.NET基于Microsoft Access数据库演示的任务分配管理的程序
💻 VB
📖 第 1 页 / 共 4 页
字号:
                End Try
            End If

            SaveSettings()

            'dispose the tray icon
            If Not trayIcon Is Nothing Then trayIcon.Dispose()
        Catch ex As Exception
            LogError.Write(ex.Message & vbNewLine & ex.StackTrace)
        End Try
    End Sub
#End Region

#Region " DataLayer Helper Methods "
    Private Enum ResultStatus
        Success = 0
        Failure = 1
        Retry = 2
    End Enum

    Private Function CheckResult(ByVal dlResult As DataLayerResult) As ResultStatus
        If dlResult = DataLayerResult.Success Then
            Return ResultStatus.Success
        ElseIf dlResult = DataLayerResult.AuthenticationFailure Then
            If DisplayLoginForm() = System.Windows.Forms.DialogResult.Cancel Then Return ResultStatus.Failure
        ElseIf dlResult = DataLayerResult.ConnectionFailure Then
            '
            Dim mbResult As System.Windows.Forms.DialogResult = MessageBox.Show(m_ResourceManager.GetString("MessageBoxShow_The_remote_server_is_unreachable") & vbNewLine & vbNewLine & m_ResourceManager.GetString("Try_Again"), m_ResourceManager.GetString("Error_Error"), MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
            If mbResult <> System.Windows.Forms.DialogResult.Yes Then Return ResultStatus.Failure
        ElseIf dlResult = DataLayerResult.ServiceFailure Then
            Dim mbResult As System.Windows.Forms.DialogResult = MessageBox.Show(m_ResourceManager.GetString("MessageBoxShow_An_error_has_occurred") & vbNewLine & vbNewLine & m_ResourceManager.GetString("Try_Again"), m_ResourceManager.GetString("Error"), MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
            If mbResult <> System.Windows.Forms.DialogResult.Yes Then Return ResultStatus.Failure
        Else
            Return ResultStatus.Failure
        End If

        Return ResultStatus.Retry
    End Function

    Private Function GetProjects() As Boolean 'Returns TRUE if successful
        Do
            ShowProgressBar(m_ResourceManager.GetString("Retrieving_projects"))
            Dim dlResult As DataLayerResult = DataLayerResult.ServiceFailure

            If m_DataLayer.Projects.Count > 0 Then
                Dim db As New Database.AccessDb
                Dim ds As DataSet = db.GetDataSet("SELECT * FROM Projects")

                dsProjects.Clear()
                dsProjects.Merge(ds)

                dlResult = DataLayerResult.Success
            End If

            HideProgressBar()
            UpdateStatusBarText()

            'process the result
            Select Case CheckResult(dlResult)
                Case ResultStatus.Failure
                    Return False
                Case ResultStatus.Success
                    Return True
            End Select
        Loop
    End Function

    Private Function GetTasks(ByVal projectID As Integer, ByVal clearData As Boolean) As Boolean 'Returns TRUE if successful
        Do
            'discard pending background refreshes
            m_AsyncTasksResult = Nothing
            ShowProgressBar(m_ResourceManager.GetString("Retrieving_tasks"))
            Dim dlResult As DataLayerResult = DataLayerResult.ServiceFailure

            If projectID > 0 Then
                Dim db As New Database.AccessDb
                Dim ds As DataSet = db.GetDataSet("SELECT * FROM Tasks WHERE " + Database.Columns.Task.ProjectIDColumn + "=" + projectID.ToString)

                If clearData Then dsTasks.Clear()
                dsTasks.Merge(ds)

                dlResult = DataLayerResult.Success
            End If

            HideProgressBar()
            UpdateStatusBarText()

            'process the result
            Select Case CheckResult(dlResult)
                Case ResultStatus.Failure
                    Return False
                Case ResultStatus.Success
                    Return True
            End Select
        Loop
    End Function

    Private Sub UpdateTasks()
        If m_IsOnline AndAlso dsTasks.HasChanges Then
            'discard pending background refreshes
            m_AsyncTasksResult = Nothing

            ResetDataGrid(True)
            ShowProgressBar(m_ResourceManager.GetString("Updating_tasks"))

            Dim facade As New Database.TaskFacade
            Dim dlResult As DataLayerResult = DataLayerResult.ServiceFailure
            Dim dr As DataRow

            For Each dr In dsTasks.Tables(0).Rows
                Dim TaskID As Integer = CType(dr("TaskID"), Integer)
                Dim task As Business.Task = facade.GetTask(TaskID)

                If Not task Is Nothing Then
                    PrepareTask(dr, task)

                    facade.UpdateTask(task)
                    dlResult = DataLayerResult.Success
                End If
            Next

            HideProgressBar()
            UpdateStatusBarText()

        End If
    End Sub
#End Region

    Private Sub PrepareTask(ByVal dr As DataRow, ByRef task As Business.Task)
        With task
            .AssignedID = CType(dr("AssignedID"), Integer)
            .DateCreated = CType(dr("DateCreated"), Date)
            .DateDue = CType(dr("DateDue"), Date)
            .DateModified = CType(dr("DateModified"), Date)
            .Description = CType(dr("Description"), String)
            .IsDeleted = CType(dr("IsDeleted"), Boolean)
            .PriorityID = CType(dr("PriorityID"), Integer)
            .Progress = CType(dr("Progress"), String)
            .ProjectID = CType(dr("ProjectID"), Integer)
            .StateID = CType(dr("StateID"), Integer)
            .Summary = CType(dr("Summary"), String)
            .UserID = CType(dr("UserID"), Integer)
        End With
    End Sub

#Region " ComboBox Filters "
    Private Sub cbFilter_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbFilter.SelectedIndexChanged
        If m_ControlsLocked Then Return

        m_SelectedFilter = CType(cbFilter.SelectedItem, TaskFilter).Value
        ResetViewFilter()
        ResetDataGrid(True)
    End Sub
#End Region

#Region " ComboBox Projects "
    Private Sub cbProjects_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProjects.SelectedIndexChanged
        If m_ControlsLocked Then Return

        LockControls(True)

        'only do something if the selected project changes
        Dim selectedProject As Integer = CType(cbProjects.SelectedValue, Integer)
        If selectedProject <> m_ProjectID Then

            If m_IsOnline Then
                hPanel.DataSource = Nothing
                If GetTasks(selectedProject, True) Then
                    m_ProjectID = selectedProject
                    ResetViewFilter()
                    ResetDataGrid(True)
                Else
                    'rollback the combobox
                    cbProjects.SelectedValue = m_ProjectID
                End If
            Else
                'we're offline
                m_ProjectID = selectedProject
                ResetViewFilter()
            End If
        End If

        LockControls(False)
    End Sub
#End Region

#Region " DataGridViewTasks1 "

    Private Sub DataGridViewTasks1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridViewTasks1.CellFormatting
        If DataGridViewTasks1.Columns(e.ColumnIndex).Name = "PriorityText" Then
            DataGridViewTasks1.formatImage(e)
        End If

        If (DataGridViewTasks1.Columns(e.ColumnIndex).Name = "DateDue" _
            Or DataGridViewTasks1.Columns(e.ColumnIndex).Name = "DateModified" _
            Or DataGridViewTasks1.Columns(e.ColumnIndex).Name = "DateCreated") Then
            DataGridViewTasks1.formatDate(e)
        End If

    End Sub

    Private Sub DataGridViewTasks1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewTasks1.CurrentCellChanged
        Dim taskID As Integer = GetSelectedTaskID()

        'update the preview pane
        Dim dr As DataRow = dsTasks.Tables(0).Rows.Find(taskID)
        If dr Is Nothing Then
            lblModifiedByText.Text = String.Empty
            lblAssignedToText.Text = String.Empty
            lblSummaryText.Text = String.Empty
            txtDescriptionText.Text = String.Empty

            HideOverDueLabel()
        Else
            lblModifiedByText.Text = CType(dr.Item("UserID"), String)
            lblAssignedToText.Text = CType(dr.Item("AssignedID"), String)
            lblSummaryText.Text = CType(dr.Item("Summary"), String)
            txtDescriptionText.Text = CType(dr.Item("Description"), String)

            'check the overdue status
            If CType(dr.Item("DateDue"), DateTime).Date < DateTime.Now.Date Then
                ShowOverDueLabel()
            Else
                HideOverDueLabel()
            End If
        End If

        'set the history panel TaskID
        hPanel.SelectedTaskID = taskID
    End Sub

    Private Sub DataGridViewTasks1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewTasks1.DoubleClick
        ShowTaskFormFromDataGrid()
    End Sub

    Private Sub DataGridViewTasks1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridViewTasks1.KeyDown
        If e.KeyCode = Keys.Enter Then
            ShowTaskFormFromDataGrid()
        ElseIf e.KeyCode = Keys.Delete Then
            Dim mbResult As System.Windows.Forms.DialogResult = MessageBox.Show(m_ResourceManager.GetString("Are_you_sure_you_want_to_delete"), m_ResourceManager.GetString("Confirm_Task_Delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
            Me.Refresh()

            If mbResult = System.Windows.Forms.DialogResult.Yes Then
                Dim taskID As Integer = GetSelectedTaskID()
                Dim dr As DataRow = dsTasks.Tables(0).Rows.Find(taskID)

                If Not dr Is Nothing Then dr.Item("IsDeleted") = True
                UpdateTasks()
            End If
        End If
    End Sub

    Private Sub DataGridViewTasks1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridViewTasks1.DragEnter
        If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effect = DragDropEffects.All
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub DataGridViewTasks1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridViewTasks1.DragDrop
        If e.Data.GetDataPresent(DataFormats.Text) Then
            'create a new task with this description text
            CreateNewTask(CStr(e.Data.GetData("Text")))
        End If
    End Sub

#End Region

#Region " MainMenu Items "

    Private Sub NewTaskToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewTaskToolStripMenuItem.Click
        CreateNewTask(Nothing)
    End Sub

    Private Sub ExporttoExcelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExporttoExcelToolStripMenuItem.Click
        Dim sb As New System.Text.StringBuilder
        sb.Append("Function disabled in this version." + Environment.NewLine + Environment.NewLine)
        sb.Append("Requires: " + Environment.NewLine)
        sb.Append("Excel.Interop.dll" + Environment.NewLine)
        sb.Append("Interop.Microsoft.Office.Core.dll" + Environment.NewLine)
        sb.Append("Interop.VBIDE.dll" + Environment.NewLine + Environment.NewLine)
        sb.Append("Download Available:" + Environment.NewLine)
        sb.Append("http://support.microsoft.com/kb/897646/en-us?spid=2529&sid=global ")

⌨️ 快捷键说明

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