7ceb4aa92b
- modifica nome eventi chiusura finestre.
328 lines
10 KiB
VB.net
328 lines
10 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports EgtUILib
|
|
|
|
Public Class ImportExportMachiningWindowVM
|
|
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 delle lavorazioni
|
|
Private m_FamilyList As New ObservableCollection(Of ImpExpMachiningFamily)
|
|
Public Property FamilyList As ObservableCollection(Of ImpExpMachiningFamily)
|
|
Get
|
|
Return m_FamilyList
|
|
End Get
|
|
Set(value As ObservableCollection(Of ImpExpMachiningFamily))
|
|
m_FamilyList = value
|
|
End Set
|
|
End Property
|
|
|
|
' Percorso del file da cui importare le lavorazioni
|
|
Private m_ImportFilePath As String
|
|
Public ReadOnly Property ImportFilePath As String
|
|
Get
|
|
Return m_ImportFilePath
|
|
End Get
|
|
End Property
|
|
|
|
' Lista delle lavorazioni presenti nel file da cui importare
|
|
Private m_ImportFileMachiningNameList As String()
|
|
Public ReadOnly Property ImportFileMachiningNameList As String()
|
|
Get
|
|
Return m_ImportFileMachiningNameList
|
|
End Get
|
|
End Property
|
|
|
|
' Lista delle lavorazioni importate con successo
|
|
Private m_vsImported As String()
|
|
Public ReadOnly Property vsImported As String()
|
|
Get
|
|
Return m_vsImported
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property IsEnabledOkBtn As Boolean
|
|
Get
|
|
For Each Family In FamilyList
|
|
For Each Machining In Family.MachiningList
|
|
If Machining.Active Then Return True
|
|
Next
|
|
Next
|
|
Return False
|
|
End Get
|
|
End Property
|
|
|
|
Friend Event OnCloseWindow(bDialogResult As Boolean)
|
|
|
|
#Region "MESSAGES"
|
|
|
|
Public ReadOnly Property OkMsg As String
|
|
Get
|
|
If WindowMode = WindowModeEnum.IMPORT Then
|
|
Return EgtMsg(31450) ' Importa
|
|
Else
|
|
Return EgtMsg(31451) ' Esporta
|
|
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 ConfirmImpExpMachinings)
|
|
End If
|
|
Return m_cmdOk
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand.
|
|
''' </summary>
|
|
Public Sub ConfirmImpExpMachinings(param As Object)
|
|
Select Case WindowMode
|
|
Case WindowModeEnum.IMPORT
|
|
Dim FinalNameList As New List(Of String)
|
|
Dim ImportMachiningNameList As New List(Of String)(ImportFileMachiningNameList)
|
|
For Each Family In FamilyList
|
|
For Each Machining In Family.MachiningList
|
|
If Machining.Active Then
|
|
FinalNameList.Add(Machining.Name)
|
|
Else
|
|
ImportMachiningNameList.Remove(Machining.Name)
|
|
End If
|
|
Next
|
|
Next
|
|
Dim vsFinalName = FinalNameList.ToArray()
|
|
Dim vsImportMachiningName = ImportMachiningNameList.ToArray()
|
|
' Eseguo importazione
|
|
EgtMdbImport(ImportFilePath, vsImportMachiningName, vsFinalName, m_vsImported)
|
|
' Report
|
|
Dim ImportedMachiningList As New List(Of String)(vsImported)
|
|
MessageBox.Show(EgtMsg(31455) & " " & vbCrLf & String.Join(vbCrLf, ImportedMachiningList.ToArray()), "", MessageBoxButton.OK)
|
|
'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31455) & " " & vbCrLf & String.Join(vbCrLf, ImportedMachiningList.ToArray()), "", MessageBoxButton.OK) ' Le seguenti Lavorazioni sono state importate correttamente:
|
|
|
|
Case WindowModeEnum.EXPORT
|
|
' recupero le lavorazioni checkate
|
|
Dim FinalNameList As New List(Of String)
|
|
For Each Family In FamilyList
|
|
For Each Machining In Family.MachiningList
|
|
If Machining.Active Then
|
|
FinalNameList.Add(Machining.Name)
|
|
End If
|
|
Next
|
|
Next
|
|
If FinalNameList.Count() = 0 Then Return
|
|
Dim FinalNameArray = FinalNameList.ToArray()
|
|
' chiedo il nome con cui salvare il file .data
|
|
Dim SaveFileDlg As New System.Windows.Forms.SaveFileDialog() With {
|
|
.Title = EgtMsg(31451) & " " & EgtMsg(31452),
|
|
.Filter = "File data (*.data)|*.data|Tutti i file (*.*)|*.*",
|
|
.FileName = String.Empty
|
|
}
|
|
'Dim SaveFileDlg As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
|
|
' .Title = EgtMsg(31451) & " " & EgtMsg(31452), ' Esporta lavorazioni
|
|
' .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
|
|
' Eseguo esportazione
|
|
EgtMdbExport(FinalNameArray, sFilePath)
|
|
|
|
End Select
|
|
|
|
' Chiusura finestra
|
|
RaiseEvent OnCloseWindow(True)
|
|
End Sub
|
|
|
|
#End Region ' OkCommand
|
|
|
|
#End Region ' Commands
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New(FamilyList As ObservableCollection(Of ImpExpMachiningFamily), bExport As Boolean, Optional sImportFilePath As String = Nothing, Optional vsImportFileMachiningNameList As String() = Nothing)
|
|
If bExport Then
|
|
m_WindowMode = WindowModeEnum.EXPORT
|
|
Else
|
|
m_WindowMode = WindowModeEnum.IMPORT
|
|
m_ImportFilePath = sImportFilePath
|
|
m_ImportFileMachiningNameList = vsImportFileMachiningNameList
|
|
End If
|
|
' carico lista
|
|
Me.FamilyList = FamilyList
|
|
ImpExpMachiningItem.m_delEnableOkBtn = AddressOf EnableOkBtn
|
|
End Sub
|
|
|
|
#End Region ' Constructor
|
|
|
|
#Region "METHODS"
|
|
|
|
Private Sub EnableOkBtn()
|
|
NotifyPropertyChanged(NameOf(IsEnabledOkBtn))
|
|
End Sub
|
|
|
|
#End Region ' Methods
|
|
|
|
End Class
|
|
|
|
Public Class ImpExpMachiningFamily
|
|
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_MachiningList As New ObservableCollection(Of ImpExpMachiningItem)
|
|
Public Property MachiningList As ObservableCollection(Of ImpExpMachiningItem)
|
|
Get
|
|
Return m_MachiningList
|
|
End Get
|
|
Set(value As ObservableCollection(Of ImpExpMachiningItem))
|
|
m_MachiningList = 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 ImpExpMachiningItem
|
|
Inherits VMBase
|
|
|
|
' Actions
|
|
Friend Shared m_delEnableOkBtn As Action
|
|
|
|
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 sovrascriverla
|
|
If value Then
|
|
If m_AlreadyExist Then
|
|
Select Case System.Windows.MessageBox.Show(EgtMsg(31453), "", MessageBoxButton.YesNoCancel)
|
|
'Select Case EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31453), "", MessageBoxButton.YesNoCancel) ' La lavorazione esiste già, sovrascriverla?
|
|
Case MessageBoxResult.Yes
|
|
m_ChangeName = False
|
|
m_Active = True
|
|
Case MessageBoxResult.No
|
|
System.Windows.MessageBox.Show(EgtMsg(31454), "", MessageBoxButton.OK)
|
|
'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31454), "", MessageBoxButton.OK) ' La lavorazione verrà importata col nome seguito da "_imp"
|
|
m_ChangeName = True
|
|
m_Active = True
|
|
Case Else
|
|
m_Active = False
|
|
End Select
|
|
NotifyPropertyChanged(NameOf(Active))
|
|
Else
|
|
m_Active = True
|
|
End If
|
|
Else
|
|
m_ChangeName = False
|
|
m_Active = False
|
|
End If
|
|
If Not IsNothing(m_delEnableOkBtn) Then m_delEnableOkBtn()
|
|
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(NameOf(Name))
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Name As String, AlreadyExist As Boolean)
|
|
m_Name = Name
|
|
m_AlreadyExist = AlreadyExist
|
|
End Sub
|
|
|
|
End Class
|