在 VB ASP.Net 中获取包含时差计数的报告的 SQL 数据
Getting SQL data for a report with Time Difference count in VB ASP.Net
我一直在努力让报告正确显示。我想要实现的是我有估计工作时间的项目。员工记录他们的时间表条目,(start\end) 日期和时间被保存到这个特定项目和员工的 SQL table 中,所以我想报告项目的估计预设时间与员工实际花费的时间相比,这是我使用代码所做的场景:
我有Table个:
1-Projects Table---> ProjectID,Estimate Project Estimate Duration(以小时为单位)
2-ProjectResources Table--->ProjectID, ResourceID
3 个时间表条目 Table--->时间表条目 ID、项目 ID、用户 ID、开始日期时间、结束日期时间
我创建的内容如下:
1-我使用项目名称作为文本和项目 ID 作为值填充下拉列表
2-在列表selectedIndexChanged事件中我查询得到Project的所有资源如下:
将 TimesheetsTotalTime 调暗为十进制 = 0
Dim query As String = "SELECT resourceid FROM projectresources where projectID='" & ProjectID & "'"
Dim dt As DataTable = GetData(查询)
对于 x 作为整数 = 0 到 dt.Rows.Count - 1
将 resourceID 调暗为整数
resourceID = dt.Rows(x).项目(0)
totalTimesheetTime = totalTimesheetTime + GetTotalTimesheetsPerUser(项目ID, resourceID)
下一个
私有共享函数 GetTotalTimesheetsPerUser(ProjectID As Integer, ResourceID As Integer) As Decimal
将 TimesheetsTotalTime 变暗为十进制 = 0
Dim query As String = "SELECT timesheetid FROM timesheet where projectID='" & ProjectID & "' and userid='" & ResourceID & "'"
Dim dt As DataTable = GetData(query)
For x As Integer = 0 To dt.Rows.Count - 1
Dim TimesheetID As Integer
TimesheetID = dt.Rows(x).Item(0).ToString
TimesheetsTotalTime = TimesheetsTotalTime + GetTimeDifferenceForTask(TimesheetID)
Next
Return TimesheetsTotalTime
结束函数
私有共享函数 GetTimeDifferenceForTask(timeSheetID As Integer) As Decimal
将 CountedHours 调暗为十进制
Dim query As String = "SELECT StartTime, EndTime FROM Timesheet where TimesheetID='" & timeSheetID & "'"
Dim dt As DataTable = GetData(query)
If dt.Rows.Count > 0 Then
Dim startTime As DateTime = dt.Rows(0).Item(0)
Dim endTime As DateTime = dt.Rows(0).Item(1)
CountedHours = DateDiff(DateInterval.Hour, startTime, endTime)
Return CountedHours
End If
结束函数
每当我将最终数据添加到 RadHTMLChart 时,作为所有用户的所有时间表条目的总时间返回的时间是不正确的。我总共得到了“13”小时,而数字是 13.5,而对于另一个项目,我得到了“17”小时,而它应该是 29。
请指教,谢谢
你得到 13 而不是 13.5,因为你的 DateDiff
是在 DateInterval.Hour
中计算的。要获得您正在寻找的 decimal
结果,请将其更改为:
CountedHours = DateDiff(DateInterval.Minute, startTime, endTime) / 60
至于在预期结果为 29 时得到结果 17...请确保您的输入是 datetime
而不仅仅是 time
,并且如果结果相同 - post 用于分析的输入值。
我一直在努力让报告正确显示。我想要实现的是我有估计工作时间的项目。员工记录他们的时间表条目,(start\end) 日期和时间被保存到这个特定项目和员工的 SQL table 中,所以我想报告项目的估计预设时间与员工实际花费的时间相比,这是我使用代码所做的场景:
我有Table个:
1-Projects Table---> ProjectID,Estimate Project Estimate Duration(以小时为单位) 2-ProjectResources Table--->ProjectID, ResourceID 3 个时间表条目 Table--->时间表条目 ID、项目 ID、用户 ID、开始日期时间、结束日期时间
我创建的内容如下:
1-我使用项目名称作为文本和项目 ID 作为值填充下拉列表
2-在列表selectedIndexChanged事件中我查询得到Project的所有资源如下:
将 TimesheetsTotalTime 调暗为十进制 = 0 Dim query As String = "SELECT resourceid FROM projectresources where projectID='" & ProjectID & "'" Dim dt As DataTable = GetData(查询)
对于 x 作为整数 = 0 到 dt.Rows.Count - 1 将 resourceID 调暗为整数 resourceID = dt.Rows(x).项目(0) totalTimesheetTime = totalTimesheetTime + GetTotalTimesheetsPerUser(项目ID, resourceID)
下一个
私有共享函数 GetTotalTimesheetsPerUser(ProjectID As Integer, ResourceID As Integer) As Decimal 将 TimesheetsTotalTime 变暗为十进制 = 0
Dim query As String = "SELECT timesheetid FROM timesheet where projectID='" & ProjectID & "' and userid='" & ResourceID & "'"
Dim dt As DataTable = GetData(query)
For x As Integer = 0 To dt.Rows.Count - 1
Dim TimesheetID As Integer
TimesheetID = dt.Rows(x).Item(0).ToString
TimesheetsTotalTime = TimesheetsTotalTime + GetTimeDifferenceForTask(TimesheetID)
Next
Return TimesheetsTotalTime
结束函数
私有共享函数 GetTimeDifferenceForTask(timeSheetID As Integer) As Decimal 将 CountedHours 调暗为十进制
Dim query As String = "SELECT StartTime, EndTime FROM Timesheet where TimesheetID='" & timeSheetID & "'"
Dim dt As DataTable = GetData(query)
If dt.Rows.Count > 0 Then
Dim startTime As DateTime = dt.Rows(0).Item(0)
Dim endTime As DateTime = dt.Rows(0).Item(1)
CountedHours = DateDiff(DateInterval.Hour, startTime, endTime)
Return CountedHours
End If
结束函数
每当我将最终数据添加到 RadHTMLChart 时,作为所有用户的所有时间表条目的总时间返回的时间是不正确的。我总共得到了“13”小时,而数字是 13.5,而对于另一个项目,我得到了“17”小时,而它应该是 29。
请指教,谢谢
你得到 13 而不是 13.5,因为你的 DateDiff
是在 DateInterval.Hour
中计算的。要获得您正在寻找的 decimal
结果,请将其更改为:
CountedHours = DateDiff(DateInterval.Minute, startTime, endTime) / 60
至于在预期结果为 29 时得到结果 17...请确保您的输入是 datetime
而不仅仅是 time
,并且如果结果相同 - post 用于分析的输入值。