Imports System.IO Imports System.Windows.Threading Imports EgtBEAMWALL.Core Imports EgtBEAMWALL.Core.ConstBeam Imports EgtUILib Imports EgtWPFLib5 Imports System.Collections.ObjectModel Public Class MainMenuVM Inherits VMBase #Region "FIELDS & PROPERTIES" Public Enum UserLevel As Integer USER = 1 ADVANCED = 5 ADMINISTRATOR = 10 End Enum 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 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 SetConfigurationImagePath("pack://application:,,,/Resources/NewPage/configuration.png") End If 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 SetConfigurationImagePath("pack://application:,,,/Resources/NewPage/configuration.png") End If 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 SetConfigurationImagePath("pack://application:,,,/Resources/NewPage/configuration.png") End If End Set End Property Public Property ConfigProgram_IsChecked As Boolean Get Return m_SelPage = Pages.CONFIGPROGRAM End Get Set(value As Boolean) If value Then SelPage = Pages.CONFIGPROGRAM SetConfigurationImagePath("pack://application:,,,/Resources/NewPage/configurationIsChecked.png") Else SetConfigurationImagePath("pack://application:,,,/Resources/NewPage/configuration.png") End If 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, Pages.CONFIGPROGRAM 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, Pages.CONFIGPROGRAM InitONLYPRODPAGE() End Select End If ' aggiorno visualizzazione RadioButton NotifyPropertyChanged(NameOf(Supervisor_IsChecked)) NotifyPropertyChanged(NameOf(Config_IsChecked)) NotifyPropertyChanged(NameOf(OnlyProdPage_IsChecked)) NotifyPropertyChanged(NameOf(ConfigProgram_IsChecked)) End Sub Private m_sConfigurationImagePath As String = "pack://application:,,,/Resources/NewPage/configuration.png" Public ReadOnly Property sConfigurationImagePath As String Get Return m_sConfigurationImagePath End Get End Property Friend Sub SetConfigurationImagePath(value As String) m_sConfigurationImagePath = value NotifyPropertyChanged(NameOf(sConfigurationImagePath)) End Sub Private m_bUserAdmin_IsChecked As Boolean = False Public Property UserAdmin_IsChecked As Boolean Get Return m_bUserAdmin_IsChecked End Get Set(value As Boolean) m_bUserAdmin_IsChecked = value If Not IsNothing(Map.refForcedStrategyPanelVM.SelStrategy) Then ShowParam(Map.refForcedStrategyPanelVM.StrategyList) End If For Each StrategySetupItem As StrategySetup In Map.refStrategyManagerVM.StrategySetupList For Each StrategyFeatureItem As StrategyFeature In StrategySetupItem.StrategyFeatureList For Each TopologyItem As Topology In StrategyFeatureItem.TopologyList ShowParam(TopologyItem.StrategyList) Next Next Next NotifyPropertyChanged(NameOf(UserAdmin_IsChecked)) End Set End Property Friend Sub SetUserAdmin_IsChecked(value As Boolean) m_bUserAdmin_IsChecked = value NotifyPropertyChanged(NameOf(UserAdmin_IsChecked)) End Sub Private m_UserFontWeight As FontWeight = FontWeights.Bold Public ReadOnly Property UserFontWeight As FontWeight Get Return m_UserFontWeight End Get End Property Friend Sub SetUserFontWeight(value As FontWeight) m_UserFontWeight = value NotifyPropertyChanged(NameOf(UserFontWeight)) End Sub Private m_AdminFontWeight As FontWeight = FontWeights.Normal Public ReadOnly Property AdminFontWeight As FontWeight Get Return m_AdminFontWeight End Get End Property Friend Sub SetAdminFontWeight(value As FontWeight) m_AdminFontWeight = value NotifyPropertyChanged(NameOf(AdminFontWeight)) End Sub Private m_UnloackImage As String = "pack://application:,,,/Resources/NewPage/padlock.png" Public ReadOnly Property UnloackImage As String Get Return m_UnloackImage End Get End Property Friend Sub SetUnloackImage(value As String) m_UnloackImage = value NotifyPropertyChanged(NameOf(UnloackImage)) End Sub Private m_bUnlockAllIsChecked As Boolean = False Public Property UnlockAllIsChecked As Boolean Get Return m_bUnlockAllIsChecked End Get Set(value As Boolean) m_bUnlockAllIsChecked = value If m_bUnlockAllIsChecked Then If UnLockParameter() Then SetUnloackImage("pack://application:,,,/Resources/NewPage/padlock-unlock.png") Else Return End If Else SetUnloackImage("pack://application:,,,/Resources/NewPage/padlock.png") End If If Not IsNothing(Map.refForcedStrategyPanelVM.SelStrategy) Then If m_bUnlockAllIsChecked Then UnlockAll(Map.refForcedStrategyPanelVM.StrategyList) Else LockAll(Map.refForcedStrategyPanelVM.StrategyList) End If End If For Each StrategySetupItem As StrategySetup In Map.refStrategyManagerVM.StrategySetupList For Each StrategyFeatureItem As StrategyFeature In StrategySetupItem.StrategyFeatureList For Each TopologyItem As Topology In StrategyFeatureItem.TopologyList If m_bUnlockAllIsChecked Then UnlockAll(TopologyItem.StrategyList) Else LockAll(TopologyItem.StrategyList) End If Next Next Next NotifyPropertyChanged(NameOf(UnlockAllIsChecked)) End Set End Property #Region "Messages" 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 UserMsg As String Get Return EgtMsg(61748) End Get End Property Public ReadOnly Property AdvanceMsg As String Get Return EgtMsg(61749) End Get End Property #Region "ToolTip" 'Proprietà ToolTip Public ReadOnly Property SendFeedbackToolTip As String Get Return EgtMsg(30513) End Get End Property Public ReadOnly Property ConfigurationProgramToolTip As String Get Return EgtMsg(30515) 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 If Not IsNothing(Map.refMachinePanelVM.SelectedMachine) Then 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 ''' ''' Funzione che gestisce la visibilità dei parametri in base al livello utente ''' ''' Friend Sub UserLevelVisibility(Param As StrategyParameter, Visibility As Visibility) Select Case Param.GetType() Case GetType(BooleanStrategyParameter) DirectCast(Param, BooleanStrategyParameter).SetbBooleanVisibility(Visibility) Case GetType(DoubleStrategyParameter) DirectCast(Param, DoubleStrategyParameter).SetbDoubleVisibility(Visibility) Case GetType(ComboStrategyParameter) DirectCast(Param, ComboStrategyParameter).SetbComboBoxVisibility(Visibility) Case GetType(StringStrategyParameter) DirectCast(Param, StringStrategyParameter).SetbStringVisibility(Visibility) Case GetType(ListStrategyParameter) DirectCast(Param, ListStrategyParameter).SetbListBoxVisibility(Visibility) End Select End Sub Friend Sub UserLevelGenericVisibility(Generic As ProjectParameters, Visibility As Visibility) Select Case Generic.GetType() Case GetType(BooleanGenericParameter) DirectCast(Generic, BooleanGenericParameter).SetbBooleanVisibility(Visibility) Case GetType(DoubleGenericParameter) DirectCast(Generic, DoubleGenericParameter).SetbDoubleVisibility(Visibility) Case GetType(ComboGenericParameter) DirectCast(Generic, ComboGenericParameter).SetbComboBoxVisibility(Visibility) Case GetType(StringGenericParameter) DirectCast(Generic, StringGenericParameter).SetbStringVisibility(Visibility) Case GetType(ListGenericParameter) DirectCast(Generic, ListGenericParameter).SetbListBoxVisibility(Visibility) End Select End Sub Friend Sub ShowParam(StrategyList As ObservableCollection(Of Strategy)) SetAdminFontWeight(If(m_bUserAdmin_IsChecked, FontWeights.Bold, FontWeights.Normal)) SetUserFontWeight(If(m_bUserAdmin_IsChecked, FontWeights.Normal, FontWeights.Bold)) For Each StrategyItem As Strategy In StrategyList For Each ParamItem In StrategyItem.ParameterList Select Case ParamItem.sMinUserLevel Case UserLevel.ADVANCED UserLevelVisibility(ParamItem, If(m_bUserAdmin_IsChecked, Visibility.Visible, Visibility.Collapsed)) Case Else If Not m_bUserAdmin_IsChecked Then UserLevelVisibility(ParamItem, If(ParamItem.sMinUserLevel = UserLevel.USER, Visibility.Visible, Visibility.Collapsed)) SetUnloackImage("pack://application:,,,/Resources/NewPage/padlock.png") End If End Select Next Next If Not IsNothing(Map.refGeneralParametersStrategyVM) Then For Each GenericItem As ProjectParameters In Map.refGeneralParametersStrategyVM.GeneralParametersList Select Case GenericItem.sMinUserLevel Case UserLevel.ADVANCED UserLevelGenericVisibility(GenericItem, If(m_bUserAdmin_IsChecked, Visibility.Visible, Visibility.Collapsed)) Case Else If Not m_bUserAdmin_IsChecked Then UserLevelGenericVisibility(GenericItem, If(GenericItem.sMinUserLevel = UserLevel.USER, Visibility.Visible, Visibility.Collapsed)) SetUnloackImage("pack://application:,,,/Resources/NewPage/padlock.png") End If End Select Next End If End Sub Friend Function UnLockParameter() As Boolean Dim InputPwdWndVM As New InputPwdWndVM() Dim InputPwdWnd As New OnlyProdInputPwdWndV(Application.Current.MainWindow, InputPwdWndVM) Dim sPwdIni As String = String.Empty If InputPwdWnd.ShowDialog() Then If GetMainPrivateProfileString(S_STRATEGY, K_PARAMPASSWORD, "", sPwdIni) <> 0 Then If sPwdIni <> InputPwdWndVM.sPassword Then MessageBox.Show("Password Errata", EgtMsg(15002), MessageBoxButton.OK, MessageBoxImage.Error) Return False End If End If Else Return False End If SetAdminFontWeight(If(m_bUserAdmin_IsChecked, FontWeights.Bold, FontWeights.Normal)) SetUserFontWeight(If(m_bUserAdmin_IsChecked, FontWeights.Normal, FontWeights.Bold)) Return True End Function ''' ''' Funzione sblocca tutti paramatri delle strategie con una password ''' Public Sub UnlockAll(StrategyList As ObservableCollection(Of Strategy)) SetUserAdmin_IsChecked(True) For Each StrategyItem As Strategy In StrategyList For Each ParamItem As StrategyParameter In StrategyItem.ParameterList If ParamItem.sMinUserLevel >= UserLevel.ADVANCED Then ' Rendo visibili i parametri che hanno sMinUserLevel a 10 UserLevelVisibility(ParamItem, Visibility.Visible) End If Next Next If Not IsNothing(Map.refGeneralParametersStrategyVM) Then For Each GenericItem As ProjectParameters In Map.refGeneralParametersStrategyVM.GeneralParametersList If GenericItem.sMinUserLevel >= UserLevel.ADVANCED Then ' Rendo visibili i parametri che hanno sMinUserLevel a 10 UserLevelGenericVisibility(GenericItem, Visibility.Visible) End If Next End If End Sub ''' ''' Funzione blocca tutti paramatri delle strategie con una password ''' Public Sub LockAll(StrategyList As ObservableCollection(Of Strategy)) SetUserAdmin_IsChecked(False) For Each StrategyItem As Strategy In StrategyList For Each ParamItem As StrategyParameter In StrategyItem.ParameterList If ParamItem.sMinUserLevel >= UserLevel.ADVANCED Then ' Rendo visibili i parametri che hanno sMinUserLevel a 10 UserLevelVisibility(ParamItem, Visibility.Collapsed) End If Next Next If Not IsNothing(Map.refGeneralParametersStrategyVM) Then For Each GenericItem As ProjectParameters In Map.refGeneralParametersStrategyVM.GeneralParametersList If GenericItem.sMinUserLevel >= UserLevel.ADVANCED Then ' Rendo visibili i parametri che hanno sMinUserLevel a 10 UserLevelGenericVisibility(GenericItem, Visibility.Visible) End If Next End If 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" ''' ''' Returns a command that do SendFeedback. ''' 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 ''' ''' Execute the SendFeedback. This method is invoked by the SendFeedbackCommand. ''' 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