Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
 
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 21-Feb-13 6:17am
Edited 21-Feb-13 8:15am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This solved the problem
 
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
  Permalink  

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

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100