Foxtable(狐表)用户栏目专家坐堂 → [求助]请老师帮我写个根据要求抽取数据的代码


  共有3776人关注过本帖树形打印复制链接

主题:[求助]请老师帮我写个根据要求抽取数据的代码

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 11:43:00 [显示全部帖子]

Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "日期,卷号")
drs(0)("投料量")=drs(0)("重量")
For i As Integer = 1 To drs.Count - 1
    If drs(i)("卷号") <> drs(i-1)("卷号") AndAlso drs(i)("卷号").Contains(drs(i-1)("卷号")) Then
        drs(i)("投料量") = drs(i)("重量") / (drs(i)("重量")+drs(i+1)("重量")) * drs(i-1)("重量")
        drs(i+1)("投料量") = drs(i+1)("重量") / (drs(i)("重量")+drs(i+1)("重量")) * drs(i-1)("重量")
        i += 1
    Else
        drs(i)("投料量") = drs(i)("重量")
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 12:43:00 [显示全部帖子]

Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "日期,卷号")
drs(0)("投料量")=drs(0)("重量")
Dim tll As Double = drs(0)("重量")
For i As Integer = 1 To drs.Count - 1
    If drs(i)("卷号") = drs(i-1)("卷号")
        drs(i)("投料量") = tll
    Else If drs(i)("卷号").Contains(drs(i-1)("卷号")) Then
        drs(i)("投料量") = drs(i)("重量") / (drs(i)("重量")+drs(i+1)("重量")) * drs(i-1)("投料量")
        drs(i+1)("投料量") = drs(i+1)("重量") / (drs(i)("重量")+drs(i+1)("重量")) * drs(i-1)("投料量")
        i += 1
        tll = drs(i)("投料量")
    Else
        tll = drs(i)("重量")
        drs(i)("投料量") = tll
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 15:17:00 [显示全部帖子]

 汗

 

Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "日期,卷号")
drs(0)("投料量")=drs(0)("重量")
Dim tll As Double = drs(0)("重量")
For i As Integer = 1 To drs.Count - 1
    If drs(i)("卷号") = drs(i-1)("卷号")
        drs(i)("投料量") = tll
    Else
        Dim fdr As DataRow = DataTables("轧机1号").Find("卷号 = '" & drs(i)("卷号").Substring(0,drs(i)("卷号").length - 1)  & "'")
        If fdr IsNot Nothing Then
            Dim drs_temp As List(of DataRow) = DataTables("轧机1号").Select("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = '" & fdr("卷号") & "' and len(卷号) = " & drs(i)("卷号").Length, "日期")
            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
            drs(i)("投料量") = drs(i)("重量") / zl * fdr("投料量")
            tll = drs(i)("投料量")
        Else
            tll = drs(i)("重量")
            drs(i)("投料量") = tll
        End If
    End If
Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 17:22:00 [显示全部帖子]

Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "卷号")
drs(0)("投料量")=drs(0)("重量")
Dim tll As Double = drs(0)("重量")
Dim dic As New Dictionary(Of String, Double())
For i As Integer = 1 To drs.Count - 1
    If drs(i)("卷号") = drs(i-1)("卷号")
        drs(i)("投料量") = tll
    Else
        Dim str As String = drs(i)("卷号").Substring(0,drs(i)("卷号").length - 1)
        If dic.ContainsKey(str) = False Then
            Dim fdr As DataRow = DataTables("轧机1号").Find("卷号 = '" & str  & "'", "起始时间")
            If fdr IsNot Nothing Then
                Dim drs_temp As List(of DataRow) = DataTables("轧机1号").Select("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = '" & fdr("卷号") & "' and len(卷号) = " & drs(i)("卷号").Length, "卷号")
                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, fdr("投料量")})
            Else
                tll = drs(i)("重量")
                drs(i)("投料量") = tll
                Continue For
            End If
        End If
        drs(i)("投料量") = drs(i)("重量") / dic(str)(0) * dic(str)(1)
        tll = drs(i)("投料量")
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 18:11:00 [显示全部帖子]

以下是引用huangfanzi在2015-1-11 17:51:00的发言:
甜老师,代码放入项目文件执行后完全正确了,但效率问题还是没解决,整张表执行完用了5分钟,有什么办法改善吗?

 

没办法改善的,最多如下。如果要改,就多加两列 父重量、子重量

 

DataTables("轧机1号").StopRedraw
Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "卷号")
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 - 1)
        If dic.ContainsKey(str) = False Then
            Dim fdr As DataRow = DataTables("轧机1号").Find("卷号 = '" & str  & "'", "起始时间")
            If fdr IsNot Nothing Then
                Dim drs_temp As List(of DataRow) = DataTables("轧机1号").Select("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = '" & fdr("卷号") & "' and len(卷号) = " & drs(i)("卷号").Length, "卷号")
                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, fdr("投料量")})
            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
DataTables("轧机1号").ResumeRedraw


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 19:24:00 [显示全部帖子]

DataTables("轧机1号").StopRedraw
Dim drs As List(Of DataRow) = DataTables("轧机1号").Select("", "卷号")
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 - 1)
        If dic.ContainsKey(str) = False Then
            Dim fdr As DataRow = DataTables("轧机1号").Find("卷号 = '" & str  & "'", "起始时间")
            If fdr IsNot Nothing Then
                Dim drs_temp As List(of DataRow) = DataTables("轧机1号").Select("substring(卷号,1," & drs(i)("卷号").Length - 1 & ") = '" & fdr("卷号") & "' and len(卷号) = " & drs(i)("卷号").Length, "卷号")
                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
                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
DataTables("轧机1号").ResumeRedraw

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/1/11 20:12:00 [显示全部帖子]

 
ALterLoad事件

e.form.baseform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
 

 回到顶部