Foxtable(狐表)用户栏目专家坐堂 → 运行程序就未响应,是不是for循环太多了。怎么改


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

主题:运行程序就未响应,是不是for循环太多了。怎么改

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


加好友 发短信
等级:童狐 帖子:204 积分:1738 威望:0 精华:0 注册:2018/8/23 14:16:00
运行程序就未响应,是不是for循环太多了。怎么改  发帖心情 Post By:2020/5/14 9:50:00 [只看该作者]

Dim kh As WinForm.ComboBox = e.Form.Controls("款号")
Dim jj As WinForm.CheckedComboBox = e.Form.Controls("季节")
Dim pl As WinForm.ComboBox = e.Form.Controls("品类")
Dim pm As WinForm.ComboBox = e.Form.Controls("品名")
Dim drts As WinForm.TextBox = e.Form.Controls("调入天数")
Dim cks As WinForm.CheckedComboBox = e.Form.Controls("仓库")

Dim Filter As String
Dim cnt As Integer
Dim dr As DataRow
Dim dc As DataRow


If DeleteFilter.Length>0 Then
    Dim Values() As String
    Values = DeleteFilter.Split(",")
    For Index As Integer = 0 To Values.Length-1
        DataTables("库存分发总部库存").DataCols.Delete(Values(Index))
    Next
End If
If cks.Text.Length>0 Then
    DeleteFilter = cks.text
    For Each ck As DataRow In DataTables("销售统计").Select("仓库 In ('" & cks.text.replace(",", "','") & "')")
        DataTables("库存分发总部库存").DataCols.Add(ck("仓库"),Gettype(String), "")
    Next
Else
    For Each ck As DataRow In DataTables("销售统计").Select("")
        If DataTables("库存分发总部库存").DataCols.Contains(ck("仓库")) Then
        Else
            DataTables("库存分发总部库存").DataCols.Add(ck("仓库"),Gettype(String), "")
        End If
    Next
End If


Filter="款号 Like '" & kh.Value & "%' and 品类 Like '*" & pl.Value & "'and 品名 like '*" & pm.Value & "'And 数量>'0'"
If jj.Text.Length>0 Then
    Filter = Filter & "and 季节 in ('" & jj.text.replace(",", "','") & "')"
End If
Tables("库存分发总部库存").Filter=Filter



For Each drs As DataRow In DataTables("库存分发总部库存").Select(Filter)
    cnt=drs("数量")
    For Each v As String In DataTables("销售统计").GetValues("仓库","仓库 In ('" & cks.text.replace(",", "','") & "')","销售总金额 desc")
        If DataTables("转仓单明细").Compute("sum(数量)","款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "'and 仓库='" & v & "'") = 0 Then
            If cnt > 0 Then
                drs(v) = 1
                cnt = cnt - 1
            Else
                drs(v) = Nothing
            End If
        End If
    Next
    If cnt>0 Then
        For Each ck As String In DataTables("销售款号统计").GetValues("仓库","款号='" & drs("款号") & "' And 花色码='" & drs("花色码") & "' and 尺码码 = '" & drs("尺码码") & "'","数量 desc")
            If DataTables("销售统计").Find("仓库='"& ck &"'and 仓库 In ('" & cks.text.replace(",", "','") & "')") IsNot Nothing Then
                If DataTables("库存表").Compute("sum(数量)","款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 仓库='" & ck & "'") <= 0 Then
                    If drts.Text.Length>0 Then
                        dr=DataTables("转仓单明细").Find("款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 仓库='" & ck & "'","日期")
                        dc=DataTables("转仓单明细").Find("款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 调出仓库='" & ck & "'","日期")
                        If dc IsNot Nothing And dr IsNot Nothing Then
                            Dim t1 As TimeSpan =  dc("日期") - dr("日期")
                            If t1.TotalDays<drts.Text
                                If cnt > 0 Then
                                    drs(ck) = 1
                                    cnt = cnt - 1
                                Else
                                    drs(ck) = Nothing
                                End If
                            End If
                        End If
                    Else
                        If cnt > 0 Then
                            drs(ck) = 1
                            cnt = cnt - 1
                        Else
                            drs(ck) = Nothing
                        End If
                    End If
                End If
            End If
        Next
    End If
    If cnt>0 Then
        For Each cv As String In DataTables("销售统计").GetValues("仓库","仓库 In ('" & cks.text.replace(",", "','") & "')","销售总金额 desc")
            If DataTables("库存表").Compute("sum(数量)","款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 仓库='" & cv & "'") <= 0 Then
                If drts.Text.Length>0 Then
                    dr=DataTables("转仓单明细").Find("款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 仓库='" & cv & "'","日期")
                    dc=DataTables("转仓单明细").Find("款号='" & drs("款号") & "' And 花色='" & drs("花色") & "' and 尺码 = '" & drs("尺码") & "' and 调出仓库='" & cv & "'","日期")
                    If dc IsNot Nothing And dr IsNot Nothing Then
                        Dim t1 As TimeSpan =  dc("日期") - dr("日期")
                        If t1.TotalDays<drts.Text
                            If cnt > 0 Then
                                drs(cv) = 1
                                cnt = cnt - 1
                            Else
                                drs(cv) = Nothing
                            End If
                        End If
                    End If
                Else
                    If cnt > 0 Then
                        drs(cv) = 1
                        cnt = cnt - 1
                    Else
                        drs(cv) = Nothing
                    End If
                End If
            End If
        Next
    End If
    drs("剩余")=cnt
Next

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


加好友 发短信
等级:超级版主 帖子:106207 积分:540158 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/5/14 10:00:00 [只看该作者]

我也判断不了是什么问题。调试技巧:http://www.foxtable.com/webhelp/scr/1485.htm

可以参考下面的代码计算一下各段代码执行的时间,看哪一段代码慢:

Dim t1 As Date = Date.Now
Dim 
Sum As Long
For 
i As Integer = 1 To 10000000
    Sum = Sum + i

Next

Output.Show(
"计算结束, 耗时: " & (Date.Now - t1).TotalSeconds & "秒"
)



另外可以看看:http://www.foxtable.com/webhelp/topics/2225.htm



 回到顶部