为什么要考虑日期增量?
For Each dr As DataRow In DataTables("表A").DataRows
dr("插卡时间") = Nothing
dr("拔卡时间") = Nothing
dr("插拔间隔") = Nothing
dr("插插间隔") = Nothing
dr("拔插间隔") = Nothing
dr("工效") = Nothing
dr("午休标记") = Nothing
Next
Dim fdxs As Integer = 6 '工位工时浮动系数
Dim cgsj As Date = #08:00:00# '上午出工时间
Dim swsgsj As Date = #11:00:00# '上午收工时间
Dim wxjg As Integer = 5400 '午休间隔
'Dim rqzl As Integer = 86400 '日期增量
'填充当天工位首次插拔卡时间
For Each dr As DataRow In DataTables("表A").DataRows
Dim pr As DataRow = DataTables("表A").Find("日期 = '" & dr("日期") & "' and 工位ID = '" & dr("工位ID") & "'","采集序号")
If pr.IsNull("插卡时间") Then
pr("插卡时间") = pr("日期") &" "& cgsj
'pr("拔卡时间") = CDate(pr("插卡时间")).AddSeconds(pr("工位工时"))
pr("拔卡时间") = CDate(pr("插卡时间")).AddSeconds(pr("工位工时") * Rand.Next(100 - fdxs,100 + fdxs) / 100)
End If
Next
For Each dr As DataRow In DataTables("表A").DataRows
Dim pr As DataRow = DataTables("表A").Find("工位ID = '" & dr("工位ID") & "' and 采集序号 < '" & dr("采集序号") & "'","采集序号 Desc") '同批次工位的上一行
Dim pr2 As DataRow = DataTables("表A").Find("工位ID = '" & dr("工位ID") & "' And 午休标记 = 1")
If dr.IsNull("插卡时间") Then
If pr("拔卡时间").AddSeconds(dr("工位工时")) > pr("日期") &" "& swsgsj And pr2 Is Nothing '判断本节拍结束时间大于中午收工时间以及当天本工位无午休标记
If dr("日期") = pr("日期") Then
dr("插卡时间") = pr("拔卡时间")
dr("插插间隔") = (dr("插卡时间") - pr("插卡时间")).TotalSeconds()
dr("拔插间隔") = (dr("插卡时间") - pr("拔卡时间")).TotalSeconds()
Else
dr("插卡时间") = pr("拔卡时间")'.AddSeconds(rqzl)
dr("插插间隔") = (dr("插卡时间") - pr("插卡时间")).TotalSeconds()' - rqzl
dr("拔插间隔") = (dr("插卡时间") - pr("拔卡时间")).TotalSeconds() '- rqzl
End If
'dr("拔卡时间") = CDate(dr("插卡时间")).AddSeconds(dr("工位工时") + wxjg)
dr("拔卡时间") = CDate(dr("插卡时间")).AddSeconds(dr("工位工时") * Rand.Next(100 - fdxs,100 + fdxs) / 100 + wxjg)
dr("午休标记") = 1 '添加午休标记
Else
If dr("日期") = pr("日期") Then
dr("插卡时间") = pr("拔卡时间")
dr("插插间隔") = (dr("插卡时间") - pr("插卡时间")).TotalSeconds()
dr("拔插间隔") = (dr("插卡时间") - pr("拔卡时间")).TotalSeconds()
Else
dr("插卡时间") = pr("拔卡时间")'.AddSeconds(rqzl)
dr("插插间隔") = (dr("插卡时间") - pr("插卡时间")).TotalSeconds() '- rqzl
dr("拔插间隔") = (dr("插卡时间") - pr("拔卡时间")).TotalSeconds() '- rqzl
End If
If pr("午休标记") = 1 Then
dr("插插间隔") = (dr("插卡时间") - pr("插卡时间")).TotalSeconds() - wxjg
End If
'dr("拔卡时间") = CDate(dr("插卡时间")).AddSeconds(dr("工位工时")
dr("拔卡时间") = CDate(dr("插卡时间")).AddSeconds(dr("工位工时") * Rand.Next(100 - fdxs,100 + fdxs) / 100)
End If
End If
Next
For Each dr As DataRow In DataTables("表A").DataRows
If dr.IsNull("插拔间隔") Then
If dr("午休标记") = 1 Then
dr("插拔间隔") = (dr("拔卡时间") - dr("插卡时间")).TotalSeconds() - wxjg
Else
dr("插拔间隔") = (dr("拔卡时间") - dr("插卡时间")).TotalSeconds()
End If
End If
If dr.IsNull("插插间隔") Then
dr("插插间隔") = dr("插拔间隔")
End If
dr("工效") = dr("工位工时") / dr("插插间隔")
Next
Tables("表A").AutoSizeCols()
DataTables("表A").Save()