Files
egtbeamwall/EgtBEAMWALL.Optimizer/MainMenu/MainMenuVM.vb
T
Demetrio Cassarino f08a7bdef7 -sistemato messaggi
2025-09-19 11:15:21 +02:00

403 lines
14 KiB
VB.net

Imports System.IO
Imports System.Windows.Threading
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Core.ConstBeam
Imports EgtUILib
Imports EgtWPFLib5
Public Class MainMenuVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_OpenPage_Timer As New DispatcherTimer
Private m_bOpenPage As Boolean = False
Private m_nPageToOpen As Pages = Pages.MACHINING
Private m_MainMenu_IsEnabled As Boolean = True
Public ReadOnly Property MainMenu_IsEnabled As Boolean
Get
Return m_MainMenu_IsEnabled
End Get
End Property
Private m_SendFeedbackIsEnabled As Boolean = True
Public ReadOnly Property SendFeedbackIsEnabled As Boolean
Get
Return m_SelPage = Pages.ONLYPRODPAGE
End Get
End Property
Public Property OnlyProdPage_IsChecked As Boolean
Get
Return m_SelPage = Pages.ONLYPRODPAGE
End Get
Set(value As Boolean)
If value Then SelPage = Pages.ONLYPRODPAGE
End Set
End Property
Public Property Supervisor_IsChecked As Boolean
Get
Return m_SelPage = Pages.SUPERVISOR
End Get
Set(value As Boolean)
If value Then SelPage = Pages.SUPERVISOR
End Set
End Property
Public Property Config_IsChecked As Boolean
Get
Return m_SelPage = Pages.CONFIG
End Get
Set(value As Boolean)
If value Then SelPage = Pages.CONFIG
End Set
End Property
Private m_Supervisor_Visibility As Visibility
Public ReadOnly Property Supervisor_Visibility As Visibility
Get
Return m_Supervisor_Visibility
End Get
End Property
Private m_SelPage As Integer = -1
Public Property SelPage As Integer
Get
Return m_SelPage
End Get
Set(value As Integer)
' lancio selezione pagina con verifica file modificato
SetSelPage(value)
End Set
End Property
' funzione che permette di cambiare pagina
' bVerifyModification: se vero verifica modifiche su file e chiede di salvare
Friend Sub SetSelPage(Page As Pages, Optional bVerifyModification As Boolean = True)
Dim bOk As Boolean = True
' Esco dallo stato corrente
Select Case m_SelPage
Case Pages.CONFIG
bOk = ExitCONFIG()
Case Pages.ONLYPRODPAGE
bOk = ExitONLYPRODPAGE(bVerifyModification)
End Select
If bOk Then
' Entro nel nuovo stato
m_SelPage = Page
Select Case m_SelPage
Case Pages.CONFIG
InitCONFIG()
Case Pages.ONLYPRODPAGE
InitONLYPRODPAGE()
End Select
End If
' aggiorno visualizzazione RadioButton
NotifyPropertyChanged(NameOf(Supervisor_IsChecked))
NotifyPropertyChanged(NameOf(Config_IsChecked))
NotifyPropertyChanged(NameOf(OnlyProdPage_IsChecked))
End Sub
#Region "Messages"
Public ReadOnly Property Viewer_Msg As String
Get
Return EgtMsg(61830)
End Get
End Property
Public ReadOnly Property Optimizer_Msg As String
Get
Return EgtMsg(61831)
End Get
End Property
Public ReadOnly Property Configuration_Msg As String
Get
Return EgtMsg(61832)
End Get
End Property
Public ReadOnly Property Supervisor_Msg As String
Get
Return EgtMsg(62500)
End Get
End Property
Public ReadOnly Property OnlyProdPage_Msg As String
Get
Return EgtMsg(61896)
End Get
End Property
Public ReadOnly Property NVersion_Msg As String
Get
Return EgtMsg(61747)
End Get
End Property
#Region "ToolTip"
'Proprietà ToolTip
Public ReadOnly Property SendFeedbackToolTip As String
Get
Return EgtMsg(30513)
End Get
End Property
#End Region ' ToolTip
#End Region ' Messages
' Definizione comandi
Private m_cmdSupervisor As ICommand
Private m_cmdSendFeedback As ICommand
#End Region ' Fields & Properties
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in EgtCAM5Map
Map.SetRefMainMenuVM(Me)
' abilito supervisore
If Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.SUPERVISOR) Then
m_Supervisor_Visibility = Visibility.Visible
Else
m_Supervisor_Visibility = Visibility.Collapsed
End If
' imposto timer di apertura da ottimizzatore
m_OpenPage_Timer.Interval = TimeSpan.FromMilliseconds(500)
AddHandler m_OpenPage_Timer.Tick, AddressOf OpenPage_Tick
m_OpenPage_Timer.Start()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub SetMainMenuIsEnabled(bIsEnabled As Boolean)
m_MainMenu_IsEnabled = bIsEnabled
NotifyPropertyChanged(NameOf(MainMenu_IsEnabled))
End Sub
Private Function InitCONFIG() As Boolean
EgtSetCurrMachine(Map.refMachinePanelVM.SelectedMachine.Name)
Map.refMainWindowVM.NotifyPropertyChanged(NameOf(Map.refMainWindowVM.nSelTabPage))
Map.refMainMenuVM.NotifyPropertyChanged(NameOf(Map.refMainMenuVM.SendFeedbackIsEnabled))
Return True
End Function
Private Function ExitCONFIG() As Boolean
Map.refConfigurationPageVM.VerifyConfigPageModification()
' resetto flag inserimento password
Map.refConfigurationPageVM.bModifyMachParam = False
If Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
Map.refRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Map.refFeatureInPartInRawPartListVM.UpdateColumns(CurrentMachine.nType)
Else
Map.refRawPartListVM.UpdateColumns(BWType.BEAM)
Map.refFeatureInPartInRawPartListVM.UpdateColumns(CurrentMachine.nType)
End If
Return True
End Function
Private Function InitONLYPRODPAGE() As Boolean
' Gestione cambio pagina
If Not IsNothing(ProjectManagerVM.CurrProd) Then EgtSetCurrMachine(ProjectManagerVM.CurrProd.sMachine)
Map.refMainWindowVM.NotifyPropertyChanged(NameOf(Map.refMainWindowVM.nSelTabPage))
Return True
End Function
Private Function ExitONLYPRODPAGE(bVerifyModification As Boolean) As Boolean
' verifico se progetto modificato, e chiedo se salvare
If bVerifyModification Then
If ProdFileVM.VerifyProjectModification(ProjectManagerVM.CurrProd) = MessageBoxResult.Cancel Then
Return False
End If
End If
' EgtResetCurrMachGroup()
Return True
End Function
Public Sub OpenPageFromSupervisor(Page As Pages)
If m_SelPage <> Page Then
m_nPageToOpen = Page
m_bOpenPage = True
End If
End Sub
Public Sub OpenPage_Tick()
If Not m_bOpenPage Then Return
m_bOpenPage = False
' apro la pagina
SelPage = m_nPageToOpen
m_nPageToOpen = Pages.MACHINING
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "Supervisor"
Public ReadOnly Property Supervisor_Command As ICommand
Get
If m_cmdSupervisor Is Nothing Then
m_cmdSupervisor = New Command(AddressOf Supervisor)
End If
Return m_cmdSupervisor
End Get
End Property
Public Sub Supervisor()
Dim sSupervisorName As String = "EgtBEAMWALL.SupervisorR32"
' recupero processo del supervisore
Dim localProc As Process() = Process.GetProcessesByName(sSupervisorName)
If localProc.Length > 0 Then
For Each p As Process In localProc
' porto in primo piano il Supervisor
BringWindowToFront(p.MainWindowHandle)
Exit For
Next
Else
Dim sSupervisorPath As String = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) & "\" & sSupervisorName & ".exe"
Try
Process.Start(sSupervisorPath)
Catch ex As Exception
EgtOutLog("Error: impossible starting supervisor from path " & sSupervisorPath)
End Try
End If
End Sub
#End Region ' Supervisor
#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)
If (SelPage = Pages.MACHINING OrElse SelPage = Pages.ONLYPRODPAGE) AndAlso IsNothing(ProjectManagerVM.CurrProd) Then
MessageBox.Show(EgtMsg(61891), EgtMsg(15001), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' 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(30510), EgtMsg(15001), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' Recupero numero chiave
Dim sKey As String = String.Empty
EgtGetKeyInfo(sKey)
' Esporto il progetto
Dim ProjFileMList As List(Of ProjFileM)
If (SelPage = Pages.MACHINING OrElse SelPage = Pages.ONLYPRODPAGE) And Not IsNothing(ProjectManagerVM.CurrProd) Then
ProjFileMList = DbControllers.m_ProjController.GetByProdAsc(ProjectManagerVM.CurrProd.nProdId)
'Map.refProjManagerVM.SetCurrProj(ProjFileMList(0).nProjId)
Map.refOnlyProdManagerVM.SetCurrProj(ProjFileMList(0).nProjId)
End If
Dim sExportFileName = ProjectManagerVM.CurrProj.nProjId.ToString("0000") & " - " & ProjectManagerVM.CurrProj.sBTLFileName & " - ProjectExport"
'Dim sExpZipToCreate = Map.refProjManagerVM.ExportProject(sExportFileName)
Dim sExpZipToCreate = Map.refOnlyProdManagerVM.ExportProject(sExportFileName)
' 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 progetto esportato
If File.Exists(sExpZipToCreate) Then
zip.AddItem(sExpZipToCreate, "")
End If
' aggiungo Prod e Proj associati
Dim ProdId As Integer
Select Case Map.refMainMenuVM.SelPage
Case Pages.VIEW
ProdId = ProjectManagerVM.CurrProj.nProdId
Case Pages.MACHINING, Pages.ONLYPRODPAGE
ProdId = ProjectManagerVM.CurrProd.nProdId
End Select
If ProdId = 0 Then
zip.AddItem(ProjectManagerVM.CurrProj.sProjDirPath, "Projs\" & ProjectManagerVM.CurrProj.nProjId.ToString("0000"))
Else
ProjFileMList = DbControllers.m_ProjController.GetByProdAsc(ProdId)
' se piu' di uno
If IsNothing(ProjFileMList) Then
Return
ElseIf ProjFileMList.Count > 0 Then
Dim ProjFileVMList As New List(Of ProjectFileVM)
For Each Project In ProjFileMList
ProjFileVMList.Add(New ProjFileVM(Project))
Next
For Each ProjFileVMItem In ProjFileVMList
zip.AddItem(ProjFileVMItem.sProjDirPath, "Projs\" & ProjFileVMItem.nProjId.ToString("0000"))
Next
zip.AddItem(ProjFileVMList(0).sProdDirPath, "Prods\" & ProjFileVMList(0).nProdId.ToString("0000"))
End If
End If
' aggiungo cartella macchina del progetto
Dim sMachineDir As String = Map.refMainWindowVM.MainWindowM.sMachinesRoot & "\" & sMachineName
If Directory.Exists(sMachineDir) Then
zip.AddItem(sMachineDir, sMachineName)
End If
' aggiungo file log
If File.Exists(Map.refMainWindowVM.MainWindowM.sLogFile) Then
zip.AddItem(Map.refMainWindowVM.MainWindowM.sLogFile, "")
End If
' aggiungo file parametri P e Q
If File.Exists(BTLIniFile.m_sBTLIniFile) Then
zip.AddItem(BTLIniFile.m_sBTLIniFile, "")
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
Dim bEx As Boolean = False
Try
Dim sAddressArray As String() = sSupportAddress.Split(CType(",", Char()))
Dim SendFeedbackWindow As New EgtWPFLib5.MapiMailMessage("EgtBEAMWALL 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(30512), sSupportAddress, sZipToCreate), EgtMsg(15003), MessageBoxButton.OK, MessageBoxImage.Information)
Else
Map.refMyStatusBarVM.SetOutputMessage(EgtMsg(30514))
End If
End Sub
#End Region ' SendFeedbackCommand
#End Region ' COMMANDS
End Class