Files
Dario Sassi 2648b704cc EgtCAM5 2.7l1 :
- piccoli aggiustamenti a ExecuteWindow.
2025-12-03 15:04:07 +01:00

274 lines
8.5 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class SetUpDbVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private Const SETUP_FILEEXTENSION As String = ".stu"
Friend Event OnCloseWindow(bDialogResult As Boolean)
Private m_SetUpList As New ObservableCollection(Of String)
Public ReadOnly Property SetUpList As ObservableCollection(Of String)
Get
Return m_SetUpList
End Get
End Property
Private m_SelSetUp As String
Public Property SelSetUp As String
Get
Return m_SelSetUp
End Get
Set(value As String)
' se setup modificato, chiedo se salvare
If m_SetUpVM.IsModifiedSetUp OrElse m_IsNew Then
Select Case MessageBox.Show(EgtMsg(9007), EgtMsg(9006), MessageBoxButton.YesNo, MessageBoxImage.Question)
Case MessageBoxResult.Yes
Save()
Case MessageBoxResult.No
' non devo fare nulla
End Select
End If
m_SelSetUp = value
m_IsNew = False
m_SetUpVM.LoadSetupFromFile(m_SelSetUp, True)
NotifyPropertyChanged("SelSetUp")
End Set
End Property
Private Sub SetSelSetup(SetupName As String)
m_SelSetUp = SetupName
m_SetUpVM.LoadSetupFromFile(m_SelSetUp, True)
NotifyPropertyChanged("SelSetUp")
End Sub
Private m_SetUpVM As New SetUpVM
Public ReadOnly Property SetUpVM As SetUpVM
Get
Return m_SetUpVM
End Get
End Property
' Variabile che indica se il setup corrente è nuovo e mai salvato
Private m_IsNew As Boolean = False
' path cartella attrezzaggi
Private m_SetUpDir_FilePath As String
#Region "Messages"
Public ReadOnly Property Title As String
Get
Return EgtMsg(MSG_SETUP + 1)
End Get
End Property
Public ReadOnly Property SaveMsg As String
Get
Return EgtMsg(MSG_SETUP + 3)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdSave As ICommand
Private m_cmdAddSetup As ICommand
Private m_cmdRemoveSetup As ICommand
Private m_cmdClose As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Carico lista degli attrezzaggi
m_SetUpDir_FilePath = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp"
Dim FileList As IEnumerable(Of String) = Directory.EnumerateFiles(m_SetUpDir_FilePath)
For Each File In FileList
If Path.GetExtension(File) = SETUP_FILEEXTENSION Then
m_SetUpList.Add(Path.GetFileNameWithoutExtension(File))
End If
Next
' inizializzo le posizioni di attrezzaggio
m_SetUpVM.InitSetUp()
' Se esiste seleziono l'attrezzaggio di default
If Not String.IsNullOrWhiteSpace(MachOptionModule.m_sSelectedDefaultSetUp) Then
SelSetUp = MachOptionModule.m_sSelectedDefaultSetUp
ElseIf m_SetUpList.Count > 0 Then
SelSetUp = m_SetUpList(0)
End If
End Sub
#End Region ' CONSTRUCTOR
#Region "COMMANDS"
#Region "Save"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property Save_Command 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 Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub Save()
If Not m_SetUpVM.Save(m_SetUpDir_FilePath & "\" & m_SelSetUp & SETUP_FILEEXTENSION) Then
EgtOutLog("Error in setup saving: can't find the directory")
MessageBox.Show("Error in saving Setup.", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
Else
m_IsNew = False
m_SetUpVM.ResetModifiedSetUp()
End If
End Sub
#End Region ' Save
#Region "AddSetup"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property AddSetup_Command As ICommand
Get
If m_cmdAddSetup Is Nothing Then
m_cmdAddSetup = New Command(AddressOf AddSetup)
End If
Return m_cmdAddSetup
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub AddSetup()
' se setup modificato, chiedo se salvare
If m_SetUpVM.IsModifiedSetUp OrElse m_IsNew Then
Select Case MessageBox.Show(EgtMsg(9007), EgtMsg(9006), MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
Case MessageBoxResult.Yes
Save()
Case MessageBoxResult.No
' non devo fare nulla
Case MessageBoxResult.Cancel
Return
End Select
End If
' chiedo il nome del nuovo setup
Dim SaveFileDialogViewVM As New SaveFileDialogVM With {
.Title = EgtMsg(MSG_SETUP + 7) & " " & EgtMsg(MSG_SETUP + 1),
.Extension = ".stu",
.Directory = m_SetUpDir_FilePath,
.FileName = String.Empty
}
Dim SaveFileDialogView As New EgtWPFLib5.SaveFileDialogV(Application.Current.MainWindow, SaveFileDialogViewVM)
If Not SaveFileDialogView.ShowDialog() Then Return
Dim sFilePath As String = String.Empty
sFilePath = SaveFileDialogViewVM.FileName
' lo aggiungo alla lista setup
Dim NewSetupName As String = Path.GetFileNameWithoutExtension(sFilePath)
m_SetUpList.Add(NewSetupName)
m_IsNew = True
m_SelSetUp = NewSetupName
' resetto tutte le posizioni e lista utensili
m_SetUpVM.InitSetUp()
m_SetUpVM.LoadMachineTools()
NotifyPropertyChanged("SelSetUp")
End Sub
#End Region ' AddSetup
#Region "RemoveSetup"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property RemoveSetup_Command As ICommand
Get
If m_cmdRemoveSetup Is Nothing Then
m_cmdRemoveSetup = New Command(AddressOf RemoveSetup)
End If
Return m_cmdRemoveSetup
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub RemoveSetup()
' chiedo conferma
If MessageBox.Show("Are you sure you want to delete this setup?", "Setup", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.No Then Return
' recupero indice setup corrente
Dim DeletedIndex As Integer = m_SetUpList.IndexOf(m_SelSetUp)
' elimino il file
Dim DeleteFilePath As String = m_SetUpDir_FilePath & "\" & m_SelSetUp & SETUP_FILEEXTENSION
If File.Exists(DeleteFilePath) Then
Try
File.Delete(DeleteFilePath)
Catch ex As Exception
EgtOutLog("Error in deleting setup file: " & ex.ToString)
MessageBox.Show("Impossible deleting the setup file.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation)
Return
End Try
End If
' carico il precedente
If DeletedIndex > 0 Then
SetSelSetup(m_SetUpList(DeletedIndex - 1))
ElseIf m_SetUpList.Count > 1 Then
SetSelSetup(m_SetUpList(DeletedIndex + 1))
End If
' elimino nome dalla lista
m_SetUpList.RemoveAt(DeletedIndex)
End Sub
#End Region ' RemoveSetup
#Region "Close"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property Close_Command As ICommand
Get
If m_cmdClose Is Nothing Then
m_cmdClose = New Command(AddressOf Close)
End If
Return m_cmdClose
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub Close()
' se setup modificato, chiedo se salvare
If m_SetUpVM.IsModifiedSetUp OrElse m_IsNew Then
Select Case MessageBox.Show(EgtMsg(9007), EgtMsg(9006), MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
Case MessageBoxResult.Yes
Save()
Case MessageBoxResult.No
' non devo fare nulla
Case MessageBoxResult.Cancel
Return
End Select
End If
RaiseEvent OnCloseWindow(True)
End Sub
#End Region ' Close
#End Region ' Commands
End Class