以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]时间计算代码修改 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=57573) |
-- 作者:yyzlxc -- 发布时间:2014/9/26 20:38:00 -- [求助]时间计算代码修改 计算同一员工时间记录的时差,如何通过修改代码,实现计算时差为实际时差的5倍,请各位老师指教,谢谢。 drs = DataTables("C").Select("[序号] >= " & dr("序号") & " And [员工] = \'" & dr("员工") & "\'", "[序号]") For k As Integer = 1 To drs.Count - 1 \'重算余下行的时差 Dim t As TimeSpan = CDate(drs(k)("时间")) - CDate(drs(k-1)("时间")) drs(k)("用时") = (Format(t.Hours,"00") & ":" & Format(t.Minutes,"00") & ":" & Format(t.Seconds,"00")) Next |
-- 作者:yyzlxc -- 发布时间:2014/9/27 8:04:00 -- 自己设法解决,方法是先将时间转换为以秒为单位的数值格式,乘以5以后再转换成时间格式。有没有更简洁的方法,请各位老师指教,谢谢 For Each dr As DataRow In DataTables("C").DataRows Dim N As Integer Dim mr As DataRow = dr Dim drs As List(of DataRow) If dr.IsNull("用时") Then dr = DataTables("C").Find("[序号] < " & mr("序号") & " And [员工] = \'" & mr("员工") & "\'And [日期] = \'" & mr("日期") & "\'", "[序号] Desc") \'找出上一行 If dr Is Nothing Then \'如果没有找到上一行,说明本行就是第一行 N = mr("工时") mr("用时") = (new Date(1,1,1,0,0,0)).AddSeconds(N) dr = mr End If drs = DataTables("C").Select("[序号] >= " & dr("序号") & " And [员工] = \'" & dr("员工") & "\'And [日期] = \'" & mr("日期") & "\'", "[序号]") For k As Integer = 1 To drs.Count - 1 \'重算余下行的时差 Dim t As TimeSpan = CDate(drs(k)("时间")) - CDate(drs(k-1)("时间")) Dim d4 As Integer = t.Hours * 3600 + t.Minutes * 60 + t.Seconds Dim N1,h,m,s As Integer Dim sj As Date N1 = d4 * 5 h = N1 \\ 3600 m = (N1 Mod 3600) \\ 60 s = N1 Mod 60 drs(k)("用时") = Format(new Date(1,1,1,h,m,s), "HH:mm:ss") Next End If Next |