Imports System.IO Module TableUtility Private Const MMACHINEDATA As String = ".MMachineData" Private Const MTABLE As String = ".MTable" Private Const DATETIME As String = "%DATE_TIME%" Private Const TABLENAME As String = "%TABLE_NAME%" Friend Sub WriteDoorsTable(SelectedTable As MTableListBoxItem, sTableNamePath As String) Dim FileContent As IEnumerable(Of String) = File.ReadLines(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) PrintActiveMachinesList(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 PrintActiveMachinesList(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), ", 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 End Module