00a338c202
This reverts commit1f49d0936e, reversing changes made to236eeac038.
144 lines
4.5 KiB
VB.net
144 lines
4.5 KiB
VB.net
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(MSG_EGTSAVEFILEDIALOG + 11)
|
|
Else
|
|
Return EgtMsg(MSG_EGTSAVEFILEDIALOG + 10)
|
|
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(MSG_MACHININGDBERRORS + 4),
|
|
EgtMsg(MSG_EGTSAVEFILEDIALOG + 7),
|
|
MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
NotifyPropertyChanged("WriteFileName")
|
|
End Set
|
|
End Property
|
|
|
|
#Region "Messages"
|
|
|
|
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 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("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(MSG_EGTSAVEFILEDIALOG + 8), EgtMsg(MSG_EGTSAVEFILEDIALOG + 7), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return False
|
|
End If
|
|
If IsFolder Then
|
|
If System.IO.Directory.Exists(sCompleteFileName) Then
|
|
If MessageBox.Show(m_WriteFileName & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3) & vbCrLf & EgtMsg(MSG_EGTSAVEFILEDIALOG + 4), EgtMsg(MSG_EGTSAVEFILEDIALOG + 9), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then
|
|
Return False
|
|
End If
|
|
End If
|
|
Else
|
|
If File.Exists(sCompleteFileName) Then
|
|
If MessageBox.Show(m_WriteFileName & " " & EgtMsg(MSG_EGTSAVEFILEDIALOG + 3) & vbCrLf & EgtMsg(MSG_EGTSAVEFILEDIALOG + 4), EgtMsg(MSG_EGTSAVEFILEDIALOG + 9), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) <> MessageBoxResult.Yes Then
|
|
Return False
|
|
End If
|
|
End If
|
|
End If
|
|
m_FileName = sCompleteFileName
|
|
Return True
|
|
End Function
|
|
|
|
End Class
|