90842e061b
- Aggiunta gestione verifica assenza cartella machines e doors nella finestra MTable durante l'utilizzo. - Aggiunta ricerca per nome Nella MTable. - Aggiunti ToolTip nomi nella MTable.
213 lines
11 KiB
VB.net
213 lines
11 KiB
VB.net
Imports System.Text.RegularExpressions
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
|
|
Module TableUtility
|
|
|
|
Friend Const DATETIME As String = "%DATE_TIME%"
|
|
Friend Const TABLENAME As String = "%TABLE_NAME%"
|
|
Private Const MMACHINEDATA As String = ".MMachineData"
|
|
Private Const MACHNAME As String = "MachName"
|
|
Private Const NCGENERATE As String = "NcGenerate"
|
|
Private Const MAKERAW As String = "MakeRaw"
|
|
Private Const MTABLE As String = ".MTable"
|
|
Private Const NAME As String = "Name"
|
|
Private Const ONCONST As String = "On"
|
|
Private Const MACH As String = "Mach"
|
|
Private Const MACHUP As String = "MachUp"
|
|
Private Const MACHDW As String = "MachDw"
|
|
Private Const MACHID As String = "MachId"
|
|
Private Const SHIFT As String = "Shift"
|
|
Private Const OPER As String = "Oper"
|
|
|
|
Friend Function ReadDoorsTable(Table As MTableListBoxItem) As Boolean
|
|
Dim FileContent As String() = File.ReadAllLines(Table.m_TableNamePath)
|
|
Dim bMMachineData As Boolean = False
|
|
Dim bMTable As Boolean = False
|
|
For LineIndex As Integer = 0 To FileContent.Count - 1
|
|
If FileContent(LineIndex).Contains(MMACHINEDATA) Then
|
|
bMMachineData = True
|
|
ElseIf FileContent(LineIndex).Contains(MTABLE) Then
|
|
bMTable = True
|
|
End If
|
|
Dim Open As Integer = CountCharacter(FileContent(LineIndex), "{"c)
|
|
Dim Close As Integer = CountCharacter(FileContent(LineIndex), "}"c)
|
|
If Close > Open Then
|
|
If bMMachineData Then
|
|
bMMachineData = False
|
|
ElseIf bMTable Then
|
|
bMTable = False
|
|
End If
|
|
End If
|
|
If bMMachineData Then
|
|
Dim sMachName As String = SearchKey(FileContent(LineIndex), MACHNAME)
|
|
Dim bNcGenerate As Boolean = False
|
|
Dim bMakeraw As Boolean = False
|
|
If Not String.IsNullOrEmpty(sMachName) Then
|
|
Dim sNcGenerate As String = SearchKey(FileContent(LineIndex), NCGENERATE)
|
|
If Not String.IsNullOrEmpty(sNcGenerate) Then
|
|
bNcGenerate = Convert.ToBoolean(sNcGenerate)
|
|
End If
|
|
Dim sMakeraw As String = SearchKey(FileContent(LineIndex), MAKERAW)
|
|
If Not String.IsNullOrEmpty(sMakeraw) Then
|
|
bMakeraw = Convert.ToBoolean(sMakeraw)
|
|
End If
|
|
Try
|
|
Table.SharedMachIndex += 1
|
|
Table.ActiveMachinesList.Add(New MTableMachineListBoxItem(sMachName, bNcGenerate, bMakeraw, Table.SharedMachIndex))
|
|
Table.m_MachIdList.Add(Table.SharedMachIndex)
|
|
Catch ex As Exception
|
|
EgtOutLog(ex.ToString)
|
|
Return False
|
|
End Try
|
|
End If
|
|
End If
|
|
If bMTable Then
|
|
Dim sName As String = SearchKey(FileContent(LineIndex), NAME)
|
|
Dim bOn As Boolean = False
|
|
Dim sMach As String = String.Empty
|
|
Dim sMachUp As String = String.Empty
|
|
Dim sMachDw As String = String.Empty
|
|
Dim nMachId As Integer = 1
|
|
Dim nShift As Integer = 0
|
|
Dim sOper As String = String.Empty
|
|
If Not String.IsNullOrEmpty(sName) Then
|
|
Dim sOn As String = SearchKey(FileContent(LineIndex), ONCONST)
|
|
If Not String.IsNullOrEmpty(sOn) Then
|
|
Dim nValue As Integer
|
|
Integer.TryParse(sOn, nValue)
|
|
bOn = nValue <> 0
|
|
End If
|
|
sMach = SearchKey(FileContent(LineIndex), MACH)
|
|
sMachUp = SearchKey(FileContent(LineIndex), MACHUP)
|
|
sMachDw = SearchKey(FileContent(LineIndex), MACHDW)
|
|
Dim sMachId = SearchKey(FileContent(LineIndex), MACHID)
|
|
If String.IsNullOrEmpty(sMachId) Then
|
|
' il suo valore di default è 1 quindi lo imposto a questo valore
|
|
nMachId = 1
|
|
Else
|
|
Integer.TryParse(sMachId, nMachId)
|
|
End If
|
|
Dim sShift = SearchKey(FileContent(LineIndex), SHIFT)
|
|
If String.IsNullOrEmpty(sShift) Then
|
|
' il suo valore di default è 1 quindi lo imposto a questo valore
|
|
nShift = 0
|
|
Else
|
|
Integer.TryParse(sShift, nShift)
|
|
End If
|
|
sOper = SearchKey(FileContent(LineIndex), OPER)
|
|
' verifico che il MachId letto sia valido
|
|
If nMachId > Table.m_MachIdList.Count Then
|
|
nMachId = 0
|
|
End If
|
|
Table.AssociationList.Add(New MTableAssociationGridBoxItem(bOn, sName, nMachId, nShift, sOper, sMach, sMachUp, sMachDw, Table.ActiveMachinesList))
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
|
|
' se nessuna macchina, ne aggiungo una vuota
|
|
If Table.ActiveMachinesList.Count = 0 Then
|
|
Table.SharedMachIndex += 1
|
|
Table.ActiveMachinesList.Add(New MTableMachineListBoxItem(String.Empty, False, False, Table.SharedMachIndex))
|
|
Table.m_MachIdList.Add(Table.SharedMachIndex)
|
|
End If
|
|
' se nessuna lavorazione, ne aggiungo una vuota
|
|
If Table.AssociationList.Count = 0 Then
|
|
Table.AssociationList.Add(New MTableAssociationGridBoxItem(False, String.Empty, 0, 0, String.Empty, String.Empty, String.Empty, String.Empty, Table.ActiveMachinesList))
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function SearchKey(sLine As String, sKey As String) As String
|
|
Return Regex.Match(sLine, "[,|{|\s]" & sKey & "\s*=\s*['|\""]?(.*?)\s*?[,|}|'|\""]").Groups(1).Value
|
|
End Function
|
|
|
|
Public Function CountCharacter(ByVal sLine As String, ByVal cValue As Char) As Integer
|
|
Dim nCount As Integer = 0
|
|
Dim cArray() As Char = sLine.ToCharArray
|
|
For Index As Integer = 0 To cArray.Count - 1
|
|
If cArray(Index) = cValue Then nCount += 1
|
|
Next
|
|
Return nCount
|
|
End Function
|
|
|
|
Friend Sub WriteDoorTable(SelectedTable As MTableListBoxItem, sTableNamePath As String)
|
|
Dim FileContent As String() = File.ReadAllLines(IniFile.m_sTablesRoot & "\" & MTABLETEMPLATE_FILE)
|
|
Dim NewTableFileContent As New List(Of String)
|
|
Dim bMMachineData As Boolean = False
|
|
Dim bMTable 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, Path.GetFileNameWithoutExtension(sTableNamePath))
|
|
|
|
If sCurrLine.Contains(MMACHINEDATA) Then
|
|
bMMachineData = True
|
|
NewTableFileContent.Add(sCurrLine)
|
|
PrintActiveMachineList(SelectedTable, NewTableFileContent)
|
|
ElseIf sCurrLine.Contains(MTABLE) Then
|
|
bMTable = True
|
|
NewTableFileContent.Add(sCurrLine)
|
|
PrintActiveMachiningList(SelectedTable, NewTableFileContent)
|
|
End If
|
|
|
|
If Not bMMachineData AndAlso Not bMTable Then
|
|
NewTableFileContent.Add(sCurrLine)
|
|
Else
|
|
bMMachineData = False
|
|
bMTable = False
|
|
End If
|
|
Next
|
|
File.WriteAllLines(sTableNamePath, NewTableFileContent, Text.Encoding.UTF8)
|
|
End Sub
|
|
|
|
Private Sub PrintActiveMachineList(SelectedTable As MTableListBoxItem, NewTableFileContent As List(Of String))
|
|
For Index As Integer = 0 To SelectedTable.ActiveMachinesList.Count - 1
|
|
Dim CurrentLine As String = " { MachName = '" & SelectedTable.ActiveMachinesList(Index).SelectedMachine & "', NcGenerate = " & SelectedTable.ActiveMachinesList(Index).NcGenerate.ToString.ToLower _
|
|
& ", MakeRaw = " & SelectedTable.ActiveMachinesList(Index).Makeraw.ToString.ToLower & " }"
|
|
If Index < SelectedTable.ActiveMachinesList.Count - 1 Then
|
|
CurrentLine &= " ,"
|
|
End If
|
|
NewTableFileContent.Add(CurrentLine)
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub PrintActiveMachiningList(SelectedTable As MTableListBoxItem, NewTableFileContent As List(Of String))
|
|
For Index As Integer = 0 To SelectedTable.AssociationList.Count - 1
|
|
If String.IsNullOrEmpty(SelectedTable.AssociationList(Index).Name) Then Continue For
|
|
Dim CurrentLine As String = " { On = " & If(SelectedTable.AssociationList(Index).OnPar, 1, 0) & ", Name = '" & SelectedTable.AssociationList(Index).Name & "'" _
|
|
& If(Not String.IsNullOrEmpty(SelectedTable.AssociationList(Index).Oper), ", Oper = '" & SelectedTable.AssociationList(Index).Oper & "'", String.Empty) _
|
|
& If(Not IsNothing(SelectedTable.AssociationList(Index).MachId) AndAlso SelectedTable.AssociationList(Index).MachId > 1, ", MachId = " & SelectedTable.AssociationList(Index).MachId.ToString, String.Empty) _
|
|
& If(SelectedTable.AssociationList(Index).Shift <> 0, ", Shift = " & SelectedTable.AssociationList(Index).Shift.ToString, String.Empty) _
|
|
& If(Not String.IsNullOrEmpty(SelectedTable.AssociationList(Index).Mach), ", Mach = '" & SelectedTable.AssociationList(Index).Mach & "'", String.Empty) _
|
|
& If(Not String.IsNullOrEmpty(SelectedTable.AssociationList(Index).MachUp), ", MachUp = '" & SelectedTable.AssociationList(Index).MachUp & "'", String.Empty) _
|
|
& If(Not String.IsNullOrEmpty(SelectedTable.AssociationList(Index).MachDw), ", MachDw = '" & SelectedTable.AssociationList(Index).MachDw & "'", String.Empty) & " }"
|
|
If Index < SelectedTable.AssociationList.Count - 1 Then
|
|
CurrentLine &= " ,"
|
|
End If
|
|
NewTableFileContent.Add(CurrentLine)
|
|
Next
|
|
End Sub
|
|
|
|
Friend Function VerifyDoorsDir() As Boolean
|
|
' verifico l'esistenza della cartella Machines
|
|
If String.IsNullOrWhiteSpace(IniFile.m_sDoorsDirPath) Then
|
|
Return False
|
|
End If
|
|
Return RecursiveVerifyDoorsDir()
|
|
End Function
|
|
|
|
Private Function RecursiveVerifyDoorsDir() As Boolean
|
|
If Directory.Exists(IniFile.m_sDoorsDirPath) Then
|
|
Return True
|
|
Else
|
|
If MessageBox.Show(String.Format(EgtMsg(MSG_DOORSERRORS + 15) & Environment.NewLine & EgtMsg(MSG_DOORSERRORS + 16), IniFile.m_sDoorsDirPath), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.YesNo, MessageBoxImage.Error) = MessageBoxResult.Yes Then
|
|
Return RecursiveVerifyDoorsDir()
|
|
End If
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
End Module
|