Files
EgtWPFLib5/ToolDbWindow/ImportExportToolWindowVM.vb
T
Renzo Lanza c7f49cf1dc EgtWPFLib5 2.3c4 :
- rivisto aggiornamento lista utensili appena importati
- resi più compatti i TreeView di Db Ut., Db Lav. e ImportExportToolWindow
2021-03-30 07:57:53 +00:00

298 lines
8.7 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtUILib
Public Class ImportExportToolWindowVM
Inherits VMBase
' Modalita' di apertura della finestra
Public Enum WindowModeEnum As Integer
IMPORT
EXPORT
End Enum
Private m_WindowMode As WindowModeEnum
Public ReadOnly Property WindowMode As WindowModeEnum
Get
Return m_WindowMode
End Get
End Property
' Lista degli utensili
Private m_FamilyList As New ObservableCollection(Of ImpExpFamily)
Public Property FamilyList As ObservableCollection(Of ImpExpFamily)
Get
Return m_FamilyList
End Get
Set(value As ObservableCollection(Of ImpExpFamily))
m_FamilyList = value
End Set
End Property
' Percorso del file da cui importare gli utensili
Private m_ImportFilePath As String
Public ReadOnly Property ImportFilePath As String
Get
Return m_ImportFilePath
End Get
End Property
' Lista degli utensili presenti nel file da cui importare
Private m_ImportFileToolNameList As String()
Public ReadOnly Property ImportFileToolNameList As String()
Get
Return m_ImportFileToolNameList
End Get
End Property
' Lista degli utensili importati con successo
Private m_vsImported As String()
Public ReadOnly Property vsImported As String()
Get
Return m_vsImported
End Get
End Property
Friend Event m_CloseWindow(bDialogResult As Boolean)
#Region "MESSAGES"
Public ReadOnly Property OkMsg As String
Get
If WindowMode = WindowModeEnum.IMPORT Then
Return EgtMsg(31161)
Else
Return EgtMsg(31162)
End If
End Get
End Property
#End Region ' Messages
#Region "COMMANDS"
' Definizione comandi
Private m_cmdOk As ICommand
#Region "OkCommand"
''' <summary>
''' Returns a command that remove the current selected machining.
''' </summary>
Public ReadOnly Property OkCommand() As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf ConfirmImpExpTools)
End If
Return m_cmdOk
End Get
End Property
''' <summary>
''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand.
''' </summary>
Public Sub ConfirmImpExpTools(param As Object)
Select Case WindowMode
Case WindowModeEnum.IMPORT
Dim FinalNameList As New List(Of String)
Dim ImportToolNameList As New List(Of String)(ImportFileToolNameList)
Dim ImportToolNameIndex As Integer = 0
For Each Family In FamilyList
For Each Tool In Family.ToolList
If Tool.Active Then
FinalNameList.Add(Tool.Name)
ImportToolNameIndex += 1
Else
ImportToolNameList.RemoveAt(ImportToolNameIndex)
End If
Next
Next
Dim vsFinalName = FinalNameList.ToArray()
Dim vsImportToolName = ImportToolNameList.ToArray()
EgtTdbImport(ImportFilePath, vsImportToolName, vsFinalName, m_vsImported)
Dim ImportedToolList As New List(Of String)(vsImported)
MessageBox.Show(EgtMsg(31166) & " " & vbCrLf &
String.Join(vbCrLf, ImportedToolList.ToArray()), "", MessageBoxButton.OK)
Case WindowModeEnum.EXPORT
' chiedo il nome con cui salvare il file .data
Dim SaveFileDlg As New System.Windows.Forms.SaveFileDialog() With {
.Title = EgtMsg(31162) & " " & EgtMsg(31163),
.Filter = "File data (*.data)|*.data|Tutti i file (*.*)|*.*",
.FileName = String.Empty
}
If SaveFileDlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return
Dim sFilePath As String = String.Empty
sFilePath = SaveFileDlg.FileName
' recupero gli utensili checkati
Dim FinalNameList As New List(Of String)
For Each Family In FamilyList
For Each Tool In Family.ToolList
If Tool.Active Then
FinalNameList.Add(Tool.Name)
End If
Next
Next
Dim FinalNameArray = FinalNameList.ToArray()
EgtTdbExport(FinalNameArray, sFilePath)
End Select
' Chiusura finestra
RaiseEvent m_CloseWindow(True)
End Sub
#End Region ' OkCommand
#End Region ' Commands
#Region "CONSTRUCTOR"
Sub New(FamilyList As ObservableCollection(Of ImpExpFamily), Optional sImportFilePath As String = Nothing, Optional vsImportFileToolNameList As String() = Nothing)
If IsNothing(sImportFilePath) OrElse IsNothing(vsImportFileToolNameList) Then
m_WindowMode = WindowModeEnum.EXPORT
Else
m_WindowMode = WindowModeEnum.IMPORT
m_ImportFilePath = sImportFilePath
m_ImportFileToolNameList = vsImportFileToolNameList
End If
' carico lista
Me.FamilyList = FamilyList
End Sub
#End Region ' Constructor
End Class
Public Class ImpExpFamily
Inherits VMBase
Private m_Name As String
Public Property Name As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_FamilyType As Integer
''' <summary>
''' Property that determines the tool type of the family
''' </summary>
Public Property FamilyType As Integer
Get
Return m_FamilyType
End Get
Set(value As Integer)
m_FamilyType = value
End Set
End Property
Private m_ToolList As New ObservableCollection(Of ImpExpItem)
Public Property ToolList As ObservableCollection(Of ImpExpItem)
Get
Return m_ToolList
End Get
Set(value As ObservableCollection(Of ImpExpItem))
m_ToolList = value
End Set
End Property
Private m_sPictureString As String
Public Property PictureString As String
Get
Return m_sPictureString
End Get
Set(value As String)
If value <> m_sPictureString Then
m_sPictureString = value
End If
End Set
End Property
Sub New(Name As String, FamilyType As Integer)
m_Name = Name
m_FamilyType = FamilyType
m_sPictureString = "/Resources/TreeView/Folder.png"
End Sub
End Class
Public Class ImpExpItem
Inherits VMBase
Private m_Name As String
Public Property Name As String
Get
If m_ChangeName Then
Return m_Name & "_imp"
Else
Return m_Name
End If
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Active As Boolean
Public Property Active As Boolean
Get
Return m_Active
End Get
Set(value As Boolean)
' se esiste gia' chiedo se sovrascriverlo
If value Then
If m_AlreadyExist Then
Select Case System.Windows.MessageBox.Show(EgtMsg(31164), "", MessageBoxButton.YesNoCancel)
Case MessageBoxResult.Yes
m_ChangeName = False
m_Active = True
Case MessageBoxResult.No
System.Windows.MessageBox.Show(EgtMsg(31165), "", MessageBoxButton.OK)
m_ChangeName = True
m_Active = True
Case Else
m_Active = False
End Select
NotifyPropertyChanged("Active")
Else
m_Active = True
End If
Else
m_ChangeName = False
m_Active = False
End If
End Set
End Property
' Parametro che indica se questo item da importare esiste gia'
Private m_AlreadyExist As Boolean
Friend ReadOnly Property AlreadyExist As Boolean
Get
Return m_AlreadyExist
End Get
End Property
' Parametro che indica se cambiare il nome di un item che esiste gia' o sovrascriverlo
Private m_ChangeName As Boolean
Friend Property ChangeName As Boolean
Get
Return m_ChangeName
End Get
Set(value As Boolean)
m_ChangeName = value
NotifyPropertyChanged("Name")
End Set
End Property
Sub New(Name As String, AlreadyExist As Boolean)
m_Name = Name
m_AlreadyExist = AlreadyExist
End Sub
End Class