Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/AddSectionXMaterialWnd/AddSectionXMaterialWndVM.vb
T
RenzoL 80dd455ef3 - Correzione riferimenti tipo progetto laddove veniva usato ancora tipo macchina
- Aggiunti commenti su aggiunta/rimozione file a lista MRU in base a tipo progetto
2021-07-02 12:02:55 +02:00

228 lines
8.6 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Imports EgtBEAMWALL.Core
Public Class AddSectionXMaterialWndVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Friend Event m_CloseWindow(bDialogResult As Boolean)
Private m_NewSectionXMaterialList As New ObservableCollection(Of SectionXMaterial)
Public Property NewSectionXMaterialList As ObservableCollection(Of SectionXMaterial)
Get
Return m_NewSectionXMaterialList
End Get
Set(value As ObservableCollection(Of SectionXMaterial))
m_NewSectionXMaterialList = value
End Set
End Property
' Definizione comandi
Private m_cmdOk As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "MESSAGES"
Public ReadOnly Property SectionXMaterial_Msg As String
Get
Return EgtMsg(61771)
End Get
End Property
Public ReadOnly Property Alias_Msg As String
Get
Return EgtMsg(61772)
End Get
End Property
Public ReadOnly Property Values_Msg As String
Get
Return EgtMsg(61773)
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
Public ReadOnly Property Error_Msg As String
Get
Return EgtMsg(61764)
End Get
End Property
Public ReadOnly Property IncorrectValues_Msg As String
Get
Return EgtMsg(61768)
End Get
End Property
#End Region ' MESSAGES
#Region "CONSTRUCTOR"
Sub New(SectXMatList As List(Of SectionXMaterial))
NewSectionXMaterialList = New ObservableCollection(Of SectionXMaterial)(SectXMatList)
' Rimuovo il primo elemento perché sempre vuoto
NewSectionXMaterialList.RemoveAt(0)
' Prendo i SectionXMaterial appena messi nella Lista di questa finestra e li confronto con ciascuno di quelli presenti in BTLStructure.SectionList.
' Se le sezioni sono uguali carico i materiali relativi alla medesima sezione.
' Se i materiali di quella medesima sezione non ci sono disabilito la CheckBox Alias.
For Each NewSectXMatItem In NewSectionXMaterialList
NewSectXMatItem.Alias_IsChecked = False
For Each SectionListItem In Map.refProjectVM.BTLStructureVM.SectionList
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
If NewSectXMatItem.dW = SectionListItem.dW AndAlso NewSectXMatItem.dH = SectionListItem.dH Then
' Se le sezioni sono uguali allora indago sui materiali
For Index As Integer = 0 To SectionListItem.sMaterial.Count - 1
If Not NewSectXMatItem.MaterialForSameSection_List.Contains(SectionListItem.sMaterial(Index)) And Not NewSectXMatItem.sMaterial.Contains(SectionListItem.sMaterial(Index)) Then
NewSectXMatItem.MaterialForSameSection_List.Add(SectionListItem.sMaterial(Index))
End If
If NewSectXMatItem.MaterialForSameSection_List.Count > 0 Then
NewSectXMatItem.Alias_IsEnabled = True
End If
Next
End If
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
If NewSectXMatItem.dH = SectionListItem.dH Then
' Se le sezioni sono uguali allora indago sui materiali
For Index As Integer = 0 To SectionListItem.sMaterial.Count - 1
If Not NewSectXMatItem.MaterialForSameSection_List.Contains(SectionListItem.sMaterial(Index)) And Not NewSectXMatItem.sMaterial.Contains(SectionListItem.sMaterial(Index)) Then
NewSectXMatItem.MaterialForSameSection_List.Add(SectionListItem.sMaterial(Index))
End If
If NewSectXMatItem.MaterialForSameSection_List.Count > 0 Then
NewSectXMatItem.Alias_IsEnabled = True
End If
Next
End If
End If
Next
Next
End Sub
#End Region ' CONSTRUCTOR
#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 i valori non sono corretti segnalo l'errore e impedisco il salvataggio
For Index As Integer = 0 To NewSectionXMaterialList.Count - 1
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM AndAlso NewSectionXMaterialList(Index).dNewL < 0 Then
MessageBox.Show(IncorrectValues_Msg, Error_Msg)
Return
End If
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL AndAlso (NewSectionXMaterialList(Index).dNewW < 0 Or NewSectionXMaterialList(Index).dNewL < 0) Then
MessageBox.Show(IncorrectValues_Msg, Error_Msg)
Return
End If
Index += 1
Next
' Se i valori sono corretti salvo
Save()
End Sub
#End Region ' Ok
#End Region ' CONSTRUCTOR
#Region "METHODS"
#Region "Save"
Public Sub Save()
' Indice per scansionare NewSectionXMaterialList
Dim Index = 0
' Indice da incrementare in modo da scrivere i nuovi parametri L/S a partire dal giusto numero
Dim ParamIndex = 1
Dim sWarehousePath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_MEDIUM_INI_FILE_NAME
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' Ciclo sui parametri L esistenti nell'INI in modo da avere l'indice di partenza per gli ulteriori parametri da scrivere
Dim sValue As String = String.Empty
While EgtUILib.GetPrivateProfileString(S_BEAM, "L" & ParamIndex, String.Empty, sValue, sWarehousePath)
ParamIndex += 1
End While
' Se i valori sono tutti >= 0 li scrivo nel file INI
Index = 0
For Each NewSxMItem In NewSectionXMaterialList
Dim sAlias As String = String.Empty
For Each Mat In NewSectionXMaterialList(Index).sMaterial
sAlias &= Mat & ";"
Next
sAlias = sAlias.TrimEnd(";")
' Se Alias è checkato aggiungo l'Alias scelto dalla ComboBox alla stringa
If NewSxMItem.Alias_IsChecked Then sAlias &= ";" & NewSxMItem.SelMaterialForSameSection
' Scrivo il parametro
WritePrivateProfileString(S_BEAM, K_L & ParamIndex, LenToString(NewSectionXMaterialList(Index).dW, 3) & "," &
LenToString(NewSectionXMaterialList(Index).dH, 3) & "," &
sAlias & "," &
LenToString(NewSectionXMaterialList(Index).dNewL, 3), sWarehousePath)
Index += 1
ParamIndex += 1
Next
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
' Ciclo sui parametri S esistenti nell'INI in modo da avere l'indice di partenza per gli ulteriori parametri da scrivere
Dim sValue As String = String.Empty
While EgtUILib.GetPrivateProfileString(S_WALL, "S" & ParamIndex, String.Empty, sValue, sWarehousePath)
ParamIndex += 1
End While
' Se i valori sono tutti > 0 li scrivo nel file INI
Index = 0
For Each NewSxMItem In NewSectionXMaterialList
Dim sAlias As String = String.Empty
For Each Mat In NewSectionXMaterialList(Index).sMaterial
sAlias &= Mat & ";"
Next
sAlias = sAlias.TrimEnd(";")
' Se Alias è checkato aggiungo l'Alias scelto dalla ComboBox alla stringa
If NewSxMItem.Alias_IsChecked Then sAlias &= ";" & NewSxMItem.SelMaterialForSameSection
' Scrivo il parametro
WritePrivateProfileString(S_WALL, K_S & ParamIndex, LenToString(NewSectionXMaterialList(Index).dH, 3) & "," &
sAlias & "," &
LenToString(NewSectionXMaterialList(Index).dNewW, 3) & "," &
LenToString(NewSectionXMaterialList(Index).dNewL, 3), sWarehousePath)
Index += 1
ParamIndex += 1
Next
End If
RaiseEvent m_CloseWindow(True)
End Sub
#End Region ' Save
#End Region ' METHODS
End Class