Imports System.IO Imports EgtUILib Public Class SaveFileDialogVM Inherits VMBase Private m_Title As String Public Property Title As String Get If IsNothing(m_Title) Then If IsFolder Then Return EgtMsg(30011) ' Nome File Else Return EgtMsg(30010) ' Nome Cartella End If Else Return m_Title End If End Get Set(value As String) m_Title = value End Set End Property Private m_sDirectory As String Public Property Directory As String Get Return m_sDirectory End Get Set(value As String) m_sDirectory = value End Set End Property Private m_sExtension As String = String.Empty Public Property Extension As String Get Return m_sExtension End Get Set(value As String) m_sExtension = value End Set End Property Private m_FileName As String Public Property FileName As String Get Return m_FileName End Get Set(value As String) m_FileName = value End Set End Property Private m_IsFolder As Boolean = False Public Property IsFolder As Boolean Get Return m_IsFolder End Get Set(value As Boolean) m_IsFolder = value End Set End Property Private m_WriteFileName As String Public Property WriteFileName As String Get Return m_WriteFileName End Get Set(value As String) Dim TempName As String = value For Each cInvalid In Path.GetInvalidFileNameChars() TempName = TempName.Replace(cInvalid, "") Next If TempName.Length = value.Length Then m_WriteFileName = value Else MessageBox.Show(EgtMsg(31404), EgtMsg(31407), MessageBoxButton.OK, MessageBoxImage.Error) 'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(31404), ' I caratteri \ / : * ? " < > | non sono permessi ' EgtMsg(31407), ' CANCELLA ' MessageBoxButton.OK, MessageBoxImage.Error) End If NotifyPropertyChanged(NameOf(WriteFileName)) End Set End Property #Region "Messages" Public ReadOnly Property SaveMsg As String Get Return EgtMsg(30001) ' Salva End Get End Property Public ReadOnly Property CancelMsg As String Get Return EgtMsg(30002) ' Annulla End Get End Property #End Region Public Sub Initialize() ' se la cartella d'origine non è stata impostata, esco If String.IsNullOrWhiteSpace(m_sDirectory) Then Throw New Exception("Exception: Directory is null or white space!") End If ' se non esiste, esco If Not IO.Directory.Exists(m_sDirectory) Then Throw New Exception("Exception: Directory doesn't exist!") End If If String.IsNullOrWhiteSpace(m_sExtension) And Not IsFolder Then Throw New Exception("Exception: Extension is null or white space!") End If ' verifico se è impostato un nome di default If Not String.IsNullOrWhiteSpace(m_FileName) Then m_WriteFileName = m_FileName End If NotifyPropertyChanged(NameOf(WriteFileName)) If IsFolder Then m_sExtension = "" End Sub Friend Function Save() As Boolean Dim sCompleteFileName As String = m_sDirectory & "\" & m_WriteFileName & If(IsFolder, "", m_sExtension) If String.IsNullOrWhiteSpace(m_WriteFileName) Then MessageBox.Show(EgtMsg(30008), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) 'EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(30008), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) ' Il nome non può essere vuoto! - ERRORE Return False End If If IsFolder Then If System.IO.Directory.Exists(sCompleteFileName) Then If MessageBox.Show(m_WriteFileName & " " & EgtMsg(30003) & vbCrLf & EgtMsg(30004), EgtMsg(30009), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then 'If EgtMessageBoxV.Show(Application.Current.MainWindow, m_WriteFileName & " " & EgtMsg(30003) & vbCrLf & EgtMsg(30004), EgtMsg(30009), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then ' esiste già - Sostituirlo? - ATTENZIONE Return False End If End If Else If File.Exists(sCompleteFileName) Then If MessageBox.Show(m_WriteFileName & " " & EgtMsg(30003) & vbCrLf & EgtMsg(30004), EgtMsg(30009), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then 'If EgtMessageBoxV.Show(Application.Current.MainWindow, m_WriteFileName & " " & EgtMsg(30003) & vbCrLf & EgtMsg(30004), EgtMsg(30009), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then ' esiste già - Sostituirlo? - ATTENZIONE Return False End If End If End If m_FileName = sCompleteFileName Return True End Function End Class