8cdfa8252c
- Introdotto SetupDb e modificato CurrSetup di conseguenza.
521 lines
16 KiB
VB.net
521 lines
16 KiB
VB.net
Imports System.IO
|
|
Imports System.Collections.ObjectModel
|
|
Imports EgtUILib
|
|
|
|
Public Class BeamMachiningsWindowVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private Const MACH_CUT As String = "Cut"
|
|
Private Const MACH_DRILL As String = "Drill"
|
|
Private Const MACH_MILLING As String = "Milling"
|
|
Private Const MACH_POCKETING As String = "Pocketing"
|
|
Private Const MACH_SAWING As String = "Sawing"
|
|
Private Const ONCONST As String = "On"
|
|
Private Const NAME As String = "Name"
|
|
Private Const TYPE As String = "Type"
|
|
Private Const DATETIME As String = "%DATE_TIME%"
|
|
Private Const TABLENAME As String = "%TABLE_NAME%"
|
|
Friend Const BEAMTABLETEMPLATE_FILE As String = "BeamTableTemplate.ini"
|
|
|
|
Friend Event m_CloseWindow(bDialogResult As Boolean)
|
|
|
|
Private m_MachiningList As New ObservableCollection(Of String)({MACH_CUT, MACH_DRILL, MACH_MILLING, MACH_POCKETING, MACH_SAWING})
|
|
Public ReadOnly Property MachiningList As ObservableCollection(Of String)
|
|
Get
|
|
Return m_MachiningList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelMachining As String
|
|
Public Property SelMachining As String
|
|
Get
|
|
Return m_SelMachining
|
|
End Get
|
|
Set(value As String)
|
|
' verifico se pagina precedente modificata
|
|
Dim TableModified As Boolean = False
|
|
For Each Line In m_TableRowList
|
|
If Line.IsModified Then
|
|
TableModified = True
|
|
Exit For
|
|
End If
|
|
Next
|
|
' se modificata, chiedo se salvare
|
|
If TableModified 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_SelMachining = value
|
|
LoadMachiningList()
|
|
LoadTypeList()
|
|
ReadTableFile()
|
|
NotifyPropertyChanged("SelMachining")
|
|
End Set
|
|
End Property
|
|
Private Sub SetSelMachining(value As String)
|
|
m_SelMachining = value
|
|
LoadMachiningList()
|
|
LoadTypeList()
|
|
ReadTableFile()
|
|
NotifyPropertyChanged("SelMachining")
|
|
End Sub
|
|
|
|
Private m_TableRowList As ObservableCollection(Of GridLine)
|
|
Public Property TableRowList As ObservableCollection(Of GridLine)
|
|
Get
|
|
Return m_TableRowList
|
|
End Get
|
|
Set(value As ObservableCollection(Of GridLine))
|
|
m_TableRowList = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_SelRowIndex As Integer = 0
|
|
Public Property SelRowIndex As Integer
|
|
Get
|
|
Return m_SelRowIndex
|
|
End Get
|
|
Set(value As Integer)
|
|
m_SelRowIndex = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_TypeIni_FilePath As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\MachiningTypes.ini"
|
|
Private m_BeamTableTemplate_FilePath As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\" & BEAMTABLETEMPLATE_FILE
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property Title As String
|
|
Get
|
|
Return EgtMsg(9000)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property OnHdr As String
|
|
Get
|
|
Return EgtMsg(9001)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property NameHdr As String
|
|
Get
|
|
Return EgtMsg(9002)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property TypeHdr As String
|
|
Get
|
|
Return EgtMsg(9003)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property AddRowMsg As String
|
|
Get
|
|
Return EgtMsg(9004)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property DeleteRowMsg As String
|
|
Get
|
|
Return EgtMsg(9005)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property SaveMsg As String
|
|
Get
|
|
Return EgtMsg(9006)
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' Messages
|
|
|
|
' Definizione comandi
|
|
Private m_cmdMoveRowUp As ICommand
|
|
Private m_cmdMoveRowDown As ICommand
|
|
Private m_cmdAddRow As ICommand
|
|
Private m_cmdDeleteRow As ICommand
|
|
Private m_cmdSave As ICommand
|
|
Private m_cmdClose As ICommand
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Imposto direttori
|
|
m_TypeIni_FilePath = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\MachiningTypes.ini"
|
|
m_BeamTableTemplate_FilePath = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\" & BEAMTABLETEMPLATE_FILE
|
|
' Seleziono la prima lavorazione
|
|
If m_MachiningList.Count > 0 Then
|
|
SetSelMachining(m_MachiningList(0))
|
|
End If
|
|
NotifyPropertyChanged("MachiningList")
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Private Function LoadMachiningList() As Boolean
|
|
Dim MachiningList As New List(Of String)
|
|
Select Case SelMachining
|
|
Case MACH_CUT
|
|
LoadMachiningListByType(MachiningList, MCH_MY.MILLING, MCH_TF.SAWBLADE)
|
|
Case MACH_DRILL
|
|
LoadMachiningListByType(MachiningList, MCH_MY.DRILLING, 0)
|
|
LoadMachiningListByType(MachiningList, MCH_MY.POCKETING, 0, False)
|
|
LoadMachiningListByType(MachiningList, MCH_MY.MILLING, MCH_TF.MILL, False)
|
|
Case MACH_MILLING
|
|
LoadMachiningListByType(MachiningList, MCH_MY.MILLING, MCH_TF.MILL)
|
|
Case MACH_POCKETING
|
|
LoadMachiningListByType(MachiningList, MCH_MY.POCKETING, 0)
|
|
Case MACH_SAWING
|
|
LoadMachiningListByType(MachiningList, MCH_MY.MORTISING, 0)
|
|
End Select
|
|
GridLine.SetNamesList(New ObservableCollection(Of String)(MachiningList))
|
|
Return True
|
|
End Function
|
|
|
|
Private Function LoadTypeList() As Boolean
|
|
Dim TypeList As New List(Of String)
|
|
Dim Index As Integer = 1
|
|
Dim Type As String = ""
|
|
While EgtUILib.GetPrivateProfileString(SelMachining, Index.ToString, "", Type, m_TypeIni_FilePath) > 0
|
|
TypeList.Add(Type)
|
|
Index += 1
|
|
End While
|
|
GridLine.SetTypeList(New ObservableCollection(Of String)(TypeList))
|
|
Return True
|
|
End Function
|
|
|
|
Private Function ReadTableFile() As Boolean
|
|
' svuoto la lista
|
|
m_TableRowList = New ObservableCollection(Of GridLine)
|
|
Dim FilePath As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\" & SelMachining & "Data.lua"
|
|
If Not File.Exists(FilePath) Then Return False
|
|
Dim FileContent As String() = File.ReadAllLines(FilePath)
|
|
Dim FoundTableName As Boolean = False
|
|
For LineIndex As Integer = 0 To FileContent.Count - 1
|
|
If FileContent(LineIndex).Contains(SelMachining & "Data") Then
|
|
FoundTableName = True
|
|
End If
|
|
Dim Open As Integer = CountCharacter(FileContent(LineIndex), "{"c)
|
|
Dim Close As Integer = CountCharacter(FileContent(LineIndex), "}"c)
|
|
If Close > Open Then
|
|
If FoundTableName Then
|
|
FoundTableName = False
|
|
End If
|
|
End If
|
|
If FoundTableName Then
|
|
Dim sOn As String = SearchKey(FileContent(LineIndex), ONCONST)
|
|
Dim sName As String = SearchKey(FileContent(LineIndex), NAME)
|
|
Dim sType As String = SearchKey(FileContent(LineIndex), TYPE)
|
|
If Not String.IsNullOrWhiteSpace(sOn) AndAlso Not String.IsNullOrWhiteSpace(sName) AndAlso Not String.IsNullOrWhiteSpace(sType) Then
|
|
If String.Compare(sOn, "true", True) = 0 Then
|
|
TableRowList.Add(New GridLine(True, sName, sType))
|
|
ElseIf String.Compare(sOn, "false", True) = 0 Then
|
|
TableRowList.Add(New GridLine(False, sName, sType))
|
|
Else
|
|
Continue For
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
NotifyPropertyChanged("TableRowList")
|
|
Return True
|
|
End Function
|
|
|
|
Private Function WriteTableFile() As Boolean
|
|
' inizio routine di scrittura
|
|
Dim FileContent As String() = File.ReadAllLines(m_BeamTableTemplate_FilePath)
|
|
Dim NewTableFileContent As New List(Of String)
|
|
Dim bBeamTable As Boolean = False
|
|
For LineIndex As Integer = 0 To FileContent.Count - 1
|
|
Dim sCurrLine As String = FileContent(LineIndex)
|
|
sCurrLine = sCurrLine.Replace(DATETIME, System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"))
|
|
sCurrLine = sCurrLine.Replace(TABLENAME, SelMachining & "Data")
|
|
|
|
If sCurrLine.Contains(SelMachining & "Data") AndAlso sCurrLine.Contains("=") Then
|
|
bBeamTable = True
|
|
NewTableFileContent.Add(sCurrLine)
|
|
PrintActiveMachiningList(NewTableFileContent)
|
|
End If
|
|
|
|
If Not bBeamTable Then
|
|
NewTableFileContent.Add(sCurrLine)
|
|
Else
|
|
bBeamTable = False
|
|
End If
|
|
Next
|
|
Dim FilePath As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\" & "Beam" & "\" & SelMachining & "Data.lua"
|
|
File.WriteAllLines(FilePath, NewTableFileContent, Text.Encoding.UTF8)
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub PrintActiveMachiningList(NewTableFileContent As List(Of String))
|
|
For Index As Integer = 0 To m_TableRowList.Count - 1
|
|
If String.IsNullOrEmpty(m_TableRowList(Index).Name) Then Continue For
|
|
Dim CurrentLine As String = " { On = " & If(m_TableRowList(Index).OnPar, "true", "false") & ", Name = '" & m_TableRowList(Index).Name & "', Type = '" & m_TableRowList(Index).Type & "'}"
|
|
If Index < m_TableRowList.Count - 1 Then
|
|
CurrentLine &= ","
|
|
End If
|
|
NewTableFileContent.Add(CurrentLine)
|
|
Next
|
|
End Sub
|
|
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "MoveRowUp"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Exec.
|
|
''' </summary>
|
|
Public ReadOnly Property MoveRowUp_Command As ICommand
|
|
Get
|
|
If m_cmdMoveRowUp Is Nothing Then
|
|
m_cmdMoveRowUp = New Command(AddressOf MoveRowUp)
|
|
End If
|
|
Return m_cmdMoveRowUp
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Sub MoveRowUp()
|
|
If SelRowIndex > 0 Then
|
|
m_TableRowList.Move(SelRowIndex, SelRowIndex - 1)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' MoveRowUp
|
|
|
|
#Region "MoveRowDown"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Exec.
|
|
''' </summary>
|
|
Public ReadOnly Property MoveRowDown_Command As ICommand
|
|
Get
|
|
If m_cmdMoveRowDown Is Nothing Then
|
|
m_cmdMoveRowDown = New Command(AddressOf MoveRowDown)
|
|
End If
|
|
Return m_cmdMoveRowDown
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Sub MoveRowDown()
|
|
If SelRowIndex < m_TableRowList.Count - 1 Then
|
|
m_TableRowList.Move(SelRowIndex, SelRowIndex + 1)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' MoveRowDown
|
|
|
|
#Region "AddRow"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Exec.
|
|
''' </summary>
|
|
Public ReadOnly Property AddRow_Command As ICommand
|
|
Get
|
|
If m_cmdAddRow Is Nothing Then
|
|
m_cmdAddRow = New Command(AddressOf AddRow)
|
|
End If
|
|
Return m_cmdAddRow
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Sub AddRow()
|
|
m_TableRowList.Insert(SelRowIndex + 1, New GridLine(False, "", ""))
|
|
End Sub
|
|
|
|
#End Region ' AddRow
|
|
|
|
#Region "DeleteRow"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do Exec.
|
|
''' </summary>
|
|
Public ReadOnly Property DeleteRow_Command As ICommand
|
|
Get
|
|
If m_cmdDeleteRow Is Nothing Then
|
|
m_cmdDeleteRow = New Command(AddressOf DeleteRow)
|
|
End If
|
|
Return m_cmdDeleteRow
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the Exec. This method is invoked by the ExecCommand.
|
|
''' </summary>
|
|
Public Sub DeleteRow()
|
|
m_TableRowList.RemoveAt(SelRowIndex)
|
|
End Sub
|
|
|
|
#End Region ' DeleteRow
|
|
|
|
#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()
|
|
' scrivo il file
|
|
WriteTableFile()
|
|
' resetto le modifiche
|
|
For Each Line In m_TableRowList
|
|
Line.ResetIsModified()
|
|
Next
|
|
End Sub
|
|
|
|
#End Region ' Save
|
|
|
|
#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()
|
|
' verifico se pagina precedente modificata
|
|
Dim TableModified As Boolean = False
|
|
For Each Line In m_TableRowList
|
|
If Line.IsModified Then
|
|
TableModified = True
|
|
Exit For
|
|
End If
|
|
Next
|
|
' se modificata, chiedo se salvare
|
|
If TableModified 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
|
|
RaiseEvent m_CloseWindow(True)
|
|
End Sub
|
|
|
|
#End Region ' Close
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|
|
|
|
Public Class GridLine
|
|
Inherits VMBase
|
|
|
|
Friend ReadOnly Property IsModified As Boolean
|
|
Get
|
|
Return m_IsOnModified Or m_IsNameModified Or m_IsTypeModified
|
|
End Get
|
|
End Property
|
|
Friend Sub ResetIsModified()
|
|
m_IsOnModified = False
|
|
m_IsNameModified = False
|
|
m_IsTypeModified = False
|
|
End Sub
|
|
|
|
Private m_IsOnModified As Boolean = False
|
|
Private m_On As Boolean
|
|
Public Property OnPar As Boolean
|
|
Get
|
|
Return m_On
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_On = value
|
|
m_IsOnModified = True
|
|
End Set
|
|
End Property
|
|
|
|
Private Shared m_NamesList As ObservableCollection(Of String)
|
|
Public ReadOnly Property NamesList As ObservableCollection(Of String)
|
|
Get
|
|
Return m_NamesList
|
|
End Get
|
|
End Property
|
|
Friend Shared Sub SetNamesList(NamesList As ObservableCollection(Of String))
|
|
m_NamesList = NamesList
|
|
End Sub
|
|
|
|
Private m_IsNameModified As Boolean = False
|
|
Private m_Name As String
|
|
Public Property Name As String
|
|
Get
|
|
Return m_Name
|
|
End Get
|
|
Set(value As String)
|
|
m_Name = value
|
|
m_IsNameModified = True
|
|
End Set
|
|
End Property
|
|
|
|
Private Shared m_TypeList As ObservableCollection(Of String)
|
|
Public ReadOnly Property TypeList As ObservableCollection(Of String)
|
|
Get
|
|
Return m_TypeList
|
|
End Get
|
|
End Property
|
|
Friend Shared Sub SetTypeList(TypeList As ObservableCollection(Of String))
|
|
m_TypeList = TypeList
|
|
End Sub
|
|
|
|
Private m_IsTypeModified As Boolean = False
|
|
Private m_Type As String
|
|
Public Property Type As String
|
|
Get
|
|
Return m_Type
|
|
End Get
|
|
Set(value As String)
|
|
m_Type = value
|
|
m_IsTypeModified = True
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(bOnPar As Boolean, sName As String, sType As String)
|
|
m_On = bOnPar
|
|
m_Name = sName
|
|
m_Type = sType
|
|
End Sub
|
|
|
|
End Class |