3f11963c4f
- aggiornata versione
824 lines
34 KiB
VB.net
824 lines
34 KiB
VB.net
Imports Newtonsoft.Json
|
|
Imports Newtonsoft.Json.Linq
|
|
Imports System.Collections.ObjectModel
|
|
Imports System.Globalization
|
|
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports Effector.Plugin.Lib
|
|
Imports Effector.Plugin.FiveLakes.Door
|
|
|
|
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
|
|
|
|
Private m_DoorToBeFixedList As New ObservableCollection(Of DoorToBeFixed)
|
|
Public ReadOnly Property DoorToBeFixedList As ObservableCollection(Of DoorToBeFixed)
|
|
Get
|
|
Return m_DoorToBeFixedList
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property VariableList As ObservableCollection(Of Variable)
|
|
Get
|
|
Return Map.refMachinePageVM.VariableList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_OkBtn_Visibility As Visibility = True
|
|
Public ReadOnly Property OkBtn_Visibility As Visibility
|
|
Get
|
|
Return m_OkBtn_Visibility
|
|
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
|
|
' scrive tutte le variabili dell'intera linea
|
|
'For nIndex = 0 To 4
|
|
' Dim dValue As Double = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORPRESENCE & "M1P" & nIndex, 0)
|
|
' WriteVariableValueToName(1, "@WP_PR_0" & nIndex.ToString(), dValue)
|
|
' Dim nValue As Integer = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORINDEX & "M1P" & nIndex, 0)
|
|
' WriteVariableValueToName(1, "@DOORN_S" & nIndex.ToString(), nValue)
|
|
' dValue = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORPRESENCE & "M2P" & nIndex, 0)
|
|
' WriteVariableValueToName(2, "@WP_PR_0" & nIndex.ToString(), dValue)
|
|
' nValue = GetPluginPrivateProfileDouble(S_DEBUG, K_DOORINDEX & "M2P" & nIndex, 0)
|
|
' WriteVariableValueToName(2, "@DOORN_S" & nIndex.ToString(), nValue)
|
|
'Next
|
|
End If
|
|
|
|
' riporto lista porte su log
|
|
Map.refMachinePageVM.PrintAllDoorInList()
|
|
' riporto lista variabili macchina su log
|
|
Map.refMachinePageVM.PrintAllVariableInLog()
|
|
|
|
Dim sBackupFilePath As String = ""
|
|
GetPluginPrivateProfileString("General", "BackupDir", "", sBackupFilePath)
|
|
sBackupFilePath &= "\LuaBackup.json"
|
|
|
|
Dim JsonLuaDoorList As List(Of JsonLuaDoor) = Nothing
|
|
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()
|
|
' riporto lista porte come letta da Json
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors read from json start")
|
|
Map.refSupervisorFunction.PlgOutLog("CircIndex Id State DDFName")
|
|
For Each Door In JsonLuaDoorList
|
|
Map.refSupervisorFunction.PlgOutLog(Door.nCircIndex & " " & Door.nId & " " & Door.nState & " " & Door.sDDFName)
|
|
Next
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors read from json end")
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: File json does not exist!")
|
|
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
|
|
If Not IsNothing(JsonLuaDoorList) AndAlso JsonLuaDoorList(nCircindex - 1).nId > 0 Then
|
|
m_DoorOnMachineArray(nPositionIndex) = New RestartDoor(JsonLuaDoorList(nCircindex - 1))
|
|
Else
|
|
m_OkBtn_Visibility = Visibility.Collapsed
|
|
NotifyPropertyChanged(NameOf(OkBtn_Visibility))
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
NotifyPropertyChanged(NameOf(DoorOnMachineArray))
|
|
|
|
' riporto lista porte dopo verifica presenza
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors for restart window start")
|
|
Map.refSupervisorFunction.PlgOutLog("Position CircIndex Id State DDFName")
|
|
For DoorIndex = 0 To m_DoorOnMachineArray.Count - 1
|
|
Dim Door As RestartDoor = m_DoorOnMachineArray(DoorIndex)
|
|
If IsNothing(Door) Then
|
|
Map.refSupervisorFunction.PlgOutLog(DoorIndex & " Empty")
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog(DoorIndex & " " & Door.nCircIndex & " " & Door.nId & " " & Door.nState & " " & Door.sDDFName)
|
|
End If
|
|
Next
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors for restart window end")
|
|
|
|
' percorro la lista lua
|
|
If Not IsNothing(JsonLuaDoorList) Then
|
|
For LuaDoorIndex = 0 To JsonLuaDoorList.Count - 1
|
|
Dim LuaDoor As JsonLuaDoor = JsonLuaDoorList(LuaDoorIndex)
|
|
If nMachineIndex = 1 Then
|
|
' verifico che in base allo stato siano in una posizione conforme, altrimenti li azzero
|
|
Select Case LuaDoor.nState
|
|
Case 1, 2 ' IMPORTED, SENT_1
|
|
Dim nCircIndex0 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S0", nCircIndex0)
|
|
If nCircIndex0 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
Case 3 ' START_MACHINING_1
|
|
Dim nCircIndex0 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S0", nCircIndex0)
|
|
Dim nCircIndex1 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S1", nCircIndex1)
|
|
Dim nCircIndex2 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S2", nCircIndex2)
|
|
If nCircIndex0 <> LuaDoor.nCircIndex AndAlso nCircIndex1 <> LuaDoor.nCircIndex AndAlso nCircIndex2 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
Case 4 ' MACHINED_1
|
|
Dim nCircIndex2 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S2", nCircIndex2)
|
|
Dim nCircIndex3 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S3", nCircIndex3)
|
|
Dim nCircIndex4 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S4", nCircIndex4)
|
|
If nCircIndex2 <> LuaDoor.nCircIndex AndAlso nCircIndex3 <> LuaDoor.nCircIndex AndAlso nCircIndex4 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
End Select
|
|
ElseIf nMachineIndex = 2 Then
|
|
Select Case LuaDoor.nState
|
|
Case 5 ' SENT_2
|
|
Dim nCircIndex0 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S0", nCircIndex0)
|
|
If nCircIndex0 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
Case 6 ' START_MACHINING_2
|
|
Dim nCircIndex0 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S0", nCircIndex0)
|
|
Dim nCircIndex1 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S1", nCircIndex1)
|
|
Dim nCircIndex2 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S2", nCircIndex2)
|
|
If nCircIndex0 <> LuaDoor.nCircIndex AndAlso nCircIndex1 <> LuaDoor.nCircIndex AndAlso nCircIndex2 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
Case 7 ' MACHINED_2
|
|
Dim nCircIndex2 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S2", nCircIndex2)
|
|
Dim nCircIndex3 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S3", nCircIndex3)
|
|
Dim nCircIndex4 As Integer = 0
|
|
GetVariableValueFromName(nMachineIndex, "@DOORN_S4", nCircIndex4)
|
|
If nCircIndex2 <> LuaDoor.nCircIndex AndAlso nCircIndex3 <> LuaDoor.nCircIndex AndAlso nCircIndex4 <> LuaDoor.nCircIndex Then
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End If
|
|
Case 8 ' UNLOADED
|
|
ResetLuaDoor(LuaDoorIndex, JsonLuaDoorList)
|
|
End Select
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
' riporto lista porte che scrivo su json
|
|
If IsNothing(JsonLuaDoorList) Then
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: File json does not exist!")
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors to be written on json start")
|
|
Map.refSupervisorFunction.PlgOutLog("CircIndex Id State DDFName")
|
|
For Each Door In JsonLuaDoorList
|
|
Map.refSupervisorFunction.PlgOutLog(Door.nCircIndex & " " & Door.nId & " " & Door.nState & " " & Door.sDDFName)
|
|
Next
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors to be written on json end")
|
|
End If
|
|
|
|
' aggiorno file backup del lua
|
|
If File.Exists(sBackupFilePath) Then
|
|
Try
|
|
File.Delete(sBackupFilePath)
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
Dim sWriteFile As String = JsonConvert.SerializeObject(JsonLuaDoorList, Formatting.Indented)
|
|
File.WriteAllText(sBackupFilePath, sWriteFile)
|
|
End If
|
|
|
|
' verifico se in lista porte ci sono porte non gestite
|
|
|
|
For DoorIndex = 0 To Map.refDoorListPageVM.DoorList.Count - 1
|
|
Dim CurrDoor As Door = Map.refDoorListPageVM.DoorList(DoorIndex)
|
|
Select Case CurrDoor.nState
|
|
Case Door.DoorStates.PRODUCED
|
|
Continue For
|
|
Case Door.DoorStates.MACHINE_2_END
|
|
If nMachineIndex = 1 Then Continue For
|
|
' cerco porta tra quelle in restart
|
|
If Not IdIsInRestartList(CurrDoor.nId) Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
Case Door.DoorStates.MACHINE_2_START
|
|
If nMachineIndex = 1 Then Continue For
|
|
' cerco porta tra quelle in restart
|
|
If Not IdIsInRestartList(CurrDoor.nId) Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
Case Door.DoorStates.MACHINE_1_END
|
|
If nMachineIndex = 2 Then
|
|
Dim bOnMachine1 As Boolean = False
|
|
' verifico che l'id sia in Json Door
|
|
Dim Machine1EndDoor As JsonLuaDoor = JsonLuaDoorList.FirstOrDefault(Function(x) x.nId = CurrDoor.nId)
|
|
If Not IsNothing(Machine1EndDoor) Then
|
|
' verifico che l'id sia in qualche posizione
|
|
For nPositionIndex As Integer = 4 To 0 Step -1
|
|
Dim dWPValue As Double = 0
|
|
GetVariableValueFromName(1, "@WP_PR_0" & nPositionIndex.ToString(), dWPValue)
|
|
If dWPValue <> 0 Then
|
|
' verifico indice
|
|
Dim nCircindex As Integer = 0
|
|
GetVariableValueFromName(1, "@DOORN_S" & nPositionIndex.ToString(), nCircindex)
|
|
If nCircindex = Machine1EndDoor.nCircIndex Then
|
|
bOnMachine1 = True
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
End If
|
|
If Not bOnMachine1 Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
Else
|
|
' cerco porta tra quelle in restart
|
|
If Not IdIsInRestartList(CurrDoor.nId) Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
End If
|
|
Case Door.DoorStates.MACHINE_1_START
|
|
If nMachineIndex = 2 Then Continue For
|
|
' cerco porta tra quelle in restart
|
|
If Not IdIsInRestartList(CurrDoor.nId) Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
Case Door.DoorStates.ON_LOAD_STATION
|
|
If nMachineIndex = 2 Then Continue For
|
|
' cerco porta tra quelle in restart
|
|
If Not IdIsInRestartList(CurrDoor.nId) Then
|
|
m_DoorToBeFixedList.Add(New DoorToBeFixed(CurrDoor, nMachineIndex))
|
|
End If
|
|
End Select
|
|
Next
|
|
|
|
' riporto lista porte non gestite
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors not managed from list start")
|
|
Map.refSupervisorFunction.PlgOutLog("Id State")
|
|
For Each Door In m_DoorToBeFixedList
|
|
Map.refSupervisorFunction.PlgOutLog(Door.nId & " " & Door.SelState)
|
|
Next
|
|
Map.refSupervisorFunction.PlgOutLog("Machine" & nMachineIndex & ".lua: Doors not managed from list end")
|
|
|
|
' riporto lista porte su log
|
|
Map.refMachinePageVM.PrintAllDoorInList()
|
|
|
|
'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
|
|
|
|
' carico immagine della macchina
|
|
Dim sResourcesDirPath As String = ""
|
|
GetPluginPrivateProfileString(S_GENERAL, K_RESOURCESDIR, "", sResourcesDirPath)
|
|
m_sMachineImagePath = sResourcesDirPath & "\Machine" & m_nMachineIndex & ".png"
|
|
End Sub
|
|
|
|
Private Function IdIsInRestartList(nId As Integer) As Boolean
|
|
For Each Door In m_DoorOnMachineArray
|
|
If IsNothing(Door) Then Continue For
|
|
If Door.nId = nId Then Return True
|
|
Next
|
|
Return False
|
|
End Function
|
|
|
|
Private Sub ResetLuaDoor(Index As Integer, LuaDoorList As List(Of JsonLuaDoor))
|
|
LuaDoorList(Index) = New JsonLuaDoor(0, LuaDoorList(Index).nCircIndex, 0, "", "", "", "", "", "", 0, 0, 0, 0, 0, 0)
|
|
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()
|
|
' se ci sono porte da sistemare
|
|
If m_DoorToBeFixedList.Count > 0 Then
|
|
' verifico se devo cambiarne l'ordine
|
|
For Each ToBeFixedDoor In m_DoorToBeFixedList
|
|
Dim Door As Door = Map.refDoorListPageVM.DoorList.FirstOrDefault(Function(x) x.nId = ToBeFixedDoor.nId)
|
|
If ToBeFixedDoor.SelState = Door.DoorStates.NOTPRODUCE Then
|
|
Dim DoorIndex As Integer = Map.refDoorListPageVM.DoorList.IndexOf(Door)
|
|
For Index = 0 To Map.refDoorListPageVM.DoorList.Count - 1
|
|
If Map.refDoorListPageVM.DoorList(Index).nState < Door.DoorStates.READY_FOR_PRODUCTION Then
|
|
Map.refDoorListPageVM.DoorList.Move(DoorIndex, If(Index > 0, Index - 1, 0))
|
|
Exit For
|
|
End If
|
|
Next
|
|
Door.SetState(Door.DoorStates.NOTPRODUCE)
|
|
ElseIf ToBeFixedDoor.SelState = Door.DoorStates.READY_FOR_PRODUCTION Then
|
|
Door.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
|
|
Door.SetProdState(Door.DoorProdStates.NOT_INIT)
|
|
'Door.SetLoadTime(0)
|
|
'Door.SetMachining1Start(0)
|
|
'Door.SetMachining1End(0)
|
|
'Door.SetMachining2Start(0)
|
|
'Door.SetMachining2End(0)
|
|
'Door.SetUnloadTime(0)
|
|
ElseIf ToBeFixedDoor.SelState = Door.DoorStates.PRODUCED Then
|
|
Door.SetState(Door.DoorStates.PRODUCED)
|
|
Door.SetProdState(Door.DoorProdStates.UNLOADED)
|
|
If Door.dtMachining2End = DateTime.MinValue Then
|
|
Door.SetMachining2End(DateTime.Now)
|
|
End If
|
|
If Door.dtUnloadTime = DateTime.MinValue Then
|
|
Door.SetUnloadTime(DateTime.Now)
|
|
End If
|
|
End If
|
|
Next
|
|
End If
|
|
Map.refDoorListPageVM.NotifyPropertyChanged(NameOf(Map.refDoorListPageVM.DoorList))
|
|
RaiseEvent m_CloseWindow(True)
|
|
End Sub
|
|
|
|
Private Function IdIsInToBeFixedList(nId As Integer) As Boolean
|
|
For Each Door In m_DoorToBeFixedList
|
|
If IsNothing(Door) Then Continue For
|
|
If Door.nId = nId Then Return True
|
|
Next
|
|
Return False
|
|
End Function
|
|
|
|
#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()
|
|
Dim sDoorToRemove As String = ""
|
|
For DoorIndex As Integer = 0 To m_DoorOnMachineArray.Count - 1
|
|
Dim DoorToRemove As RestartDoor = m_DoorOnMachineArray(DoorIndex)
|
|
If Not IsNothing(DoorToRemove) Then
|
|
sDoorToRemove &= "- " & DoorToRemove.nId & DoorToRemove.sCSVName & If(DoorIndex > m_DoorOnMachineArray.Count - 1, Environment.NewLine, "")
|
|
End If
|
|
Next
|
|
MessageBox.Show("Are you sure you want to empty the machine?" & Environment.NewLine &
|
|
If(Not String.IsNullOrWhiteSpace(sDoorToRemove), "You have to remove doors:" & Environment.NewLine & sDoorToRemove, "") & Environment.NewLine &
|
|
"You have to reset the machine and then restart it.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
|
|
' se ci sono porte sulla macchina
|
|
If m_DoorOnMachineArray.Count > 0 Then
|
|
For Each DoorOnmachine In m_DoorOnMachineArray
|
|
If Not IsNothing(DoorOnmachine) Then
|
|
Dim Door As Door = Map.refDoorListPageVM.DoorList.FirstOrDefault(Function(x) x.nId = DoorOnmachine.nId)
|
|
If Not IsNothing(Door) Then
|
|
Door.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
|
|
Door.SetProdState(Door.DoorProdStates.NOT_INIT)
|
|
End If
|
|
End If
|
|
Next
|
|
End If
|
|
' se ci sono porte da sistemare
|
|
If m_DoorToBeFixedList.Count > 0 Then
|
|
' verifico se devo cambiarne l'ordine
|
|
For Each ToBeFixedDoor In m_DoorToBeFixedList
|
|
Dim Door As Door = Map.refDoorListPageVM.DoorList.FirstOrDefault(Function(x) x.nId = ToBeFixedDoor.nId)
|
|
If Not IsNothing(Door) Then
|
|
Door.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
|
|
Door.SetProdState(Door.DoorProdStates.NOT_INIT)
|
|
End If
|
|
Next
|
|
End If
|
|
' imposto stato di reset
|
|
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 ListEmptyToVisibilityConverter
|
|
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 IList Then Return Visibility.Collapsed
|
|
Dim List As IList = DirectCast(value, IList)
|
|
Return If(List.Count > 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 DoorToBeFixed
|
|
|
|
Private m_nId As Integer = -1
|
|
Public ReadOnly Property nId As Integer
|
|
Get
|
|
Return m_nId
|
|
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_nOldState As DoorStates
|
|
Public ReadOnly Property nOldState As DoorStates
|
|
Get
|
|
Return m_nOldState
|
|
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_StateList As New ObservableCollection(Of Door.DoorStates)
|
|
Public ReadOnly Property StateList As ObservableCollection(Of Door.DoorStates)
|
|
Get
|
|
Return m_StateList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelState As Door.DoorStates
|
|
Public Property SelState As Door.DoorStates
|
|
Get
|
|
Return m_SelState
|
|
End Get
|
|
Set(value As Door.DoorStates)
|
|
m_SelState = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Door As Door, nMachineIndex As Integer)
|
|
m_nId = Door.nId
|
|
m_sDDFName = Door.sDDFName
|
|
m_nOldState = Door.nState
|
|
m_sCSVName = Door.sCSVName
|
|
If nMachineIndex = 1 Then
|
|
m_StateList = New ObservableCollection(Of Door.DoorStates)({Door.DoorStates.READY_FOR_PRODUCTION, Door.DoorStates.NOTPRODUCE})
|
|
ElseIf nMachineIndex = 2 Then
|
|
m_StateList = New ObservableCollection(Of Door.DoorStates)({Door.DoorStates.READY_FOR_PRODUCTION, Door.DoorStates.NOTPRODUCE, Door.DoorStates.PRODUCED})
|
|
End If
|
|
m_SelState = Door.DoorStates.NOTPRODUCE
|
|
End Sub
|
|
|
|
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 |