在Web应用程序

时间:2017-12-11 19:03:54

标签: asp.net vb.net for-loop do-loops

因此,我的代码将遍历各种组件,并使用BuildKnittingRecords子集为各种组件创建包。我的代码在为Case "Sleeve", "Front", "Body", "Back"创建捆绑包时效果很好但是当它到达Case "Collar22-32"时,它会卡在do until循环中,因此会继续添加到PnlsToProduce }(直到它崩溃cos数字太大)而不是仅在找到该组件时运行do until循环

Private Sub knittingdetailsheaderdataset()
    bundlenum = 1
    Dim SQL As String
    Dim Adapter As New OleDbDataAdapter
    Dim dt As New DataTable
    Using con As New OleDbConnection(cnString)
        Dim cmd As New OleDbCommand()
        SQL = "Select bla bla
               FROM bla bla
               INNER Join bla bla" 
        (it's a very long sql statement, and not relevent to my issue)
        cmd.Connection = con
        cmd.CommandText = SQL
        Adapter.SelectCommand = cmd
        Adapter.Fill(dt)
        For dr As Integer = 0 To dt.Rows.Count - 1
                componentName = dt(dr)(6)
                knittOrderID = dt(dr)(4)
                componentID = dt(dr)(3)
                sizeID = dt(dr)(5)
                qtyppnl = dt(dr)(10)
                Select Case componentName
                    Case "Sleeve", "Front", "Body", "Back"
                        MxBndleSz = 36
                        PnlsToProduce = dt(dr)(11)
                        BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)                       
                    Case "Collar22-32"
                        MxBndleSz = 200
                        PnlsToProduce = 0
                        Do Until componentName <> "Collar22-32" Or dr = dt.Rows.Count - 1
                            PnlsToProduce += dt(dr)(11)
                        Loop
                        Select Case PnlsToProduce
                            Case 50 To 100
                                PnlsToProduce = PnlsToProduce + 1
                            Case 101 To 250
                                PnlsToProduce = PnlsToProduce + 2
                            Case Is > 250
                                PnlsToProduce = PnlsToProduce + 3
                        End Select
                        BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)
                End Select                  
        Next
    End Using
End Sub

因此我的问题是,为什么要这样做以及如何解决它?

这是我的BuildknittingRecord()子代码,不确定它是否与解决我的问题相关:

Private Sub BuildKnittingRecords(ByRef MaxBundleSz As Integer, ByRef compID As Integer, ByRef sizeID As Integer, ByRef PnlsToproduce As Integer, ByRef QtyPerPanel As Integer, ByRef KnittingOrderID As Integer, ByRef bundlenum As Integer)
    pnls2prod = PnlsToproduce
    Dim cmdstring As String
    Do Until pnls2prod < 10
        If bundlenum < 10 Then
            bundleNo = txtbatchno.Text & "-K0" & bundlenum
        Else
            bundleNo = txtbatchno.Text & "-K" & bundlenum
        End If
        bundlenum += 1
        If pnls2prod <= MaxBundleSz Then
            PanelsToMake = pnls2prod
            cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
            Using con As New OleDbConnection(cnString)
                Dim cmd As New OleDbCommand(cmdstring)
                cmd.CommandType = CommandType.Text
                cmd.Connection = con
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
            End Using
            Exit Do
        Else
            If pnls2prod < 10 Then
                PanelsToMake = pnls2prod + MaxBundleSz
                cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
                Using con As New OleDbConnection(cnString)
                    Dim cmd As New OleDbCommand(cmdstring)
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    cmd.Connection.Open()
                    cmd.ExecuteNonQuery()
                End Using
                Exit Do
            End If
            PanelsToMake = MaxBundleSz
            pnls2prod = pnls2prod - MaxBundleSz
            cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
            Using con As New OleDbConnection(cnString)
                Dim cmd As New OleDbCommand(cmdstring)
                cmd.CommandType = CommandType.Text
                cmd.Connection = con
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
            End Using
        End If
    Loop
End Sub

0 个答案:

没有答案