Files
effector.plugin.fivelakes/Effector.Plugin.FiveLakes/RestartWnd/RestartWndVM.vb
T
Emmanuele Sassi 717519bb2c - aggiunto debug delle ripartenze
- eliminata colonna quantita' che e' sempre 1
- aggiunto colore di sfondo righe in base allo stato
- aggiunto reset stato porte su reset macchina
- aggiunta eliminazione file di generazione porta su verifica
- aggiunta configurazione per delimitatore csv
- aggiunta gestione cartella separata dei ddf di ogni porta con indice
- aggiunta gestione grafica dello sfrido
- aggiunta posizione porta
- aggiunta progressbar su finestra di verifica
- migliorata gestione pagina di restart
2024-11-08 16:35:06 +01:00

435 lines
16 KiB
VB.net

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.IO
Imports System.Reflection
Public Class RestartWndVM
Inherits VMBase
Friend Event m_CloseWindow(bDialogResult As Boolean)
Private m_sTitle As String = ""
Public ReadOnly Property sTitle As String
Get
Return m_sTitle
End Get
End Property
Private m_nMachineIndex As Integer = 1
Public ReadOnly Property nMachineIndex As Integer
Get
Return m_nMachineIndex
End Get
End Property
Private m_RestartDoorList As ObservableCollection(Of RestartDoor)
Public ReadOnly Property RestartDoorList As ObservableCollection(Of RestartDoor)
Get
Return m_RestartDoorList
End Get
End Property
Private m_sMachineImagePath As String
Public ReadOnly Property sMachineImagePath As String
Get
Return m_sMachineImagePath
End Get
End Property
'Private m_DoorOnMachineArray(4) As RestartDoor
'Public ReadOnly Property DoorOnMachineArray As RestartDoor()
' Get
' Return m_DoorOnMachineArray
' End Get
'End Property
Private m_DoorOnMachineArray As New ObservableCollection(Of RestartDoor)
Public ReadOnly Property DoorOnMachineArray As ObservableCollection(Of RestartDoor)
Get
Return m_DoorOnMachineArray
End Get
End Property
Public ReadOnly Property VariableList As ObservableCollection(Of Variable)
Get
Return Map.refMachinePageVM.VariableList
End Get
End Property
' Definizione comandi
Private m_cmdOk As ICommand
Private m_cmdEmpty As ICommand
#Region "CONSTRUCTOR"
Sub New(nMachineIndex As Integer)
m_nMachineIndex = nMachineIndex
m_sTitle = "Machine " & m_nMachineIndex
If Map.refSupervisorFunction.PlgGetPrivateProfileInt(S_NC, K_NC_SIMULATE, 0) > 0 Then
For nIndex = 0 To 4
Dim dValue As Double = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORPRESENCE & "M" & m_nMachineIndex & "P" & nIndex, 0)
WriteVariableValueToName(nMachineIndex, "@WP_PR_0" & nIndex.ToString(), dValue)
Dim nValue As Integer = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORINDEX & "M" & m_nMachineIndex & "P" & nIndex, 0)
WriteVariableValueToName(nMachineIndex, "@DOORN_S" & nIndex.ToString(), nValue)
Next
End If
Dim sBackupFilePath As String = ""
GetPluginPrivateProfileString("General", "BackupDir", "", sBackupFilePath)
sBackupFilePath &= "\LuaBackup.json"
Dim JsonLuaDoorList As List(Of JsonLuaDoor)
If File.Exists(sBackupFilePath) Then
Dim sReadedFile As String = File.ReadAllText(sBackupFilePath)
JsonLuaDoorList = JsonConvert.DeserializeObject(Of List(Of JsonLuaDoor))(sReadedFile)
JsonLuaDoorList = JsonLuaDoorList.OrderBy(Of Integer)(Function(x) x.nCircIndex).ToList()
End If
' creo posti in lista descrizioni
For nIndex As Integer = 0 To 4
m_DoorOnMachineArray.Add(Nothing)
Next
' leggo presenze porta
For nPositionIndex As Integer = 4 To 0 Step -1
Dim dWPValue As Double = 0
GetVariableValueFromName(nMachineIndex, "@WP_PR_0" & nPositionIndex.ToString(), dWPValue)
If dWPValue <> 0 Then
' verifico indice
Dim nCircindex As Integer = 0
GetVariableValueFromName(nMachineIndex, "@DOORN_S" & nPositionIndex.ToString(), nCircindex)
If nCircindex <> 0 Then
m_DoorOnMachineArray(nPositionIndex) = New RestartDoor(JsonLuaDoorList(nCircindex - 1))
End If
End If
Next
NotifyPropertyChanged(NameOf(DoorOnMachineArray))
'If File.Exists(sBackupFilePath) Then
' Dim sReadedFile As String = File.ReadAllText(sBackupFilePath)
' Dim JsonLuaDoorList As List(Of JsonLuaDoor) = JsonConvert.DeserializeObject(Of List(Of JsonLuaDoor))(sReadedFile)
' JsonLuaDoorList = JsonLuaDoorList.OrderBy(Of Integer)(Function(x) x.nCircIndex).ToList()
' m_RestartDoorList = New ObservableCollection(Of RestartDoor)((From JsonLuaDoor In Map.refDoorListPageVM.DoorList
' Select New RestartDoor(JsonLuaDoor)).ToList())
' For JsonLuaDoorIndex = 0 To JsonLuaDoorList.Count - 1
' Dim JsonLuaDoor As JsonLuaDoor = JsonLuaDoorList(JsonLuaDoorIndex)
' Dim RestartDoor As RestartDoor = m_RestartDoorList.FirstOrDefault(Function(x) x.nId = JsonLuaDoor.nId)
' If Not IsNothing(RestartDoor) Then
' RestartDoor.Update(JsonLuaDoor)
' End If
' Next
'End If
' se macchina 1
Dim sResourcesDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_RESOURCESDIR, "", sResourcesDirPath)
m_sMachineImagePath = sResourcesDirPath & "\Multiax-C1223Ripartenza.png"
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Public Shared Function GetVariableValueFromName(nMachIndex As Integer, sName As String, ByRef nValue As Integer) As Boolean
Dim Variable As Variable = Map.refMachinePageVM.VariableList.FirstOrDefault(Function(x) x.nMachine = nMachIndex AndAlso x.sName = sName)
If IsNothing(Variable) Then Return False
Dim nIndex As Integer = 0
If Not Integer.TryParse(Variable.sIndex, nIndex) Then Return False
Return Map.refSupervisorFunction.ComReadShortVar(nIndex, nValue, nMachIndex)
End Function
Public Shared Function GetVariableValueFromName(nMachIndex As Integer, sName As String, ByRef dValue As Double) As Boolean
Dim Variable As Variable = Map.refMachinePageVM.VariableList.FirstOrDefault(Function(x) x.nMachine = nMachIndex AndAlso x.sName = sName)
If IsNothing(Variable) Then Return False
Dim nIndex As Integer = 0
If Not Integer.TryParse(Variable.sIndex, nIndex) Then Return False
Return Map.refSupervisorFunction.ComReadDoubleVar(nIndex, dValue, nMachIndex)
End Function
Public Shared Function WriteVariableValueToName(nMachIndex As Integer, sName As String, nValue As Integer) As Boolean
Dim Variable As Variable = Map.refMachinePageVM.VariableList.FirstOrDefault(Function(x) x.nMachine = nMachIndex AndAlso x.sName = sName)
If IsNothing(Variable) Then Return False
Dim nIndex As Integer = 0
If Not Integer.TryParse(Variable.sIndex, nIndex) Then Return False
Return Map.refSupervisorFunction.ComWriteShortVar(nIndex, nValue, nMachIndex)
End Function
Public Shared Function WriteVariableValueToName(nMachIndex As Integer, sName As String, dValue As Double) As Boolean
Dim Variable As Variable = Map.refMachinePageVM.VariableList.FirstOrDefault(Function(x) x.nMachine = nMachIndex AndAlso x.sName = sName)
If IsNothing(Variable) Then Return False
Dim nIndex As Integer = 0
If Not Integer.TryParse(Variable.sIndex, nIndex) Then Return False
Return Map.refSupervisorFunction.ComWriteDoubleVar(nIndex, dValue, nMachIndex)
End Function
#End Region ' METHODS
#Region "COMMANDS"
#Region "Ok"
Public ReadOnly Property Ok_Command As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf Ok)
End If
Return m_cmdOk
End Get
End Property
Public Sub Ok()
RaiseEvent m_CloseWindow(True)
End Sub
#End Region ' Ok
#Region "Empty"
Public ReadOnly Property Empty_Command As ICommand
Get
If m_cmdEmpty Is Nothing Then
m_cmdEmpty = New Command(AddressOf Empty)
End If
Return m_cmdEmpty
End Get
End Property
Public Sub Empty()
Map.refDoorListPageVM.ResetProductionQueue()
Map.refDoorListPageVM.WriteBackup()
RaiseEvent m_CloseWindow(False)
End Sub
#End Region ' Empty
#End Region ' COMMANDS
End Class
Public Class StateToVisibilityConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsNothing(value) OrElse Not TypeOf value Is Integer Then Return Visibility.Collapsed
Return If(value > 0, Visibility.Visible, Visibility.Collapsed)
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class VariableNameToVisibilityConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If IsNothing(value) OrElse Not TypeOf value Is Integer Then Return Visibility.Collapsed
If IsNothing(parameter) OrElse Not TypeOf parameter Is String OrElse String.IsNullOrWhiteSpace(parameter) Then Return Visibility.Collapsed
Dim nMachineIndex As Integer = 0
If Not Integer.TryParse(value, nMachineIndex) Then Return Visibility.Collapsed
Dim dWPValue As Double = 0
RestartWndVM.GetVariableValueFromName(nMachineIndex, "@" & parameter, dWPValue)
Return If(dWPValue = 1 OrElse dWPValue = 2 OrElse dWPValue = 3, Visibility.Visible, Visibility.Collapsed)
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Public Class RestartDoor
Inherits VMBase
Private m_nId As Integer = -1
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_nCircIndex As Integer = -1
Public ReadOnly Property nCircIndex As Integer
Get
Return m_nCircIndex
End Get
End Property
Private m_nState As Integer = 0
Public ReadOnly Property nState As Integer
Get
Return m_nState
End Get
End Property
Private m_DoorStateList As New List(Of IdNameStruct)({New IdNameStruct(0, "Not On Machine"),
New IdNameStruct(1, "Imported"),
New IdNameStruct(2, "On Load"),
New IdNameStruct(3, "On Machine 1"),
New IdNameStruct(4, "On Medium Station"),
New IdNameStruct(6, "On Machine 2"),
New IdNameStruct(7, "On Unload"),
New IdNameStruct(8, "Produced"),
New IdNameStruct(100, "Scrap")})
Public ReadOnly Property DoorStateList As List(Of IdNameStruct)
Get
Return m_DoorStateList
End Get
End Property
Public Property SelDoorState As IdNameStruct
Get
Return m_DoorStateList.FirstOrDefault(Function(x) x.Id = m_nState)
End Get
Set(value As IdNameStruct)
m_nState = value.Id
End Set
End Property
Private m_sDoorCode As String = ""
Public ReadOnly Property sDoorCode As String
Get
Return m_sDoorCode
End Get
End Property
Private m_sDoorDescription As String = ""
Public ReadOnly Property sDoorDescription As String
Get
Return m_sDoorDescription
End Get
End Property
Private m_sDDFName As String = ""
Public ReadOnly Property sDDFName As String
Get
Return m_sDDFName
End Get
End Property
Private m_sCSVName As String = ""
Public ReadOnly Property sCSVName As String
Get
Return m_sCSVName
End Get
End Property
Private m_sM1CNPath As String = ""
Public ReadOnly Property sM1CNPath As String
Get
Return m_sM1CNPath
End Get
End Property
Private m_sM2CNPath As String = ""
Public ReadOnly Property sM2CNPath As String
Get
Return m_sM2CNPath
End Get
End Property
Private m_dtLoadTime As DateTime
Public ReadOnly Property sLoadTime As String
Get
Return m_dtLoadTime.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Private m_dtMachining1Start As DateTime
Public ReadOnly Property sMachining1Start As String
Get
Return m_dtMachining1Start.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Private m_dtMachining1End As DateTime
Public ReadOnly Property sMachining1End As String
Get
Return m_dtMachining1End.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Private m_dtMachining2Start As DateTime
Public ReadOnly Property sMachining2Start As String
Get
Return m_dtMachining2Start.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Private m_dtMachining2End As DateTime
Public ReadOnly Property sMachining2End As String
Get
Return m_dtMachining2End.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Private m_dtUnloadTime As DateTime
Public ReadOnly Property sUnloadTime As String
Get
Return m_dtUnloadTime.ToString("yy/MM/dd HH:mm:ss")
End Get
End Property
Sub New(Id As Integer, IndiceCirc As Integer, Stato As Integer, CodicePorta As String, DescrizionePorta As String, NomeDDF As String, NomeCSV As String,
CN_macchina_1 As String, CN_macchina_2 As String, tempo_carico As Long, tempo_inizio_lav_1 As Long, tempo_fine_lav_1 As Long, tempo_inizio_lav_2 As Long,
tempo_fine_lav_2 As Long, tempo_scarico As Long)
m_nId = Id
m_nCircIndex = IndiceCirc
m_nState = Stato
m_sDoorCode = CodicePorta
m_sDoorDescription = DescrizionePorta
m_sDDFName = NomeDDF
m_sCSVName = NomeCSV
m_sM1CNPath = CN_macchina_1
m_sM2CNPath = CN_macchina_2
m_dtLoadTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_carico).ToLocalTime()
m_dtMachining1Start = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_inizio_lav_1).ToLocalTime()
m_dtMachining1End = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_fine_lav_1).ToLocalTime()
m_dtMachining2Start = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_inizio_lav_2).ToLocalTime()
m_dtMachining2End = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_fine_lav_2).ToLocalTime()
m_dtUnloadTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tempo_scarico).ToLocalTime()
End Sub
Sub New(Door As Door)
m_nId = Door.nId
m_nCircIndex = 0
m_nState = 0
m_sDDFName = Door.sDDFName
m_sCSVName = Door.sCSVName
m_sM1CNPath = ""
m_sM2CNPath = ""
m_dtLoadTime = DateTime.MinValue
m_dtMachining1Start = DateTime.MinValue
m_dtMachining1End = DateTime.MinValue
m_dtMachining2Start = DateTime.MinValue
m_dtMachining2End = DateTime.MinValue
m_dtUnloadTime = DateTime.MinValue
End Sub
Friend Sub New(JsonLuaDoor As JsonLuaDoor)
m_nId = JsonLuaDoor.nId
m_nCircIndex = JsonLuaDoor.nCircIndex
m_nState = JsonLuaDoor.nState
m_sDDFName = JsonLuaDoor.sDDFName
m_sCSVName = JsonLuaDoor.sCSVName
m_sM1CNPath = JsonLuaDoor.sM1CNPath
m_sM2CNPath = JsonLuaDoor.sM2CNPath
m_dtLoadTime = JsonLuaDoor.dtLoadTime
m_dtMachining1Start = JsonLuaDoor.dtMachining1Start
m_dtMachining1End = JsonLuaDoor.dtMachining1End
m_dtMachining2Start = JsonLuaDoor.dtMachining2Start
m_dtMachining2End = JsonLuaDoor.dtMachining2End
m_dtUnloadTime = JsonLuaDoor.dtUnloadTime
End Sub
End Class