Dim rq As Date = Forms("扎包数据").Controls("DateTimePicker1").Value
Dim y As Integer = rq.Year
Dim m As Integer = rq.Month
Dim dt1 As New Date(y, m, 1) '月初
Dim dt2 As New Date(y, m, Date.DaysInMonth(y, m)) '月底
Dim gwid As String = Forms("扎包数据").Controls("TextBox2").Text
MainTable = Tables("工效分析")
DataTables("工效分析").DataRows.Clear()
'删除条件列
Dim t As Table = Tables("工效分析")
For i As Integer = t.cols.count-1 To 0 Step -1
If t.cols(i).name <> "节拍序号" Then '排除列
t.DataTable.DataCols.Delete(t.cols(i).name)
End If
Next
'动态增加列
Dim b As Integer = DataTables("扎包数据").SQLGetValues("日期", "日期 >= '" & dt1 & "' and 日期 <= '" & dt2 & "'").Count
Dim j As Integer
For j = 1 To b
If DataTables("工效分析").DataCols.Contains("工效_" & j) = False Then
DataTables("工效分析").DataCols.Add("工效_" & j,Gettype(Double))
End If
Next
’填充节拍序号
Dim f As New Filler
f.SourceTable = DataTables("扎包数据") '指定数据来源
f.SourceCols = "节拍序号" '指定数据来源列
f.DataTable = DataTables("工效分析") '指定数据接收表
f.DataCols = "节拍序号" '指定数据接收列
f.Filter = "日期 >= '" & dt1 & "' and 日期 <= '" & dt2 & "'and 工位ID = '" & gwid & "'"
f.ExcludeExistValue = True
f.Fill()
'动态填充表标题
With DataTables("工效分析")
.DataCols("工效_1").Caption = "" ‘时间段内的不重复年月日
.BuildHeader()
End With
'条件填充工效
For Each dr As DataRow In DataTables("工效分析").DataRows
If dr.IsNull("节拍序号") = False Then
Dim pr As DataRow = DataTables("扎包数据").SQLFind("日期 = '" & XXX & "' And 节拍序号 = '" & dr("节拍序号") & "' And 工位ID = '" & gwid & "'")
If pr IsNot Nothing Then
dr("工效") = pr("工效")
End If
End If
Next