MyTimers("末端投料计算").Enabled = False
Dim drs任务 As List(Of DataRow) = _dt末端投料计算任务表.SQLSelect("[母捆包号] <> '' ") '读取任务表中记录并且写入drs任务集合
If drs任务.Count > 0 Then
Dim tp As TimeSpan '定义作业分钟分摊
Dim Jb2 As New List(Of String) '定义记录标记2的集合Jb2
Dim Mkbh As New List(Of String) '定义母捆包号的集合Mkbh
For Each dr As DataRow In drs任务
If dr("来源表名") = "生产记录" AndAlso Jb2.Contains(dr("记录标记2"))= False Then '将不同的来自于生产记录表的记录标记2写入Jb2集合
Jb2.Add(dr("记录标记2"))
End If
If Mkbh.Contains(dr("母捆包号"))= False Then '将不同的母捆包号写入Mkbh集合
Mkbh.Add(dr("母捆包号"))
End If
Next
For Each jlbj2 As String In Jb2
'作业分钟分摊计算
Dim drs时间 As List(Of DataRow) = _dt工序合并表.SQLSelect("记录标记2 = '" & jlbj2 & "'") '将当前的记录标记2写入集合
If drs时间.Count = 0 Then
ElseIf drs时间.Count = 1 Then
tp = drs时间(0)("结束时间") - drs时间(0)("起始时间")
drs时间(0)("作业分钟分摊") = tp.TotalSeconds()/60
Else
Dim Sum As Double = _dt工序合并表.SQLCompute("Sum(数量)","记录标记2 = '" & jlbj2 & "'")
For i As Integer = 0 To drs时间.Count - 1
tp = drs时间(i)("结束时间") - drs时间(i)("起始时间")
drs时间(i)("作业分钟分摊") = tp.TotalSeconds()/60/Sum * drs时间(i)("数量")
Next
End If
_dt工序合并表.SQLUpdate(drs时间)
Next
For Each nm As String In Mkbh
'末端标记计算
Dim drs末端 As List(Of DataRow) = _dt工序合并表.SQLSelect("母捆包号 = '" & nm & "'","","捆包号,起始时间") '将当前的母捆包号写入集合
If drs末端.Count = 0 Then
ElseIf drs末端.Count = 1 Then
drs末端(0)("末端标记") = True
Else
For i As Integer = 1 To drs末端.Count - 1
If drs末端(i)("捆包号").Contains(drs末端(i-1)("捆包号")) Then
drs末端(i-1)("末端标记") = False
Else
drs末端(i-1)("末端标记") = True
End If
Next
drs末端(drs末端.Count-1)("末端标记") = True
End If
_dt工序合并表.SQLUpdate(drs末端)
'投料量和成材率计算
Dim drs投料量 As List(Of DataRow) = _dt工序合并表.SQLSelect("母捆包号 = '" & nm & "'","","捆包号,起始时间") '将当前的母捆包号写入集合
If drs投料量.Count = 0 Then
ElseIf drs投料量.Count=1 Then
drs投料量(0)("投料量") = drs投料量(0)("数量")
drs投料量(0)("成材率") = drs投料量(0)("数量") / drs投料量(0)("投料量")
Else
drs投料量(0)("投料量")=drs投料量(0)("数量")
Dim tll As Double = drs投料量(0)("投料量") '+++
Dim dic As New Dictionary(Of String, Double())
Dim Dic_dr As new Dictionary(of DataRow, Double)
For i As Integer = 1 To drs投料量.Count - 1
If drs投料量(i)("捆包号") = drs投料量(i-1)("捆包号")
Dic_dr.Add(drs投料量(i), tll)
Else
Dim str As String = drs投料量(i)("捆包号").Substring(0,drs投料量(i)("捆包号").length - 4) '此处减去数字4代表上一个捆包编号
If dic.ContainsKey(str) = False Then
Dim fdr As DataRow = _dt工序合并表.SQLFind("捆包号 = '" & str & "'", "起始时间")
If fdr IsNot Nothing Then
Dim drs投料量_temp As List(of DataRow) = _dt工序合并表.SQLSelect("substring(捆包号,1," & drs投料量(i)("捆包号").Length - 4 & ") = '" & fdr("捆包号") & "' and len(捆包号) = " & drs投料量(i)("捆包号").Length,"","捆包号")
If drs投料量_temp.Count > 0 Then
Dim zl As Double = drs投料量_temp(0)("数量")
For j As Integer = 1 To drs投料量_temp.Count - 1
If drs投料量_temp(j)("捆包号") <> drs投料量_temp(j-1)("捆包号") Then
zl += drs投料量_temp(j)("数量")
End If
Next
dic.Add(str, new Double(){zl, tll})
Else
MessageBox.Show("发生代码运算错误,此错误的相关代码位于全局表事件的DataColChanged事件中,看到此条消息请与管理员联系!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning)
End If
Else
tll = drs投料量(i)("数量")
Dic_dr.Add(drs投料量(i), tll)
Continue For
End If
End If
tll = drs投料量(i)("数量") / dic(str)(0) * dic(str)(1)
Dic_dr.Add(drs投料量(i), tll)
End If
Next
For Each dr As DataRow In dic_dr.Keys
dr("投料量") = dic_dr(dr)
Next
For i As Integer = 0 To drs投料量.Count - 1
drs投料量(i)("成材率") = drs投料量(i)("数量") / drs投料量(i)("投料量")
Next
End If
_dt工序合并表.SQLUpdate(drs投料量)
Next
_dt末端投料计算任务表.SQLDeleteFor("母捆包号 in ('" & String.Join("','", mkbh.ToArray) & "')")
_dt末端投料计算任务表.Save
End If
MyTimers("末端投料计算").Enabled = True