我新建一个临时表,有开工时间,从固定表中追加数据时,时间字段只能把日期和小时等追加进来,不能把分钟追加进来。在固定表里有个列属性设置,在临时表里我也定义日期时间类型了。什么原因呢?请指教!
Dim dtb As New DataTableBuilder("实时工序计算表")
dtb.AddDef("日期", GetType(Date))
dtb.AddDef("清单条码编码", GetType(String), 26)
dtb.AddDef("ygdm", GetType(String), 4)
dtb.AddDef("员工姓名", GetType(String), 8)
dtb.adddef("gxdm", GetType(String), 2)
dtb.AddDef("工序名称", GetType(String), 8)
dtb.AddDef("完成件数", GetType(Short))
dtb.AddDef("开工时间", GetType(DateTime))
dtb.AddDef("结束时间", GetType(DateTime))
dtb.AddDef("重量", GetType(Double))
dtb.AddDef("工序耗时", GetType(Double))
dtb.AddDef("jsbm1", GetType(String), 20)
dtb.AddDef("jsbm2", GetType(String), 18)
dtb.Build()
''以下是计算部分
'追加开工时间
'DataTables("车间扫描表").LoadFilter = ""
'DataTables("ddqdb").LoadFilter = ""
For Each nm As String In DataTables("车间扫描表").GetValues("jsbm1")
Dim pr As DataRow = DataTables("车间扫描表").find("jsbm1='" & nm & "'")
Dim rq As Date = pr("日期")
Dim tm As String = pr("清单条码编码")
Dim yg As String = pr("ygdm")
Dim xm As String = pr("员工姓名")
Dim gx As String = pr("gxdm")
Dim gmc As String = pr("工序名称")
Dim ktime As datetime = pr("开工时间")
Dim jtime As datetime = pr("结束时间")
Dim zl As Double = pr("重量")
Dim bm As String = pr("jsbm2")
Dim dr As DataRow = DataTables("实时工序计算表").find("jsbm1='" & nm & "'")
If dr Is Nothing Then
dr = DataTables("实时工序计算表").AddNew()
dr("日期") = rq
dr("清单条码编码") = tm
dr("ygdm") = yg
dr("员工姓名") = xm
dr("gxdm") = gx
dr("工序名称") = gmc
dr("开工时间") = ktime
dr("结束时间") = jtime
dr("重量") = zl
dr("jsbm1") = nm
dr("jsbm2") = bm
End If
Next
'
'以下是计算部分
For Each nm As String In DataTables("实时工序计算表").GetValues("jsbm1")
Dim dr As DataRow = DataTables("实时工序计算表").find("jsbm1='" & nm & "'")
Dim sp As TimeSpan
If dr.isnull("结束时间") = False Then
sp = dr("结束时间") - dr("开工时间")
dr("工序耗时") = sp.TotalSeconds() / 60
Else
dr("工序耗时") = Nothing
End If
Next
我通过上述代码计算的结果是这样的:
此主题相关图片如下:d478ec5b5ffe10cdbd3e396132b3b71.jpg