timesheet.vb
来自「Beginning VB.NET DatabasesAll_Code.rar」· VB 代码 · 共 1,086 行 · 第 1/3 页
VB
1,086 行
'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
#Region " Report Procedures "
Private Sub DisplayReport(ByVal Report As ReportType)
'Initialize a new instance of the Web service
Dim objReports As New TimeSheetsWS.Reports
'Get the report
Select Case Report
Case ReportType.TimeSheetsDue
objTimeSheetDS = objReports.TimeSheetsDue( _
New Guid(strManagerID), cboEmployeeWeekEnding.SelectedItem)
Case ReportType.TimeSheetsSubmitted
objTimeSheetDS = objReports.TimeSheetsSubmitted( _
New Guid(strManagerID), cboEmployeeWeekEnding.SelectedItem)
Case ReportType.TimeSheetsMTD
objTimeSheetDS = objReports.TimeSheetsMTD(New Guid(strManagerID))
Case ReportType.TimeSheetsQTD
objTimeSheetDS = objReports.TimeSheetsQTD(New Guid(strManagerID))
Case ReportType.TimeSheetsYTD
objTimeSheetDS = objReports.TimeSheetsYTD(New Guid(strManagerID))
End Select
'Cleanup
objReports.Dispose()
objReports = Nothing
'Clear previous bindings
grdTimeSheet.DataSource = Nothing
grdTimeSheet.DataMember = String.Empty
'Set the caption text in the DataGrid
Select Case Report
Case ReportType.TimeSheetsDue, ReportType.TimeSheetsSubmitted
grdTimeSheet.CaptionText = "Report: " & _
objTimeSheetDS.Tables("ReportHeader").Rows(0).Item("Title") & _
", Manager: " & _
objTimeSheetDS.Tables("ReportHeader").Rows(0).Item( _
"ManagerName") & ", Week Ending Date: " & _
Format(objTimeSheetDS.Tables("ReportHeader").Rows(0).Item( _
"Date"), "Short Date")
Case ReportType.TimeSheetsMTD, ReportType.TimeSheetsQTD, _
ReportType.TimeSheetsYTD
grdTimeSheet.CaptionText = "Report: " & _
objTimeSheetDS.Tables("ReportHeader").Rows(0).Item("Title") & _
", Manager: " & _
objTimeSheetDS.Tables("ReportHeader").Rows(0).Item( _
"ManagerName") & ", Report Date: " & _
Format(objTimeSheetDS.Tables("ReportHeader").Rows(0).Item( _
"Date"), "Short Date")
End Select
grdTimeSheet.CaptionVisible = True
'Bind the new DataSet to the DataGrid
grdTimeSheet.DataSource = objTimeSheetDS
grdTimeSheet.DataMember = "TimeSheets"
End Sub
Private Sub mnuReportsTimesheetsDue_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles mnuReportsTimesheetsDue.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsDue)
End Sub
Private Sub mnuReportsTimesheetsSubmitted_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles mnuReportsTimesheetsSubmitted.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsSubmitted)
End Sub
Private Sub mnuReportsTimesheetsMTD_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles mnuReportsTimesheetsMTD.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsMTD)
End Sub
Private Sub mnuReportsTimesheetsQTD_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuReportsTimesheetsQTD.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsQTD)
End Sub
Private Sub mnuReportsTimesheetsYTD_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuReportsTimesheetsYTD.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsYTD)
End Sub
#End Region
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?