Imports System.Windows
Imports EgtUILib
Imports EgtWPFLib5

Public Class SectionXMaterial
   Inherits VMBase

   Private Shared m_nType As BWType
   Public Shared ReadOnly Property nType As BWType
      Get
         Return m_nType
      End Get
   End Property
   Public Shared Sub SetType(nType As BWType)
      m_nType = nType
   End Sub

   Protected m_Material As List(Of String)
   Public ReadOnly Property sMaterial As List(Of String)
      Get
         Return m_Material
      End Get
   End Property

   Protected m_MaterialForSameSection_List As New List(Of String)
   Public Property MaterialForSameSection_List As List(Of String)
      Get
         Return m_MaterialForSameSection_List
      End Get
      Set(value As List(Of String))
         m_MaterialForSameSection_List = value
      End Set
   End Property

   Protected m_SelMaterialForSameSection As String
   Public Property SelMaterialForSameSection As String
      Get
         Return m_SelMaterialForSameSection
      End Get
      Set(value As String)
         m_SelMaterialForSameSection = value
      End Set
   End Property

   Protected m_dW As Double = 0
   Public ReadOnly Property dW As Double
      Get
         Return m_dW
      End Get
   End Property

   Protected m_dH As Double = 0
   Public ReadOnly Property dH As Double
      Get
         Return m_dH
      End Get
   End Property

   Protected m_dL As Double = 0
   Public ReadOnly Property dL As Double
      Get
         Return m_dL
      End Get
   End Property

   Public ReadOnly Property sSectionXMaterial As String
      Get
         Dim sAlias As String = String.Empty
         For Each sMatItem In sMaterial
            sAlias &= sMatItem & ";"
         Next
         sAlias = sAlias.TrimEnd(";")
         If Me = Empty Then
            Return ""
         ElseIf m_nType = MachineType.BEAM Then
            Return LenToString(m_dW, 3) & " x " & LenToString(m_dH, 3) & " " & sAlias
         ElseIf m_nType = MachineType.WALL Then
            Return LenToString(m_dH, 3) & " " & sAlias
         Else Return ""
         End If
      End Get
   End Property

   Shared Operator =(ByVal S1 As SectionXMaterial, ByVal S2 As SectionXMaterial) As Boolean
      Return (Math.Abs( S1.m_dH - S2.m_dH) < 100 * EPS_SMALL AndAlso
              Math.Abs( S1.m_dW - S2.m_dW) < 100 * EPS_SMALL AndAlso
              Math.Abs( S1.m_dL - S2.m_dL) < 100 * EPS_SMALL AndAlso
              S1.m_Material.Any(Function(x) S2.m_Material.Any(Function(y) y = x)))
   End Operator

   Shared Operator <>(ByVal S1 As SectionXMaterial, ByVal S2 As SectionXMaterial) As Boolean
      Return Not S1 = S2
   End Operator

   Public Overrides Function Equals(ByVal obj As Object) As Boolean
      If TypeOf obj Is SectionXMaterial Then
         Return Me = DirectCast(obj, SectionXMaterial) '(m_dH = obj.dH AndAlso m_dW = obj.dW AndAlso m_dL = obj.dL AndAlso m_Material.Any(Function(x) DirectCast(obj.sMaterial, List(Of String)).Any(Function(y) y = x)))
      End If
      Return False
   End Function

   Sub New(dW As Double, dH As Double, dL As Double, sMaterial As String)
      If m_nType = BWType.BEAM Then
         m_dW = dW
         m_dH = dH
      ElseIf m_nType = BWType.WALL Then
         m_dH = dH
      Else
         m_dW = dW
         m_dH = dH
         m_dL = dL
      End If
      m_Material = New List(Of String)
      Dim sMaterialArray() As String = Split(sMaterial, ";")
      For Each sMatItem In sMaterialArray
         m_Material.Add(sMatItem)
      Next
   End Sub

   Public Shared Empty As New SectionXMaterial(-1, -1, -1, "")

#Region "Import BTL <-> Warehouse"

   Private m_dNewW As Double
   Public Property dNewW As Double
      Get
         Return m_dNewW
      End Get
      Set(value As Double)
         m_dNewW = value
      End Set
   End Property

   Private m_dNewL As Double
   Public Property dNewL As Double
      Get
         Return m_dNewL
      End Get
      Set(value As Double)
         m_dNewL = value
      End Set
   End Property

   Private m_nQuantity As Integer
   Public Property nQuantity As Integer
      Get
         Return m_nQuantity
      End Get
      Set(value As Integer)
         m_nQuantity = value
      End Set
   End Property

   Private m_Alias_IsEnabled As Boolean
   Public Property Alias_IsEnabled As Boolean
      Get
         Return m_Alias_IsEnabled
      End Get
      Set(value As Boolean)
         m_Alias_IsEnabled = value
      End Set
   End Property

   Private m_Alias_IsChecked As Boolean
   Public Overridable Property Alias_IsChecked As Boolean
      Get
         Return m_Alias_IsChecked
      End Get
      Set(value As Boolean)
         m_Alias_IsChecked = value
      End Set
   End Property

   Public ReadOnly Property L_Msg As String
      Get
         Return EgtMsg(61604)
      End Get
   End Property

   Public ReadOnly Property W_Msg As String
      Get
         Return EgtMsg(61605)
      End Get
   End Property

   Public ReadOnly Property H_Msg As String
      Get
         Return EgtMsg(61606)
      End Get
   End Property

   Public ReadOnly Property Quantity_Msg As String
      Get
         Return EgtMsg(61774)
      End Get
   End Property

   Sub New(dW As Double, dH As Double, dL As Double, sMaterial As String, nQuantity As Integer)
      If m_nType = BWType.BEAM Then
         m_dW = dW
         m_dH = dH
      ElseIf m_nType = BWType.WALL Then
         m_dH = dH
      Else
         m_dW = dW
         m_dH = dH
         m_dL = dL
      End If
      m_Material = New List(Of String)
      Dim sMaterialArray() As String = Split(sMaterial, ";")
      For Each sMatItem In sMaterialArray
         m_Material.Add(sMatItem)
      Next
      m_nQuantity = nQuantity
   End Sub

#End Region ' Import BTL <-> Warehouse

End Class

