Imports DBUtilsDataTable
Imports log4net
Imports VCBC_Performance.Balances.Operator.ConfigBalanceActivity.DataAccess

Namespace Balances.Operator.ConfigBalanceActivity.Entities

    Public Class ConfigBalanceActivityManager
        Private Shared ReadOnly log As ILog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)


#Region "constructor"

        Public Sub New(Optional ByVal useEmptyRow As Boolean = False)
            Try
                SetBalanceActivityToList()
            Catch ex As Exception
                log.ErrorFormat(ex.StackTrace)
                log.Error("ConfigBalanceActivityManager() - Load balance activity Failed")
                MsgBox("Fel vid laddning av aktiviteter. Vid upprepning felanmäl felet till SPOC:en", MsgBoxStyle.OkOnly, "Felmeddelande")
                HasError = True
            End Try
        End Sub

        Public Sub New(ByVal processType As String, Optional ByVal useEmptyRow As Boolean = False)
            Try
                SetBalanceActivityToList()
            Catch ex As Exception
                log.ErrorFormat(ex.StackTrace)
                log.Error("ConfigBalanceActivityManager() - Load balance activity Failed")
                MsgBox("Fel vid laddning av aktiviteter. Vid upprepning felanmäl felet till SPOC:en", MsgBoxStyle.OkOnly, "Felmeddelande")
                HasError = True
            End Try
        End Sub

#End Region

#Region "Properties"

        Public Property BalanceActivityList As New List(Of ConfigBalanceActivityItem)
        Public Property HasError() As Boolean = False

        Public ReadOnly Property BalanceActivityTypeListIndex(ByVal balanceActivityTypeID As Integer) As Integer
            Get
                Return GetBalanceActivityListIndex(balanceActivityTypeID)
            End Get
        End Property

#End Region

#Region "Methods"

        Private Sub SetBalanceActivityToList()
            BalanceActivityList.Clear()
            Try
                Dim item1 As New ConfigBalanceActivityItem
                item1.BalanceActivityID = 1
                item1.BalanceActivityName = "End job EOL"
                item1.BalanceActivityDescription = "Stamping"
                item1.ProcessType = "S"
                item1.StandardTime = 2.1F
                BalanceActivityList.Add(item1)

                Dim item2 As New ConfigBalanceActivityItem
                item2.BalanceActivityID = 2
                item2.BalanceActivityName = "Start Job FOL"
                item2.BalanceActivityDescription = "Stamping"
                item2.ProcessType = "S"
                item2.StandardTime = 5.6F
                BalanceActivityList.Add(item2)

                Dim item3 As New ConfigBalanceActivityItem
                item3.BalanceActivityID = 3
                item3.BalanceActivityName = "Start Robot"
                item3.BalanceActivityDescription = "Assy"
                item3.ProcessType = "A"
                item3.StandardTime = 9.4F
                BalanceActivityList.Add(item3)

            Catch ex As Exception
                log.ErrorFormat(ex.StackTrace)
                log.Error("ConfigActivityManager() - Failed when set balance activity to list")
            End Try
        End Sub

#End Region

#Region "Functions"

        Private Function GetBalanceActivityListIndex(ByVal balanceActivityID As Integer) As Integer
            Dim result As Integer = -1I
            Try
                result = BalanceActivityList.FindIndex(Function(item) item.BalanceActivityID = balanceActivityID)
            Catch ex As Exception
                log.ErrorFormat(ex.StackTrace)
                log.Error("ConfigActivityManager() - Failed when get balance activity index")
            End Try

            Return result
        End Function

#End Region

    End Class

End Namespace
