Files
2022-03-07 20:31:50 +01:00

492 lines
15 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class CsvWindowVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_CsvPath As String
Public Property CsvPath As String
Get
Return m_CsvPath
End Get
Set(value As String)
m_CsvPath = value
NotifyPropertyChanged("CsvPath")
End Set
End Property
Private m_CsvTypeList As New ObservableCollection(Of CsvPartType)
Public Property CsvTypeList As ObservableCollection(Of CsvPartType)
Get
Return m_CsvTypeList
End Get
Set(value As ObservableCollection(Of CsvPartType))
m_CsvTypeList = value
End Set
End Property
Private m_Plus_IsChecked As Boolean
Public Property Plus_IsChecked As Boolean
Get
Return m_Plus_IsChecked
End Get
Set(value As Boolean)
If value Then
m_Minus_IsChecked = False
NotifyPropertyChanged("Minus_IsChecked")
End If
m_Plus_IsChecked = value
End Set
End Property
Private m_Minus_IsChecked As Boolean
Public Property Minus_IsChecked As Boolean
Get
Return m_Minus_IsChecked
End Get
Set(value As Boolean)
If value Then
m_Plus_IsChecked = False
NotifyPropertyChanged("Plus_IsChecked")
End If
m_Minus_IsChecked = value
End Set
End Property
#Region "Messages"
Public ReadOnly Property TitleMsg As String
Get
Return EgtMsg(MSG_CADCUTPAGEUC + 8)
End Get
End Property
Public ReadOnly Property NewMsg As String
Get
Return EgtMsg(MSG_CSVPAGEUC + 3)
End Get
End Property
Public ReadOnly Property OpenMsg As String
Get
Return EgtMsg(MSG_CSVPAGEUC + 1)
End Get
End Property
Public ReadOnly Property InsertMsg As String
Get
Return EgtMsg(MSG_CSVPAGEUC + 2)
End Get
End Property
Public ReadOnly Property RemoveMsg As String
Get
Return EgtMsg(MSG_CSVPAGEUC + 4)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdNew As ICommand
Private m_cmdOpen As ICommand
Private m_cmdInsert As ICommand
Private m_cmdRemove As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Visualizzazione lista
ShowTreeView()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Private Sub ShowTreeView()
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
' Path del file Csv
Dim TempPath As New Text.StringBuilder(260)
PathCompactPathEx(TempPath, CsvM.CsvPath, 56, 0)
CsvPath = TempPath.ToString()
' Pezzi del file Csv
m_CsvTypeList.Clear()
Dim sCurrMat As String = String.Empty
Dim dCurrTh As Double = 0
Dim sCurrPath As String = String.Empty
Dim nCatToNest As Integer = 0
Dim nCatCount As Integer = 0
Dim PartCathegory As New CsvPartType("", 0)
For i As Integer = 1 To CsvM.CsvPartList.Count()
' Dati pezzo corrente
Dim CurrPart As CsvPart = CsvM.CsvPartList(i - 1)
' Gestione categoria
If i = 1 Then
sCurrMat = CurrPart.m_sMaterial
dCurrTh = CurrPart.m_dTh
sCurrPath = CurrPart.m_sPath
ElseIf String.Compare(sCurrMat, CurrPart.m_sMaterial, True) <> 0 Or
String.Compare(sCurrPath, CurrPart.m_sPath, True) <> 0 Or
Math.Abs(dCurrTh - CurrPart.m_dTh) > 10 * EPS_SMALL Then
If bFull Then
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
" - " & LenToString(dCurrTh, 2) &
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
PartCathegory.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
Else
PartCathegory.Name = nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
PartCathegory.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
End If
PartCathegory.IsExpanded = True
CsvTypeList.Add(PartCathegory)
sCurrMat = CurrPart.m_sMaterial
dCurrTh = CurrPart.m_dTh
sCurrPath = CurrPart.m_sPath
PartCathegory = New CsvPartType("", 0)
nCatToNest = 0
nCatCount = 0
End If
' Gestione pezzo
nCatToNest += CurrPart.m_nToNest
nCatCount += CurrPart.m_nCount + CurrPart.m_nAdd
Dim sCount As String = CurrPart.m_nToNest.ToString() & "/" & CurrPart.m_nCount.ToString()
If CurrPart.m_nAdd > 0 Then sCount &= "+" & CurrPart.m_nAdd.ToString()
Dim sDim As String = LenToString(CurrPart.m_dDimX, 1) & "x" & LenToString(CurrPart.m_dDimY, 1)
PartCathegory.CsvPartList.Add(New CsvPartItem(CurrPart.m_sName, i, sCount, sDim, CurrPart.m_bActive))
Next
' Inserisco ultima categoria
If bFull Then
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
" - " & LenToString(dCurrTh, 2) &
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
PartCathegory.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
Else
PartCathegory.Name = nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
PartCathegory.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
End If
PartCathegory.IsExpanded = True
CsvTypeList.Add(PartCathegory)
NotifyPropertyChanged("CsvTypeList")
End Sub
Private Sub UpdateTreeView()
Dim bFull = OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.CSV_AUTO) And
(GetMainPrivateProfileInt(S_CSV, K_FULL, 1) <> 0)
For Each CatItem As CsvPartType In m_CsvTypeList
Dim sCurrMat As String = String.Empty
Dim dCurrTh As Double = 0
Dim sCurrPath As String = String.Empty
Dim nCatToNest As Integer = 0
Dim nCatCount As Integer = 0
For Each PrtItem As CsvPartItem In CatItem.CsvPartList
Dim PartData As CsvPart = CsvM.CsvPartList(PrtItem.nType - 1)
Dim sCount As String = PartData.m_nToNest.ToString() & "/" & PartData.m_nCount.ToString()
If PartData.m_nAdd > 0 Then sCount &= "+" & PartData.m_nAdd.ToString()
PrtItem.sText1 = sCount
sCurrMat = PartData.m_sMaterial
dCurrTh = PartData.m_dTh
sCurrPath = PartData.m_sPath
nCatToNest += PartData.m_nToNest
nCatCount += PartData.m_nCount + PartData.m_nAdd
Next
If bFull Then
CatItem.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
" - " & LenToString(dCurrTh, 2) &
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
CatItem.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
Else
CatItem.Name = nCatToNest.ToString() & "/" & nCatCount.ToString()
If Not String.IsNullOrWhiteSpace(sCurrPath) Then
CatItem.Name &= vbCrLf & Path.GetFileNameWithoutExtension(sCurrPath)
End If
End If
Next
End Sub
Friend Sub PartItemClick(CsvPartItem As CsvPartItem)
Dim PartData As CsvPart = CsvM.CsvPartList(CsvPartItem.nType - 1)
Dim nPlusMinus As Integer = GetPlusMinus()
If nPlusMinus <> 0 Then
' Posso sempre aggiungere pezzi in più
If nPlusMinus > 0 Then
PartData.m_nToNest += 1
PartData.m_nAdd += 1
' Posso togliere solo pezzi aggiunti non ancora inseriti
ElseIf PartData.m_nAdd > 0 And PartData.m_nToNest > 0 Then
PartData.m_nToNest -= 1
PartData.m_nAdd -= 1
End If
UpdateTreeView()
Else
CsvPartItem.bIsActive = Not CsvPartItem.bIsActive
PartData.m_bActive = CsvPartItem.bIsActive
End If
End Sub
Private Function GetPlusMinus() As Integer
If Plus_IsChecked Then
Return 1
ElseIf Minus_IsChecked Then
Return -1
Else
Return 0
End If
End Function
#End Region ' METHODS
#Region "COMMANDS"
#Region "NewCommand"
Public ReadOnly Property NewCommand As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New Command(AddressOf NewCmd)
End If
Return m_cmdNew
End Get
End Property
Public Sub NewCmd(ByVal param As Object)
CsvM.NewCmd()
' Visualizzazione lista
ShowTreeView()
End Sub
#End Region ' NewCommand
#Region "OpenCommand"
Public ReadOnly Property OpenCommand As ICommand
Get
If m_cmdOpen Is Nothing Then
m_cmdOpen = New Command(AddressOf Open)
End If
Return m_cmdOpen
End Get
End Property
Public Sub Open(ByVal param As Object)
CsvM.Open()
' Visualizzazione lista
ShowTreeView()
End Sub
#End Region ' OpenCommand
#Region "InsertCommand"
Public ReadOnly Property InsertCommand As ICommand
Get
If m_cmdInsert Is Nothing Then
m_cmdInsert = New Command(AddressOf Insert)
End If
Return m_cmdInsert
End Get
End Property
Public Sub Insert(ByVal param As Object)
' Passo al contesto principale
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx())
' Eseguo inserimento
CsvM.Insert()
' Aggiorno TreeView
UpdateTreeView()
End Sub
#End Region ' InsertCommand
#Region "RemoveCommand"
Public ReadOnly Property RemoveCommand As ICommand
Get
If m_cmdRemove Is Nothing Then
m_cmdRemove = New Command(AddressOf Remove)
End If
Return m_cmdRemove
End Get
End Property
Public Sub Remove(ByVal param As Object)
' Passo al contesto principale
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostVM.MainScene.GetCtx())
' Eseguo rimozione, con elenco eventuali altre liste Csv riferite dai pezzi
Dim bOther As Boolean = False
Dim sOtherCsv As String = String.Empty
CsvM.Remove(bOther, sOtherCsv)
' Aggiorno TreeView
UpdateTreeView()
' Eventuale messaggi di pezzi liberi o da altre liste
If bOther Then
' Pezzi non rimossi perché liberi
Dim sOut As String = EgtMsg(MSG_EGTMSGBOX + 13)
If Not String.IsNullOrWhiteSpace(sOtherCsv) Then
' o di altre liste Csv
sOut &= EgtMsg(MSG_EGTMSGBOX + 14) & " (" & sOtherCsv.TrimEnd(", ".ToCharArray()) & ")"
End If
MessageBox.Show(sOut, "", MessageBoxButton.OK, MessageBoxImage.Warning)
End If
End Sub
#End Region ' RemoveCommand
#End Region ' COMMANDS
End Class
Public Class CsvPartItem
Inherits VMBase
Private m_nType As Integer
Public ReadOnly Property nType As Integer
Get
Return m_nType
End Get
End Property
Private m_sName As String
Public Property Name As String
Get
Return m_sName
End Get
Set(value As String)
m_sName = value
NotifyPropertyChanged("Name")
End Set
End Property
Private m_sText1 As String
Public Property sText1 As String
Get
Return m_sText1
End Get
Set(value As String)
m_sText1 = value
NotifyPropertyChanged("sText1")
End Set
End Property
Private m_sText2 As String
Public Property sText2 As String
Get
Return m_sText2
End Get
Set(value As String)
m_sText2 = value
NotifyPropertyChanged("sText2")
End Set
End Property
Private m_bIsActive As Boolean
Public Property bIsActive As Boolean
Get
Return m_bIsActive
End Get
Set(value As Boolean)
If value <> m_bIsActive Then
m_bIsActive = value
NotifyPropertyChanged("bIsActive")
End If
End Set
End Property
#Region "CONSTRUCTORS"
Sub New(Title As String, nType As Integer, sText1 As String, sText2 As String)
m_nType = nType
m_sName = Title
m_sText1 = sText1
m_sText2 = sText2
m_bIsActive = True
End Sub
Sub New(Title As String, nType As Integer, sText1 As String, sText2 As String, bIsActive As Boolean)
m_nType = nType
m_sName = Title
m_sText1 = sText1
m_sText2 = sText2
m_bIsActive = bIsActive
End Sub
#End Region ' CONSTRUCTORS
End Class
Public Class CsvPartType
Inherits VMBase
Private m_nFType As Integer
Public ReadOnly Property nFType As Integer
Get
Return m_nFType
End Get
End Property
Private m_sName As String
Public Property Name As String
Get
Return m_sName
End Get
Set(value As String)
m_sName = value
NotifyPropertyChanged("Name")
End Set
End Property
Private m_isExpanded As Boolean
Public Property IsExpanded As Boolean
Get
Return m_isExpanded
End Get
Set(value As Boolean)
If (value <> m_isExpanded) Then
m_isExpanded = value
NotifyPropertyChanged("IsExpanded")
End If
End Set
End Property
Public ReadOnly Property PictureString As String
Get
Return "/Resources/TreeView/Folder.png"
End Get
End Property
Private m_CsvPartList As ObservableCollection(Of CsvPartItem)
Public Property CsvPartList As ObservableCollection(Of CsvPartItem)
Get
Return m_CsvPartList
End Get
Set(value As ObservableCollection(Of CsvPartItem))
m_CsvPartList = value
End Set
End Property
Sub New(sName As String, nType As Integer)
m_nFType = nType
m_sName = sName
m_CsvPartList = New ObservableCollection(Of CsvPartItem)
End Sub
End Class