Files
omagoffice/CsvWindow/CsvWindowVM.vb
T
Emmanuele Sassi 8f61ba413d OmagOFFICE :
- Aggiunta importazione Csv.
2017-05-08 08:36:16 +00:00

379 lines
10 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Public Class CsvWindowVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
' Riferimento alla classe CsvM
Private m_refCsvM As CsvM
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
#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()
' recupero riferimento alla classe CsvM
m_refCsvM = OmagOFFICEMap.refCsvM
' Visualizzazione lista
ShowTreeView()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Private Sub ShowTreeView()
' Path del file Csv
Dim TempPath As New Text.StringBuilder(260)
PathCompactPathEx(TempPath, OmagOFFICEMap.refCsvM.CsvPath, 28, 0)
CsvPath = TempPath.ToString()
' Pezzi del file Csv
m_CsvTypeList.Clear()
Dim sCurrMat As String = String.Empty
Dim dCurrTh As Double = 0
Dim nCatToNest As Integer = 0
Dim nCatCount As Integer = 0
Dim PartCathegory As New CsvPartType("", 0)
For i As Integer = 1 To OmagOFFICEMap.refCsvM.CsvPartList.Count()
' Dati pezzo corrente
Dim CurrPart As CsvPart = OmagOFFICEMap.refCsvM.CsvPartList(i - 1)
' Gestione categoria
If i = 1 Then
sCurrMat = CurrPart.m_sMaterial
dCurrTh = CurrPart.m_dTh
ElseIf String.Compare(sCurrMat, CurrPart.m_sMaterial, True) <> 0 Or
Math.Abs(dCurrTh - CurrPart.m_dTh) > 10 * EPS_SMALL Then
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
" - " & LenToString(dCurrTh, 2) &
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
PartCathegory.IsExpanded = True
CsvTypeList.Add(PartCathegory)
sCurrMat = CurrPart.m_sMaterial
dCurrTh = CurrPart.m_dTh
PartCathegory = New CsvPartType("", 0)
nCatToNest = 0
nCatCount = 0
End If
' Gestione pezzo
nCatToNest += CurrPart.m_nToNest
nCatCount += CurrPart.m_nCount
Dim sCount As String = CurrPart.m_nToNest.ToString() & "/" & CurrPart.m_nCount.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
PartCathegory.Name = If(String.IsNullOrWhiteSpace(sCurrMat), "***", sCurrMat) &
" - " & LenToString(dCurrTh, 2) &
" - " & nCatToNest.ToString() & "/" & nCatCount.ToString()
PartCathegory.IsExpanded = True
CsvTypeList.Add(PartCathegory)
NotifyPropertyChanged("CsvTypeList")
End Sub
Private Sub UpdateTreeView()
For Each CatItem As CsvPartType In m_CsvTypeList
For Each PrtItem As CsvPartItem In CatItem.CsvPartList
Dim PartData As CsvPart = OmagOFFICEMap.refCsvM.CsvPartList(PrtItem.nType - 1)
Dim sCount As String = PartData.m_nToNest.ToString() & "/" & PartData.m_nCount.ToString()
PrtItem.sText1 = sCount
Next
Next
End Sub
#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)
OmagOFFICEMap.refCsvM.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)
OmagOFFICEMap.refCsvM.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)
OmagOFFICEMap.refCsvM.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)
' Elenco eventuali altre liste Csv riferite dai pezzi
Dim bOther As Boolean = False
Dim sOtherCsv As String = String.Empty
OmagOFFICEMap.refCsvM.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)
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