以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  运行程序就未响应,是不是for循环太多了。怎么改  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=149865)

--  作者:zaq3574020
--  发布时间:2020/5/14 9:50:00
--  运行程序就未响应,是不是for循环太多了。怎么改
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

--  作者:有点蓝
--  发布时间: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