Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I am trying to write a function to return the Top Level assembly(s) that a component is used on.

There are two tables involved, BomHeader, which has assembly codes, and BomDetail which has the assembly code repeated for each component code that makes up the assembly

I'm heading in this direction, but just cant seem to get my head around this.

VB
Private Function GetWhereUsedProduct(ByRef WhComp As String) As String
        'Assumes dtBom Detail has already been loaded
        Dim Component As String = WhComp

        dvBom.Sort = "WhComp"
        Dim Stk As New Stack
        Dim FoundRows() As DataRowView
        Dim result As String

        FoundRows = dvBom.FindRows(Component)
        If FoundRows.Length = 0 Then
            Return "No Usages"
        ElseIf FoundRows.Length = 1 Then
            Return FoundRows(0).Item(1)
        Else
            For i As Integer = 0 To FoundRows.Length - 1
                Stk.Push(FoundRows(i).Item(1))
            Next
        End If

        Do While Stk.Count > 0
            FoundRows = dvBom.FindRows(Stk.Pop)
            If FoundRows.Length = 1 Then
                result += FoundRows(0).Item(1) & ", "
            ElseIf FoundRows.Length > 1 Then
                For j As Integer = 0 To FoundRows.GetUpperBound(0) - 1
                    Stk.Push(FoundRows(j).Item(1))
                Next
            End If
        Loop
        Return result

    End Function


I can offer more detail on the tables or exactly what I am asking as it is rather difficult to put in words but I'm hoping someone has done this before and understands what i mean

The above code returns some assemblies correctly, but sometimes it returns an assembly that is not a Top Level Assembly, and on some components it returns a blank string, but the component does have usages?
Posted
Updated 21-Feb-13 7:15am
v2

1 solution

This solved the problem

VB
Private Function GetWhereUsedProduct(ByRef WhComp As String) As String

        Dim Component As String = WhComp
        dvBom.Sort = "WhComp"
        Dim Stk As New Stack
        Dim FoundRows() As DataRowView
        Dim result As String
        Dim stkItem As StackItem

        'Foundrows(0) = WHComp
        'Foundrows(1) = WHAssy
        'Foundrows(2) = WPD
        FoundRows = dvBom.FindRows(Component)
        If FoundRows.Length = 0 Then
            Return "No Usages"
        Else
            For i As Integer = 0 To FoundRows.Length - 1
                stkItem = New StackItem
                stkItem.WHAssy = FoundRows(i).Item(1)
                stkItem.WPD = FoundRows(i).Item(2)
                Stk.Push(stkItem)
            Next
        End If

        Do While Stk.Count > 0
            stkItem = Stk.Pop

            FoundRows = dvBom.FindRows(stkItem.WHAssy)

            If FoundRows.Length = 0 Then
                result += stkItem.WPD & ", "
            Else

                For j As Integer = 0 To FoundRows.Length - 1
                    stkItem = New StackItem
                    stkItem.WHAssy = FoundRows(j).Item(1)
                    stkItem.WPD = FoundRows(j).Item(2)
                    Stk.Push(stkItem)
                Next
            End If
        Loop
        Return result

    End Function

End Class


#Region "Class: StackObject"
 Public Class StackItem
    Dim _WHAssy As String
    Dim _WPD As String

    Public Property WHAssy() As String
        Get
            Return _WHAssy
        End Get
        Set(ByVal GuiMethod As String)
            _WHAssy = GuiMethod
        End Set
    End Property

    Public Property WPD() As String
        Get
            Return _WPD
        End Get
        Set(ByVal GuiMethod As String)
            _WPD = GuiMethod
        End Set
    End Property

End Class

#End Region
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900