Files
EgtWPFLib5/EgtSaveFileDialog.xaml.vb
T
Emmanuele Sassi 2b351326e8 EgtWPFLib5 :
- Corretti errori nelle path generate da EgtSaveFileDialog.
2017-02-10 18:34:43 +00:00

122 lines
4.1 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports EgtUILib
Public Class EgtSaveFileDialog
Implements INotifyPropertyChanged
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
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
NotifyPropertyChanged("FileName")
End Set
End Property
#Region "Messages"
Public ReadOnly Property FileNameMsg As String
Get
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 5)
End Get
End Property
Public ReadOnly Property SaveMsg As String
Get
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 1)
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 2)
End Get
End Property
#End Region
Public Function EgtShowDialog() As Boolean?
' se la cartella d'origine è stata impostata
If String.IsNullOrWhiteSpace(m_sDirectory) Then
Throw New Exception("Exception: Directory is null or white space!")
End If
' e se esiste
If Not IO.Directory.Exists(m_sDirectory) Then
Throw New Exception("Exception: Directory doesn't exist!")
End If
If String.IsNullOrWhiteSpace(m_sExtension) 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
If Not Path.GetDirectoryName(m_FileName) <> String.Empty Then
m_FileName = m_sDirectory & "\" & m_FileName & m_sExtension
End If
Else
m_FileName = m_sDirectory & "\" & m_FileName & m_sExtension
End If
NotifyPropertyChanged("FileName")
' mostro la finestra di dialogo
Return Me.ShowDialog()
End Function
Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
If String.IsNullOrWhiteSpace(m_FileName) OrElse String.IsNullOrWhiteSpace(Path.GetFileNameWithoutExtension(m_FileName)) Then
MessageBox.Show(EgtMsg(MSG_EGTSAVEFILEDIALOG + 8), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error)
Exit Sub
End If
If File.Exists(m_FileName) Then
If MessageBox.Show(m_FileName & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3) & vbCrLf & EgtMsg(MSG_EGTSAVEFILEDIALOG + 4), EgtMsg(MSG_EGTSAVEFILEDIALOG + 9), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then
Exit Sub
End If
End If
DialogResult = True
End Sub
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub NotifyPropertyChanged(propName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
End Sub
End Class
''' <summary>
''' Class that represent a Converter that convert the complete file path in the file name and vice versa.
''' </summary>
Public Class FileNameConverter
Implements IValueConverter
Dim TempPath As String
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
TempPath = CStr(value)
Return Path.GetFileNameWithoutExtension(TempPath)
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Path.GetDirectoryName(TempPath) & "\" & CStr(value) & Path.GetExtension(TempPath)
End Function
End Class