此主题相关图片如下:无标题.png
代码如下,老师看一下有没有优化的空间!
Dim tb As Table = Tables(e.Form.Name & "_Table3")
Dim dt As DataTable = tb.DataTable
Dim nmls As new List(of String)
Dim nmts As new List(of String)
Dim zd As New Dictionary(Of String, String)
zd.Clear
For Each c As Col In tb.Cols
If c.Name.StartsWith("处理结果_") Then
zd.Add(c.Caption,c.Name)
Dim cs() As String = c.Caption.Split("_")
If nmls.Contains(cs(0)) = False Then nmls.Add(cs(0))
If nmts.Contains(c.Caption) = False Then nmts.Add(c.Caption)
End If
Next
Dim nms() As String = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"}
For Each nm As String In nms
If nmls.Contains(nm) Then
Dim cn As String = Nothing
For Each c As Col In tb.Cols
If c.Caption.StartsWith(nm & "_") Then
If cn > "" Then cn &= " + "
cn &= zd(c.Caption)
End If
Next
dt.DataCols.Add(nm & "_合计",Gettype(Double), cn)
If nmts.Contains(nm & "_合格") Then dt.DataCols.Add(nm & "_合格率",Gettype(Double), "[" & zd(nm & "_合格") & "] / [" & nm & "_合计" & "]" )
If nmts.Contains(nm & "_退货") Then dt.DataCols.Add(nm & "_合格率",Gettype(Double), "[" & zd(nm & "_退货") & "] / [" & nm & "_合计" & "]" )
End If
Next