95bdf3b5e7
- verificate chiamate magazzino web solo quando attivo - commentato AddSectionXMaterial (da eliminare) - aggiunti messaggi - aggiunti Id e WarehouseMaterial su Part - sincronizzato Db rete in chiusura - gestita visibilita' bottone cancellazione barre in magazzino
250 lines
9.6 KiB
VB.net
250 lines
9.6 KiB
VB.net
Imports System.Globalization
|
|
Imports EgtBEAMWALL.Core
|
|
Imports EgtWPFLib5
|
|
Imports EgtUILib
|
|
|
|
Public Class MaterialNameManagerVM
|
|
Inherits VMBase
|
|
|
|
Friend Event m_CloseWindow(bDialogResult As Boolean)
|
|
|
|
Private m_NewMaterialList As New List(Of NewMaterial)
|
|
Public ReadOnly Property NewMaterialList As List(Of NewMaterial)
|
|
Get
|
|
Return m_NewMaterialList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_WarehouseMaterialList As New List(Of String)
|
|
Public ReadOnly Property WarehouseMaterialList As List(Of String)
|
|
Get
|
|
Return m_WarehouseMaterialList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_bCancel As Boolean = False
|
|
Public ReadOnly Property Cancel_Visibility As Visibility
|
|
Get
|
|
Return If(m_bCancel, Visibility.Visible, Visibility.Collapsed)
|
|
End Get
|
|
End Property
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property Title As String
|
|
Get
|
|
Return EgtMsg(61783)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Ok_Msg As String
|
|
Get
|
|
Return EgtMsg(61761)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Cancel_Msg As String
|
|
Get
|
|
Return EgtMsg(61763)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
' Definizione comandi
|
|
Private m_cmdOk As ICommand
|
|
|
|
Sub New()
|
|
End Sub
|
|
|
|
Public Function VerifyNewMaterialNames(Optional MaterialNameList As List(Of String) = Nothing) As Boolean
|
|
' se magazzino di rete attivo
|
|
If GetMainPrivateProfileInt(S_WAREHOUSE, K_NETWAREHOUSE, 0) = 1 Then
|
|
DbControllers.m_MagmanController.AliasSyncro()
|
|
End If
|
|
' se lista non definita, recupero lista di tutti i materiali presenti nel progetto
|
|
If IsNothing(MaterialNameList) Then
|
|
MaterialNameList = Map.refProjectVM.BTLStructureVM.BTLPartVMList.Select(Function(x) x.MaterialM.sMaterial).Distinct().ToList()
|
|
Else
|
|
m_bCancel = True
|
|
End If
|
|
For Each MaterialName In MaterialNameList
|
|
' verifico se esistono dei grezzi per questi materiali
|
|
Dim Res As DataLayer.Controllers.MaterialsController.SearchResult = DbControllers.m_MaterialsController.SearchFilt(MaterialName)
|
|
If Res.Tipo = DataLayer.Controllers.MaterialsController.SearchResult.TypeFound.NOT_FOUND OrElse Res.Tipo = DataLayer.Controllers.MaterialsController.SearchResult.TypeFound.MISSING_CODE Then
|
|
' verifico se esiste gia' un alias
|
|
Dim MaterialAlias = DbControllers.m_AliasController.FindByDbId(MaterialName)
|
|
If IsNothing(MaterialAlias) OrElse MaterialAlias.ValueOriginal <> MaterialName Then
|
|
NewMaterialList.Add(New NewMaterial(MaterialName))
|
|
End If
|
|
End If
|
|
Next
|
|
If m_NewMaterialList.Count > 0 Then
|
|
' recupero la lista dei materiali presenti in Warehouse
|
|
Dim WhSectXMatList As List(Of SectionXMaterial) = WarehouseWndVM.GetSectionXMaterialsFromWarehouse()
|
|
m_WarehouseMaterialList = WhSectXMatList.Select(Function(x) x.MaterialM.sWarehouseMaterial).Distinct().ToList()
|
|
Return True
|
|
Else Return False
|
|
End If
|
|
End Function
|
|
|
|
#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()
|
|
'verifico che tutti i campi contengano un valore valido
|
|
For Each Material In m_NewMaterialList
|
|
If (Material.bNewName_IsChecked AndAlso String.IsNullOrWhiteSpace(Material.sNewName)) OrElse
|
|
(Not Material.bNewName_IsChecked AndAlso IsNothing(Material.sSelWarehouseMaterial)) Then
|
|
MessageBox.Show("Please set a name for every material before going on.")
|
|
Return
|
|
End If
|
|
Next
|
|
' verifico se ci sono nuovi materiali che sono gia' definiti
|
|
For Each Material In m_NewMaterialList
|
|
If Material.bNewName_IsChecked And m_WarehouseMaterialList.Contains(Material.sNewName) Then
|
|
Material.sSelWarehouseMaterial = Material.sNewName
|
|
Material.bNewName_IsChecked = False
|
|
End If
|
|
Next
|
|
' riporto tutti gli alias e nuovi materiali su db
|
|
For Each Material In m_NewMaterialList
|
|
If String.IsNullOrWhiteSpace(Material.sOrigMaterial) Then
|
|
Dim EmptyMatPartList As List(Of BTLPartVM) = Map.refProjectVM.BTLStructureVM.BTLPartVMList.Where(Function(x) String.IsNullOrWhiteSpace(x.MaterialM.sMaterial)).ToList()
|
|
Dim sMaterialName As String = ""
|
|
If Material.bNewName_IsChecked Then
|
|
sMaterialName = Material.sNewName
|
|
Else
|
|
sMaterialName = Material.sSelWarehouseMaterial
|
|
End If
|
|
' aggiorno tutti i pezzi del progetto
|
|
For Each Part In EmptyMatPartList
|
|
EgtSetInfo(Part.BTLPartM.nPartId, BTL_PRT_MATERIAL, sMaterialName)
|
|
Part.BTLPartM.sMATERIAL = sMaterialName
|
|
Part.NotifyPropertyChanged(NameOf(Part.sMATERIAL))
|
|
Next
|
|
' se nuovo materiale
|
|
If Material.bNewName_IsChecked Then
|
|
' cerco un pezzo che usa questo materiale
|
|
Dim PartVM As BTLPartVM = Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.MaterialM.sMaterial = Material.sOrigMaterial)
|
|
Dim NewMaterialM As MaterialM = New MaterialM(PartVM.Section.MaterialM.dW, PartVM.Section.MaterialM.dH, PartVM.Section.MaterialM.dL, Material.sNewName, Material.sNewName)
|
|
' lo aggiungo al Db
|
|
DbControllers.m_MaterialsController.Insert(NewMaterialM)
|
|
End If
|
|
ElseIf Material.bNewName_IsChecked Then
|
|
' creo questo materiale
|
|
Dim PartVM As BTLPartVM = Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.MaterialM.sMaterial = Material.sOrigMaterial)
|
|
If IsNothing(PartVM) Then
|
|
PartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
|
|
End If
|
|
Dim NewMaterialM As MaterialM = New MaterialM(PartVM.Section.MaterialM.dW, PartVM.Section.MaterialM.dH, PartVM.Section.MaterialM.dL, Material.sOrigMaterial, Material.sNewName)
|
|
' lo aggiungo al Db
|
|
DbControllers.m_MaterialsController.Insert(NewMaterialM)
|
|
' se diverso dal nome originale, aggiungo anche l'alias
|
|
If Material.sNewName <> Material.sOrigMaterial Then
|
|
DbControllers.m_AliasController.Upsert(New DataLayer.DatabaseModels.AliasModel() With {.Family = "MatCode",
|
|
.ValueAlias = Material.sNewName,
|
|
.ValueOriginal = Material.sOrigMaterial})
|
|
' se magazzino di rete attivo
|
|
If GetMainPrivateProfileInt(S_WAREHOUSE, K_NETWAREHOUSE, 0) = 1 Then
|
|
DbControllers.m_MagmanController.AliasForceUpload()
|
|
End If
|
|
End If
|
|
Else
|
|
DbControllers.m_AliasController.Upsert(New DataLayer.DatabaseModels.AliasModel() With {.Family = "MatCode",
|
|
.ValueAlias = Material.sSelWarehouseMaterial,
|
|
.ValueOriginal = Material.sOrigMaterial})
|
|
' se magazzino di rete attivo
|
|
If GetMainPrivateProfileInt(S_WAREHOUSE, K_NETWAREHOUSE, 0) = 1 Then
|
|
DbControllers.m_MagmanController.AliasForceUpload()
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
RaiseEvent m_CloseWindow(True)
|
|
End Sub
|
|
|
|
#End Region ' Ok
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|
|
|
|
Public Class NewMaterial
|
|
Inherits VMBase
|
|
|
|
Private m_sOrigMaterial As String
|
|
Public ReadOnly Property sOrigMaterial As String
|
|
Get
|
|
Return m_sOrigMaterial
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sSelWarehouseMaterial As String
|
|
Public Property sSelWarehouseMaterial As String
|
|
Get
|
|
Return m_sSelWarehouseMaterial
|
|
End Get
|
|
Set(value As String)
|
|
m_sSelWarehouseMaterial = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_sNewName As String
|
|
Public Property sNewName As String
|
|
Get
|
|
Return m_sNewName
|
|
End Get
|
|
Set(value As String)
|
|
m_sNewName = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_bNewName_IsChecked As Boolean = False
|
|
Public Property bNewName_IsChecked As Boolean
|
|
Get
|
|
Return m_bNewName_IsChecked
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_bNewName_IsChecked = value
|
|
m_sNewName = m_sOrigMaterial
|
|
NotifyPropertyChanged(NameOf(sNewName))
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(sOrigMaterial As String)
|
|
m_sOrigMaterial = sOrigMaterial
|
|
End Sub
|
|
|
|
Sub New(sOrigMaterial As String, sSelWarehouseMaterial As String)
|
|
m_sOrigMaterial = sOrigMaterial
|
|
m_sSelWarehouseMaterial = sSelWarehouseMaterial
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class BooleanToVisibilityConverter
|
|
Implements IValueConverter
|
|
|
|
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
|
|
If Not IsNothing(parameter) Then
|
|
Return If(Not CBool(value), Visibility.Visible, Visibility.Collapsed)
|
|
Else
|
|
Return If(CBool(value), Visibility.Visible, Visibility.Collapsed)
|
|
End If
|
|
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 |