📄 timesheet.vb
字号:
'Set the view flag
blnEmployeeDisplay = False
End Sub
Private Sub aboutToolStripMenuItem_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles aboutToolStripMenuItem.Click
Dim objAbout As New About
objAbout.ShowDialog(Me)
objAbout.Dispose()
objAbout = Nothing
End Sub
Private Sub TimesheetsDueToolStripMenuItem_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TimesheetsDueToolStripMenuItem.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsDue)
End Sub
Private Sub TimesheetsSubmittedToolStripMenuItem_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TimesheetsSubmittedToolStripMenuItem.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsSubmitted)
End Sub
Private Sub TimesheetsMTDToolStripMenuItem_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TimesheetsMTDToolStripMenuItem.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsMTD)
End Sub
Private Sub TimesheetsQTDToolStripMenuItem_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TimesheetsQTDToolStripMenuItem.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsQTD)
End Sub
Private Sub TimesheetsYTDToolStripMenuItem_Click( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TimesheetsYTDToolStripMenuItem.Click
'Get and display the report
Call DisplayReport(ReportType.TimeSheetsYTD)
End Sub
#End Region
#Region " Utility Functions "
Private Function GetCurrentWeekEndingDate() As String
GetCurrentWeekEndingDate = DateSerial( _
Year(Now), Month(Now), DateAndTime.Day(Now) - _
DatePart("w", Now, FirstDayOfWeek.Sunday) + 6)
End Function
Private Function GetPreviousWeekEndingDate() As String
GetPreviousWeekEndingDate = DateSerial( _
Year(Now), Month(Now), DateAndTime.Day(Now) - _
DatePart("w", Now, FirstDayOfWeek.Sunday) - 1)
End Function
#End Region
#Region " Timesheet Functions "
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 Data.DataRowView
Dim objDataRowTotal As Data.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 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 btnSave_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnSave.Click
'Initialize a new instance of the business logic component
Using objTimeSheets As 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
ToolStripStatus.Text = "Timesheet saved"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Using
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
Using objTimeSheets As 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
ToolStripStatus.Text = "Timesheet submitted"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Using
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
Using objTimeSheets As 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
ToolStripStatus.Text = "Timesheet approved"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Using
End Sub
#End Region
#Region " Report Functions "
Private Sub DisplayReport(ByVal Report As ReportType)
Try
'Initialize a new instance of the Web service
Using 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
End Using
'Clear previous bindings
grdTimeSheet.DataSource = Nothing
grdTimeSheet.DataMember = String.Empty
grdTimeSheet.Columns.Clear()
'Set the text in the status bar
Select Case Report
Case ReportType.TimeSheetsDue, ReportType.TimeSheetsSubmitted
ToolStripStatus.Text = "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
ToolStripStatus.Text = "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
'Bind the new DataSet to the DataGridView
grdTimeSheet.AutoGenerateColumns = True
grdTimeSheet.DataSource = objTimeSheetDS
grdTimeSheet.DataMember = "TimeSheets"
Catch ExceptionErr As Exception
'Display the error
MessageBox.Show(ExceptionErr.Message, strAppTitle)
End Try
End Sub
#End Region
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -