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

📄 timesheet.vb

📁 Beginning VB.NET DatabasesAll_Code.rar
💻 VB
📖 第 1 页 / 共 3 页
字号:
        objTimeSheetDV = New DataView(objTimeSheetDS.Tables("TimeSheet"))

        'Initialize a new DataRowView object
        Dim objDataRowView As DataRowView = objTimeSheetDV.AddNew

        'Set the values in the columns
        objDataRowView("ProjectName") = "Total Hours"

        'Calculate and set the total hours for Monday
        intTotal = 0
        For intIndex = 0 To objTimeSheetDS.Tables("TimeSheet").Rows.Count - 1
            intTotal += objTimeSheetDS.Tables( _
                "TimeSheet").Rows(intIndex).Item("MondayHours")
        Next
        objDataRowView("MondayHours") = intTotal

        'Calculate and set the total hours for Tuesday
        intTotal = 0
        For intIndex = 0 To objTimeSheetDS.Tables("TimeSheet").Rows.Count - 1
            intTotal += objTimeSheetDS.Tables( _
                "TimeSheet").Rows(intIndex).Item("TuesdayHours")
        Next
        objDataRowView("TuesdayHours") = intTotal

        'Calculate and set the total hours for Wednesday
        intTotal = 0
        For intIndex = 0 To objTimeSheetDS.Tables("TimeSheet").Rows.Count - 1
            intTotal += objTimeSheetDS.Tables( _
                "TimeSheet").Rows(intIndex).Item("WednesdayHours")
        Next
        objDataRowView("WednesdayHours") = intTotal

        'Calculate and set the total hours for Thursday
        intTotal = 0
        For intIndex = 0 To objTimeSheetDS.Tables("TimeSheet").Rows.Count - 1
            intTotal += objTimeSheetDS.Tables( _
                "TimeSheet").Rows(intIndex).Item("ThursdayHours")
        Next
        objDataRowView("ThursdayHours") = intTotal

        'Calculate and set the total hours for Friday
        intTotal = 0
        For intIndex = 0 To objTimeSheetDS.Tables("TimeSheet").Rows.Count - 1
            intTotal += objTimeSheetDS.Tables( _
                "TimeSheet").Rows(intIndex).Item("FridayHours")
        Next
        objDataRowView("FridayHours") = intTotal

        'Commit the changes to the row
        objDataRowView.EndEdit()

        'Disallow new records
        objTimeSheetDV.AllowNew = False

        'Bind the DataView to the DataGrid
        grdTimeSheet.DataSource = objTimeSheetDV

        'Get and set the DataGridTableStyle
        Dim objDataGridTableStyle As New DataGridTableStyle
        With objDataGridTableStyle
            .AlternatingBackColor = Color.WhiteSmoke
            .MappingName = "TimeSheet"
        End With

        'Get and set a new column
        Dim objColumn1 As New DataGridTextBoxColumn
        With objColumn1
            .HeaderText = "Project Name"
            .MappingName = "ProjectName"
            .ReadOnly = True
            .Width = 225
        End With

        'Get and set a new column
        Dim objColumn2 As New DataGridTextBoxColumn
        With objColumn2
            .HeaderText = "Monday"
            .MappingName = "MondayHours"
            .Width = 70
            If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
                Or Not blnEmployeeDisplay Then
                .ReadOnly = True
            End If
        End With

        'Get and set a new column
        Dim objColumn3 As New DataGridTextBoxColumn
        With objColumn3
            .HeaderText = "Tuesday"
            .MappingName = "TuesdayHours"
            .Width = 70
            If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
                Or Not blnEmployeeDisplay Then
                .ReadOnly = True
            End If
        End With

        'Get and set a new column
        Dim objColumn4 As New DataGridTextBoxColumn
        With objColumn4
            .HeaderText = "Wednesday"
            .MappingName = "WednesdayHours"
            .Width = 70
            If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
                Or Not blnEmployeeDisplay Then
                .ReadOnly = True
            End If
        End With

        'Get and set a new column
        Dim objColumn5 As New DataGridTextBoxColumn
        With objColumn5
            .HeaderText = "Thursday"
            .MappingName = "ThursdayHours"
            .Width = 70
            If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
                Or Not blnEmployeeDisplay Then
                .ReadOnly = True
            End If
        End With

        'Get and set a new column
        Dim objColumn6 As New DataGridTextBoxColumn
        With objColumn6
            .HeaderText = "Friday"
            .MappingName = "FridayHours"
            .Width = 70
            If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
                Or Not blnEmployeeDisplay Then
                .ReadOnly = True
            End If
        End With

        ' Add the columns to the DataGridTableStyle collection 
        objDataGridTableStyle.GridColumnStyles.AddRange(New DataGridColumnStyle() _
         {objColumn1, objColumn2, objColumn3, objColumn4, objColumn5, objColumn6})

        'Add the DataGridTableStyle collection to the DataGrid
        grdTimeSheet.TableStyles.Clear()
        grdTimeSheet.TableStyles.Add(objDataGridTableStyle)

        grdTimeSheet.CurrentCell = New DataGridCell(0, 1)

        'Change the locked icon if the timesheet is readonly
        If objTimeSheetDS.Tables("TimeSheet").Rows(0).Item("Submitted") _
            Or Not blnEmployeeDisplay Then
            imgStatus.Image = ImageList1.Images(14)
        Else
            imgStatus.Image = ImageList1.Images(13)
        End If
    End Sub
#End Region

#Region " Employee Procedures "
    Private Sub LoadEmployees()
        'Clear previous bindings
        cboEmployee.DataSource = Nothing
        cboEmployee.DisplayMember = String.Empty
        cboEmployee.ValueMember = String.Empty

        'Initialize a new instance of the business logic component
        objUsers = New WroxBusinessLogic.WBLUsers( _
            strCompany, strApplication)

        'Get the timesheet for the user
        objEmployees = objUsers.GetManagerEmployees(New Guid(strManagerID))

        'Rebind ComboBox control
        cboEmployee.DataSource = objEmployees.Tables("Employees")
        cboEmployee.DisplayMember = "EmployeeName"
        cboEmployee.ValueMember = "UserID"
    End Sub

    Private Sub cboWeekEnding_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles cboWeekEnding.SelectedIndexChanged
        If Not blnEmployeeDisplay And blnLoading Then
            Exit Sub
        End If

        'Load the timesheet
        Call LoadTimeSheet(cboWeekEnding)
    End Sub

    Private Sub grdTimeSheet_CurrentCellChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles grdTimeSheet.CurrentCellChanged
        'Declare variables
        Dim objDataRowView As DataRowView
        Dim objDataRowTotal As DataRowView

        'Get the total row so we can update the totals
        objDataRowTotal = objTimeSheetDV.Item(objTimeSheetDV.Count - 1)

        'Recalculate Monday's total
        intTotal = 0
        For intIndex As Integer = 0 To objTimeSheetDV.Count - 2
            objDataRowView = objTimeSheetDV.Item(intIndex)
            intTotal += objDataRowView.Item("MondayHours")
        Next
        'Update Monday's total
        objDataRowTotal.Item("MondayHours") = intTotal

        'Recalculate Tuesday's total
        intTotal = 0
        For intIndex As Integer = 0 To objTimeSheetDV.Count - 2
            objDataRowView = objTimeSheetDV.Item(intIndex)
            intTotal += objDataRowView.Item("TuesdayHours")
        Next
        'Update Tuesday's total
        objDataRowTotal.Item("TuesdayHours") = intTotal

        'Recalculate Wednesday's total
        intTotal = 0
        For intIndex As Integer = 0 To objTimeSheetDV.Count - 2
            objDataRowView = objTimeSheetDV.Item(intIndex)
            intTotal += objDataRowView.Item("WednesdayHours")
        Next
        'Update Wednesday's total
        objDataRowTotal.Item("WednesdayHours") = intTotal

        'Recalculate Thursday's total
        intTotal = 0
        For intIndex As Integer = 0 To objTimeSheetDV.Count - 2
            objDataRowView = objTimeSheetDV.Item(intIndex)
            intTotal += objDataRowView.Item("ThursdayHours")
        Next
        'Update Thursday's total
        objDataRowTotal.Item("ThursdayHours") = intTotal

        'Recalculate Friday's total
        intTotal = 0
        For intIndex As Integer = 0 To objTimeSheetDV.Count - 2
            objDataRowView = objTimeSheetDV.Item(intIndex)
            intTotal += objDataRowView.Item("FridayHours")
        Next
        'Update Friday's total
        objDataRowTotal.Item("FridayHours") = intTotal

        'Commit the changes to the total row
        objDataRowTotal.EndEdit()
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnSave.Click
        'Initialize a new instance of the business logic component
        objTimeSheets = New WroxBusinessLogic.WBLTimeSheets( _
         strCompany, strApplication)
        Try
            'Save the timesheet changes
            If Not objTimeSheets.SaveTimeSheet(objTimeSheetDS) Then
                Throw New Exception("Save TimeSheet Failed")
            End If
            'Display a statusbar message
            StatusBar1.Panels(0).Text = "Timesheet saved"
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        Finally
            'Cleanup
            objTimeSheets.Dispose()
            objTimeSheets = Nothing
        End Try
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnSubmit.Click
        'Initialize a new instance of the business logic component
        objTimeSheets = New WroxBusinessLogic.WBLTimeSheets( _
         strCompany, strApplication)
        Try
            'Submit the timesheet
            If Not objTimeSheets.SubmitTimeSheet( _
                New Guid(objTimeSheetDS.Tables("TimeSheet").Rows(0).Item( _
                "TimeSheetID").ToString)) Then
                Throw New Exception("Submit TimeSheet Failed")
            End If
            'Reload the timesheet so it becomes read-only
            Call LoadTimeSheet(cboWeekEnding)
            'Display a statusbar message
            StatusBar1.Panels(0).Text = "Timesheet submitted"
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        Finally
            'Cleanup
            objTimeSheets.Dispose()
            objTimeSheets = Nothing
        End Try
    End Sub
#End Region

#Region " Manager Procedures "
    Private Sub cboEmployee_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles cboEmployee.SelectedIndexChanged
        strUserID = objEmployees.Tables("Employees").Rows( _
            cboEmployee.SelectedIndex).Item("UserID").ToString
    End Sub

    Private Sub cboEmployeeWeekEnding_SelectedIndexChanged( _
        ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles cboEmployeeWeekEnding.SelectedIndexChanged
        If blnLoading Then
            Exit Sub
        End If

        'Load the timesheet
        Call LoadTimeSheet(cboEmployeeWeekEnding)
    End Sub

    Private Sub btnApprove_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnApprove.Click
        'Initialize a new instance of the business logic component
        objTimeSheets = New WroxBusinessLogic.WBLTimeSheets( _
         strCompany, strApplication)
        Try
            'Submit the timesheet
            If Not objTimeSheets.ApproveTimeSheet( _
             New Guid(objTimeSheetDS.Tables("TimeSheet").Rows(0).Item( _
                "TimeSheetID").ToString), New Guid(strManagerID)) Then
                Throw New Exception("Approve TimeSheet Failed")
            End If
            'Display a statusbar message
            StatusBar1.Panels(0).Text = "Timesheet approved"
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        Finally
            'Cleanup
            objTimeSheets.Dispose()
            objTimeSheets = Nothing
        End Try
    End Sub
#End Region
End Class

⌨️ 快捷键说明

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