8b02512c63
- migliorata ricerca materiale da Db - eliminata info WarehouseMaterial da progetto nge
210 lines
8.5 KiB
VB.net
210 lines
8.5 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
|
|
' Definizione comandi
|
|
Private m_cmdOk As ICommand
|
|
|
|
Sub New()
|
|
End Sub
|
|
|
|
Public Function VerifyNewMaterialNames(Optional MaterialNameList As List(Of String) = Nothing) As Boolean
|
|
DbControllers.m_MagmanController.AliasSyncro()
|
|
' 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.sMATERIAL).Distinct().ToList()
|
|
Else
|
|
m_bCancel = True
|
|
End If
|
|
For Each MaterialName In MaterialNameList
|
|
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
|
|
NewMaterialList.Add(New NewMaterial(MaterialName))
|
|
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.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)
|
|
EgtSetInfo(Part.BTLPartM.nPartId, BTL_PRT_WAREHOUSEMATERIAL, sMaterialName)
|
|
Part.BTLPartM.sMATERIAL = sMaterialName
|
|
Part.BTLPartM.sWAREHOUSEMATERIAL = sMaterialName
|
|
Part.NotifyPropertyChanged(NameOf(Part.sMATERIAL))
|
|
Part.NotifyPropertyChanged(NameOf(Part.sWAREHOUSEMATERIAL))
|
|
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.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
|
|
' cerco un pezzo che usa questo materiale
|
|
Dim PartVM As BTLPartVM = Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.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)
|
|
' 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})
|
|
End If
|
|
Else
|
|
DbControllers.m_AliasController.Upsert(New DataLayer.DatabaseModels.AliasModel() With {.Family = "MatCode",
|
|
.ValueAlias = Material.sSelWarehouseMaterial,
|
|
.ValueOriginal = Material.sOrigMaterial})
|
|
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 |