Imports System.Collections.ObjectModel Imports EgtWPFLib5 Imports EgtUILib Imports EgtBEAMWALL.Core Imports System.Windows.Threading Imports EgtBEAMWALL.DataLayer.DatabaseModels Imports EgtBEAMWALL.Core.MachLog Public Class MachineLogPageVM Inherits VMBase Private m_colMachineLog_Type As EgtDataGridColumn Public ReadOnly Property colMachineLog_Type As EgtDataGridColumn Get Return m_colMachineLog_Type End Get End Property Private m_colMachineLog_Description As EgtDataGridColumn Public ReadOnly Property colMachineLog_Description As EgtDataGridColumn Get Return m_colMachineLog_Description End Get End Property Private m_colMachineLog_SupervisorId As EgtDataGridColumn Public ReadOnly Property colMachineLog_SupervisorId As EgtDataGridColumn Get Return m_colMachineLog_SupervisorId End Get End Property Private m_MachineLogColumns As New ObservableCollection(Of EgtDataGridColumn) Public Property MachineLogColumns As ObservableCollection(Of EgtDataGridColumn) Get Return m_MachineLogColumns End Get Set(value As ObservableCollection(Of EgtDataGridColumn)) m_MachineLogColumns = value End Set End Property Private m_MachineLogList_View As CollectionView = Nothing Private m_MachineLogList As New ObservableCollection(Of LogEvent) Public Property MachineLogList As ObservableCollection(Of LogEvent) Get Return m_MachineLogList End Get Set(value As ObservableCollection(Of LogEvent)) m_MachineLogList = value End Set End Property Private m_MachLogTypeList As New List(Of MachLogType)({New MachLogType(MachLogTypes.PART_STATUS, "PartStatus", True), New MachLogType(MachLogTypes.MACHGROUP_STATUS, "MachGroupStatus", True), New MachLogType(MachLogTypes.MACHINE_MODE, "MachineMode", True), New MachLogType(MachLogTypes.ALARM, "Alarm", True)}) Public Property MachLogTypeList As List(Of MachLogType) Get Return m_MachLogTypeList End Get Set(value As List(Of MachLogType)) m_MachLogTypeList = value End Set End Property Private m_PartEventTypeList As New List(Of String)({"", "Inizio", "Fine"}) Public ReadOnly Property PartEventTypeList As List(Of String) Get Return m_PartEventTypeList End Get End Property Private m_SelPartEventType As Integer Public Property SelPartEventType As Integer Get Return m_SelPartEventType End Get Set(value As Integer) m_SelPartEventType = value m_MachineLogList_View.Refresh() End Set End Property Private m_EntityTypeList As New List(Of String)({"", "Pezzo", "Barra"}) Public ReadOnly Property EntityTypeList As List(Of String) Get Return m_EntityTypeList End Get End Property Private m_SelEntityType As Integer Public Property SelEntityType As Integer Get Return m_SelEntityType End Get Set(value As Integer) m_SelEntityType = value m_MachineLogList_View.Refresh() End Set End Property ' Definizione comandi Private m_cmdRefresh As ICommand #Region "Messages" Public ReadOnly Property EventDateTime_Msg As String Get Return EgtMsg(62512) End Get End Property Public ReadOnly Property EventType_Msg As String Get Return EgtMsg(62513) End Get End Property Public ReadOnly Property EventValue_Msg As String Get Return EgtMsg(62514) End Get End Property Public ReadOnly Property SupervisorId_Msg As String Get Return EgtMsg(62515) End Get End Property Public ReadOnly Property ProdId_Msg As String Get Return EgtMsg(62516) End Get End Property Public ReadOnly Property MachGroupId_Msg As String Get Return EgtMsg(62517) End Get End Property Public ReadOnly Property PartId_Msg As String Get Return EgtMsg(62518) End Get End Property Public ReadOnly Property Status_Msg As String Get Return EgtMsg(62519) End Get End Property #End Region ' Messages #Region "CONSTRUCTORS" Sub New() ' imposto riferimento in Map Map.SetRefMachineLogPageVM(Me) ' carico le colonne della datagrid GetPrivateProfileColumns(S_MACHINELOG, MachineLogColumns) m_MachineLogList_View = CollectionViewSource.GetDefaultView(m_MachineLogList) m_MachineLogList_View.Filter = AddressOf MachineLogFilter ' recupero riferimento a colonna StartCut m_colMachineLog_Type = m_MachineLogColumns.FirstOrDefault(Function(x) x.Name = COL_TYPE) m_colMachineLog_Description = m_MachineLogColumns.FirstOrDefault(Function(x) x.Name = COL_DESCRIPTION) m_colMachineLog_SupervisorId = m_MachineLogColumns.FirstOrDefault(Function(x) x.Name = COL_SUPERVISORID) End Sub #End Region ' CONSTRUCTORS #Region "METHODS" Private Function MachineLogFilter(CurrEvent As Object) As Boolean Dim CurrLogEvent As LogEvent = DirectCast(CurrEvent, LogEvent) Dim bOk As Boolean = True ' se livello utente inferiore a 5, mostro solo eventi pezzo e machgroup If Map.refMainWindowVM.MainWindowM.nUserLevel < 5 Then If CurrLogEvent.EventType <> LogEvent.MachLogTypes.PART_STATUS AndAlso CurrLogEvent.EventType <> LogEvent.MachLogTypes.MACHGROUP_STATUS Then Return False End If End If Select Case m_SelEntityType Case 0 ' "" bOk = bOk And True Case 1 ' "Pezzo" bOk = bOk And CurrLogEvent.EventType = LogEvent.MachLogTypes.PART_STATUS Case 2 ' "Barra" bOk = bOk And CurrLogEvent.EventType = LogEvent.MachLogTypes.MACHGROUP_STATUS End Select If CurrLogEvent.EventType = LogEvent.MachLogTypes.PART_STATUS OrElse CurrLogEvent.EventType = LogEvent.MachLogTypes.MACHGROUP_STATUS Then Select Case m_SelPartEventType Case 0 ' "" bOk = bOk And True Case 1 ' "Inizio" bOk = bOk And CurrLogEvent.nStatus = 1 Case 2 ' "Fine" bOk = bOk And CurrLogEvent.nStatus = 2 End Select End If Return bOk End Function Friend Sub LoadMachineLogList() If Map.refMainWindowVM.MainWindowM.nUserLevel < 5 Then m_colMachineLog_Type.ColumnVisibility = Visibility.Collapsed m_colMachineLog_Description.ColumnVisibility = Visibility.Collapsed m_colMachineLog_SupervisorId.ColumnVisibility = Visibility.Collapsed End If UpdateMachineLogList() m_MachineLogList_View = CollectionViewSource.GetDefaultView(m_MachineLogList) m_MachineLogList_View.Filter = AddressOf MachineLogFilter End Sub Friend Sub UpdateMachineLogList() m_MachineLogList = New ObservableCollection(Of LogEvent)(DbControllers.m_LogMachineController.GetCoreDesc(DateTime.Now - TimeSpan.FromDays(300), DateTime.Now).Select(Of LogEvent)(Function(x) New LogEvent(x)).ToList()) NotifyPropertyChanged(NameOf(MachineLogList)) m_MachineLogList_View = CollectionViewSource.GetDefaultView(m_MachineLogList) m_MachineLogList_View.Filter = AddressOf MachineLogFilter End Sub #End Region ' METHODS #Region "COMMANDS" #Region "Refresh" ''' ''' Returns a command that do Open. ''' Public ReadOnly Property Refresh_Command As ICommand Get If m_cmdRefresh Is Nothing Then m_cmdRefresh = New Command(AddressOf Refresh) End If Return m_cmdRefresh End Get End Property ''' ''' Execute the Open. This method is invoked by the OpenCommand. ''' Friend Sub Refresh() UpdateMachineLogList() End Sub #End Region ' Refresh #End Region ' COMMANDS End Class Public Class MachLogType Inherits VMBase Private m_nId As Integer Public ReadOnly Property nId As Integer Get Return m_nId End Get End Property Private m_sName As String Public ReadOnly Property sName As String Get Return m_sName End Get End Property Private m_bOn As Boolean = False Public Property bOn As Boolean Get Return m_bOn End Get Set(value As Boolean) m_bOn = value End Set End Property Sub New(nId As Integer, sName As String, bOn As Boolean) m_nId = nId m_sName = sName m_bOn = bOn End Sub End Class