Think your job is boring?

Discussion in 'The Cheap Seats' started by Shaun Mason, May 12, 2011.

  1. Shaun Mason

    Shaun Mason Somebody you used to know.

    Joined:
    Feb 9, 2009
    Messages:
    24,887
    Featured Threads:
    5
    This is what I spent the last hour on:

    Code:
    ''' <summary>
    ''' Provides Location Based Services
    ''' </summary>
    Public Class LocationSuggestion
    
    #Region " Class Members "
    
        Private _PossibleLocations As List(Of PrioritizedLocation)
        Private _ConnectionToUse As SqlConnection
        Private _TransactionToUse As SqlTransaction
        Private _ErrorMessage As String
    
    #End Region
    
    #Region " Class Properties "
    
        ''' <summary>
        ''' Gets the error message.
        ''' </summary>
        ''' <value>The error message.</value>
        Public ReadOnly Property ErrorMessage() As String
            Get
                Return _ErrorMessage
            End Get
        End Property
    
    #End Region
    
    #Region " Class Constructor "
    
        ''' <summary>
        ''' Initializes a new instance of the <see cref="LocationSuggestion" /> class.
        ''' </summary>
        Public Sub New(ByVal area As String, _
                       ByRef connectionToUse As SqlConnection, _
                       ByRef errorMessage As String _
        )
            _ErrorMessage = errorMessage
            _ConnectionToUse = connectionToUse
            _TransactionToUse = Nothing
            _PossibleLocations = New List(Of PrioritizedLocation)
            Call LoadPossibleLocations(area)
        End Sub
    
        ''' <summary>
        ''' Initializes a new instance of the <see cref="LocationSuggestion" /> class.
        ''' </summary>
        ''' <param name="area">The area.</param>
        ''' <param name="transactionToUse">The transaction to use.</param>
        ''' <param name="errorMessage">The error message.</param>
        Public Sub New(ByVal area As String, _
                       ByRef transactionToUse As SqlTransaction, _
                       ByRef errorMessage As String _
    )
            _ErrorMessage = errorMessage
            _ConnectionToUse = transactionToUse.Connection
            _TransactionToUse = transactionToUse
            _PossibleLocations = New List(Of PrioritizedLocation)
            Call LoadPossibleLocations(area)
        End Sub
    
    #End Region
    
    #Region " Class Methods "
    
        ''' <summary>
        ''' Alls the locations in use.
        ''' </summary>
        ''' <param name="area">The area.</param>
        ''' <returns></returns>
        Public Function AllLocationsInUse() As Boolean
            Dim AllLocationsUsed As Boolean = True
    
            For Each PotentialSpot As PrioritizedLocation In Me._PossibleLocations
                If Not PotentialSpot.Full Then
                    AllLocationsUsed = False
                End If
            Next
    
            Return AllLocationsUsed
        End Function
    
        ''' <summary>
        ''' Gets the best match.
        ''' </summary>
        ''' <param name="partNumber">The part number.</param>
        ''' <returns></returns>
        Public Function GetBestMatch(ByVal partNumber As String) As String
            Dim BestLocation As String = String.Empty
            Dim HighestLocationPriority As Integer = 0
    
            For Each PotentialSpot As PrioritizedLocation In Me._PossibleLocations
                If PotentialSpot.PartNumber.ToUpper.Trim.Equals(partNumber.ToUpper.Trim) Then
                    If PotentialSpot.LocationPriority > HighestLocationPriority AndAlso Not PotentialSpot.Full Then
                        BestLocation = PotentialSpot.Location
                        HighestLocationPriority = PotentialSpot.LocationPriority
                    End If
                End If
            Next
    
            Return BestLocation
        End Function
    
        ''' <summary>
        ''' Loads the possible locations.
        ''' </summary>
        Private Sub LoadPossibleLocations(ByVal area As String)
            Dim sSQL As String = "SELECT " & _
                                     "LOC.PARTNO AS PARTNO, " & _
                                     "DEPT, " & _
                                     "SUBDEPT, " & _
                                     "LOC_ID, " & _
                                     "ISNULL(QTYPERTOTE, 0) AS [QTYPERTOTE], " & _
                                     "ISNULL(AREAPRIORITY, 0) AS [AREAPRIORITY], " & _
                                     "ISNULL(ROWPRIORITY, 0) AS [ROWPRIORITY], " & _
                                     "ISNULL(LEVELPRIORITY, 0) AS [LEVELPRIORITY], " & _
                                     "ISNULL(LOCATIONPRIORITY, 0) AS [LOCATIONPRIORITY], " & _
                                     "CASE " & _
                                         "WHEN IC.PARTNO IS NULL THEN 0 " & _
                                         "WHEN IC.PARTNO IS NOT NULL THEN 1 " & _
                                     "END AS [FULL] " & _
                                 "FROM " & _
                                     "Inventory_System.dbo.DPD_PART_LOC LOC " & _
                                 "INNER JOIN " & _
                                     "AWD.dbo.AWD_Inventory_Layouts LO ON LO.LOCATION = LOC.LOC_ID " & _
                                 "LEFT JOIN " & _
                                     "Inventory_System.dbo.Inv_Control IC ON LOC.LOC_ID = IC.LOCATION " & _
                                 "WHERE " & _
                                     "UPPER(LTRIM(RTRIM(LO.AREA))) = @AREA " & _
                                 "ORDER BY " & _
                                    "LOC.PARTNO"
            Try
                Dim Retrieve As SqlCommand
    
                If Me._TransactionToUse Is Nothing Then
                    Retrieve = New SqlCommand(sSQL, _ConnectionToUse)
                    If _ConnectionToUse.State = ConnectionState.Closed Then
                        _ConnectionToUse.Open()
                    End If
                Else
                    Retrieve = New SqlCommand(sSQL, _ConnectionToUse, _TransactionToUse)
                End If
    
                Retrieve.Parameters.AddWithValue("@AREA", area.Trim.ToUpper)
    
                Using Reader As SqlClient.SqlDataReader = Retrieve.ExecuteReader
                    While Reader.Read
                        Dim Location As New PrioritizedLocation
                        With Location
                            .PartNumber = Reader.Item("PARTNO").ToString.Trim
                            .Department = Reader.Item("DEPT").ToString
                            .SubDepartment = Reader.Item("SUBDEPT").ToString
                            .Location = Reader.Item("LOC_ID").ToString
                            .QuantityPer = CInt(Reader.Item("QTYPERTOTE"))
                            .AreaPriority = CInt(Reader.Item("AREAPRIORITY"))
                            .RowPriority = CInt(Reader.Item("ROWPRIORITY"))
                            .LevelPriority = CInt(Reader.Item("LEVELPRIORITY"))
                            .LocationPriority = CInt(Reader.Item("LOCATIONPRIORITY"))
                            .Full = CBool(Reader.Item("FULL"))
                        End With
    
                        Me._PossibleLocations.Add(Location)
                    End While
                End Using
    
                If Me._TransactionToUse Is Nothing Then
                    _ConnectionToUse.Close()
                End If
            Catch ex As Exception
                _ErrorMessage = ex.ToString()
            End Try
        End Sub
    
    #End Region
    
    End Class

     
  2. bamagrad

    bamagrad Back to Back British Amateur Champion

    Joined:
    Jun 11, 2009
    Messages:
    2,056
    Looks Like Something from Tron. ;)

    Who could get bored with doing that. :)

    Course I work at Home, so I enjoy that and take care of the Kids.

    Hope yr Week Goes Well Shaun.
     
  3. Colemanchu

    Colemanchu GOAT SPLITTER

    Joined:
    Feb 23, 2009
    Messages:
    7,707
    Yeah but atleast you get 4 days off every week, right?
     
  4. BDSDIGITAL

    BDSDIGITAL One Time for your Mind

    Joined:
    Jun 5, 2009
    Messages:
    8,828
  5. Colemanchu

    Colemanchu GOAT SPLITTER

    Joined:
    Feb 23, 2009
    Messages:
    7,707
    :mad: I just spent 30 seconds waiting for this gif to end.
     
    • Like Like x 2

Share This Page