Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.IO Imports EgtUILib Imports System.Text.RegularExpressions Public Class MTableDbVM Inherits VMBase Friend Enum Tables As Integer LEFTTABLE = 1 RIGHTTABLE = 2 End Enum Private m_FocusedTable As Tables = Tables.LEFTTABLE Friend Property FocusedTable As Tables Get Return m_FocusedTable End Get Set(value As Tables) m_FocusedTable = value End Set End Property Private Shared m_refMTableDbVM As MTableDbVM Public Shared ReadOnly Property refMTableDbVM As MTableDbVM Get Return m_refMTableDbVM End Get End Property Friend Function SetRefMTableDbVM(MTableDbVM As MTableDbVM) As Boolean m_refMTableDbVM = MTableDbVM Return Not IsNothing(m_refMTableDbVM) End Function Private m_sPreviousActiveMachine As String Private m_TablesList As New ObservableCollection(Of MTableListBoxItem) Public Property TablesList As ObservableCollection(Of MTableListBoxItem) Get Return m_TablesList End Get Set(value As ObservableCollection(Of MTableListBoxItem)) m_TablesList = value End Set End Property Private m_TextToSearch As String Public Property TextToSearch As String Get Return m_TextToSearch End Get Set(value As String) If value <> m_TextToSearch Then If Not String.IsNullOrWhiteSpace(value) Then ' deseleziono tutto nella tabella delle lavorazioni ordinate ResetRightTableSelection() ' recupero tabella selezionata Dim SelectedMTable As MTableListBoxItem = Nothing For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then SelectedMTable = m_TablesList(TableIndex) End If Next ' se esiste, cerco il testo ed abilito il bottone reset If Not IsNothing(SelectedMTable) Then SearchText(value, SelectedMTable) IsEnabledResetSearch = True End If Else ' altrimenti resetto la ricerca e disabilito il bottone reset ResetSearchedRow() IsEnabledResetSearch = False End If m_TextToSearch = value NotifyPropertyChanged("TextToSearch") End If End Set End Property Private m_IsEnabledResetSearch As Boolean Public Property IsEnabledResetSearch As Boolean Get Return m_IsEnabledResetSearch End Get Set(value As Boolean) If value <> m_IsEnabledResetSearch Then m_IsEnabledResetSearch = value NotifyPropertyChanged("IsEnabledResetSearch") End If End Set End Property Private m_FocusSearchTextState As Boolean Public Property FocusSearchTextState As Boolean Get Return m_FocusSearchTextState End Get Set(value As Boolean) m_FocusSearchTextState = value NotifyPropertyChanged("FocusSearchTextState") End Set End Property Private m_AddRemoveRow_IsEnabled As Boolean Public Property AddRemoveRow_IsEnabled As Boolean Get Return m_AddRemoveRow_IsEnabled End Get Set(value As Boolean) If value <> m_AddRemoveRow_IsEnabled Then m_AddRemoveRow_IsEnabled = value NotifyPropertyChanged("AddRemoveRow_IsEnabled") End If End Set End Property Private m_MoveRow_IsEnabled As Boolean Public Property MoveRow_IsEnabled As Boolean Get Return m_MoveRow_IsEnabled End Get Set(value As Boolean) If value <> m_MoveRow_IsEnabled Then m_MoveRow_IsEnabled = value NotifyPropertyChanged("MoveRow_IsEnabled") End If End Set End Property Private m_Group_IsEnabled As Boolean Public Property Group_IsEnabled As Boolean Get Return m_Group_IsEnabled End Get Set(value As Boolean) If value <> m_Group_IsEnabled Then m_Group_IsEnabled = value NotifyPropertyChanged("Group_IsEnabled") End If End Set End Property Private m_Position_IsEnabled As Boolean Public Property Position_IsEnabled As Boolean Get Return m_Position_IsEnabled End Get Set(value As Boolean) If value <> m_Position_IsEnabled Then m_Position_IsEnabled = value NotifyPropertyChanged("Position_IsEnabled") End If End Set End Property #Region "Messages" Public ReadOnly Property Title As String Get Return EgtMsg(MSG_MAINWINDOW + 20) End Get End Property Public ReadOnly Property MachListHeader As String Get Return EgtMsg(MSG_DOORS + 8) End Get End Property Public ReadOnly Property MachineNameTxBl As String Get Return EgtMsg(MSG_DOORS + 9) End Get End Property Public ReadOnly Property NcGenerateTxBl As String Get Return EgtMsg(MSG_DOORS + 10) End Get End Property Public ReadOnly Property MakeRawTxBl As String Get Return EgtMsg(MSG_DOORS + 11) End Get End Property Public ReadOnly Property OnHdr As String Get Return EgtMsg(MSG_DOORS + 12) End Get End Property Public ReadOnly Property GeomNameHdr As String Get Return EgtMsg(MSG_DOORS + 13) End Get End Property Public ReadOnly Property OperationHdr As String Get Return EgtMsg(MSG_DOORS + 14) End Get End Property Public ReadOnly Property MIdHdr As String Get Return EgtMsg(MSG_DOORS + 15) End Get End Property Public ReadOnly Property ShiftHdr As String Get Return EgtMsg(MSG_DOORS + 16) End Get End Property Public ReadOnly Property MachTypeHdr As String Get Return EgtMsg(MSG_DOORS + 17) End Get End Property Public ReadOnly Property MachHdr As String Get Return EgtMsg(MSG_DOORS + 18) End Get End Property Public ReadOnly Property MachUpHdr As String Get Return EgtMsg(MSG_DOORS + 19) End Get End Property Public ReadOnly Property MachDownHdr As String Get Return EgtMsg(MSG_DOORS + 20) End Get End Property Public ReadOnly Property GroupHdr As String Get Return EgtMsg(MSG_DOORS + 27) End Get End Property Public ReadOnly Property PropertyHdr As String Get Return EgtMsg(MSG_DOORS + 28) End Get End Property Public ReadOnly Property MachiningHdr As String Get Return EgtMsg(MSG_DOORS + 29) End Get End Property Public ReadOnly Property JoinHdr As String Get Return EgtMsg(MSG_DOORS + 30) End Get End Property Public ReadOnly Property AddMachBtn As String Get Return EgtMsg(MSG_DOORS + 21) End Get End Property Public ReadOnly Property RemoveMachBtn As String Get Return EgtMsg(MSG_DOORS + 22) End Get End Property Public ReadOnly Property AddMachiningBtn As String Get Return EgtMsg(MSG_DOORS + 23) End Get End Property Public ReadOnly Property RemoveMachiningBtn As String Get Return EgtMsg(MSG_DOORS + 24) End Get End Property Public ReadOnly Property CurrMsg As String Get Return EgtMsg(MSG_DOORS + 25) End Get End Property Public ReadOnly Property AssHdr As String Get Return EgtMsg(MSG_DOORS + 25) End Get End Property Public ReadOnly Property OrdMachHdr As String Get Return EgtMsg(MSG_DOORS + 25) End Get End Property #End Region ' Messages #Region "ToolTip" 'Proprietà ToolTip Public ReadOnly Property NewTableToolTip As String Get Return EgtMsg(MSG_DOORS + 1) End Get End Property Public ReadOnly Property SaveTableToolTip As String Get Return EgtMsg(MSG_DOORS + 2) End Get End Property Public ReadOnly Property SaveAsTableToolTip As String Get Return EgtMsg(MSG_DOORS + 3) End Get End Property Public ReadOnly Property RemoveTableToolTip As String Get Return EgtMsg(MSG_DOORS + 4) End Get End Property Public ReadOnly Property SetActiveTableToolTip As String Get Return EgtMsg(MSG_DOORS + 26) End Get End Property #End Region ' ToolTip ' Definizione comandi Private m_cmdNewTable As ICommand Private m_cmdSaveTable As ICommand Private m_cmdSaveTableAs As ICommand Private m_cmdRemoveTable As ICommand Private m_cmdSetActiveTable As ICommand Private m_cmdResetSearch As ICommand Private m_cmdSearchPrevious As ICommand Private m_cmdSearchNext As ICommand Private m_cmdFocusSearch As ICommand Private m_cmdAddMach As ICommand Private m_cmdRemoveMach As ICommand Private m_cmdAddRow As ICommand Private m_cmdRemoveRow As ICommand Private m_cmdMoveRowUp As ICommand Private m_cmdMoveRowDown As ICommand Private m_cmdGroup As ICommand Private m_cmdPosition As ICommand Private m_cmdCloseMTableWindow As ICommand #Region "CONSTRUCTOR" Sub New() ' Creo riferimento a questa classe SetRefMTableDbVM(Me) ' Passo all'item della lista il delegato alla funzuione che permette di cancellare una lavorazione MTableListBoxItem.m_delSaveMTable = AddressOf SaveTable MTableMachineListBoxItem.m_delCloseMTableWnd = AddressOf CloseWindow MTableListBoxItem.m_delCloseMTableWnd = AddressOf CloseWindow MTableAssociationGridBoxItem.m_delCloseMTableWnd = AddressOf CloseWindow MTableListBoxItem.m_delSearchInMTable = AddressOf SearchInNewlySelectedMTable ' recupero macchina corrente all'apertura della finestra per poterla ripristinare alla fine EgtGetCurrMachineName(m_sPreviousActiveMachine) ' Azzero indice per nome tabella di default MTableListBoxItem.NewMTableIndex = 0 ' Creo liste operazioni e proprietà MTableAssociationGridBoxItem.LoadOperationList() MTableMachiningGridBoxItem.LoadPropertyList() ' Carico lista tabelle UpdateTables() Dim bActiveMTableFound As Boolean = False For Index = 0 To m_TablesList.Count - 1 If m_TablesList(Index).ActiveTable Then m_TablesList(Index).IsSelected = True m_TablesList(Index).SelMachine = m_TablesList(Index).ActiveMachinesList(0) bActiveMTableFound = True Exit For End If Next If EgtVerifyMachinesDir() AndAlso Not bActiveMTableFound AndAlso m_TablesList.Count > 0 Then m_TablesList(0).IsSelected = True m_TablesList(0).SelMachine = m_TablesList(0).ActiveMachinesList(0) End If End Sub #End Region #Region "METHODS" Private Sub UpdateTables() m_TablesList.Clear() ' se trovo la cartella carico la lista di tabelle Dim FileTableList As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(IniFile.m_sTablesRoot) For Index As Integer = 0 To FileTableList.Count - 1 If Path.GetExtension(FileTableList(Index)).ToLower = ".mtl" Then m_TablesList.Add(New MTableListBoxItem(Path.GetFileNameWithoutExtension(FileTableList(Index)), FileTableList(Index))) VerifyNewName(Path.GetFileNameWithoutExtension(FileTableList(Index))) End If Next SetActiveTable() End Sub Private Sub VerifyNewName(sNewName As String) Dim sNameIndex As String = Regex.Match(sNewName, "MTable_(\d+)").Groups(1).Value Dim nNameIndex As Integer = 0 If Not String.IsNullOrEmpty(sNameIndex) Then Integer.TryParse(sNameIndex, nNameIndex) End If If nNameIndex > MTableListBoxItem.NewMTableIndex Then MTableListBoxItem.NewMTableIndex = nNameIndex End If End Sub Private Const MTABLENAME As String = "MTableName" Private Const MTNAME As String = "MTName" Private Sub SetActiveTable() Dim ActiveMTableName As String = String.Empty GetPrivateProfileString(S_DOORS, K_CURRMTABLE, "", ActiveMTableName) 'Dim ActiveMTableFilePath As String = Path.GetDirectoryName(IniFile.m_sTablesRoot) & "\CurrMTable.lua" 'If File.Exists(ActiveMTableFilePath) Then ' Dim ReadFile As String() = File.ReadAllLines(ActiveMTableFilePath) ' For LineIndex As Integer = 0 To ReadFile.Count - 1 ' If ReadFile(LineIndex).Contains(MTABLENAME) Then ' ActiveMTableName = TableUtility.SearchKey(ReadFile(LineIndex), MTNAME) ' Exit For ' End If ' Next For Index As Integer = 0 To m_TablesList.Count - 1 If m_TablesList(Index).TableName = ActiveMTableName Then m_TablesList(Index).ActiveTable = True Exit For End If Next 'End If End Sub Private Sub SearchText(sText As String, SelectedMTable As MTableListBoxItem) Dim bFirst As Boolean = True ' cerco nella tabella associazioni For AssociationIndex = 0 To SelectedMTable.AssociationList.Count - 1 Dim CurrAssociation As MTableAssociationGridBoxItem = SelectedMTable.AssociationList(AssociationIndex) If CurrAssociation.Name.ToLower.Contains(sText) Then If bFirst Then CurrAssociation.IsSelected = True bFirst = False End If CurrAssociation.IsValidForSearch = True Else CurrAssociation.IsValidForSearch = False End If Next ' cerco nella tabella lavorazioni ordinate For MachineIndex = 0 To SelectedMTable.ActiveMachinesList.Count - 1 For MachiningIndex = 0 To SelectedMTable.ActiveMachinesList(MachineIndex).MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.ActiveMachinesList(MachineIndex).MachiningList(MachiningIndex) If CurrMachining.Geometry.ToLower.Contains(sText) Then CurrMachining.IsValidForSearch = True Else CurrMachining.IsValidForSearch = False End If Next Next End Sub Private Sub SearchInNewlySelectedMTable(SelectedMTable As MTableListBoxItem) If Not String.IsNullOrWhiteSpace(m_TextToSearch) Then SearchText(m_TextToSearch, SelectedMTable) IsEnabledResetSearch = True End If End Sub #Region "SelectRow" Friend Sub LeftSelect(SelectedRow As MTableMachiningGridBoxItem) ' se è già selezionato, lo deseleziono If SelectedRow.IsSelected Then ' verifico se è in mezzo a due gruppi selezionati Dim bIsPrevSel As Boolean = False Dim bIsNextSel As Boolean = False For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then ' trovo posizione dell'elemento selezionato Dim nSelItemIndex As Integer = m_TablesList(TableIndex).SelMachine.MachiningList.IndexOf(SelectedRow) ' cerco il primo precedente non dello stesso gruppo For MachiningIndex = nSelItemIndex - 1 To 0 Step -1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId <> SelectedRow.GroupId Then bIsPrevSel = CurrMachining.IsSelected Exit For End If Next ' verifico se i successivi sono dello stesso gruppo For MachiningIndex = nSelItemIndex + 1 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId <> SelectedRow.GroupId Then bIsNextSel = CurrMachining.IsSelected Exit For End If Next Exit For End If Next If bIsPrevSel And bIsNextSel Then Return SelectGroup(SelectedRow) ' verifico cosa è rimasto selezionato e gestisco di conseguenza i bottoni VerifyDeselection() Return End If ' verifico se ci sono elementi già selezionati Dim bFirstIsGroup As Boolean = False Dim bLastIsGroup As Boolean = False Dim bZeroItemFound As Boolean = False Dim bItemFound As Boolean = False Dim nSelFirstGroupId As Integer = -1 Dim nSelLastGroupId As Integer = -1 For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For MachiningIndex = 0 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.IsSelected Then If CurrMachining.GroupId = 0 Then ' se cerco di selezionare un secondo elemento di gruppo zero, esco If SelectedRow.GroupId = 0 Then Return Else bZeroItemFound = True End If Else ' se ci sono già un elemento con gruppo zero ed un gruppo ordinato selezionati, esco If bZeroItemFound Then Return End If If nSelFirstGroupId = -1 Then ' se c'è già un altro gruppo ordinato selezionato nSelFirstGroupId = CurrMachining.GroupId nSelLastGroupId = CurrMachining.GroupId bItemFound = True ' verifico se sono selezionati gruppi o singole lavorazioni If MachiningIndex >= 1 Then If m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex - 1).GroupId <> CurrMachining.GroupId Then bFirstIsGroup = True End If Else bFirstIsGroup = True End If If MachiningIndex < m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Then If m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex + 1).GroupId <> CurrMachining.GroupId Then bLastIsGroup = True End If Else bLastIsGroup = True End If ElseIf CurrMachining.GroupId = nSelLastGroupId Or (CurrMachining.GroupId = nSelLastGroupId + 1 And CurrMachining.IsSelected) Then ' se il successivo ha lo stesso gruppo, o il gruppo successivo ed è selezionato nSelLastGroupId = CurrMachining.GroupId ' verifico se sono selezionati gruppi o singole lavorazioni If MachiningIndex = m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Then bLastIsGroup = True ElseIf m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex + 1).GroupId <> CurrMachining.GroupId Then bLastIsGroup = True End If End If End If End If Next Exit For End If Next ' se ho trovato un elemento If bItemFound Then ' se non è adiacente e ( non ha gruppo zero e indice inizio e fine selezione coincidono) e indice di inizio e fine non sono gruppi, esco If (Not (SelectedRow.GroupId <> 0 And (nSelFirstGroupId - 1 = SelectedRow.GroupId Or nSelLastGroupId + 1 = SelectedRow.GroupId)) And Not (SelectedRow.GroupId = 0 And nSelFirstGroupId = nSelLastGroupId)) Or Not (bFirstIsGroup And bLastIsGroup And nSelFirstGroupId <> -1) Then Return End If End If ' procedo con la selezione dell'elemento SelectGroup(SelectedRow) ' gestisco bottoni ' se ho selezionato un gruppo 0 e c'è un gruppo già selezionato If SelectedRow.GroupId = 0 And nSelFirstGroupId = nSelLastGroupId And bItemFound Then ManageMachiningButtons(False, True, False, False) ElseIf SelectedRow.GroupId <> 0 And nSelFirstGroupId = nSelLastGroupId And bZeroItemFound Then ManageMachiningButtons(False, True, False, False) ElseIf SelectedRow.GroupId <> 0 And bItemFound Then ManageMachiningButtons(False, False, True, False) ElseIf SelectedRow.GroupId <> 0 And Not bItemFound Then ManageMachiningButtons(False, False, False, True) Else ManageMachiningButtons(False, False, False, False) End If End Sub Private Sub VerifyDeselection() ' verifico se ci sono elementi già selezionati Dim bFirstIsGroup As Boolean = False Dim bLastIsGroup As Boolean = False Dim bZeroItemFound As Boolean = False Dim bItemFound As Boolean = False Dim nSelFirstGroupId As Integer = -1 Dim nSelLastGroupId As Integer = -1 For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For MachiningIndex = 0 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.IsSelected Then If CurrMachining.GroupId = 0 Then bZeroItemFound = True Else If nSelFirstGroupId = -1 Then nSelFirstGroupId = CurrMachining.GroupId nSelLastGroupId = CurrMachining.GroupId bItemFound = True ' verifico se sono selezionati gruppi o singole lavorazioni If MachiningIndex >= 1 Then If m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex - 1).GroupId <> CurrMachining.GroupId Then bFirstIsGroup = True End If Else bFirstIsGroup = True End If If MachiningIndex < m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Then If m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex + 1).GroupId <> CurrMachining.GroupId Then bLastIsGroup = True End If Else bLastIsGroup = True End If ElseIf CurrMachining.GroupId = nSelLastGroupId Or (CurrMachining.GroupId = nSelLastGroupId + 1 And CurrMachining.IsSelected) Then ' se il successivo ha lo stesso gruppo, o il gruppo successivo ed è selezionato nSelLastGroupId = CurrMachining.GroupId ' verifico se sono selezionati gruppi o singole lavorazioni If m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 = MachiningIndex OrElse m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex + 1).GroupId <> CurrMachining.GroupId Then bLastIsGroup = True End If End If End If End If Next Exit For End If Next ' gestisco bottoni ' se ho selezionato un gruppo 0 e c'è un gruppo già selezionato If bItemFound And nSelFirstGroupId = nSelLastGroupId Then ManageMachiningButtons(False, False, False, True) Else ManageMachiningButtons(False, False, False, False) End If End Sub Private Sub SelectGroup(SelectedRow As MTableMachiningGridBoxItem) If IsNothing(SelectedRow) Then Return ' seleziono l'elemento cliccato SelectedRow.IsSelected = Not SelectedRow.IsSelected ' se il gruppo è zero non seleziono le altre righe If SelectedRow.GroupId = 0 Then Return For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then ' trovo posizione dell'elemento selezionato Dim nSelItemIndex As Integer = m_TablesList(TableIndex).SelMachine.MachiningList.IndexOf(SelectedRow) ' verifico se i precedenti sono dello stesso gruppo For MachiningIndex = nSelItemIndex - 1 To 0 Step -1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId = SelectedRow.GroupId Then CurrMachining.IsSelected = SelectedRow.IsSelected Else Exit For End If Next ' verifico se i successivi sono dello stesso gruppo For MachiningIndex = nSelItemIndex + 1 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId = SelectedRow.GroupId Then CurrMachining.IsSelected = SelectedRow.IsSelected Else Exit For End If Next Exit For End If Next End Sub Friend Sub RightSelect(SelectedRow As MTableMachiningGridBoxItem) Dim bIsRowSelected As Boolean = SelectedRow.IsSelected ' deseleziono tutto ResetRightTableSelection() If Not bIsRowSelected Then ' seleziono la lavorazione clickata SelectedRow.IsSelected = True ' attivo solo tasti di movimento ManageMachiningButtons(False, False, False, True) Else ' disattivo tutti i tasti ManageMachiningButtons(False, False, False, False) End If End Sub Friend Sub ResetRightTableSelection() For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For MachiningIndex = 0 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).SelMachine.MachiningList(MachiningIndex) CurrMachining.IsSelected = False Next Exit For End If Next End Sub Friend Sub ResetLeftTableSelection() For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For AssociationIndex = 0 To m_TablesList(TableIndex).AssociationList.Count - 1 Dim CurrAssociation As MTableAssociationGridBoxItem = m_TablesList(TableIndex).AssociationList(AssociationIndex) CurrAssociation.IsSelected = False Next Exit For End If Next End Sub #End Region ' SelectGroupCommand Friend Sub ManageMachiningButtons(bAddRemoveRow As Boolean, bPosition As Boolean, bGroup As Boolean, bMove As Boolean) AddRemoveRow_IsEnabled = bAddRemoveRow Position_IsEnabled = bPosition Group_IsEnabled = bGroup MoveRow_IsEnabled = bMove End Sub #End Region #Region "COMMANDS" #Region "NewTableCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property NewTableCommand As ICommand Get If m_cmdNewTable Is Nothing Then m_cmdNewTable = New Command(AddressOf NewTable) End If Return m_cmdNewTable End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub NewTable(param As Object) Dim NewMTable As MTableListBoxItem = New MTableListBoxItem("MTable_" & (MTableListBoxItem.NewMTableIndex + 1).ToString, String.Empty) m_TablesList.Add(NewMTable) MTableListBoxItem.NewMTableIndex += 1 If Not IsNothing(param) Then Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) SelectedMTable.IsSelected = False End If NewMTable.IsSelected = True End Sub #End Region ' NewTableCommand #Region "SaveTableCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SaveTableCommand As ICommand Get If m_cmdSaveTable Is Nothing Then m_cmdSaveTable = New Command(AddressOf SaveTable) End If Return m_cmdSaveTable End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SaveTable(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return If String.IsNullOrEmpty(SelectedMTable.TableNamePath) Then SaveTableAs(SelectedMTable) Else ' verifico di essere collegato alla cartella doors If Not VerifyDoorsDir() Then CloseWindow() Return End If TableUtility.WriteDoorTable(SelectedMTable, SelectedMTable.TableNamePath) SelectedMTable.IsModifiedReset() End If End Sub #End Region ' SaveTableCommand #Region "SaveTableAsCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SaveTableAsCommand As ICommand Get If m_cmdSaveTableAs Is Nothing Then m_cmdSaveTableAs = New Command(AddressOf SaveTableAs) End If Return m_cmdSaveTableAs End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SaveTableAs(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return ' verifico di essere collegato alla cartella doors If Not VerifyDoorsDir() Then CloseWindow() Return End If Dim sFile As String = String.Empty If SaveTableAsDialog(sFile, SelectedMTable.TableName) Then SelectedMTable.IsModifiedReset() VerifyNewName(Path.GetFileNameWithoutExtension(sFile)) TableUtility.WriteDoorTable(SelectedMTable, sFile) UpdateTables() ' seleziono la tabella appena salvata For Index As Integer = 0 To m_TablesList.Count - 1 If m_TablesList(Index).TableNamePath = sFile Then m_TablesList(Index).IsSelected = True End If Next End If End Sub Public Function SaveTableAsDialog(ByRef sPath As String, sTableName As String) As Boolean ' Direttorio corrente per MTable Dim sDir As String = IniFile.m_sTablesRoot ' Apertura dialogo di scelta file DDF Dim SaveFileDialogView As New EgtWPFLib5.EgtSaveFileDialog SaveFileDialogView.Title = EgtMsg(MSG_DOORS + 5) SaveFileDialogView.Extension = ".mtl" SaveFileDialogView.Directory = sDir SaveFileDialogView.FileName = sTableName If Not SaveFileDialogView.EgtShowDialog Then Return False End If sPath = SaveFileDialogView.FileName Return True End Function #End Region ' SaveTableAsCommand #Region "RemoveTableCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RemoveTableCommand As ICommand Get If m_cmdRemoveTable Is Nothing Then m_cmdRemoveTable = New Command(AddressOf RemoveTable) End If Return m_cmdRemoveTable End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub RemoveTable(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return ' verifico di essere collegato alla cartella doors If Not VerifyDoorsDir() Then CloseWindow() Return End If ' cancello tutte le tavole nella lista impostate su non visibili (quelle rimaste quando viene creata una nuova tabella e passando ad un altra non la si salva) Dim Index As Integer = m_TablesList.Count - 1 While Index >= 0 If m_TablesList(Index).Visibility <> Visibility.Visible Then m_TablesList.RemoveAt(Index) End If Index -= 1 End While ' verifico se la tabella selezionata è quella attiva If SelectedMTable.ActiveTable Then MessageBox.Show(EgtMsg(MSG_DOORSERRORS + 8) & vbCrLf & EgtMsg(MSG_DOORSERRORS + 9), "", MessageBoxButton.OK, MessageBoxImage.Stop) Exit Sub End If ' chiedo conferma prima di cancellare la tabella If MessageBox.Show(EgtMsg(MSG_DOORS + 6), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then If Not String.IsNullOrEmpty(SelectedMTable.TableNamePath) Then File.Delete(SelectedMTable.TableNamePath) End If Dim SelectedTableIndex As Integer = m_TablesList.IndexOf(SelectedMTable) m_TablesList.RemoveAt(SelectedTableIndex) If SelectedTableIndex > 0 Then TablesList(SelectedTableIndex - 1).IsSelected = True End If End If End Sub #End Region ' RemoveTableCommand #Region "SetActiveTableCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SetActiveTableCommand As ICommand Get If m_cmdSetActiveTable Is Nothing Then m_cmdSetActiveTable = New Command(AddressOf SetActiveTable) End If Return m_cmdSetActiveTable End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SetActiveTable(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return If WritePrivateProfileString(S_DOORS, K_CURRMTABLE, SelectedMTable.TableName) Then For Index As Integer = 0 To m_TablesList.Count - 1 If m_TablesList(Index).TableName = SelectedMTable.TableName Then m_TablesList(Index).ActiveTable = True Else m_TablesList(Index).ActiveTable = False End If Next End If '' Scrivo il file di configurazione con il nome di questa tavola 'Dim FileContent As String() = File.ReadAllLines(Path.GetDirectoryName(IniFile.m_sTablesRoot) & "\" & CURRMTABLE_FILE) 'Dim NewTableFileContent As New List(Of String) 'For LineIndex As Integer = 0 To FileContent.Count - 1 ' Dim sCurrLine As String = FileContent(LineIndex) ' sCurrLine = sCurrLine.Replace(TableUtility.DATETIME, System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")) ' sCurrLine = sCurrLine.Replace(TableUtility.TABLENAME, SelectedMTable.TableName) ' NewTableFileContent.Add(sCurrLine) 'Next 'File.WriteAllLines(Path.ChangeExtension(Path.GetDirectoryName(IniFile.m_sTablesRoot) & "\" & CURRMTABLE_FILE, ".lua"), NewTableFileContent, Text.Encoding.UTF8) End Sub #End Region ' SetActiveTableCommand #Region "ResetSearchCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ResetSearchCommand As ICommand Get If m_cmdResetSearch Is Nothing Then m_cmdResetSearch = New Command(AddressOf ResetSearch) End If Return m_cmdResetSearch End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub ResetSearch() TextToSearch = String.Empty End Sub Public Sub ResetSearchedRow() ' analizzo tabella associazioni For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For AssociationIndex = 0 To m_TablesList(TableIndex).AssociationList.Count - 1 Dim CurrAssociation As MTableAssociationGridBoxItem = m_TablesList(TableIndex).AssociationList(AssociationIndex) CurrAssociation.IsValidForSearch = False Next Exit For End If Next ' analizzo tabella lavorazioni ordinate For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For MachineIndex = 0 To m_TablesList(TableIndex).ActiveMachinesList.Count - 1 For MachiningIndex = 0 To m_TablesList(TableIndex).ActiveMachinesList(MachineIndex).MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = m_TablesList(TableIndex).ActiveMachinesList(MachineIndex).MachiningList(MachiningIndex) CurrMachining.IsValidForSearch = False Next Next Exit For End If Next End Sub #End Region ' ResetSearchCommand #Region "SearchPreviousCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SearchPreviousCommand As ICommand Get If m_cmdSearchPrevious Is Nothing Then m_cmdSearchPrevious = New Command(AddressOf SearchPrevious) End If Return m_cmdSearchPrevious End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SearchPrevious() If String.IsNullOrWhiteSpace(m_TextToSearch) Then Return End If Dim bFound As Boolean = False Dim LastSearchedRow As MTableAssociationGridBoxItem = Nothing For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For AssociationIndex = 0 To m_TablesList(TableIndex).AssociationList.Count - 1 Dim CurrAssociation As MTableAssociationGridBoxItem = m_TablesList(TableIndex).AssociationList(AssociationIndex) If CurrAssociation.IsSelected Then If Not IsNothing(LastSearchedRow) Then LastSearchedRow.IsSelected = True End If Return End If If CurrAssociation.IsValidForSearch Then LastSearchedRow = CurrAssociation End If Next Exit For End If Next End Sub #End Region ' SearchPreviousCommand #Region "SearchNextCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SearchNextCommand As ICommand Get If m_cmdSearchNext Is Nothing Then m_cmdSearchNext = New Command(AddressOf SearchNext) End If Return m_cmdSearchNext End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SearchNext() If String.IsNullOrWhiteSpace(m_TextToSearch) Then Return End If Dim bFound As Boolean = False For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then For AssociationIndex = 0 To m_TablesList(TableIndex).AssociationList.Count - 1 Dim CurrAssociation As MTableAssociationGridBoxItem = m_TablesList(TableIndex).AssociationList(AssociationIndex) If bFound AndAlso CurrAssociation.IsValidForSearch Then CurrAssociation.IsSelected = True Return End If If CurrAssociation.IsSelected Then bFound = True End If Next Exit For End If Next End Sub #End Region ' SearchNextCommand #Region "FocusSearchCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property FocusSearchCommand As ICommand Get If m_cmdFocusSearch Is Nothing Then m_cmdFocusSearch = New Command(AddressOf FocusSearch) End If Return m_cmdFocusSearch End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub FocusSearch() FocusSearchTextState = Not m_FocusSearchTextState End Sub #End Region ' FocusSearchCommand #Region "AddMachCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property AddMachCommand As ICommand Get If m_cmdAddMach Is Nothing Then m_cmdAddMach = New Command(AddressOf AddMach) End If Return m_cmdAddMach End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub AddMach(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return SelectedMTable.SharedMachIndex += 1 SelectedMTable.ActiveMachinesList.Add(New MTableMachineListBoxItem(String.Empty, False, False, SelectedMTable.SharedMachIndex)) SelectedMTable.MachIdList.Add(SelectedMTable.SharedMachIndex) End Sub #End Region ' AddMachCommand #Region "RemoveMachCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RemoveMachCommand As ICommand Get If m_cmdRemoveMach Is Nothing Then m_cmdRemoveMach = New Command(AddressOf RemoveMach) End If Return m_cmdRemoveMach End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub RemoveMach(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If Not IsNothing(SelectedMTable) AndAlso SelectedMTable.ActiveMachinesList.Count > 1 Then ' Chiedo conferma cancellazione associazione macchina If MessageBox.Show(EgtMsg(MSG_DOORSERRORS + 12), EgtMsg(MSG_DOORSERRORS + 11), MessageBoxButton.YesNo, MessageBoxImage.Question) <> MessageBoxResult.Yes Then Return End If SelectedMTable.ActiveMachinesList.RemoveAt(SelectedMTable.SharedMachIndex - 1) SelectedMTable.MachIdList.RemoveAt(SelectedMTable.SharedMachIndex - 1) SelectedMTable.SharedMachIndex -= 1 End If End Sub #End Region ' RemoveMachCommand #Region "AddRowCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property AddRowCommand As ICommand Get If m_cmdAddRow Is Nothing Then m_cmdAddRow = New Command(AddressOf AddRow) End If Return m_cmdAddRow End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub AddRow(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If Not IsNothing(SelectedMTable) AndAlso Not IsNothing(SelectedMTable.SelectedAssociation) Then Dim SelectedIndex As Integer = SelectedMTable.AssociationList.IndexOf(SelectedMTable.SelectedAssociation) Dim NewEmptyRow As MTableAssociationGridBoxItem = New MTableAssociationGridBoxItem(False, String.Empty, 1, 0, String.Empty, Nothing, String.Empty, Nothing, String.Empty, Nothing, String.Empty, SelectedMTable.ActiveMachinesList, SelectedMTable.AssociationList) SelectedMTable.AssociationList.Insert(SelectedIndex + 1, NewEmptyRow) SelectedMTable.SelectedAssociation = NewEmptyRow SelectedMTable.NotifyPropertyChanged("SelectedAssociation") End If End Sub #End Region ' AddRowCommand #Region "RemoveRowCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RemoveRowCommand As ICommand Get If m_cmdRemoveRow Is Nothing Then m_cmdRemoveRow = New Command(AddressOf RemoveRow) End If Return m_cmdRemoveRow End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub RemoveRow(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If Not IsNothing(SelectedMTable) AndAlso SelectedMTable.AssociationList.Count > 1 Then If IsNothing(SelectedMTable.SelectedAssociation) Then Return ' Chiedo conferma cancellazione riga di associazione If MessageBox.Show(EgtMsg(MSG_DOORSERRORS + 10), EgtMsg(MSG_DOORSERRORS + 11), MessageBoxButton.YesNo, MessageBoxImage.Question) <> MessageBoxResult.Yes Then Return End If Dim SelectedIndex As Integer = SelectedMTable.AssociationList.IndexOf(SelectedMTable.SelectedAssociation) ' rimuovo Item associati dalla lisa lavorazioni ordinata RemoveMachItem(SelectedIndex, SelectedMTable, SelectedMTable.AssociationList(SelectedIndex).RefMachItem) RemoveMachItem(SelectedIndex, SelectedMTable, SelectedMTable.AssociationList(SelectedIndex).RefMachUpItem) RemoveMachItem(SelectedIndex, SelectedMTable, SelectedMTable.AssociationList(SelectedIndex).RefMachDwItem) SelectedMTable.AssociationList.RemoveAt(SelectedIndex) If Not SelectedIndex < SelectedMTable.AssociationList.Count Then SelectedIndex = SelectedMTable.AssociationList.Count - 1 End If SelectedMTable.SelectedAssociation = SelectedMTable.AssociationList(SelectedIndex) SelectedMTable.NotifyPropertyChanged("SelectedAssociation") End If End Sub Private Sub RemoveMachItem(SelectedIndex As Integer, SelectedMTable As MTableListBoxItem, RefMachItem As MTableMachiningGridBoxItem) ' Se ha un Item a cui si riferisce nella lista ordinata delle lavorazioni If Not IsNothing(RefMachItem) Then ' verifico se viene usato anche da altre associazioni For AssIndex = 0 To SelectedMTable.AssociationList.Count - 1 If SelectedIndex <> AssIndex And (SelectedMTable.AssociationList(AssIndex).RefMachItem Is RefMachItem Or SelectedMTable.AssociationList(AssIndex).RefMachUpItem Is RefMachItem Or SelectedMTable.AssociationList(AssIndex).RefMachDwItem Is RefMachItem) Then Return End If Next For MachIndex = 0 To SelectedMTable.ActiveMachinesList.Count - 1 If SelectedMTable.ActiveMachinesList(MachIndex).MachId = SelectedMTable.AssociationList(SelectedIndex).MachId Then MTableMachiningGridBoxItem.Remove(RefMachItem, SelectedMTable.ActiveMachinesList(MachIndex).MachiningList) End If Next End If End Sub #End Region ' RemoveRowCommand #Region "MoveRowUpCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property MoveRowUpCommand As ICommand Get If m_cmdMoveRowUp Is Nothing Then m_cmdMoveRowUp = New Command(AddressOf MoveRowUp) End If Return m_cmdMoveRowUp End Get End Property ''' ''' Right table Movement ''' Public Sub MoveRowUp(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return If m_FocusedTable = Tables.LEFTTABLE Then LeftTableMoveRowUp(SelectedMTable) Else RightTableMoveRowUp(SelectedMTable) End If End Sub ' Left table Movement Public Sub LeftTableMoveRowUp(SelectedMTable As MTableListBoxItem) Dim SelectedIndex As Integer = SelectedMTable.AssociationList.IndexOf(SelectedMTable.SelectedAssociation) If SelectedIndex >= 1 Then SelectedMTable.AssociationList.Move(SelectedIndex, SelectedIndex - 1) End If End Sub Public Sub RightTableMoveRowUp(SelectedMTable As MTableListBoxItem) SelectedMTable.m_IsMachiningOrdModified = True MoveRow(SelectedMTable, True) End Sub Private Sub MoveRow(SelectedMTable As MTableListBoxItem, bMoveUp As Boolean) Dim bIsSingleSelected As Boolean = False Dim bIsGroupSelected As Boolean = False Dim nLastItemIndex As Integer = -1 For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then Dim bFirstSelItem As Boolean = True For MachiningIndex = 0 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If CurrMachining.IsSelected Then If bIsSingleSelected Then bIsGroupSelected = True Exit For Else bIsSingleSelected = True nLastItemIndex = CurrMachining.GroupId If MachiningIndex > 0 AndAlso SelectedMTable.SelMachine.MachiningList(MachiningIndex - 1).GroupId = CurrMachining.GroupId Then Exit For ElseIf MachiningIndex = SelectedMTable.SelMachine.MachiningList.Count - 1 Then bIsGroupSelected = True ElseIf SelectedMTable.SelMachine.MachiningList(MachiningIndex + 1).GroupId <> CurrMachining.GroupId Then bIsGroupSelected = True Exit For End If End If Else If bIsGroupSelected Then Exit For End If End If Next End If Next For TableIndex = 0 To m_TablesList.Count - 1 If m_TablesList(TableIndex).IsSelected Then If bMoveUp Then MoveUp(TableIndex, bIsGroupSelected, SelectedMTable) Else MoveDown(TableIndex, bIsGroupSelected, SelectedMTable) End If Exit For End If Next End Sub Private Function CalcPrevGroup(SelectedIndex As Integer, SelMachining As MTableMachiningGridBoxItem, bIsGroupSelected As Boolean, SelectedMTable As MTableListBoxItem) As Integer Dim PositionIndex As Integer = 0 ' cerco il primo precedente non dello stesso gruppo Dim nPrevGroupIndex As Integer = -1 For MachiningIndex = SelectedIndex - 1 To 0 Step -1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If nPrevGroupIndex = -1 Then If CurrMachining.GroupId <> SelMachining.GroupId Then nPrevGroupIndex = CurrMachining.GroupId PositionIndex += 1 If bIsGroupSelected Then 'aumento di uno l'indice di gruppo del gruppo precedente CurrMachining.GroupId += 1 End If End If Else If CurrMachining.GroupId = nPrevGroupIndex Then PositionIndex += 1 If bIsGroupSelected Then 'aumento di uno l'indice di gruppo del gruppo precedente CurrMachining.GroupId += 1 End If Else Exit For End If End If Next Return PositionIndex End Function Private Function CalcNextGroup(SelectedIndex As Integer, SelMachining As MTableMachiningGridBoxItem, bIsGroupSelected As Boolean, SelectedMTable As MTableListBoxItem) As Integer Dim PositionIndex As Integer = 0 ' cerco il primo successivo non dello stesso gruppo Dim nNextGroupIndex As Integer = -1 For MachiningIndex = SelectedIndex + 1 To SelectedMTable.SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If nNextGroupIndex = -1 Then If CurrMachining.GroupId <> SelMachining.GroupId Then nNextGroupIndex = CurrMachining.GroupId PositionIndex += 1 If bIsGroupSelected Then 'aumento di uno l'indice di gruppo del gruppo precedente CurrMachining.GroupId -= 1 End If End If Else If CurrMachining.GroupId = nNextGroupIndex Then PositionIndex += 1 If bIsGroupSelected Then 'aumento di uno l'indice di gruppo del gruppo precedente CurrMachining.GroupId -= 1 End If Else Exit For End If End If Next Return PositionIndex End Function Private Sub MoveUp(TableIndex As Integer, bIsGroupSelected As Boolean, SelectedMTable As MTableListBoxItem) Dim nFirstMovedIndex As Integer = -1 Dim nLastMovedIndex As Integer = -1 Dim bExitFromGroup As Boolean = False Dim nDelta As Integer = -1 For MachiningIndex = 0 To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) ' se singola lavorazione che esce dal gruppo, incremento tutte le successive If bExitFromGroup Then CurrMachining.GroupId += 1 End If If CurrMachining.IsSelected And Not bExitFromGroup Then ' calcolo indice item corrente Dim SelectedIndex As Integer = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) If SelectedIndex >= 1 AndAlso SelectedMTable.SelMachine.MachiningList(SelectedIndex - 1).GroupId > 0 Then If bIsGroupSelected Then ' Calcolo dimensione gruppo precedente per sapere di quante posizioni spostarlo nDelta = If(nDelta = -1, CalcPrevGroup(SelectedIndex, CurrMachining, bIsGroupSelected, SelectedMTable), nDelta) ' diminuisco di uno l'indice di quello selezionato CurrMachining.GroupId -= 1 Else ' assegno spostamento se singola lavorazione selezionata nDelta = 1 ' se il precedente ha gruppo diverso If SelectedMTable.SelMachine.MachiningList(SelectedIndex - 1).GroupId <> CurrMachining.GroupId Then bExitFromGroup = True End If End If If nFirstMovedIndex = -1 Then nFirstMovedIndex = SelectedIndex nLastMovedIndex = SelectedIndex Else nLastMovedIndex = SelectedIndex End If If Not bExitFromGroup Then SelectedMTable.SelMachine.MachiningList.Move(SelectedIndex, SelectedIndex - nDelta) ElseIf SelectedIndex = 0 And Not bIsGroupSelected Then nFirstMovedIndex = SelectedIndex bExitFromGroup = True Else Return End If End If Next ' Aggiorno visualizzazione indici spostati (per converter che li nasconde) For Index = nFirstMovedIndex - nDelta To nLastMovedIndex Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(Index) CurrMachining.NotifyPropertyChanged("GroupId") CurrMachining.NotifyPropertyChanged("PropertyPar") Next End Sub Private Sub MoveDown(TableIndex As Integer, bIsGroupSelected As Boolean, SelectedMTable As MTableListBoxItem) Dim nFirstMovedIndex As Integer = -1 Dim nLastMovedIndex As Integer = -1 Dim bExitFromGroup As Boolean = False Dim nDelta As Integer = -1 For MachiningIndex = m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 To 0 Step -1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If CurrMachining.IsSelected And Not bExitFromGroup Then ' calcolo indice item corrente Dim SelectedIndex As Integer = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) If SelectedIndex < SelectedMTable.SelMachine.MachiningList.Count - 1 AndAlso SelectedMTable.SelMachine.MachiningList(SelectedIndex + 1).GroupId > 0 Then If bIsGroupSelected Then ' Calcolo dimensione gruppo precedente per sapere di quante posizioni spostarlo nDelta = If(nDelta = -1, CalcNextGroup(SelectedIndex, CurrMachining, bIsGroupSelected, SelectedMTable), nDelta) ' diminuisco di uno l'indice di quello selezionato CurrMachining.GroupId += 1 Else ' assegno spostamento se singola lavorazione selezionata nDelta = 1 ' se il successivo ha gruppo diverso If SelectedMTable.SelMachine.MachiningList(SelectedIndex + 1).GroupId <> CurrMachining.GroupId Then bExitFromGroup = True End If End If If nFirstMovedIndex = -1 Then nFirstMovedIndex = SelectedIndex nLastMovedIndex = SelectedIndex Else nLastMovedIndex = SelectedIndex End If If Not bExitFromGroup Then SelectedMTable.SelMachine.MachiningList.Move(SelectedIndex, SelectedIndex + nDelta) ElseIf SelectedIndex = SelectedMTable.SelMachine.MachiningList.Count - 1 And Not bIsGroupSelected Then nFirstMovedIndex = SelectedIndex bExitFromGroup = True Exit For Else Return End If End If Next ' se singola lavorazione che esce dal gruppo, incremento tutte le successive If bExitFromGroup Then For MachiningIndex = nFirstMovedIndex To m_TablesList(TableIndex).SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) CurrMachining.GroupId += 1 Next End If ' Aggiorno visualizzazione indici spostati (per converter che li nasconde) For Index = nFirstMovedIndex + nDelta To nLastMovedIndex Step -1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(Index) CurrMachining.NotifyPropertyChanged("GroupId") CurrMachining.NotifyPropertyChanged("PropertyPar") Next End Sub #End Region ' MoveRowUpCommand #Region "MoveRowDownCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property MoveRowDownCommand As ICommand Get If m_cmdMoveRowDown Is Nothing Then m_cmdMoveRowDown = New Command(AddressOf MoveRowDown) End If Return m_cmdMoveRowDown End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub MoveRowDown(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return If m_FocusedTable = Tables.LEFTTABLE Then LeftTableMoveRowDown(SelectedMTable) Else RigthTableMoveRowDown(SelectedMTable) End If End Sub ' Spostamento sulla tabella delle associazioni Public Sub LeftTableMoveRowDown(SelectedMTable As MTableListBoxItem) Dim SelectedIndex As Integer = SelectedMTable.AssociationList.IndexOf(SelectedMTable.SelectedAssociation) If SelectedIndex < SelectedMTable.AssociationList.Count - 1 Then SelectedMTable.AssociationList.Move(SelectedIndex, SelectedIndex + 1) End If End Sub ' Spostamento sulla tabella ordine lavorazioni Public Sub RigthTableMoveRowDown(SelectedMTable As MTableListBoxItem) SelectedMTable.m_IsMachiningOrdModified = True MoveRow(SelectedMTable, False) End Sub #End Region ' MoveRowDownCommand #Region "GroupCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property GroupCommand As ICommand Get If m_cmdGroup Is Nothing Then m_cmdGroup = New Command(AddressOf Group) End If Return m_cmdGroup End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Group(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return SelectedMTable.m_IsMachiningOrdModified = True Dim bGroupStarted As Boolean = False Dim bGroupEnded As Boolean = False Dim nGroupIndex As Integer = 0 Dim nFirstGroupIndex As Integer = -1 Dim nLastGroupIndex As Integer = -1 For MachIndex = 0 To SelectedMTable.SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachIndex) If CurrMachining.IsSelected Then If CurrMachining.GroupId = 0 Then ' Bisogna posizionare le lavorazioni prima di raggrupparle Return End If If bGroupStarted Then nLastGroupIndex = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) CurrMachining.GroupId = nGroupIndex Else nFirstGroupIndex = CurrMachining.GroupId nGroupIndex = CurrMachining.GroupId bGroupStarted = True End If Else If bGroupStarted And Not bGroupEnded Then bGroupEnded = True nLastGroupIndex = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) - 1 nGroupIndex = CurrMachining.GroupId - nGroupIndex - 1 End If End If If bGroupEnded Then CurrMachining.GroupId = CurrMachining.GroupId - nGroupIndex End If Next ' se solo uno dei due gruppi ha una proprietà la tengo, altrimenti la cancello Dim FirstGroupItem As MTableMachiningGridBoxItem = Nothing Dim LastGroupItem As MTableMachiningGridBoxItem = Nothing For MachiningIndex = 0 To SelectedMTable.SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId = nFirstGroupIndex Then FirstGroupItem = CurrMachining Exit For End If Next LastGroupItem = SelectedMTable.SelMachine.MachiningList(nLastGroupIndex) If FirstGroupItem.PropertyPar = String.Empty Then FirstGroupItem.PropertyPar = LastGroupItem.PropertyPar ElseIf LastGroupItem.PropertyPar = String.Empty Or FirstGroupItem.PropertyPar = LastGroupItem.PropertyPar Then FirstGroupItem.PropertyPar = FirstGroupItem.PropertyPar Else FirstGroupItem.PropertyPar = String.Empty End If For MachiningIndex = 0 To SelectedMTable.SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachiningIndex) If CurrMachining.GroupId = nFirstGroupIndex Then CurrMachining.NotifyPropertyChanged("PropertyPar") End If Next End Sub #End Region ' GroupCommand #Region "PositionCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property PositionCommand As ICommand Get If m_cmdPosition Is Nothing Then m_cmdPosition = New Command(AddressOf Position) End If Return m_cmdPosition End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Position(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If IsNothing(SelectedMTable) Then Return SelectedMTable.m_IsMachiningOrdModified = True Dim MachToMove As MTableMachiningGridBoxItem = Nothing Dim MachRef As MTableMachiningGridBoxItem = Nothing Dim OldIndex As Integer = -1 Dim NewIndex As Integer = -1 Dim bMoved As Boolean = False For MachIndex = 0 To SelectedMTable.SelMachine.MachiningList.Count - 1 Dim CurrMachining As MTableMachiningGridBoxItem = SelectedMTable.SelMachine.MachiningList(MachIndex) If Not bMoved Then If NewIndex > 0 Then If CurrMachining.GroupId <> MachRef.GroupId Then SelectedMTable.SelMachine.MachiningList.Move(OldIndex, NewIndex) MachToMove.GroupId = CurrMachining.GroupId CurrMachining.GroupId += 1 bMoved = True End If End If If CurrMachining.IsSelected Then If OldIndex >= 0 Then NewIndex = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) MachRef = CurrMachining CurrMachining.IsSelected = False End If If CurrMachining.GroupId = 0 Then MachToMove = CurrMachining OldIndex = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) ElseIf NewIndex = 0 Then NewIndex = SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) End If End If If NewIndex > 0 And Not bMoved Then If SelectedMTable.SelMachine.MachiningList.IndexOf(CurrMachining) = SelectedMTable.SelMachine.MachiningList.Count - 1 Then SelectedMTable.SelMachine.MachiningList.Move(OldIndex, NewIndex) MachToMove.GroupId = CurrMachining.GroupId + 1 bMoved = True End If End If Else CurrMachining.GroupId += 1 End If Next ' Rivaluto bottoni che dipendono da selezione ManageMachiningButtons(False, False, False, True) End Sub #End Region ' PositionCommand #Region "CloseMTableWindowCommand" ''' ''' Returns a command that remove the current selected machining. ''' Public ReadOnly Property CloseMTableWindowCommand() As ICommand Get If m_cmdCloseMTableWindow Is Nothing Then m_cmdCloseMTableWindow = New Command(AddressOf CloseMTableWindow) End If Return m_cmdCloseMTableWindow End Get End Property ''' ''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand. ''' Public Sub CloseMTableWindow(param As Object) Dim SelectedMTable As MTableListBoxItem = DirectCast(param, MTableListBoxItem) If Not IsNothing(SelectedMTable) AndAlso (SelectedMTable.IsModified() OrElse String.IsNullOrEmpty(SelectedMTable.m_TableNamePath)) Then ' chiedo se salvare la tabella corrente prima di passare alla successiva If MessageBox.Show(EgtMsg(MSG_DOORS + 7), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then SaveTable(SelectedMTable) End If End If CloseWindow() End Sub Public Sub CloseWindow() ' ripristino la macchina selezionata all'apertura della finestra EgtSetCurrMachine(m_sPreviousActiveMachine) ' Chiusura finestra MTableListBoxItem.m_delSaveMTable = Nothing MTableMachineListBoxItem.m_delCloseMTableWnd = Nothing MTableAssociationGridBoxItem.m_delCloseMTableWnd = Nothing For Each Window In Application.Current.Windows If TypeOf Window Is MTableDbV Then Dim MTableDbView As MTableDbV = DirectCast(Window, MTableDbV) MTableDbView.DataContext = Nothing MTableDbView.Close() End If Next End Sub #End Region ' CloseMTableWindowCommand #End Region End Class Public Class GroupConverter Implements IMultiValueConverter Public Function Convert(value() As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IMultiValueConverter.Convert Dim CurrItem As MTableMachiningGridBoxItem = DirectCast(value(1), MTableMachiningGridBoxItem) Dim CurrItemIndex As Integer = -1 For TableIndex = 0 To MTableDbVM.refMTableDbVM.TablesList.Count - 1 If MTableDbVM.refMTableDbVM.TablesList(TableIndex).IsSelected Then CurrItemIndex = MTableDbVM.refMTableDbVM.TablesList(TableIndex).SelMachine.MachiningList.IndexOf(CurrItem) If CurrItem.GroupId = 0 Then Return CurrItem.GroupId.ToString End If If CurrItemIndex >= 1 Then If MTableDbVM.refMTableDbVM.TablesList(TableIndex).SelMachine.MachiningList(CurrItemIndex - 1).GroupId = CurrItem.GroupId Then Return String.Empty Else Return CurrItem.GroupId.ToString End If Else Return CurrItem.GroupId.ToString End If End If Next Return CurrItem.GroupId.ToString End Function Public Function ConvertBack(value As Object, targetType() As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack Throw New NotImplementedException End Function End Class Public Class PropertyConverter Implements IMultiValueConverter Public Function Convert(value() As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IMultiValueConverter.Convert Dim CurrItem As MTableMachiningGridBoxItem = DirectCast(value(1), MTableMachiningGridBoxItem) Dim CurrItemIndex As Integer = -1 For TableIndex = 0 To MTableDbVM.refMTableDbVM.TablesList.Count - 1 If MTableDbVM.refMTableDbVM.TablesList(TableIndex).IsSelected Then CurrItemIndex = MTableDbVM.refMTableDbVM.TablesList(TableIndex).SelMachine.MachiningList.IndexOf(CurrItem) If CurrItemIndex >= 1 Then If CurrItem.PropertyPar = String.Empty Then Return String.Empty End If If MTableDbVM.refMTableDbVM.TablesList(TableIndex).SelMachine.MachiningList(CurrItemIndex - 1).GroupId = CurrItem.GroupId Then Return String.Empty Else Return CurrItem.PropertyPar End If Else Return CurrItem.PropertyPar End If End If Next Return CurrItem.PropertyPar End Function Public Function ConvertBack(value As Object, targetType() As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack Throw New NotImplementedException End Function End Class