Imports System.Collections.ObjectModel Imports EgtUILib Imports EgtWPFLib5 Public Class CurrMachWindowVM Inherits VMBase #Region "FIELDS & PROPERTIES" Private m_CurrSawingList As New List(Of String) Public Property CurrSawingList As List(Of String) Get Return m_CurrSawingList End Get Set(value As List(Of String)) m_CurrSawingList = value End Set End Property Private m_SelCurrSawing As String = String.Empty Public Property SelCurrSawing As String Get Return m_SelCurrSawing End Get Set(value As String) If value <> m_SelCurrSawing Then m_SelCurrSawing = value End If CurrentMachine.sCurrSawing = m_SelCurrSawing End Set End Property Private m_AuxMachTypeList As New List(Of StringIdCmBx) Public Property AuxMachTypeList As List(Of StringIdCmBx) Get Return m_AuxMachTypeList End Get Set(value As List(Of StringIdCmBx)) m_AuxMachTypeList = value End Set End Property Private m_SelAuxMachType As StringIdCmBx Public Property SelAuxMachType As StringIdCmBx Get Return m_SelAuxMachType End Get Set(value As StringIdCmBx) If value IsNot m_SelAuxMachType Then m_SelAuxMachType = value Select Case m_SelAuxMachType.nId Case 0 CurrentMachine.sCurrDrilling = String.Empty CurrentMachine.sCurrMilling = String.Empty CurrDrilling_Visibility = Visibility.Collapsed CurrMilling_Visibility = Visibility.Collapsed Case 1 If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then SelCurrDrilling = CurrentMachine.sCurrDrilling End If CurrentMachine.sCurrMilling = String.Empty CurrDrilling_Visibility = Visibility.Visible CurrMilling_Visibility = Visibility.Collapsed Case 2 If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then SelCurrMilling = CurrentMachine.sCurrMilling End If CurrentMachine.sCurrDrilling = String.Empty CurrDrilling_Visibility = Visibility.Collapsed CurrMilling_Visibility = Visibility.Visible Case 3 If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrDrilling) Then SelCurrDrilling = CurrentMachine.sCurrDrilling End If If Not String.IsNullOrWhiteSpace(CurrentMachine.sCurrMilling) Then SelCurrMilling = CurrentMachine.sCurrMilling End If CurrDrilling_Visibility = Visibility.Visible CurrMilling_Visibility = Visibility.Visible End Select End If End Set End Property Private m_AuxMachType_Visibility As Visibility Public Property AuxMachType_Visibility As Visibility Get Return m_AuxMachType_Visibility End Get Set(value As Visibility) m_AuxMachType_Visibility = value NotifyPropertyChanged("AuxiliaryMach_Visibility") End Set End Property Private m_CurrDrillingList As New List(Of String) Public Property CurrDrillingList As List(Of String) Get Return m_CurrDrillingList End Get Set(value As List(Of String)) m_CurrDrillingList = value End Set End Property Private m_SelCurrDrilling As String Public Property SelCurrDrilling As String Get Return m_SelCurrDrilling End Get Set(value As String) If value <> m_SelCurrDrilling Then m_SelCurrDrilling = value CurrentMachine.sCurrDrilling = m_SelCurrDrilling End If End Set End Property Private m_CurrDrilling_Visibility As Visibility Public Property CurrDrilling_Visibility As Visibility Get Return m_CurrDrilling_Visibility End Get Set(value As Visibility) m_CurrDrilling_Visibility = value NotifyPropertyChanged("CurrDrilling_Visibility") End Set End Property Private m_CurrMillingList As New List(Of String) Public Property CurrMillingList As List(Of String) Get Return m_CurrMillingList End Get Set(value As List(Of String)) m_CurrMillingList = value End Set End Property Private m_SelCurrMilling As String Public Property SelCurrMilling As String Get Return m_SelCurrMilling End Get Set(value As String) If value <> m_SelCurrMilling Then m_SelCurrMilling = value CurrentMachine.sCurrMilling = m_SelCurrMilling End If End Set End Property Private m_CurrMilling_Visibility As Visibility Public Property CurrMilling_Visibility As Visibility Get Return m_CurrMilling_Visibility End Get Set(value As Visibility) m_CurrMilling_Visibility = value NotifyPropertyChanged("CurrMilling_Visibility") End Set End Property Private m_AvailableSawList As New List(Of String) Private m_AvailableMillList As New List(Of String) Private m_AvailableDrillList As New List(Of String) #Region "Messages" Public ReadOnly Property TitleMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 9) End Get End Property Public ReadOnly Property CurrSawingMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 1) End Get End Property Public ReadOnly Property AuxMachTypeMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 2) End Get End Property Public ReadOnly Property CurrDrillingMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 3) End Get End Property Public ReadOnly Property CurrMillingMsg As String Get Return EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 4) End Get End Property Public ReadOnly Property OkMsg As String Get Return "Ok" End Get End Property Public ReadOnly Property ExitMsg As String Get Return "Exit" End Get End Property #End Region ' Messages #End Region ' FIELDS & PROPERTIES #Region "CONSTRUCTOR" Sub New() InitializeMachiningLists() End Sub #End Region ' CONSTRUCTOR #Region "METHODS" Private Sub InitializeMachiningLists() ' Creo liste utensili disponibili da attrezzaggio CreateAvailableToolList() ' Creo lista lavorazioni di lama CreateMachiningList(MCH_MY.SAWING, m_AvailableSawList, m_CurrSawingList) ' Verifico la configurazione della macchina per creare i combobox Select Case CurrentMachine.MountedToolConfig Case CurrentMachine.MountedToolConfigs.SAW AuxMachType_Visibility = Visibility.Collapsed Case CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL, CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER, CurrentMachine.MountedToolConfigs.TOOLCHANGER 'Creo lista lavorazioni foretto e fresa If CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL Then CreateMachiningList(MCH_MY.DRILLING, m_AvailableDrillList, m_CurrDrillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_CurrDrillingList.Count = 0 Then CurrentMachine.sCurrDrilling = String.Empty End If CreateMachiningList(MCH_MY.MILLING, m_AvailableMillList, m_CurrMillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_CurrMillingList.Count = 0 Then CurrentMachine.sCurrMilling = String.Empty End If ElseIf CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER Or CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.TOOLCHANGER Then CreateMachiningList(MCH_MY.DRILLING, m_AvailableDrillList, m_CurrDrillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_CurrDrillingList.Count = 0 Then CurrentMachine.sCurrDrilling = String.Empty End If CreateMachiningList(MCH_MY.MILLING, m_AvailableMillList, m_CurrMillingList) ' Se la lista è vuota cancello la lavorazione corrente di questo tipo If m_CurrMillingList.Count = 0 Then CurrentMachine.sCurrMilling = String.Empty End If End If ' Definizione di due righe della tabella con la giusta altezza AuxMachType_Visibility = Visibility.Visible End Select If m_CurrSawingList.Count > 0 Then SelCurrSawing = m_CurrSawingList(0) Else CurrentMachine.sCurrSawing = String.Empty End If If Not CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAW Then If CurrentMachine.bDrilling Then m_AuxMachTypeList.Add(New StringIdCmBx(1, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 6))) If CurrentMachine.bMilling Then m_AuxMachTypeList.Add(New StringIdCmBx(2, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 7))) If CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER Or CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.TOOLCHANGER Then m_AuxMachTypeList.Add(New StringIdCmBx(3, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 8))) End If End If Else If CurrentMachine.bMilling Then m_AuxMachTypeList.Add(New StringIdCmBx(2, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 7))) End If End If ' Aggiungo nessuna come ultimo elemento della lista m_AuxMachTypeList.Add(New StringIdCmBx(0, EgtMsg(MSG_CHOOSEMACHININGPAGEUC + 5))) If CurrentMachine.sCurrDrilling <> String.Empty Then If CurrentMachine.sCurrMilling <> String.Empty Then SelAuxMachType = StringIdCmBx.FromIdToStringIdCmBx(3, m_AuxMachTypeList) Else SelAuxMachType = StringIdCmBx.FromIdToStringIdCmBx(1, m_AuxMachTypeList) End If Else If CurrentMachine.sCurrMilling <> String.Empty Then SelAuxMachType = StringIdCmBx.FromIdToStringIdCmBx(2, m_AuxMachTypeList) Else SelAuxMachType = StringIdCmBx.FromIdToStringIdCmBx(0, m_AuxMachTypeList) End If End If End If End Sub Private Sub CreateAvailableToolList() ' recupero il gruppo del setup Dim nSetUpGroup As Integer = EgtGetCurrSetup() ' leggo l'attrezzaggio del progetto Dim sPosition As String = String.Empty Dim IniIndex As Integer = 1 ' recupero stringa di ogni posizione While EgtGetInfo(nSetUpGroup, K_POS & IniIndex, sPosition) ReadPositionString(IniIndex, sPosition, True) IniIndex += 1 End While End Sub ' Funzione che dati l'indice della posizione e la sua stringa di attrezzaggio, carica l'attrezzaggio descritto Private Sub ReadPositionString(nIndex As Integer, sPosition As String, bOriginal As Boolean) Dim sToolList As New List(Of String) ' la spezzo sui ; Dim sItems() As String = sPosition.Split(";".ToCharArray) ' se ci sono almeno tre elementi sono sicuro che ci sia almeno un'uscita attrezzata If sItems.Count >= 3 Then ' separo le uscite divise dalla , Dim sExitToolAssList() As String = sItems(2).Split(",".ToCharArray) sToolList.Clear() ' creo le liste di uscite e utensili attrezzati ricavati For AssIndex = 0 To sExitToolAssList.Count() - 1 Dim sExitToolAssItem() As String = sExitToolAssList(AssIndex).Split("/".ToCharArray) If sExitToolAssItem.Count > 1 Then sToolList.Add(sExitToolAssItem(1)) End If Next ' verifico se gli utensili esistono ancora nel db For ToolIndex = sToolList.Count - 1 To 0 Step -1 Dim sSearchedTool As String = String.Empty EgtTdbGetToolFromUUID(sToolList(ToolIndex), sSearchedTool) ' Se non trovo l'utensile lo elimino; l'attrezzaggio è sbagliato If String.IsNullOrWhiteSpace(sSearchedTool) Then sToolList.RemoveAt(ToolIndex) ' Impossibile trovare l'utensile xxx nel DB utensili 'MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 3) & " " & sSearchedTool & " " & EgtMsg(MSG_SETUPERRORS + 4), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Error) ' Altrimenti lo inserisco nelle liste a seconda del tipo Else EgtTdbSetCurrTool(sSearchedTool) Dim ToolType As Integer = 0 EgtTdbGetCurrToolParam(MCH_TP.TYPE, ToolType) If (ToolType And MCH_TF.DRILLBIT) <> 0 Then m_AvailableDrillList.Add(sToolList(ToolIndex)) ElseIf (ToolType And MCH_TF.SAWBLADE) <> 0 Then m_AvailableSawList.Add(sToolList(ToolIndex)) ElseIf (ToolType And MCH_TF.MILL) <> 0 Then m_AvailableMillList.Add(sToolList(ToolIndex)) End If End If Next End If End Sub Private Sub CreateMachiningList(MachiningType As Integer, AvailableToolList As List(Of String), MachiningList As List(Of String)) For ToolIndex = 0 To AvailableToolList.Count - 1 ' Recupero UUID dell'utensile Dim sTuuid As String = AvailableToolList(ToolIndex) ' Cerco tutte le lavorazioni che utilizzano l'utensile corrente e le aggiungo alla lista Dim MachiningName As String = String.Empty Dim bOk As Boolean = EgtMdbGetFirstMachining(MachiningType, MachiningName) While bOk EgtMdbSetCurrMachining(MachiningName) Dim sMachTuuid As String = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sMachTuuid) If sMachTuuid = sTuuid AndAlso VerifyMatThickCompatibility() Then MachiningList.Add(MachiningName) End If bOk = EgtMdbGetNextMachining(MachiningType, MachiningName) End While Next ' Aggiungo lavorazione nulla MachiningList.Add(String.Empty) End Sub ' Funzione che data la stringa di materiali e spessori della lavorazione, e i dati del grezzo corrente, restituisce se la lavorazione è valida oppure no Friend Shared Function VerifyMatThickCompatibility() As Boolean If Not IsNothing(EstCalc.GetMaterialName) Then Dim SysNotes As String = String.Empty EgtMdbGetCurrMachiningParam(MCH_MP.SYSNOTES, SysNotes) If SysNotes <> String.Empty Then Dim MachiningMaterials() = SysNotes.Split(";".ToCharArray) For Each Material In MachiningMaterials Dim Param() As String = Material.Split(",".ToCharArray) If Param.Count() < 2 Then Continue For Dim CurrMatId As String = String.Empty For Each Mat In CurrentMachine.Materials If Mat.sName = EstCalc.GetMaterialName Then CurrMatId = Mat.nId.ToString() Exit For End If Next If Param(0) = CurrMatId Then Dim MatMinH As Double = 0 StringToDouble(Param(1), MatMinH) Dim MatMaxH As Double = 0 StringToDouble(Param(2), MatMaxH) If EstCalc.GetRawHeight > MatMinH - EPS_SMALL And EstCalc.GetRawHeight < MatMaxH + EPS_SMALL Then Return True End If End If Next Return False Else Return True End If Else Return True End If End Function #End Region ' METHODS End Class Public Class StringIdCmBx Private m_nId As Integer Private m_sName As String Friend ReadOnly Property nId As Integer Get Return m_nId End Get End Property Public ReadOnly Property sName As String Get Return m_sName End Get End Property Sub New(Id As Integer, sName As String) m_nId = Id m_sName = sName End Sub Friend Overloads Shared Function FromIdToStringIdCmBx(nId As Integer, List As List(Of StringIdCmBx)) As StringIdCmBx For Each Item In List If Item.nId = nId Then Return Item End If Next Return Nothing End Function Friend Overloads Shared Function FromIdToStringIdCmBx(nId As Integer, List As ObservableCollection(Of StringIdCmBx)) As StringIdCmBx For Each Item In List If Item.nId = nId Then Return Item End If Next Return Nothing End Function End Class