Files
Emmanuele Sassi 54c5d41c67 - correzione eliminazione superficie pezzo
- correzione contextMenu in ManagePart
- Tooltip su tutte le icone
- gestione disattivazione interfaccia durante import
2023-03-13 18:32:58 +01:00

389 lines
12 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class MachiningDbVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_MachiningList As New ObservableCollection(Of Machining)
Public ReadOnly Property MachiningList As ObservableCollection(Of Machining)
Get
Return m_MachiningList
End Get
End Property
Private m_SelMachining As Machining
Public Property SelMachining As Machining
Get
Return m_SelMachining
End Get
Set(value As Machining)
Dim IsExpandedList As New List(Of Boolean)
If Not IsNothing(m_SelMachining) Then
' verifico se modificato
If m_SelMachining.bIsModified Then
' chiedo se salvare
Select Case MessageBox.Show("Do you want to save the modification done on the selected machining?", "Info", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
Case MessageBoxResult.Yes
m_SelMachining.Save()
Case MessageBoxResult.No
m_SelMachining.ResetModification()
Case MessageBoxResult.Cancel
NotifyPropertyChanged(NameOf(SelMachining))
Return
End Select
End If
' recupero stato IsExpanded di tutte le categorie
For Each Cathegory In m_SelMachining.CathegoryList
IsExpandedList.Add(Cathegory.Cathegory_IsExpanded)
Next
End If
m_SelMachining = value
' ripristino stato IsExpanded di tutte le categorie
If Not IsNothing(m_SelMachining) Then
For Index = 0 To m_SelMachining.CathegoryList.Count - 1
If IsExpandedList.Count() >= Index + 1 Then
m_SelMachining.CathegoryList(Index).Cathegory_IsExpanded = IsExpandedList(Index)
End If
Next
End If
NotifyPropertyChanged(NameOf(ImpExp_IsEnabled))
End Set
End Property
Private m_Name_Visibility As Visibility = Visibility.Collapsed
Public ReadOnly Property Name_Visibility As Visibility
Get
Return m_Name_Visibility
End Get
End Property
Private m_Combo_Visibility As Visibility = Visibility.Visible
Public ReadOnly Property Combo_Visibility As Visibility
Get
Return m_Combo_Visibility
End Get
End Property
' variabile che indica se una qualunque lavorazione e' stata modificata
Private m_bIsModified As Boolean = False
Public ReadOnly Property bIsModified As Boolean
Get
Return m_bIsModified
End Get
End Property
Friend Sub SetIsModified(value As Boolean)
m_bIsModified = value
End Sub
Private m_IsEnabled As Boolean = True
Public ReadOnly Property IsEnabled As Boolean
Get
Return m_IsEnabled
End Get
End Property
Friend Sub SetIsEnabled(value As Boolean)
m_IsEnabled = value
NotifyPropertyChanged(NameOf(IsEnabled))
End Sub
Private m_UserShouldEditValueNow As Boolean = False
Public Property UserShouldEditValueNow As Boolean
Get
Return m_UserShouldEditValueNow
End Get
Set(value As Boolean)
m_UserShouldEditValueNow = value
End Set
End Property
Friend Sub SetUserShouldEditValueNow()
m_UserShouldEditValueNow = True
NotifyPropertyChanged(NameOf(UserShouldEditValueNow))
m_UserShouldEditValueNow = False
NotifyPropertyChanged(NameOf(UserShouldEditValueNow))
End Sub
Public ReadOnly Property ImpExp_IsEnabled As Boolean
Get
Return m_IsEnabled AndAlso (IsNothing(m_SelMachining) OrElse Not m_SelMachining.bIsModified)
End Get
End Property
#Region "Tooltip"
Public ReadOnly Property Import_ToolTip As String
Get
Return "Import"
End Get
End Property
Public ReadOnly Property Export_ToolTip As String
Get
Return "Export"
End Get
End Property
Public ReadOnly Property EditName_ToolTip As String
Get
Return "Edit Name"
End Get
End Property
#End Region ' Tooltip
' Definizione comandi
Private m_cmdOk As ICommand
Private m_cmdNew As ICommand
Private m_cmdSave As ICommand
Private m_cmdDelete As ICommand
Private m_cmdEditName As ICommand
Private m_cmdImport As ICommand
Private m_cmdExport As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTORS"
Sub New()
' Creo riferimento a questa classe in EgtCAM5Map
Map.SetRefMachiningDbVM(Me)
End Sub
#End Region ' CONSTRUCTORS
#Region "METHODS"
Friend Sub Init()
MachiningList.Clear()
Dim nIndex As Integer = 1
Dim sGUID As String = ""
Dim sName As String = ""
While ReadMachiningParamString(nIndex, MAC_GUID, "", sGUID) > 0
MachiningList.Add(New Machining(nIndex))
nIndex += 1
End While
Dim sCurrMachining As String = ""
GetMainPrivateProfileString(S_PRINTING3D, K_CURRMACHINING, "", sCurrMachining)
m_SelMachining = MachiningList.FirstOrDefault(Function(x) x.sGUID = sCurrMachining)
NotifyPropertyChanged(NameOf(SelMachining))
NotifyPropertyChanged(NameOf(ImpExp_IsEnabled))
End Sub
Friend Sub SetNameVisibility(bValue As Boolean)
m_Name_Visibility = If(bValue, Visibility.Visible, Visibility.Collapsed)
m_Combo_Visibility = If(Not bValue, Visibility.Visible, Visibility.Collapsed)
NotifyPropertyChanged(NameOf(Name_Visibility))
NotifyPropertyChanged(NameOf(Combo_Visibility))
If bValue Then SetUserShouldEditValueNow()
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "Ok"
Public ReadOnly Property Ok_Command As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf Ok)
End If
Return m_cmdOk
End Get
End Property
Public Sub Ok()
If Not IsNothing(m_SelMachining) AndAlso m_SelMachining.bIsModified Then
' chiedo se salvare
Select Case MessageBox.Show("Do you want to save modified parameters?", "Warning", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning)
Case MessageBoxResult.Yes
m_SelMachining.Save()
Case MessageBoxResult.No
m_SelMachining.ResetModification()
Case MessageBoxResult.Cancel
Return
End Select
End If
If m_bIsModified Then
Dim sBakMacIniFilePath As String = Path.ChangeExtension(CurrentMachine.sMachiningFilePath, ".bak")
If File.Exists(sBakMacIniFilePath) Then
Try
' elimino vecchio file bak
File.Delete(sBakMacIniFilePath)
Catch ex As Exception
End Try
End If
If File.Exists(CurrentMachine.sMachiningFilePath) Then
Try
' cambio estensione in bak a file Db vecchio
File.Move(CurrentMachine.sMachiningFilePath, sBakMacIniFilePath)
Catch ex As Exception
End Try
End If
' se ancora esiste lo elimino
If File.Exists(CurrentMachine.sMachiningFilePath) Then
Try
File.Delete(CurrentMachine.sMachiningFilePath)
Catch ex As Exception
End Try
End If
' creo nuovo file
If Not File.Exists(CurrentMachine.sMachiningFilePath) Then
Try
File.WriteAllLines(CurrentMachine.sMachiningFilePath, {"; Commento per evitare BOM con UTF-8"})
Catch ex As Exception
End Try
End If
' salvo tutte le lavorazioni sul Db
For Index = 0 To m_MachiningList.Count - 1
m_MachiningList(Index).WriteParamsOnDb(Index + 1)
Next
m_bIsModified = False
' aggiorno combo top
Dim CurrSelTopMachining As MachiningIndex = Map.refTopPanelVM.SelMachining
Map.refTopPanelVM.InitMachiningsList()
Map.refTopPanelVM.SetSelMachining(CurrSelTopMachining)
End If
' ripristino modalita' standard
Map.refTopPanelVM.SelPage = Pages.MODIFY
End Sub
#End Region ' Ok
#Region "New"
Public ReadOnly Property New_Command As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New Command(AddressOf NewCmd)
End If
Return m_cmdNew
End Get
End Property
Public Sub NewCmd()
Dim nIndex As Integer = m_MachiningList.Max(Function(x) x.nIndex) + 1
Dim NewMachining As Machining = New Machining(nIndex)
MachiningList.Add(NewMachining)
m_SelMachining = NewMachining
NotifyPropertyChanged(NameOf(SelMachining))
SetNameVisibility(True)
SetIsModified(True)
End Sub
#End Region ' New
#Region "Save"
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
Public Sub Save()
If IsNothing(m_SelMachining) Then Return
m_SelMachining.Save()
NotifyPropertyChanged(NameOf(ImpExp_IsEnabled))
End Sub
#End Region ' Save
#Region "Delete"
Public ReadOnly Property Delete_Command As ICommand
Get
If m_cmdDelete Is Nothing Then
m_cmdDelete = New Command(AddressOf Delete)
End If
Return m_cmdDelete
End Get
End Property
Public Sub Delete()
If IsNothing(m_SelMachining) Then Return
' chiedo conferma
Select Case MessageBox.Show("Are you sure you want to delete the selected machining?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning)
Case MessageBoxResult.Yes
m_MachiningList.Remove(m_SelMachining)
SetIsModified(True)
If m_MachiningList.Count > 0 Then
SelMachining = m_MachiningList(0)
End If
Case MessageBoxResult.No
Return
End Select
End Sub
#End Region ' Delete
#Region "EditName"
Public ReadOnly Property EditName_Command As ICommand
Get
If m_cmdEditName Is Nothing Then
m_cmdEditName = New Command(AddressOf EditName)
End If
Return m_cmdEditName
End Get
End Property
Public Sub EditName()
If IsNothing(m_SelMachining) Then Return
SetNameVisibility(True)
SetIsEnabled(False)
End Sub
#End Region ' EditName
#Region "Import"
Public ReadOnly Property Import_Command As ICommand
Get
If m_cmdImport Is Nothing Then
m_cmdImport = New Command(AddressOf Import)
End If
Return m_cmdImport
End Get
End Property
Public Sub Import()
' chiedo il nome del file .data da aprire
Dim OpenFileDlg As New System.Windows.Forms.OpenFileDialog() With {.Title = EgtMsg(31451) & " " & EgtMsg(31452),
.Filter = "File data (*" & ImportExportMachiningPanelVM.MachiningDataExtension & ")|*" & ImportExportMachiningPanelVM.MachiningDataExtension,
.FileName = String.Empty}
If OpenFileDlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return
Dim ImportWindow As New ImportExportMachiningPanelV(Application.Current.MainWindow, New ImportExportMachiningPanelVM(ImportExportMachiningPanelVM.WindowTypeEnum.MACHINING, ImportExportMachiningPanelVM.WindowModeEnum.IMPORT, OpenFileDlg.FileName))
ImportWindow.ShowDialog()
End Sub
#End Region ' Import
#Region "Export"
Public ReadOnly Property Export_Command As ICommand
Get
If m_cmdExport Is Nothing Then
m_cmdExport = New Command(AddressOf Export)
End If
Return m_cmdExport
End Get
End Property
Public Sub Export()
Dim ExportWindow As New ImportExportMachiningPanelV(Application.Current.MainWindow, New ImportExportMachiningPanelVM(ImportExportMachiningPanelVM.WindowTypeEnum.MACHINING, ImportExportMachiningPanelVM.WindowModeEnum.EXPORT))
ExportWindow.ShowDialog()
End Sub
#End Region ' Export
#End Region ' COMMANDS
End Class