Files
omagoffice/TopCommandBar/TopCommandBarVM.vb
T
2025-06-05 17:01:57 +02:00

490 lines
16 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class TopCommandBarVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Friend m_MruFiles As New MruList
Public ReadOnly Property MruFileNames As ObservableCollection(Of String)
Get
Return m_MruFiles.FileNames
End Get
End Property
Private m_IsEnabled As Boolean
Public Property IsEnabled As Boolean
Get
Return m_IsEnabled
End Get
Set(value As Boolean)
If value <> m_IsEnabled Then
m_IsEnabled = value
NotifyPropertyChanged("IsEnabled")
End If
End Set
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_cmdExport As ICommand
Private m_cmdDxfOut As ICommand
Private m_cmdOptions As ICommand
Private m_cmdSendFeedback 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 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(91505) 'Esporta in macchina
End Get
End Property
Public ReadOnly Property DxfOutToolTip As String
Get
Return EgtMsg(91506) 'Esporta DXF
End Get
End Property
Public ReadOnly Property OptionsToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 9)
End Get
End Property
Public ReadOnly Property SendFeedbackToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 13)
End Get
End Property
#End Region ' ToolTip
#End Region ' Fields & Properties
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in OmagOFFICEMap
OmagOFFICEMap.SetRefTopCommandBarVM(Me)
' Impostazioni MruLists
m_MruFiles.Init(S_MRUFILES, 8)
End Sub
#End Region ' CONSTRUCTOR
#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 Command(AddressOf NewCmd)
End If
Return m_cmdNew
End Get
End Property
''' <summary>
''' Execute the New. This method is invoked by the NewCommand.
''' </summary>
Friend Sub NewCmd()
OmagOFFICEMap.refSceneHostVM.NewProject()
OmagOFFICEMap.refMachGroupPanelVM.InitMachGroupList(False)
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 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(String.Empty)
End Sub
Friend Sub OpenProject(sFilePath As String)
OmagOFFICEMap.refSceneHostVM.OpenProject(sFilePath)
OmagOFFICEMap.refMachGroupPanelVM.InitMachGroupList()
End Sub
#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 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)
OmagOFFICEMap.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)
'Dim SaveFileDialog As New System.Windows.Forms.SaveFileDialog()
'SaveFileDialog.Filter = "(*.nge) |*.nge"
'SaveFileDialog.FilterIndex = 2
'' avvio la ricerca nell'ultimo direttorio aperto
'Dim sFilePath As String = String.Empty
'EgtGetCurrFilePath(sFilePath)
'SaveFileDialog.InitialDirectory = Path.GetExtension(sFilePath)
'SaveFileDialog.FileName = Path.GetFileName(sFilePath)
'' apro la finestra di dialogo
'Dim bChangeProject As Boolean = True
'If SaveFileDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return
'Dim sNewFilePath As String = SaveFileDialog.FileName
' non posso avere la stessa lastra in due progetti -> gestita da DataBase
OmagOFFICEMap.refSceneHostVM.SaveAsProject()
End Sub
#End Region ' SaveAsCommand
#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)
OmagOFFICEMap.refSceneHostVM.ExportProject()
End Sub
#End Region ' ExportCommand
#Region "DxfOutCommand"
''' <summary>
''' Returns a command that do DxfOut.
''' </summary>
Public ReadOnly Property DxfOutCommand As ICommand
Get
If m_cmdDxfOut Is Nothing Then
m_cmdDxfOut = New Command(AddressOf DxfOut)
End If
Return m_cmdDxfOut
End Get
End Property
''' <summary>
''' Execute the DxfOut. This method is invoked by the ExportCommand.
''' </summary>
Public Sub DxfOut(ByVal param As Object)
DirectCast(OmagOFFICEMap.refSceneHostVM, MySceneHostVM).DxfOutProject()
End Sub
#End Region ' DxfOutCommand
#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 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.Height = 614
'OptionsWindow.Width = 1024
OptionsWindow.DataContext = New OptionWindowVM
OptionsWindow.Owner = Application.Current.MainWindow
OptionsWindow.ShowDialog()
End Sub
#End Region ' OptionsCommand
#Region "SendFeedbackCommand"
''' <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, chiedo se si vuole salvare
If String.IsNullOrWhiteSpace(sCurrProject) Then
If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
OmagOFFICEMap.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
OmagOFFICEMap.refSceneHostVM.SaveProject()
End If
End If
End If
' 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) AndAlso Machines.IndexOf(sMachineName) < 0 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) AndAlso Directory.Exists(sCurrProjectDir) Then
Dim sTitleName As String = Path.GetFileNameWithoutExtension(sCurrProject)
Dim TempFiles() As String = Directory.GetFiles(sCurrProjectDir)
For FileIndex = 0 To TempFiles.Count - 1
If Path.GetFileNameWithoutExtension(TempFiles(FileIndex)).Contains(sTitleName) 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 = OmagOFFICEMap.refMainWindowVM.MainWindowM.sTempDir & "\Feedback.zip"
If File.Exists(sZipToCreate) Then
File.Delete(sZipToCreate)
End If
Try
Using zip As New Ionic.Zip.ZipFile(sZipToCreate)
zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always
zip.AlternateEncoding = Text.Encoding.UTF8
' aggiungo file macchine
For Each sMachineName As String In Machines
Dim sMachineDir As String = OmagOFFICEMap.refMainWindowVM.MainWindowM.sMachinesRoot & "\" & sMachineName
If Directory.Exists(sMachineDir) Then
zip.AddItem(sMachineDir, sMachineName)
End If
Next
' aggiungo progetto corrente
If Not String.IsNullOrWhiteSpace(sCurrProject) Then
zip.AddItem(sCurrProject, "")
End If
' aggiungo file log
zip.AddItem(OmagOFFICEMap.refMainWindowVM.MainWindowM.sLogFile, "")
' 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 SendFeedbackWindow As New EgtWPFLib5.MapiMailMessage("OmagOFFICE Feedback - " & sKey)
SendFeedbackWindow.Recipients.Add(sSupportAddress)
If Not String.IsNullOrWhiteSpace(sZipToCreate) AndAlso File.Exists(sZipToCreate) Then
SendFeedbackWindow.Files.Add(OmagOFFICEMap.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
' Mandare il feedback a xxx con allegata la cartella yyy.
Dim sText As String = String.Format(EgtMsg(MSG_TOPCOMMANDBAR + 12), sSupportAddress, sZipToCreate)
MessageBox.Show(sText, EgtMsg(MSG_MESSAGEBOX + 3), MessageBoxButton.OK, MessageBoxImage.Information)
Else
' Mail di feedback pronta.
OmagOFFICEMap.refStatusBarVM.SetOutputMessage(EgtMsg(MSG_TOPCOMMANDBAR + 14), 10, MSG_TYPE.INFO)
End If
End Sub
#End Region ' SendFeedbackCommand
#End Region ' Commands
Public Shared Sub SetInfoProj(Optional sFilePath As String = "")
EgtOutLog(" *** SAVE PROJECT ***")
' Recupero l'ID della macchinata corrente
Dim CurrGrpId As Integer = EgtGetCurrMachGroup()
' Path completa del progetto corrente
If String.IsNullOrEmpty(sFilePath) Then EgtGetCurrFilePath(sFilePath)
Dim nPartInRawsProj As Integer = 0
Dim nGrpId = EgtGetFirstMachGroup()
While nGrpId <> GDB_ID.NULL
' Imposto la macchinata corrente
EgtSetCurrMachGroup(nGrpId)
' recupero il primo grezzo della macchinata corrente
Dim nRawId As Integer = EgtGetFirstRawPart()
While nRawId <> GDB_ID.NULL
nPartInRawsProj += EgtGetPartInRawPartCount(nRawId)
nRawId = EgtGetNextRawPart(nRawId)
End While
nGrpId = EgtGetNextMachGroup(nGrpId)
End While
nGrpId = EgtGetFirstMachGroup()
While nGrpId <> GDB_ID.NULL
' percorso progetto
EgtSetInfo(nGrpId, "ProjPath", sFilePath)
' Anno/Mese/Giorno/Ora/min di salvataggio
EgtSetInfo(nGrpId, "Released", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))
' numero di pezzi presenti nel progetto
EgtSetInfo(nGrpId, "NbrProjParts", nPartInRawsProj.ToString)
nGrpId = EgtGetNextMachGroup(nGrpId)
End While
EgtOutLog(" ProjPath:" & sFilePath)
EgtOutLog(" Released:" & DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))
EgtOutLog(" NbrProjParts:" & nPartInRawsProj.ToString)
' Reimposto la macchina corrente
EgtSetCurrMachGroup(CurrGrpId)
' Nascondo tutte le lavorazioni
CamAuto.HideAllMachinings()
End Sub
End Class