Vars("_kssj") = Date.Now
Dim rq As Date = RibbonTabs("实时采集")("日期单位").Items("日期").Value
Dim bz As String = RibbonTabs("实时采集").Groups("班组查询").Items("班组").Text
Dim pc As String = RibbonTabs("实时采集").Groups("班组查询").Items("批次").Text
Dim cpkh As String = RibbonTabs("实时采集").Groups("班组查询").Items("款号").Text
Dim drf As DataRow = DataTables("采集模板").Find("班组 = '"& bz &"'")
Dim bzid As String = drf("班组ID")
If RibbonTabs("实时采集").Groups("班组查询").Items("款号").Text = "" Then
MessageBox.Show("请选择班组,批次","提示")
Return
End If
'填充工位节拍
DataTables("工位节拍").DataRows.Clear()
Dim lst As New Dictionary(of String ,DataRow)
For Each dr1 As DataRow In DataTables("采集模板").DataRows
If dr1("车位ID") <> "" And dr1("产品款号") = cpkh Then
Dim nms() As String = dr1("车位ID").Split("_")
Dim v1 As Double = dr1("标准工时") '标准工时
Dim v3 As Double = dr1("标准工价") '标准工价
For Each nm As String In nms
Dim dr2 As DataRow
If lst.ContainsKey(nm)
dr2= lst(nm)
Else
dr2 = DataTables("工位节拍").AddNew()
dr2("车位ID") = nm
lst.add(nm,dr2)
End If
dr2("标准工时") = dr2("标准工时") + v1
dr2("标准工价") = dr2("标准工价") + v3
Next
End If
Next
For Each dr3 As DataRow In DataTables("工位节拍").DataRows
If dr3.IsNull("车位ID") = False
Dim cwid As String = dr3("车位ID")
dr3("工序编号") = DataTables("采集模板").GetComboListString("工序编号","(车位ID = '" & cwid & "' or 车位ID like '" & cwid & "_%' or 车位ID like '%_" & cwid & "' or 车位ID like '%_" & cwid & "_%') and 产品款号 = '"& cpkh &"'").Replace("|","_")
End If
Next
For Each dr1 As DataRow In DataTables("工位节拍").DataRows
dr1("分流工位") = DataTables("工位节拍").Compute("Count([工序编号])","工序编号 = '"& dr1("工序编号") &"'") '工序计数
dr1("节拍工时") = dr1("标准工时") / dr1("分流工位")
dr1("节拍工价") = dr1("标准工价") / dr1("分流工位")
Next
For Each dr4 As DataRow In DataTables("工位节拍").DataRows
If dr4.IsNull("工序编号") Then
dr4("工序道数") = Nothing
Else
dr4("工序道数") = dr4("工序编号").Split("_").Length
dr4("产品款号") = cpkh
End If
Next
Tables("工位节拍").AutoSizeCols()
DataTables("工位节拍").Save()
Dim sql As String
sql = " S elect CycleTime As 日期,StructureID As 班组ID,pc As 批次,jp,TerminalID As 车位ID,PersonnelID As 人员ID,StyleID As 款式ID,AVG(CompleteCount) As 平均,SUM(SAM * CompleteCount) As 定额累计,SUM(UseTime1) As 用时累计,SUM(NormalPrice2 * CompleteCount) As 实现产值 From {BundleCardRecord_2} Where CycleTime = '"& rq &"' and StructureID = '"& bzid &"' And pc = '"& pc &"' GROUP BY CycleTime,StructureID,StyleID,pc,jp,TerminalID,PersonnelID"
Dim b2 As New GroupTableBuilder("实时信息",sql,"MES")
b2.Groups.AddDef("日期",DateGroupEnum.None)
b2.Groups.AddDef("班组ID")
b2.Groups.AddDef("批次")
b2.Groups.AddDef("车位ID")
b2.Groups.AddDef("人员ID")
b2.Groups.AddDef("款式ID")
b2.Totals.AddDef("平均","完成产量")
b2.Totals.AddDef("定额累计")
b2.Totals.AddDef("用时累计")
b2.Totals.AddDef("实现产值")
b2.Build
DataTables("实时信息").DataCols.Add("班组", Gettype(String),16)
DataTables("实时信息").DataCols.Add("工位编号", Gettype(String),16)
DataTables("实时信息").DataCols.Add("姓名", Gettype(String),16)
DataTables("实时信息").DataCols.Add("开始时间", Gettype(Date))
DataTables("实时信息").DataCols.Add("结束时间", Gettype(Date))
DataTables("实时信息").DataCols.Add("计划产量", Gettype(Integer))
DataTables("实时信息").DataCols.Add("剩余产量", Gettype(Integer))
DataTables("实时信息").DataCols.Add("剩余工时", Gettype(String),16)
DataTables("实时信息").DataCols.Add("工序道数", Gettype(Integer))
DataTables("实时信息").DataCols.Add("分流工位", Gettype(Integer))
DataTables("实时信息").DataCols.Add("定额", Gettype(Double))
DataTables("实时信息").DataCols.Add("累计用时", Gettype(String),16)
DataTables("实时信息").DataCols.Add("工效", Gettype(Double))
DataTables("实时信息").DataCols("开始时间").SetDateTimeFormat(DateTimeFormatEnum.DateLongTime)
DataTables("实时信息").DataCols("结束时间").SetDateTimeFormat(DateTimeFormatEnum.DateLongTime)
For Each dr As DataRow In DataTables("实时信息").DataRows
If dr.IsNull("车位ID") = False Then
Dim pr As DataRow = DataTables("工位节拍").Find("车位ID = '" & dr("车位ID") & "'")
If pr IsNot Nothing Then
dr("工序道数") = pr("工序道数")
dr("分流工位") = pr("分流工位")
End If
End If
Next
Dim pr4 As DataRow = DataTables("模拟批次").SQLFind("日期 = '"& rq & "' and 班组 = '" & bz & "' and 批次 = '" & pc & "'")
For Each dr As DataRow In DataTables("实时信息").DataRows
dr("计划产量") = pr4("计划产量") / dr("分流工位")
dr("剩余产量") = dr("计划产量") - dr("完成产量")
dr("定额") = dr("定额累计") / dr("完成产量")
dr("工效") = dr("定额累计") / dr("用时累计") * 100
Dim N2,h2,m2,s2 As Integer
N2 = dr("用时累计")
h2 = N2 \ 3600
m2 = (N2 Mod 3600) \ 60
s2 = N2 Mod 60
dr("累计用时") = Format(new Date(1,1,1,h2,m2,s2), "HH:mm:ss")
Dim N3,h3,m3,s3 As Integer
N3 = dr("定额") * dr("剩余产量")
h3 = N3 \ 3600
m3 = (N3 Mod 3600) \ 60
s3 = N3 Mod 60
dr("剩余工时") = Format(new Date(1,1,1,h3,m3,s3), "HH:mm:ss")
Next
For Each dr As DataRow In DataTables("实时信息").DataRows
If dr.IsNull("人员ID") = False Then
Dim pr As DataRow = DataTables("在线动态").Find("人员ID = '" & dr("人员ID") & "'")
If pr IsNot Nothing Then
dr("班组") = pr("班组")
dr("工位编号") = pr("工位编号")
dr("姓名") = pr("人员姓名")
End If
End If
Next
For Each dr As DataRow In DataTables("实时信息").DataRows
If dr.IsNull("车位ID") = False Then
Dim pr1 As DataRow = DataTables("BundleCardRecord_2").SQLFind("TerminalID = '" & dr("车位ID") & "'and CycleTime = '"& rq & "' and StructureID = '" & bzid & "' and pc = '" & pc & "'","BeginTime")
Dim pr2 As DataRow = DataTables("BundleCardRecord_2").SQLFind("TerminalID = '" & dr("车位ID") & "'and CycleTime = '"& rq & "' and StructureID = '" & bzid & "' and pc = '" & pc & "'","EndTime DESC")
If pr1 IsNot Nothing Then
dr("开始时间") = pr1("BeginTime")
dr("结束时间") = pr2("EndTime")
End If
End If
Next
DataTables("实时信息").SysStyles("Frozen").BackColor = Color.LightCyan
DataTables("实时信息").SysStyles("CurrentRow").BackColor = Color.Blue
DataTables("实时信息").SysStyles("CurrentRow").ForeColor = Color.White
Tables("实时信息").ListMode = True
DataTables("实时信息").GlobalHandler.DrawCell = True '启用DrawCell的全局表事件
Tables("实时信息").AutoSizeCols()
If DataTables.Contains("模拟信息_Table1") = True Then
LockBaseMainForm
Tables("模拟信息_Table1").StopRedraw
End If
Forms("模拟信息").Open
Tables("模拟信息_Table1").DataSource = DataTables("实时信息")
Tables("模拟信息_Table1").Cols("车位ID").Visible = False
Tables("模拟信息_Table1").Cols("人员ID").Visible = False
Tables("模拟信息_Table1").Cols("班组ID").Visible = False
Tables("模拟信息_Table1").Cols("批次").Visible = False
Tables("模拟信息_Table1").Cols("款式ID").Visible = False
Tables("模拟信息_Table1").Cols("定额累计").Visible = False
Tables("模拟信息_Table1").Cols("用时累计").Visible = False
Tables("模拟信息_Table1").Cols("班组").Move(2)
Tables("模拟信息_Table1").Cols("工位编号").Move(3)
Tables("模拟信息_Table1").Cols("姓名").Move(4)
Tables("模拟信息_Table1").Cols("开始时间").Move(5)
Tables("模拟信息_Table1").Cols("结束时间").Move(6)
Tables("模拟信息_Table1").Cols("计划产量").Move(7)
Tables("模拟信息_Table1").Cols("完成产量").Move(8)
Tables("模拟信息_Table1").Cols("剩余产量").Move(9)
Tables("模拟信息_Table1").Cols("剩余工时").Move(10)
Tables("模拟信息_Table1").DataTable.DataCols("开始时间").SetDateTimeFormat(DateTimeFormatEnum.DateLongTime)
Tables("模拟信息_Table1").DataTable.DataCols("结束时间").SetDateTimeFormat(DateTimeFormatEnum.DateLongTime)
Tables("模拟信息_Table1").DataTable.DataCols("实现产值").SetFormat("0.00")
Tables("模拟信息_Table1").DataTable.DataCols("工效").SetFormat("0.00")
Tables("模拟信息_Table1").AutoSizeCols()
Dim t1 As Table = Tables("模拟信息_Table1")
For Each c As Col In t1.Cols
If c.DataCol.IsNumeric = False Then
If c.name <> "姓名" Then
c.TextAlign = TextAlignEnum.Center
End If
End If
If c.name = "工序道数" Or c.name = "分流工位" Then
c.TextAlign = TextAlignEnum.Center
End If
Next
Tables("模拟信息_Table1").ResumeRedraw
UnLockBaseMainForm
Vars("_jssj") = Date.Now