514 lines
16 KiB
VB.net
514 lines
16 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtWPFLib5
|
|
Imports EgtUILib
|
|
|
|
Public Class ProjManagerVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private m_ProjCmd_IsEnabled As Boolean = True
|
|
Public ReadOnly Property ProjCmd_IsEnabled As Boolean
|
|
Get
|
|
Return m_ProjCmd_IsEnabled
|
|
End Get
|
|
End Property
|
|
Friend Sub SetProjCmdIsEnabled(value As Boolean)
|
|
m_ProjCmd_IsEnabled = value
|
|
NotifyPropertyChanged(NameOf(ProjCmd_IsEnabled))
|
|
End Sub
|
|
|
|
Private m_MruFiles As New MruList
|
|
Public ReadOnly Property MruFiles As MruList
|
|
Get
|
|
Return m_MruFiles
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property MruFileNames As ObservableCollection(Of String)
|
|
Get
|
|
For Each FileName In m_MruFiles.FileNames.ToList()
|
|
If Not File.Exists(FileName) Then
|
|
m_MruFiles.Remove(FileName)
|
|
End If
|
|
Next
|
|
Return m_MruFiles.FileNames
|
|
End Get
|
|
End Property
|
|
|
|
Private m_MruImportFiles As New MruList
|
|
Public ReadOnly Property MruImportFiles As MruList
|
|
Get
|
|
Return m_MruImportFiles
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property MruImportFileNames As ObservableCollection(Of String)
|
|
Get
|
|
For Each FileName In m_MruImportFiles.FileNames.ToList()
|
|
If Not File.Exists(FileName) Then
|
|
m_MruImportFiles.Remove(FileName)
|
|
End If
|
|
Next
|
|
Return m_MruImportFiles.FileNames
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdNew As ICommand
|
|
Private m_cmdOpen As ICommand
|
|
Private m_cmdOpenMruFile As ICommand
|
|
Private m_cmdSave As ICommand
|
|
Private m_cmdSaveAs As ICommand
|
|
Private m_cmdImport As ICommand
|
|
Private m_cmdExport As ICommand
|
|
Private m_cmdOptions As ICommand
|
|
Private m_cmdSendFeedback As ICommand
|
|
Private m_cmdHelp As ICommand
|
|
|
|
|
|
#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 ImportToolTip As String
|
|
Get
|
|
Return "Import"
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property ExportToolTip As String
|
|
Get
|
|
Return "Export"
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property OptionsToolTip As String
|
|
Get
|
|
Return "Options"
|
|
End Get
|
|
End Property
|
|
Public ReadOnly Property SendFeedbackToolTip As String
|
|
Get
|
|
Return "Send Feedback"
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' ToolTip
|
|
|
|
#End Region ' Fields & Properties
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in Map
|
|
Map.SetRefProjManagerVM(Me)
|
|
' Impostazioni MruLists
|
|
m_MruFiles.Init(S_MRUFILES, 8)
|
|
m_MruImportFiles.Init(S_MRUIMPORTFILES, 8)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "New"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Save.
|
|
''' </summary>
|
|
Public ReadOnly Property New_Command As ICommand
|
|
Get
|
|
If m_cmdNew Is Nothing Then
|
|
m_cmdNew = New Command(AddressOf NewProjectCmd)
|
|
End If
|
|
Return m_cmdNew
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Save. This method is invoked by the SaveCommand.
|
|
''' </summary>
|
|
Public Sub NewProjectCmd()
|
|
NewProject(True)
|
|
End Sub
|
|
|
|
Friend Sub NewProject(bDialog As Boolean)
|
|
' Gestisco eventuale file corrente modificato
|
|
If Not Map.refSceneHostVM.MainController.ManageModified() Then Return
|
|
EgtResetModified()
|
|
Dim NewProjMachine As Machine
|
|
If bDialog AndAlso Map.refMachinePanelVM.MachineList.Count > 0 Then
|
|
Dim ChooseMachineWndVM As New ChooseMachineWndVM
|
|
Dim ChooseMachineWnd As New ChooseMachineWndV(Application.Current.MainWindow, ChooseMachineWndVM)
|
|
Dim bResult As Boolean = ChooseMachineWnd.ShowDialog()
|
|
If IsNothing(bResult) OrElse Not bResult Then Return
|
|
NewProjMachine = ChooseMachineWndVM.SelMachine
|
|
Else
|
|
NewProjMachine = Map.refMachinePanelVM.SelectedMachine
|
|
End If
|
|
' imposto la macchina
|
|
Map.refMachinePanelVM.SelectedMachine = NewProjMachine
|
|
' creo nuovo progetto
|
|
Map.refSceneHostVM.MainController.NewProject(True)
|
|
NotifyPropertyChanged(NameOf(MruFileNames))
|
|
End Sub
|
|
|
|
#End Region ' New
|
|
|
|
#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 Command(AddressOf Open)
|
|
End If
|
|
Return m_cmdOpen
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Open. This method is invoked by the OpenCommand.
|
|
''' </summary>
|
|
Friend Sub Open()
|
|
OpenProject("")
|
|
End Sub
|
|
|
|
Friend Function OpenProject(sFilePath As String) As Boolean
|
|
Map.refSceneHostVM.OpenProject(sFilePath)
|
|
End Function
|
|
|
|
#End Region ' OpenCommand
|
|
|
|
#Region "OpenMruFileCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Open.
|
|
''' </summary>
|
|
Public ReadOnly Property OpenMruFileCommand As ICommand
|
|
Get
|
|
If m_cmdOpenMruFile Is Nothing Then
|
|
m_cmdOpenMruFile = New Command(AddressOf OpenMruFile)
|
|
End If
|
|
Return m_cmdOpenMruFile
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Open. This method is invoked by the OpenCommand.
|
|
''' </summary>
|
|
Public Sub OpenMruFile(ByVal param As Object)
|
|
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 Command(AddressOf SaveCmd)
|
|
End If
|
|
Return m_cmdSave
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub SaveCmd()
|
|
Save()
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Execute the Save. This method is invoked by the SaveCommand.
|
|
''' </summary>
|
|
Public Sub Save()
|
|
Map.refSceneHostVM.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 Command(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)
|
|
Map.refSceneHostVM.SaveAsProject()
|
|
End Sub
|
|
|
|
#End Region ' SaveAsCommand
|
|
|
|
#Region "Import"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Import.
|
|
''' </summary>
|
|
Public ReadOnly Property ImportCommand As ICommand
|
|
Get
|
|
If m_cmdImport Is Nothing Then
|
|
m_cmdImport = New Command(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)
|
|
Map.refSceneHostVM.InsertProject()
|
|
End Sub
|
|
|
|
#End Region ' Import
|
|
|
|
#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 Command(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)
|
|
Map.refSceneHostVM.ExportProject()
|
|
End Sub
|
|
|
|
#End Region ' ExportCommand
|
|
|
|
#Region "Options"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Export.
|
|
''' </summary>
|
|
Public ReadOnly Property OptionsCommand As ICommand
|
|
Get
|
|
If m_cmdOptions Is Nothing Then
|
|
m_cmdOptions = New Command(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 OptionWindowV
|
|
OptionsWindow.DataContext = New OptionWindowVM
|
|
OptionsWindow.Owner = Application.Current.MainWindow
|
|
OptionsWindow.ShowDialog()
|
|
End Sub
|
|
|
|
#End Region ' Options
|
|
|
|
#Region "SendFeedback"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do SendFeedback.
|
|
''' </summary>
|
|
Public ReadOnly Property SendFeedbackCommand As ICommand
|
|
Get
|
|
If m_cmdSendFeedback Is Nothing Then
|
|
m_cmdSendFeedback = New Command(AddressOf SendFeedback)
|
|
End If
|
|
Return m_cmdSendFeedback
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the SendFeedback. This method is invoked by the SendFeedbackCommand.
|
|
''' </summary>
|
|
Public Sub SendFeedback(ByVal param As Object)
|
|
' Recupero indirizzo a cui spedire la mail
|
|
Dim sSupportAddress As String = String.Empty
|
|
GetMainPrivateProfileString(S_GENERAL, K_SUPPORT, "support@egaltech.com", 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)
|
|
' se nome file vuoto o con estensione non valida, chiedo se si vuole salvare
|
|
If String.IsNullOrWhiteSpace(sCurrProject) Or EgtGetFileType(sCurrProject) <> FT.NGE Then
|
|
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
|
|
Map.refSceneHostVM.SaveProject()
|
|
End If
|
|
EgtGetCurrFilePath(sCurrProject)
|
|
' se modificato, chiedo se si vuole salvare
|
|
Else
|
|
If EgtGetModified() Then
|
|
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
|
|
Map.refSceneHostVM.SaveProject()
|
|
End If
|
|
End If
|
|
End If
|
|
' Verifico se il progetto corrente è una porta
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
If nPartId = GDB_ID.NULL Then
|
|
nPartId = EgtGetFirstPartInRawPart(EgtGetFirstRawPart())
|
|
End If
|
|
Dim sPartName As String = String.Empty
|
|
EgtGetName(nPartId, sPartName)
|
|
Dim bPrjIsDoor As Boolean = (String.Compare(sPartName, "DOOR") = 0)
|
|
' Recupero macchine dei gruppi di lavoro del progetto
|
|
Dim Machines As New List(Of String)
|
|
Dim nMchGrpId As Integer = EgtGetFirstMachGroup()
|
|
While nMchGrpId <> GDB_ID.NULL
|
|
Dim sMachineName As String = String.Empty
|
|
EgtGetMachGroupMachineName(nMchGrpId, sMachineName)
|
|
If Not String.IsNullOrWhiteSpace(sMachineName) Then
|
|
Machines.Add(sMachineName)
|
|
End If
|
|
nMchGrpId = EgtGetNextMachGroup(nMchGrpId)
|
|
End While
|
|
' Recupero altri file con lo stesso nome del progetto
|
|
Dim OtherFiles As New List(Of String)
|
|
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
|
|
OtherFiles.Add(TempFiles(FileIndex))
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
' Creo zip file da allegare
|
|
Dim sZipToCreate As String = Map.refMainWindowVM.MainWindowM.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 macchine
|
|
For Each sMachineName As String In Machines
|
|
Dim sMachineDir As String = Map.refMainWindowVM.MainWindowM.sMachinesRoot & "\" & sMachineName
|
|
If Directory.Exists(sMachineDir) Then
|
|
zip.AddItem(sMachineDir, sMachineName)
|
|
End If
|
|
Next
|
|
' aggiungo progetto corrente
|
|
If File.Exists(sCurrProject) Then
|
|
zip.AddItem(sCurrProject, "")
|
|
End If
|
|
' aggiungo file log
|
|
If File.Exists(Map.refMainWindowVM.MainWindowM.sLogFile) Then
|
|
zip.AddItem(Map.refMainWindowVM.MainWindowM.sLogFile, "")
|
|
End If
|
|
' aggiungo file ausiliari
|
|
For Each sOther As String In OtherFiles
|
|
zip.AddItem(sOther, "")
|
|
Next
|
|
' 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
|
|
Dim bEx As Boolean = False
|
|
Try
|
|
Dim sAddressArray As String() = sSupportAddress.Split(CType(",", Char()))
|
|
Dim SendFeedbackWindow As New EgtWPFLib5.MapiMailMessage("Icarus Feedback - " & sKey)
|
|
SendFeedbackWindow.Recipients.Add(sAddressArray(0))
|
|
For index As Integer = 1 To sAddressArray.Length() - 1
|
|
SendFeedbackWindow.Recipients.Add(sAddressArray(index), EgtWPFLib5.MapiMailMessage.RecipientType.CC)
|
|
Next
|
|
If Not String.IsNullOrWhiteSpace(sZipToCreate) AndAlso File.Exists(sZipToCreate) Then
|
|
SendFeedbackWindow.Files.Add(Map.refMainWindowVM.MainWindowM.sTempDir & "\Feedback.zip")
|
|
End If
|
|
SendFeedbackWindow.ShowDialog()
|
|
Catch ex As Exception
|
|
EgtOutLog("Feedback exception: " & ex.ToString)
|
|
bEx = True
|
|
End Try
|
|
If bEx OrElse EgtWPFLib5.MapiMailMessage.m_ErrorCode <> 0 Then
|
|
MessageBox.Show(String.Format(EgtMsg(MSG_TOPCOMMANDBAR + 12), sSupportAddress, sZipToCreate), EgtMsg(MSG_MESSAGEBOX + 3), MessageBoxButton.OK, MessageBoxImage.Information)
|
|
Else
|
|
Map.refMyStatusBarVM.SetOutputMessage(EgtMsg(MSG_TOPCOMMANDBAR + 14), 5)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' SendFeedback
|
|
|
|
#Region "Help"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do SendFeedback.
|
|
''' </summary>
|
|
Public ReadOnly Property Help_Command As ICommand
|
|
Get
|
|
If m_cmdHelp Is Nothing Then
|
|
m_cmdHelp = New Command(AddressOf Help)
|
|
End If
|
|
Return m_cmdHelp
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the SendFeedback. This method is invoked by the SendFeedbackCommand.
|
|
''' </summary>
|
|
Public Sub Help(ByVal param As Object)
|
|
Dim HelpWnd As New HelpWndV(Application.Current.MainWindow, New HelpWndVM())
|
|
HelpWnd.Show()
|
|
End Sub
|
|
|
|
#End Region ' Help
|
|
|
|
#End Region ' Commands
|
|
|
|
End Class
|