Public Class MachLog

#Region "Private Fields"

   Public Enum MachLogTypes
      PART_STATUS = 1
      MACHGROUP_STATUS = 2
      MACHINE_MODE = 3
      MACHINE_STATUS = 4
      MACHINE_COMMAND = 5
      READ_VAR = 6
      WRITE_VAR = 7
      ALARM = 8
      OPERATOR_MSG = 9
      PROGRAM_SEND = 10
   End Enum

   Private m_AlarmCode As String
   Private m_AlarmDateTime As DateTime
   Private m_AlarmMessage As String
   Private m_AlarmOperation As Integer
   Private m_AlarmType As Integer
   Private m_CommandExecutedCorrectly As Boolean
   Private m_CommandState As CommandStates
   Private m_CommandType As LogCommandTypes
   Private m_Description As String
   Private m_newOpState As Integer
   Private m_ResultType As ResultTypes
   Private m_VarAddress As String
   Private m_VarValue As String

   ' variabili del log macchina
   Public ReadOnly Property EventType As MachLogTypes
      Get
         Return m_ResultType
      End Get
   End Property
   Public ReadOnly Property EventDateTime As DateTime
      Get
         Return m_AlarmDateTime
      End Get
   End Property
   Public ReadOnly Property EventValue As String
      Get
         Return m_VarValue
      End Get
   End Property

   Public ReadOnly Property sEventType As String
      Get
         Select Case m_ResultType
            Case MachLogTypes.PART_STATUS
               Return String.Format("({0}) Stato pezzo", 1)
            Case MachLogTypes.MACHGROUP_STATUS
               Return String.Format("({0}) Stato barra", 2)
            Case MachLogTypes.MACHINE_MODE = 3
               Return String.Format("({0}) Modalità macchina", 3)
            Case MachLogTypes.MACHINE_STATUS = 4
               Return String.Format("({0}) Stato macchina", 4)
            Case MachLogTypes.MACHINE_COMMAND = 5
               Return String.Format("({0}) Comando macchina", 5)
            Case MachLogTypes.READ_VAR = 6
               Return String.Format("({0}) Lettura variabile", 6)
            Case MachLogTypes.WRITE_VAR = 7
               Return String.Format("({0}) Scrittura variabile", 7)
            Case MachLogTypes.ALARM = 8
               Return String.Format("({0}) Allarme", 8)
            Case MachLogTypes.OPERATOR_MSG = 9
               Return String.Format("({0}) Messaggio opertore", 9)
            Case MachLogTypes.PROGRAM_SEND = 10
               Return String.Format("({0}) Invio programma", 10)
            Case Else
               Return "Altro"
         End Select
      End Get
   End Property
   Public ReadOnly Property sEventDateTime As String
      Get
         Return m_AlarmDateTime
      End Get
   End Property
   Public ReadOnly Property sEventValue As String
      Get
         Return m_VarValue
      End Get
   End Property

   Public ReadOnly Property sPROD As String
      Get
         Return m_VarValue
      End Get
   End Property

#End Region

#Region "Protected Constructors"

   Protected Sub New()
      m_AlarmCode = ""
      m_AlarmDateTime = DateTime.MinValue
      m_AlarmMessage = ""
      m_AlarmOperation = 0
      m_AlarmType = 0
      m_CommandExecutedCorrectly = False
      m_CommandState = CommandStates.NULL
      m_CommandType = LogCommandTypes.NULL
      m_Description = ""
      m_newOpState = 0
      m_ResultType = ResultTypes.NULL
      m_VarAddress = ""
      m_VarValue = ""
   End Sub

#End Region

#Region "Public Properties"

   Public ReadOnly Property AlarmCode As String
      Get
         Return m_AlarmCode
      End Get
   End Property

   Public ReadOnly Property AlarmDateTime As Date
      Get
         Return m_AlarmDateTime
      End Get
   End Property

   Public ReadOnly Property AlarmMessage As String
      Get
         Return m_AlarmMessage
      End Get
   End Property

   Public ReadOnly Property AlarmOperation As Integer
      Get
         Return m_AlarmOperation
      End Get
   End Property

   Public ReadOnly Property AlarmType As Integer
      Get
         Return m_AlarmType
      End Get
   End Property

   Public ReadOnly Property CommandExecutedCorrectly As Boolean
      Get
         Return m_CommandExecutedCorrectly
      End Get
   End Property

   Public ReadOnly Property CommandState As CommandStates
      Get
         Return m_CommandState
      End Get
   End Property

   Public ReadOnly Property CommandType As LogCommandTypes
      Get
         Return m_CommandType
      End Get
   End Property

   Public ReadOnly Property Description As String
      Get
         Return m_Description
      End Get
   End Property

   Public ReadOnly Property newOpState As Integer
      Get
         Return m_newOpState
      End Get
   End Property

   Public ReadOnly Property ResultType As ResultTypes
      Get
         Return m_ResultType
      End Get
   End Property

   Public ReadOnly Property VarAddress As String
      Get
         Return m_VarAddress
      End Get
   End Property

   Public ReadOnly Property VarValue As String
      Get
         Return m_VarValue
      End Get
   End Property

#End Region

#Region "Internal Methods"

   Public Shared Function CreateAlarmLog(AlarmOperation As Integer, AlarmType As Integer, AlarmMessage As String, AlarmCode As String, AlarmDateTime As String)
      Dim NewMachLog As New MachLog
      NewMachLog.m_CommandType = LogCommandTypes.ALARM
      NewMachLog.m_AlarmOperation = AlarmOperation
      NewMachLog.m_AlarmType = AlarmType
      NewMachLog.m_AlarmMessage = AlarmMessage
      NewMachLog.m_AlarmCode = AlarmCode
      DateTime.TryParse(AlarmDateTime, NewMachLog.m_AlarmDateTime)
      Return NewMachLog
   End Function

   Public Shared Function CreateOPStateLog(newOpState As Integer)
      Dim NewMachLog As New MachLog
      NewMachLog.m_CommandType = LogCommandTypes.NEWOP
      NewMachLog.m_newOpState = newOpState
      NewMachLog.m_AlarmDateTime = DateTime.Now()
      Return NewMachLog
   End Function

   Public Shared Function CreateReadLog(CommandExecutedCorrectly As Boolean, VarAddress As String, VarValue As String)
      Dim NewMachLog As New MachLog
      NewMachLog.m_CommandType = CommandTypes.READ_TPA
      NewMachLog.m_CommandExecutedCorrectly = CommandExecutedCorrectly
      NewMachLog.m_VarAddress = VarAddress
      NewMachLog.m_VarValue = VarValue
      NewMachLog.m_AlarmDateTime = DateTime.Now()
      Return NewMachLog
   End Function

   Public Shared Function CreateResultLog(CommandType As LogCommandTypes, CommandState As CommandStates, ResultType As ResultTypes, Description As String)
      Dim NewMachLog As New MachLog
      NewMachLog.m_CommandType = CommandType
      NewMachLog.m_CommandState = CommandState
      NewMachLog.m_ResultType = ResultType
      NewMachLog.m_Description = Description
      NewMachLog.m_AlarmDateTime = DateTime.Now()
      Return NewMachLog
   End Function

   Public Shared Function CreateMachLog(EventType As MachLogTypes, EventDateTime As DateTime, Value As String, SupervisorID As String)
      Dim NewMachEvent As New MachLog
      NewMachEvent.m_ResultType = EventType
      NewMachEvent.m_AlarmDateTime = EventDateTime
      NewMachEvent.m_VarValue = Value
      NewMachEvent.m_VarAddress = SupervisorID
      Return NewMachEvent
   End Function

#End Region

#Region "Public Methods"

   Public Shared Function CreateMachLog(AlarmCode As String, AlarmDateTime As Date, AlarmMessage As String, AlarmOperation As Integer, AlarmType As Integer, CommandExecutedCorrectly As Boolean, CommandState As CommandStates, CommandType As LogCommandTypes, Description As String, newOpState As Integer, ResultType As ResultTypes, VarAddress As String, VarValue As String) As MachLog

      Dim NewMachLog As New MachLog
      NewMachLog.m_AlarmCode = AlarmCode
      NewMachLog.m_AlarmDateTime = AlarmDateTime
      NewMachLog.m_AlarmMessage = AlarmMessage
      NewMachLog.m_AlarmOperation = AlarmOperation
      NewMachLog.m_AlarmType = AlarmType
      NewMachLog.m_CommandExecutedCorrectly = CommandExecutedCorrectly
      NewMachLog.m_CommandState = CommandState
      NewMachLog.m_CommandType = CommandType
      NewMachLog.m_Description = Description
      NewMachLog.m_newOpState = newOpState
      NewMachLog.m_ResultType = ResultType
      NewMachLog.m_VarAddress = VarAddress
      NewMachLog.m_VarValue = VarValue

      Return NewMachLog
   End Function

#End Region

End Class