65dee8bf4c
-> aggiornamento automatico della lista "PartList"; -> verifica funzionamento ultima versione.
491 lines
17 KiB
VB.net
491 lines
17 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class WarehouseVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private m_GridBoxesV As GridBoxesV
|
|
|
|
' identificativo del magazzino: A=2, B=1
|
|
Private m_Id As Warehouses
|
|
Public ReadOnly Property Id As Warehouses
|
|
Get
|
|
Return m_Id
|
|
End Get
|
|
End Property
|
|
|
|
' stato del magazzino (può essere disponibile ma non attivo)
|
|
Private m_State As States
|
|
Friend ReadOnly Property State As States
|
|
Get
|
|
Return m_State
|
|
End Get
|
|
End Property
|
|
|
|
' identifica se il magazzino corrente è attivo
|
|
Private m_IsActive As Boolean = True
|
|
Friend ReadOnly Property IsActive As Boolean
|
|
Get
|
|
Return m_IsActive
|
|
End Get
|
|
End Property
|
|
|
|
' definisce il magazzino in uso-> disabilita le selezioni da interfaccia
|
|
Private m_IsEnable As Boolean = True
|
|
Public ReadOnly Property IsEnabled As Boolean
|
|
Get
|
|
m_IsEnable = Not (m_IsActive Or m_State = States.AVAILABLE)
|
|
Return m_IsEnable
|
|
End Get
|
|
End Property
|
|
|
|
'-----------------------------------------------------------------------------
|
|
' queste propprietà sono state spostate all'interno della GridBoxVM
|
|
Private m_Configuration As ConfigWarehose = ConfigWarehose.PALLET
|
|
Public ReadOnly Property Configuration As ConfigWarehose
|
|
Get
|
|
Return m_Configuration
|
|
End Get
|
|
End Property
|
|
|
|
' associato al bottone "Pallet"
|
|
Private m_IsPallet As Boolean
|
|
Public Property IsPallet As Boolean
|
|
Get
|
|
Return m_IsPallet
|
|
End Get
|
|
Set(value As Boolean)
|
|
If value Then
|
|
m_Configuration = ConfigWarehose.PALLET
|
|
m_IsPallet = value
|
|
m_IsRack = Not value
|
|
End If
|
|
NotifyPropertyChanged("IsRack")
|
|
End Set
|
|
End Property
|
|
|
|
' Associato al bottone "Rack"
|
|
Private m_IsRack As Boolean
|
|
Public Property IsRack As Boolean
|
|
Get
|
|
Return m_IsRack
|
|
End Get
|
|
Set(value As Boolean)
|
|
If value Then
|
|
m_Configuration = ConfigWarehose.RACK
|
|
m_IsRack = value
|
|
m_IsPallet = Not value
|
|
End If
|
|
NotifyPropertyChanged("IsPallet")
|
|
End Set
|
|
End Property
|
|
|
|
'-----------------------------------------------------------------------------
|
|
|
|
' lista dei Box contenuti nella Werahouse
|
|
Private m_Boxes As New ObservableCollection(Of Box)
|
|
Public Property Boxes As ObservableCollection(Of Box)
|
|
Get
|
|
Return m_Boxes
|
|
End Get
|
|
Set(value As ObservableCollection(Of Box))
|
|
m_Boxes = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_nColumnWarehouse As Integer = 3
|
|
' lista delle colonne magazzino
|
|
Private m_GridBoxList As New ObservableCollection(Of GridBoxesVM)
|
|
Public ReadOnly Property GridBoxList As ObservableCollection(Of GridBoxesVM)
|
|
Get
|
|
Return m_GridBoxList
|
|
End Get
|
|
End Property
|
|
|
|
' configurazione colonne in magazzino-> utilizzato solo nella Init() per inizializzare le colonne
|
|
Private m_ConfigurationList As New ObservableCollection(Of ConfigWarehose)
|
|
|
|
' indice del Box attivo
|
|
Private m_ActiveBox_Index As Integer
|
|
' riferiento al Box attivo
|
|
Private m_ActiveBox As Box
|
|
|
|
' indica la media delle percentuali dei box riempiti
|
|
Public ReadOnly Property FillPercentage As String
|
|
Get
|
|
Dim Counter As Integer = 0
|
|
Dim Fill As Integer = 0
|
|
For Each ItemBox In Boxes
|
|
' conto tutti box disponibili e pieni, trascuro quelli non disponibili
|
|
If ItemBox.State <> States.NOT_AVAILABLE Then
|
|
Counter += 1
|
|
Fill += ItemBox.nFillPercentage
|
|
ItemBox.NotifyPropertyChanged("FillPercentage")
|
|
End If
|
|
Next
|
|
Return DoubleToString(Fill / Counter, 0) & "%"
|
|
End Get
|
|
End Property
|
|
|
|
' se il magazzino è attivo allora mostro la media delle percentuali dei box
|
|
Public ReadOnly Property FillPercentage_Visibility As Visibility
|
|
Get
|
|
Return If(m_IsActive, Visibility.Visible, Visibility.Collapsed)
|
|
End Get
|
|
End Property
|
|
|
|
' se il magazzino non è attivo allora può essere confermato
|
|
Private m_VisibilityConfirmBtn As Visibility = Visibility.Visible
|
|
Public ReadOnly Property VisibilityConfirmBtn As Visibility
|
|
Get
|
|
Return If(IsEnabled, Visibility.Visible, Visibility.Collapsed)
|
|
End Get
|
|
End Property
|
|
|
|
' se il magazzino contiene almeno un box pieno allora rendo visibile il bottone
|
|
Private m_VisibilityUnloadedBtn As Visibility = Visibility.Visible
|
|
Public ReadOnly Property VisibilityUnloadedBtn As Visibility
|
|
Get
|
|
Dim bIsEmpty As Boolean = True
|
|
For Each Item In m_Boxes
|
|
If Item.State = States.FULL Then
|
|
bIsEmpty = False
|
|
Exit For
|
|
End If
|
|
Next
|
|
Return If(bIsEmpty Or Not IsEnabled, Visibility.Collapsed, Visibility.Visible)
|
|
End Get
|
|
End Property
|
|
|
|
' definizione comandi
|
|
Private m_cmdConfirm As ICommand
|
|
Private m_cmdUnloaded As ICommand
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New(nWarehouse As Warehouses)
|
|
m_Id = nWarehouse
|
|
NotifyPropertyChanged("Id")
|
|
' inizializzo il magazzino corrente
|
|
Init()
|
|
' definisco le colonne del magazzino
|
|
For IndexColumn = 0 To m_nColumnWarehouse - 1
|
|
Dim enColumn As ColumnsWarehouse = DirectCast(IndexColumn, ColumnsWarehouse)
|
|
Dim LocalGridBox As New GridBoxesVM(enColumn, Me, m_ConfigurationList(IndexColumn))
|
|
' costruisco la lista locale dei Box
|
|
For Each ItemBox In m_Boxes
|
|
If ItemBox.ColumnWarehouse = LocalGridBox.Column Then
|
|
LocalGridBox.BoxList.Add(ItemBox)
|
|
End If
|
|
Next
|
|
GridBoxList.Add(LocalGridBox)
|
|
m_GridBoxesV = New GridBoxesV
|
|
m_GridBoxesV.DataContext = LocalGridBox
|
|
Next
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
' definisce lo stato del magazzino
|
|
Friend Sub SetState(State As States)
|
|
m_State = State
|
|
NotifyPropertyChanged("IsEnabled")
|
|
NotifyPropertyChanged("VisibilityConfirmBtn")
|
|
NotifyPropertyChanged("FillPercentage_Visibility")
|
|
End Sub
|
|
|
|
' definisce se il magazzino deve essere attivato
|
|
Friend Sub SetIsActive(bIsActive As Boolean)
|
|
m_IsActive = bIsActive
|
|
For Index = 0 To m_Boxes.Count - 1
|
|
m_Boxes(Index).SetWarehouse_IsActive(bIsActive)
|
|
Next
|
|
NotifyPropertyChanged("IsEnabled")
|
|
NotifyPropertyChanged("VisibilityConfirmBtn")
|
|
NotifyPropertyChanged("FillPercentage_Visibility")
|
|
End Sub
|
|
|
|
Private Sub CreateBoxList(bIsPallet As Boolean)
|
|
m_Boxes.Clear()
|
|
' aggiungo i box
|
|
Dim nBox As Integer = If(bIsPallet, 6, 3)
|
|
For Index = 1 To nBox
|
|
'm_Boxes.Add(New Box(Index, bIsPallet, Me))
|
|
Next
|
|
End Sub
|
|
|
|
Friend Sub SetBoxState(Id As Integer, State As States)
|
|
Dim Index As Integer = ConvertBoxIndex(Id)
|
|
If m_IsPallet Then
|
|
Index = Math.Min(Index, 6)
|
|
Else
|
|
Index = Math.Min(Index, 3)
|
|
End If
|
|
m_Boxes(Index - 1).SetState(State)
|
|
End Sub
|
|
|
|
Friend Sub SetBoxIsActive(Id As Integer)
|
|
If Id > 0 And Id <= 6 Then
|
|
m_ActiveBox_Index = Id - 1
|
|
m_ActiveBox = Boxes(ConvertBoxIndex(Id) - 1)
|
|
For Each Box In m_Boxes
|
|
Box.SetIsActive(Box Is m_ActiveBox)
|
|
Next
|
|
Else
|
|
EgtOutLog("ActiveBox value not in the correct range. It will be ignored!")
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub FillActiveBox(Livello As Integer, Fila As Integer)
|
|
If Not IsNothing(m_ActiveBox) Then
|
|
m_ActiveBox.FillBox(Livello, Fila)
|
|
NotifyPropertyChanged("FillPercentage")
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub MaxFillActiveBox(MaxLivello As Integer, MaxFila As Integer)
|
|
If Not IsNothing(m_ActiveBox) Then
|
|
m_ActiveBox.MaxFillBox(MaxLivello, MaxFila)
|
|
End If
|
|
End Sub
|
|
|
|
' funzione che converte l'indice box che arriva dalla macchina nell'indice box della grafica
|
|
' sono disposti diversamente!
|
|
Friend Function ConvertBoxIndex(MachineIndex As Integer) As Integer
|
|
If IsPallet Then
|
|
Select Case MachineIndex
|
|
Case 1
|
|
Return 4
|
|
Case 2
|
|
Return 1
|
|
Case 3
|
|
Return 5
|
|
Case 4
|
|
Return 2
|
|
Case 5
|
|
Return 6
|
|
Case 6
|
|
Return 3
|
|
Case Else
|
|
Return 4
|
|
End Select
|
|
Else
|
|
Return MachineIndex
|
|
End If
|
|
End Function
|
|
|
|
#End Region
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "Confirm"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property Confirm_Command() As ICommand
|
|
Get
|
|
If m_cmdConfirm Is Nothing Then
|
|
m_cmdConfirm = New Command(AddressOf Confirm)
|
|
End If
|
|
Return m_cmdConfirm
|
|
End Get
|
|
End Property
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Public Sub Confirm(ByVal param As Object)
|
|
' indico che il magazzino è disponibile per la macchine (non disponibile all'operatore)
|
|
SetState(States.AVAILABLE)
|
|
If IsNothing(Map.refUnloadingAreaVM.GetCurrentWarehouse) Then Map.refUnloadingAreaVM.SetActiveWarehouse(m_Id)
|
|
NotifyPropertyChanged("IsEnabled")
|
|
' salvo la configurazione del magazzino
|
|
SetCurrentWerahouse()
|
|
|
|
End Sub
|
|
|
|
#End Region ' Confirm
|
|
|
|
#Region "Unloaded"
|
|
|
|
Public ReadOnly Property Unloaded_Command() As ICommand
|
|
Get
|
|
If m_cmdUnloaded Is Nothing Then
|
|
m_cmdUnloaded = New Command(AddressOf Unloaded)
|
|
End If
|
|
Return m_cmdUnloaded
|
|
End Get
|
|
End Property
|
|
|
|
' svuota il magazzino corrente da tutti i pezzi depositati sui palet
|
|
Public Sub Unloaded()
|
|
For Each ItemBox In Boxes
|
|
ItemBox.IsAvailable = True
|
|
'ItemBox.MyListPart.Clear()
|
|
' soltanto i box FULL tornano ad essere disponibili
|
|
Select Case ItemBox.State
|
|
Case States.FULL
|
|
ItemBox.State = States.AVAILABLE
|
|
ItemBox.MyListPart.Clear()
|
|
End Select
|
|
' fino a quando non si riconferma la warehouse come disponibile aspetto
|
|
SetCurrentWerahouse()
|
|
NotifyPropertyChanged("FillPercentage")
|
|
NotifyPropertyChanged("VisibilityUnloadedBtn")
|
|
Next
|
|
End Sub
|
|
|
|
#End Region ' Unloaded
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
#Region "New METHOD"
|
|
|
|
Public Function Init() As Boolean
|
|
GetCurrentWareHause()
|
|
Return True
|
|
End Function
|
|
|
|
' leggo la configurazione del magazzino corrente
|
|
Public Function GetCurrentWareHause() As Boolean
|
|
' leggo lo STATO del magazzino corrente
|
|
Dim sActive As String = String.Empty
|
|
If WarehauseGetPrivateProfileString(S_WAREHOUSE, K_ACTIVESTORAGE, "0", sActive) < 0 Then
|
|
EgtOutLog("Error reading file Config.ini [Warehause] -> ActiveStorage")
|
|
End If
|
|
m_IsActive = (Trim(sActive) = m_Id.ToString)
|
|
If m_IsActive Then
|
|
' significa che era stato confermato
|
|
m_State = States.AVAILABLE
|
|
End If
|
|
' leggo la CONFIGURAZIONE delle colonne del magazzino corrente
|
|
Dim sConfigWarehouse As String = String.Empty
|
|
For IndexColumn = 0 To m_nColumnWarehouse - 1
|
|
Dim Column As Integer = IndexColumn + 1
|
|
Dim x As String = "Column" & Column.ToString & K_STORAGE & m_Id.ToString
|
|
If WarehauseGetPrivateProfileString(S_WAREHOUSE, "Column" & Column.ToString & K_STORAGE & m_Id.ToString, "0", sConfigWarehouse) < 0 Then
|
|
EgtOutLog("Error reading file Config.ini [Warehause] -> ConfigStorage")
|
|
End If
|
|
If Trim(sConfigWarehouse) = "0" Then
|
|
m_ConfigurationList.Add(ConfigWarehose.PALLET)
|
|
Else
|
|
m_ConfigurationList.Add(ConfigWarehose.RACK)
|
|
End If
|
|
Next
|
|
|
|
' inizializzo l'elenco dei box da file Config
|
|
m_Boxes.Clear()
|
|
' inizio la lettura della configurazione da file Config.ini
|
|
For Index = 0 To 8
|
|
Dim IdBox = Index + 1
|
|
Dim sVal As String = String.Empty
|
|
Dim sName As String = K_BOX & m_Id.ToString & IdBox.ToString
|
|
If WarehauseGetPrivateProfileString(S_WAREHOUSE, sName, "0,0", sVal) < 0 Then
|
|
EgtOutLog("Error reading file Config.ini [Warehause] -> " & sName)
|
|
End If
|
|
Dim sItems As String() = sVal.Split(","c)
|
|
' definisco il TIPO di Box
|
|
Dim bIsPallet As Boolean = IdBox <= 6
|
|
Dim enStatus As States = States.NOT_AVAILABLE
|
|
|
|
' carico lo STATO del Box (di default non è disponibile)
|
|
If sItems.Count >= 1 And IsNumeric(sItems(0)) Then
|
|
' se il box è in fase di carico lo ridefinisco come non disponibile
|
|
If CInt(sItems(0)) = 3 Then
|
|
enStatus = CType(0, States)
|
|
Else
|
|
enStatus = CType(CInt(sItems(0)), States)
|
|
End If
|
|
|
|
End If
|
|
|
|
' carico la definizione della sua origine
|
|
Dim nOrig As Integer = 0
|
|
If sItems.Count >= 2 Then
|
|
Dim sOrig As String = sItems(1).Replace("G"c, "")
|
|
If IsNumeric(sOrig) Then
|
|
nOrig = CInt(sOrig)
|
|
Else
|
|
EgtOutLog("Error reading file Config.ini [Warehause] -> " & sName & ", wrong CN orig definition")
|
|
End If
|
|
End If
|
|
|
|
' carico le dimensioni dei pezzi che devono occupare il pallet
|
|
Dim DimX As Double = 0
|
|
Dim DimY As Double = 0
|
|
If sItems.Count >= 3 Then
|
|
' verifico che la scrittura sia corretta: 500 x 300 (oppure) 500 X 300
|
|
If sItems(2).Contains("x"c) Or sItems(2).Contains("X"c) Then
|
|
sItems(2) = sItems(2).ToLower
|
|
Dim sDim As String() = sItems(2).Split("x"c)
|
|
' carico le dimensioni dei pezzi
|
|
If sDim.Count = 2 Then
|
|
If Not (StringToLen(sDim(0), DimX) And StringToLen(sDim(1), DimY)) Then
|
|
EgtOutLog("Error reading file Config.ini [Warehause] -> " & sName & ", wrong definition: DimX x DimY ")
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
' definisco la colonna di appartenenza
|
|
Dim enColumnsWarehouse As ColumnsWarehouse = ColumnsWarehouse.THIRD
|
|
If IdBox <= 2 Or IdBox = 7 Then
|
|
enColumnsWarehouse = ColumnsWarehouse.FIRST
|
|
ElseIf IdBox = 3 Or IdBox = 4 Or IdBox = 8 Then
|
|
enColumnsWarehouse = ColumnsWarehouse.SECOND
|
|
End If
|
|
|
|
' aggiungo il Box creato alla lista (solo se appartiene alla configurazione)
|
|
Dim CurrBox As New Box(IdBox, If(bIsPallet, ConfigBox.PALLET, ConfigBox.RACK), Me, enStatus, nOrig, enColumnsWarehouse)
|
|
' aggiungo eventualmente la definizione dei pezzi da ospitare
|
|
If DimX > 0 And DimY > 0 Then
|
|
CurrBox.ReserveBox = True
|
|
CurrBox.DimPartX = DimX
|
|
CurrBox.DimPartY = DimY
|
|
Else
|
|
CurrBox.ReserveBox = False
|
|
End If
|
|
CurrBox.NotifyPropertyChanged("")
|
|
m_Boxes.Add(CurrBox)
|
|
|
|
Next
|
|
|
|
Return True
|
|
End Function
|
|
|
|
' salvo la configurazione attuale del magazzino
|
|
Public Function SetCurrentWerahouse() As Boolean
|
|
' salvo il nome del magazzino attivo
|
|
If m_IsActive Then
|
|
WarehauseWritePrivateProfileString(S_WAREHOUSE, K_ACTIVESTORAGE, m_Id.ToString)
|
|
End If
|
|
' salvo la configurazione attuale del magazzino
|
|
Dim Index As Integer = 1
|
|
For Each ItemGridBox In GridBoxList
|
|
WarehauseWritePrivateProfileString(S_WAREHOUSE, "Column" & Index.ToString & K_STORAGE & m_Id.ToString, If(ItemGridBox.IsPallet, "0", "1"))
|
|
Index = Index + 1
|
|
Next
|
|
|
|
' salvo la configurazione dei box
|
|
For Index = 0 To m_Boxes.Count - 1
|
|
Dim sName As String = K_BOX & m_Id.ToString & m_Boxes(Index).Id.ToString
|
|
' converto lo stato nell'indice associato
|
|
Dim nState As Integer = CInt(m_Boxes(Index).State)
|
|
Dim sInfo As String = nState.ToString & ", G" & m_Boxes(Index).OrigDefCN.ToString
|
|
If m_Boxes(Index).ReserveBox Then
|
|
sInfo = sInfo & ", " & DoubleToString(m_Boxes(Index).DimPartX, 2) & "x" & DoubleToString(m_Boxes(Index).DimPartY, 2)
|
|
End If
|
|
WarehauseWritePrivateProfileString(S_WAREHOUSE, sName, sInfo)
|
|
Next
|
|
|
|
Return True
|
|
End Function
|
|
|
|
|
|
#End Region 'New METHOD
|
|
|
|
End Class |