Files
EgtCAM5/TopCommandBar/TopCommandBarViewModel.vb
T
Emmanuele Sassi 79b9e49ae0 EgtCAM5 :
- Aggiunto bottoni per mandare mail all'assistenza in TopCommandBar.
- Corretta visualizzazione tooltip in setup quando caricato da archivio.
2017-02-15 19:14:28 +00:00

482 lines
17 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Namespace EgtCAM5
Public Class TopCommandBarViewModel
Inherits ViewModelBase
#Region "FIELDS & PROPERTIES"
Public ReadOnly Property MruFileNames As ObservableCollection(Of String)
Get
Return IniFile.m_MruFiles.m_FileNames
End Get
End Property
' Definizione comandi
Private m_cmdNew As ICommand
Private m_cmdOpen As ICommand
Private Shared m_cmdOpenMruFile As ICommand
Private m_cmdSave As ICommand
Private m_cmdSaveAs As ICommand
Private m_cmdInsert As ICommand
Private m_cmdImport As ICommand
Private m_cmdExport As ICommand
Private m_cmdOptions As ICommand
Private m_cmdSendFeedback As ICommand
#Region "Messages"
Public ReadOnly Property DrawMsg As String
Get
Return EgtMsg(MSG_MAINWINDOW + 1)
End Get
End Property
Public ReadOnly Property MachiningMsg As String
Get
Return EgtMsg(MSG_MAINWINDOW + 2)
End Get
End Property
#End Region ' Messages
#Region "ToolTip"
'Proprietà ToolTip
Public ReadOnly Property NewToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 1)
End Get
End Property
Public ReadOnly Property OpenToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 2)
End Get
End Property
Public ReadOnly Property SaveToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 3)
End Get
End Property
Public ReadOnly Property SaveAsToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 4)
End Get
End Property
Public ReadOnly Property InsertToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 5)
End Get
End Property
Public ReadOnly Property ImportToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 6)
End Get
End Property
Public ReadOnly Property ExportToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 7)
End Get
End Property
Public ReadOnly Property OptionsToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 9)
End Get
End Property
#End Region ' ToolTip
Private m_DrawIsChecked As Boolean
Public Property DrawIsChecked As Boolean
Get
Return m_DrawIsChecked
End Get
Set(value As Boolean)
If value <> m_DrawIsChecked Then
m_DrawIsChecked = value
If value Then
Application.Msn.NotifyColleagues(Application.DRAWMODE_ISCHECKED)
EgtResetCurrMachGroup()
EgtZoom(ZM.ALL)
Application.Msn.NotifyColleagues(Application.LOADOBJTREE)
IniFile.m_ProjectMode = ProjectModeOpt.DRAW
End If
OnPropertyChanged("DrawIsChecked")
End If
End Set
End Property
Private m_MachiningIsChecked As Boolean
Public Property MachiningIsChecked As Boolean
Get
Return m_MachiningIsChecked
End Get
Set(value As Boolean)
If value <> m_MachiningIsChecked Then
m_MachiningIsChecked = value
If value Then
Application.Msn.NotifyColleagues(Application.INITIALIZEMACHGROUPS)
Else
' Deevidenzio l'ultima operazione evidenziata
Application.Msn.NotifyColleagues(Application.REMOVEMARKFROMLASTOPERATION)
' e deseleziono tutto
EgtDeselectAll()
End If
End If
End Set
End Property
#End Region ' Fields & Properties
#Region "CONSTRUCTOR"
Sub New()
' Inizializzo la selezione della modilità Draw all'apertura del programma
DrawIsChecked = True
Application.Msn.Register(Application.SETMACHININGMODE, Sub()
MachiningIsChecked = True
OnPropertyChanged("MachiningIsChecked")
End Sub)
Application.Msn.Register(Application.MACHGROUPSRESULT, Sub(bOk As Boolean)
If bOk Then
'EgtZoom(ZM.ALL)
Application.Msn.NotifyColleagues(Application.UPDATECURRENTMACHINE)
Application.Msn.NotifyColleagues(Application.MACHININGMODE_ISCHECKED)
Application.Msn.NotifyColleagues(Application.UPDATEOPERATIONMACHININGLIST)
IniFile.m_ProjectMode = ProjectModeOpt.MACHINING
Else
m_MachiningIsChecked = False
' Error loading or creating Machining Group - Error
MessageBox.Show(EgtMsg(10008), EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error)
End If
End Sub)
End Sub
#End Region
#Region "COMMANDS"
#Region "NewCommand"
''' <summary>
''' Returns a command that do New.
''' </summary>
Public ReadOnly Property NewCommand As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New RelayCommand(AddressOf NewCmd)
End If
Return m_cmdNew
End Get
End Property
''' <summary>
''' Execute the New. This method is invoked by the NewCommand.
''' </summary>
Public Sub NewCmd(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.NEWPROJECT)
OnPropertyChanged("MruFileNames")
End Sub
#End Region ' NewCommand
#Region "OpenCommand"
''' <summary>
''' Returns a command that do Open.
''' </summary>
Public ReadOnly Property OpenCommand As ICommand
Get
If m_cmdOpen Is Nothing Then
m_cmdOpen = New RelayCommand(AddressOf Open)
End If
Return m_cmdOpen
End Get
End Property
''' <summary>
''' Execute the Open. This method is invoked by the OpenCommand.
''' </summary>
Public Sub Open(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.OPENPROJECT, String.Empty)
End Sub
#End Region ' OpenCommand
#Region "OpenMruFileCommand"
''' <summary>
''' Returns a command that do Open.
''' </summary>
Public Shared ReadOnly Property OpenMruFileCommand As ICommand
Get
If m_cmdOpenMruFile Is Nothing Then
m_cmdOpenMruFile = New RelayCommand(AddressOf OpenMruFile)
End If
Return m_cmdOpenMruFile
End Get
End Property
''' <summary>
''' Execute the Open. This method is invoked by the OpenCommand.
''' </summary>
Public Shared Sub OpenMruFile(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.OPENPROJECT, DirectCast(param, String).Replace("__", "_"))
End Sub
#End Region ' OpenMruFileCommand
#Region "SaveCommand"
''' <summary>
''' Returns a command that do Save.
''' </summary>
Public ReadOnly Property SaveCommand As ICommand
Get
If m_cmdSave Is Nothing Then
m_cmdSave = New RelayCommand(AddressOf Save)
End If
Return m_cmdSave
End Get
End Property
''' <summary>
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Save(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.SAVEPROJECT)
End Sub
#End Region ' SaveCommand
#Region "SaveAsCommand"
''' <summary>
''' Returns a command that do SaveAs.
''' </summary>
Public ReadOnly Property SaveAsCommand As ICommand
Get
If m_cmdSaveAs Is Nothing Then
m_cmdSaveAs = New RelayCommand(AddressOf SaveAs)
End If
Return m_cmdSaveAs
End Get
End Property
''' <summary>
''' Execute the SaveAs. This method is invoked by the SaveAsCommand.
''' </summary>
Public Sub SaveAs(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.SAVEASPROJECT)
End Sub
#End Region ' SaveAsCommand
#Region "InsertCommand"
''' <summary>
''' Returns a command that do Insert.
''' </summary>
Public ReadOnly Property InsertCommand As ICommand
Get
If m_cmdInsert Is Nothing Then
m_cmdInsert = New RelayCommand(AddressOf Insert)
End If
Return m_cmdInsert
End Get
End Property
''' <summary>
''' Execute the Insert. This method is invoked by the InsertCommand.
''' </summary>
Public Sub Insert(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.INSERTPROJECT)
End Sub
#End Region ' InsertCommand
#Region "ImportCommand"
''' <summary>
''' Returns a command that do Import.
''' </summary>
Public ReadOnly Property ImportCommand As ICommand
Get
If m_cmdImport Is Nothing Then
m_cmdImport = New RelayCommand(AddressOf Import)
End If
Return m_cmdImport
End Get
End Property
''' <summary>
''' Execute the Import. This method is invoked by the ImportCommand.
''' </summary>
Public Sub Import(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.IMPORTPROJECT)
End Sub
#End Region ' ImportCommand
#Region "ExportCommand"
''' <summary>
''' Returns a command that do Export.
''' </summary>
Public ReadOnly Property ExportCommand As ICommand
Get
If m_cmdExport Is Nothing Then
m_cmdExport = New RelayCommand(AddressOf Export)
End If
Return m_cmdExport
End Get
End Property
''' <summary>
''' Execute the Export. This method is invoked by the ExportCommand.
''' </summary>
Public Sub Export(ByVal param As Object)
Application.Msn.NotifyColleagues(Application.EXPORTPROJECT)
End Sub
#End Region ' ExportCommand
#Region "OptionsCommand"
''' <summary>
''' Returns a command that do Export.
''' </summary>
Public ReadOnly Property OptionsCommand As ICommand
Get
If m_cmdOptions Is Nothing Then
m_cmdOptions = New RelayCommand(AddressOf Options)
End If
Return m_cmdOptions
End Get
End Property
''' <summary>
''' Execute the Export. This method is invoked by the ExportCommand.
''' </summary>
Public Sub Options(ByVal param As Object)
Dim OptionsWindow As New OptionsView
OptionsWindow.Height = 614
OptionsWindow.Width = 1024
OptionsWindow.DataContext = New OptionsViewModel
OptionsWindow.Owner = Application.Current.MainWindow
OptionsWindow.ShowDialog()
End Sub
#End Region ' OptionsCommand
#Region "SendFeedbackCommand"
''' <summary>
''' Returns a command that do Export.
''' </summary>
Public ReadOnly Property SendFeedbackCommand As ICommand
Get
If m_cmdSendFeedback Is Nothing Then
m_cmdSendFeedback = New RelayCommand(AddressOf SendFeedback)
End If
Return m_cmdSendFeedback
End Get
End Property
''' <summary>
''' Execute the Export. This method is invoked by the ExportCommand.
''' </summary>
Public Sub SendFeedback(ByVal param As Object)
' recupero indirizzo supporto
Dim sSupportAddress As String = String.Empty
GetPrivateProfileString(S_GENERAL, K_SUPPORT, "", sSupportAddress)
' se vuoto do messaggio di errore ed esco
If String.IsNullOrWhiteSpace(sSupportAddress) Then
MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 10), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' recupero numero chiave
Dim sKey As String = String.Empty
EgtGetKeyInfo(sKey)
' recupero file del progetto corrente
Dim sCurrProject As String = String.Empty
EgtGetCurrFilePath(sCurrProject)
If String.IsNullOrWhiteSpace(sCurrProject) Then
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
Application.Msn.NotifyColleagues(Application.SAVEPROJECT)
End If
EgtGetCurrFilePath(sCurrProject)
Else
If EgtGetModified() Then
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
Application.Msn.NotifyColleagues(Application.SAVEPROJECT)
End If
End If
End If
Dim DoorOtherFiles As New List(Of String)
' se door attivo
If IniFile.IsActiveDoors Then
' recupero file con lo stesso nome del progetto
If Not String.IsNullOrWhiteSpace(sCurrProject) Then
Dim sCurrProjectDir As String = Path.GetDirectoryName(sCurrProject)
If Not String.IsNullOrWhiteSpace(sCurrProjectDir) Then
Dim TempFiles() As String = Directory.GetFiles(sCurrProjectDir)
For FileIndex = 0 To TempFiles.Count - 1
If Path.GetFileNameWithoutExtension(TempFiles(FileIndex)).Contains(Path.GetFileNameWithoutExtension(sCurrProject)) AndAlso TempFiles(FileIndex) <> sCurrProject Then
DoorOtherFiles.Add(TempFiles(FileIndex))
End If
Next
End If
End If
End If
' creo zip file da allegare
Dim sZipToCreate As String = IniFile.m_sTempDir & "\Feedback.zip"
If File.Exists(sZipToCreate) Then
File.Delete(sZipToCreate)
End If
Try
Using zip As New Ionic.Zip.ZipFile(sZipToCreate, Console.Out)
' aggiungo file macchina
zip.AddItem(IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName, IniFile.m_sMachineName)
' aggiungo progetto corrente
If Not String.IsNullOrWhiteSpace(sCurrProject) Then
zip.AddItem(sCurrProject, "")
End If
' se door attivo
If IniFile.IsActiveDoors Then
zip.AddItem(IniFile.m_sDoorsDirPath, "Doors")
If DoorOtherFiles.Count > 0 Then
For FileIndex = 0 To DoorOtherFiles.Count - 1
zip.AddItem(DoorOtherFiles(FileIndex), "")
Next
End If
End If
' salvo lo zip
zip.Save()
End Using
Catch ex1 As Exception
EgtOutLog("Exception in zip: " & ex1.ToString())
End Try
' preparo la mail per il supporto
Try
Dim SendFeedbackWindow As New EgtWPFLib5.MapiMailMessage("EgtCAM5 Feedback - " & sKey)
SendFeedbackWindow.Recipients.Add(sSupportAddress)
If Not String.IsNullOrWhiteSpace(sZipToCreate) AndAlso File.Exists(sZipToCreate) Then
SendFeedbackWindow.Files.Add(IniFile.m_sTempDir & "\Feedback.zip")
End If
SendFeedbackWindow.ShowDialog()
Catch ex As Exception
EgtOutLog("Feedback exception: " & ex.ToString)
MessageBox.Show(String.Format(EgtMsg(MSG_TOPCOMMANDBAR + 12), sSupportAddress, sZipToCreate), EgtMsg(MSG_MESSAGEBOX + 3), MessageBoxButton.OK, MessageBoxImage.Information)
End Try
End Sub
#End Region ' SendFeedbackCommand
#End Region ' Commands
End Class
End Namespace