Imports System.Data.Entity.ModelConfiguration.Configuration.Properties Imports System.IO Imports EgtBEAMWALL.Core Imports EgtUILib Imports EgtWPFLib5 Public Class RawPartManagerVM Inherits VMBase #Region "FIELDS & PROPERTIES" Private m_RawPartManager_IsEnabled As Boolean = True Public ReadOnly Property RawPartManagerIsEnabled As Boolean Get Return m_RawPartManager_IsEnabled End Get End Property Friend Sub SetRawPartManagerIsEnabled(bIsEnabled As Boolean) m_RawPartManager_IsEnabled = bIsEnabled NotifyPropertyChanged(NameOf(RawPartManagerIsEnabled)) End Sub Private m_ProduceRawPart_Visibility As Visibility Public ReadOnly Property ProduceRawPart_Visibility As Visibility Get Return m_ProduceRawPart_Visibility End Get End Property Private m_MovePartInRawPart_Visibility As Visibility Public ReadOnly Property MovePartInRawPart_Visibility As Visibility Get Return m_MovePartInRawPart_Visibility End Get End Property ' Definizione comandi Private m_cmdProduceAllRawPart As ICommand Private m_cmdProduceRawPart As ICommand Private m_cmdCopyRawPart As ICommand Private m_cmdRemoveRawPart As ICommand Private m_cmdRemoveAllRawPart As ICommand Private m_cmdMovePartInRawPart As ICommand Private m_cmdNewRawPart As ICommand Private m_cmdVerifyAll As ICommand #End Region ' Fields & Properties #Region "Messages" Public ReadOnly Property ProduceRawPart_ToolTip As String Get Return EgtMsg(61912) End Get End Property Public ReadOnly Property ProduceAllRawPart_ToolTip As String Get Return EgtMsg(61913) End Get End Property Public ReadOnly Property CopyRawPart_ToolTip As String Get Return EgtMsg(61914) End Get End Property Public ReadOnly Property RemoveRawPart_ToolTip As String Get Return EgtMsg(61915) End Get End Property Public ReadOnly Property RemoveAllRawPart_ToolTip As String Get Return EgtMsg(61976) End Get End Property Public ReadOnly Property ReOrderPart_ToolTip As String Get Return EgtMsg(61916) End Get End Property Public ReadOnly Property RemovePart_ToolTip As String Get Return EgtMsg(61919) End Get End Property Public ReadOnly Property MovePartInRawPart_ToolTip As String Get Return EgtMsg(61944) End Get End Property Public ReadOnly Property NewRawPart_ToolTip As String Get Return EgtMsg(61903) End Get End Property Public ReadOnly Property VerifyAll_ToolTip As String Get Return EgtMsg(61928) End Get End Property #End Region ' Messages #Region "CONSTRUCTORS" Sub New() Map.SetRefRawPartManagerVM(Me) ' mostro bottoni produci solo se supervisore attivo m_ProduceRawPart_Visibility = If(Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.SUPERVISOR), Visibility.Visible, Visibility.Collapsed) End Sub #End Region ' Constructors #Region "METHODS" Friend Sub UpdateMovePartInRawPartVisibility() m_MovePartInRawPart_Visibility = If(Map.refMainWindowVM.MainWindowM.nUserLevel > 5 AndAlso Not IsNothing(ProjectManagerVM.CurrProd) AndAlso ProjectManagerVM.CurrProd.nType = BWType.WALL, Visibility.Visible, Visibility.Collapsed) NotifyPropertyChanged(NameOf(MovePartInRawPart_Visibility)) End Sub ' funzione che gestisce risposta da thread di verifica, aggiorna progress e segnala comando di interruzione Private Sub ManageCalc(dProgress As Double, sProgress As String, ByRef bCancel As Boolean) If dProgress = 0 Then Map.refMyStatusBarVM.SetLoadingProgress_Visibility(True) Map.refMyStatusBarVM.SetStopProgress_IsActive(True) Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True) Map.refMyStatusBarVM.SetOutputMessage(sProgress) Map.refMyStatusBarVM.SetStopProgress_IsActive(True) Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True) ElseIf dProgress = 1 Then Map.refMyStatusBarVM.SetLoadingProgress_Visibility(False) Map.refMyStatusBarVM.SetStopProgress_IsActive(False) Map.refMyStatusBarVM.SetStopProgress_IsEnabled(False) Map.refMyStatusBarVM.SetOutputMessage(sProgress, 3) End If bCancel = Map.refMyStatusBarVM.bStopProgress Map.refMyStatusBarVM.SetLoadingProgress(dProgress * 100) Map.refMyStatusBarVM.SetOutputMessage(sProgress) End Sub #End Region ' Methods #Region "COMMANDS" #Region "ProduceRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ProduceRawPart_Command As ICommand Get If m_cmdProduceRawPart Is Nothing Then m_cmdProduceRawPart = New Command(AddressOf ProduceRawPart) End If Return m_cmdProduceRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub ProduceRawPart() If IsNothing(ProjectManagerVM.CurrProd) Then Return Dim ErrorMsg As String = "" ' se attiva opzione e non ancora calcolato If GetMainPrivateProfileInt(S_GENERAL, K_FASTPRODUCE, 0) = 1 And Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.NOTCALCULATED Then Map.refCALCPanelVM.SetFromProduce(CALCPanelVM.ProduceType.PRODUCE) Map.refCALCPanelVM.Verify() Return End If ' verifico se modalita' supervisore attiva If GetPrivateProfileInt(S_GENERAL, K_SUPERVISOR, 1, CurrentMachine.sMachIniFile) = 1 Then If Not Produce(Map.refMachGroupPanelVM.SelectedMachGroup, ErrorMsg) AndAlso Not String.IsNullOrWhiteSpace(ErrorMsg) Then MessageBox.Show(ErrorMsg) End If Else ' altrimenti lo copio se path disponibile If Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.OK Or Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.INFO Then Dim sSaveCncPath As String = "" GetPrivateProfileString(S_GENERAL, K_SAVECNCPATH, "", sSaveCncPath, CurrentMachine.sMachIniFile) Dim sSaveExt As String = "" GetPrivateProfileString(S_GENERAL, K_SAVEEXT, "", sSaveExt, CurrentMachine.sMachIniFile) If String.IsNullOrWhiteSpace(sSaveExt) Then sSaveExt = ".cnc" ElseIf sSaveExt(0) <> "." Then sSaveExt = "." & sSaveExt End If Try Dim sMachGroupFilePath As String = Map.refProdManagerVM.CurrProd.sProdDirPath & "\" & Map.refMachGroupPanelVM.SelectedMachGroup.Name.ToString() & ".cnc" Dim sNewPath As String = sSaveCncPath & "\" & Map.refProdManagerVM.CurrProd.sProdId & "-" & Map.refMachGroupPanelVM.SelectedMachGroup.Name.ToString() & sSaveExt File.Copy(sMachGroupFilePath, sNewPath, True) MessageBox.Show(String.Format("File copied! You can find it at {0}", {sNewPath}), "Info", MessageBoxButton.OK, MessageBoxImage.Information) Catch ex As Exception MessageBox.Show(String.Format("Copy to {0} folder failed!", {sSaveCncPath}), "Error", MessageBoxButton.OK, MessageBoxImage.Error) End Try End If End If End Sub Private Function Produce(MachGroup As MyMachGroupVM, ByRef ErrorMsg As String) As Boolean If IsNothing(MachGroup) Then Return False ' se barra gia' assegnata a supervisore, esco If MachGroup.nProduction_State >= ItemState.Assigned Then Return False If MachGroup.nGlobalState = CalcStates.OK Or MachGroup.nGlobalState = CalcStates.INFO Then ' se ci sono modifiche, salvo il pogetto If EgtGetModified() AndAlso Map.refMainMenuVM.SelPage = Pages.MACHINING Then Map.refProdManagerVM.Save() ElseIf EgtGetModified() AndAlso Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then Map.refOnlyProdManagerVM.Save() End If ' mando al supervisore DbControllers.m_MachGroupController.UpdateOrder(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, DbControllers.m_MachGroupController.GetMinIndex(ProjectManagerVM.CurrProd.nProdId) + 1) DbControllers.m_MachGroupController.UpdateSupervisor(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, DbControllers.m_SupervisorId) MachGroup.SentToSupervisor() For Each Part As PartVM In MachGroup.PartVMList DbControllers.m_PartController.UpdateStatus(ProjectManagerVM.CurrProd.nProdId, MachGroup.Id, Part.nPartId, ItemState.Assigned) Part.nProduction_State = ItemState.Assigned Part.NotifyPropertyChanged(NameOf(Part.Background)) ' disabilito impostazione modificato Dim DisableMgr As New DisableModifiedMgr ' blocco modifica del pezzo EgtDuploSetLocked(Part.nPartId) ' ripristino precedente impostazione modificato DisableMgr.ReEnable() Next Return True Else ErrorMsg = String.Format(EgtMsg(62568), MachGroup.Name) Return False End If End Function #End Region ' ProduceRawPart #Region "ProduceAllRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ProduceAllRawPart_Command As ICommand Get If m_cmdProduceAllRawPart Is Nothing Then m_cmdProduceAllRawPart = New Command(AddressOf ProduceAllRawPart) End If Return m_cmdProduceAllRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub ProduceAllRawPart() If IsNothing(ProjectManagerVM.CurrProd) Then Return ' se attiva opzione e non ancora calcolato If GetMainPrivateProfileInt(S_GENERAL, K_FASTPRODUCE, 0) = 1 And Map.refMachGroupPanelVM.MachGroupVMList.Any(Function(x As MyMachGroupVM) x.nProduction_State = ItemState.ND AndAlso x.nGlobalState = CalcStates.NOTCALCULATED) Then Map.refCALCPanelVM.SetFromProduce(CALCPanelVM.ProduceType.PRODUCEALL) Map.refCALCPanelVM.VerifyAll() Return End If If Map.refMachGroupPanelVM.MachGroupVMList.Count > 0 Then Dim MachgroupErrorList As New List(Of MachGroupVM) Dim sErrorMessage As String = "" Dim bErrorMessage As Boolean = False For Each Machgroup In Map.refMachGroupPanelVM.MachGroupVMList ' verifico se modalita' supervisore attiva If GetPrivateProfileInt(S_GENERAL, K_SUPERVISOR, 1, CurrentMachine.sMachIniFile) = 1 Then Dim ErrorMsg As String = "" If Not Produce(Machgroup, ErrorMsg) AndAlso Not String.IsNullOrWhiteSpace(ErrorMsg) Then MachgroupErrorList.Add(Machgroup) End If Else ' altrimenti lo copio se path disponibile If Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.OK Or Map.refMachGroupPanelVM.SelectedMachGroup.nGlobalState = CalcStates.INFO Then Dim sSaveCncPath As String = "" GetPrivateProfileString(S_GENERAL, K_SAVECNCPATH, "", sSaveCncPath, CurrentMachine.sMachIniFile) Dim sSaveExt As String = "" GetPrivateProfileString(S_GENERAL, K_SAVEEXT, "", sSaveExt, CurrentMachine.sMachIniFile) If String.IsNullOrWhiteSpace(sSaveExt) Then sSaveExt = ".cnc" ElseIf sSaveExt(0) <> "." Then sSaveExt = "." & sSaveExt End If If String.IsNullOrWhiteSpace(sSaveCncPath) OrElse Not Directory.Exists(sSaveCncPath) Then Return Try Dim sMachGroupFilePath As String = Map.refProdManagerVM.CurrProd.sProdDirPath & "\" & Machgroup.Name.ToString() & ".cnc" Dim sNewPath As String = sSaveCncPath & "\" & Map.refProdManagerVM.CurrProd.sProdId & "-" & Machgroup.Name.ToString() & sSaveExt File.Copy(sMachGroupFilePath, sNewPath, True) sErrorMessage &= String.Format("File copied! You can find it at {0}", {sNewPath}) & Environment.NewLine Catch ex As Exception sErrorMessage &= String.Format("Copy to {0} folder failed!", {sSaveCncPath}) & Environment.NewLine End Try End If End If Next If Not String.IsNullOrWhiteSpace(sErrorMessage) Then sErrorMessage = "Results for all the parts generated:" & Environment.NewLine & sErrorMessage MessageBox.Show(sErrorMessage, If(bErrorMessage, "Error", "Info"), MessageBoxButton.OK, MessageBoxImage.Information) End If If MachgroupErrorList.Count > 0 Then Dim sMachGroups As String = "" For Each MachGroup In MachgroupErrorList sMachGroups &= " " & MachGroup.Name & "," Next sMachGroups = sMachGroups.Trim({" "c, ","c}) MessageBox.Show(String.Format("Impossible sending {0} to supervisor because not machinable!", sMachGroups)) End If End If End Sub #End Region ' ProduceAllRawPart #Region "CopyRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property CopyRawPart_Command As ICommand Get If m_cmdCopyRawPart Is Nothing Then m_cmdCopyRawPart = New Command(AddressOf CopyRawPart) End If Return m_cmdCopyRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub CopyRawPart() If IsNothing(ProjectManagerVM.CurrProd) Then Return Dim nQty As Integer = 1 ' se premuto shift If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then Dim MultiCopyRawPartWndVM As New MultiCopyRawPartWndVM() Dim MultiCopyRawPartWnd As New MultiCopyRawPartWndV(Application.Current.MainWindow, MultiCopyRawPartWndVM) If Not MultiCopyRawPartWnd.ShowDialog() Then Return nQty = MultiCopyRawPartWndVM.nQuantity End If Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup If IsNothing(SelMachGroup) Then Return ' creo copia Dim NewMachGroup As MyMachGroupVM = SelMachGroup.Copy(nQty) If Not IsNothing(NewMachGroup) Then ' lo seleziono Map.refProjectVM.MachGroupPanelVM.SelectedMachGroup = NewMachGroup End If End Sub #End Region ' CopyRawPart #Region "RemoveRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RemoveRawPart_Command As ICommand Get If m_cmdRemoveRawPart Is Nothing Then m_cmdRemoveRawPart = New Command(AddressOf RemoveRawPartCmd) End If Return m_cmdRemoveRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub RemoveRawPartCmd() RemoveRawPart() End Sub Public Sub RemoveRawPart(Optional bAll As Boolean = False) If IsNothing(ProjectManagerVM.CurrProd) Then Return ' se tutti If bAll Then ' cancello tutti For Index = Map.refMachGroupPanelVM.MachGroupVMList.Count - 1 To 0 Step -1 Dim CurrMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.MachGroupVMList(Index) ' se barra gia' assegnata a supervisore, esco If CurrMachGroup.nProduction_State >= ItemState.Assigned Then Continue For CurrMachGroup.DeleteMachGroup(True) Next Else Dim SelMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup If IsNothing(SelMachGroup) Then Return ' se barra gia' assegnata a supervisore, esco If SelMachGroup.nProduction_State >= ItemState.Assigned Then Return SelMachGroup.DeleteMachGroup() If Not IsNothing(Map.refMachGroupPanelVM.SelectedMachGroup) Then Map.refMachGroupPanelVM.SelectedMachGroup = Map.refMachGroupPanelVM.MachGroupVMList(0) End If EgtDraw() ' se nessun grezzo, rimetto tutti i pezzi invisibili If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then Map.refProjectVM.BTLStructureVM.HideAll(True) End If End Sub #End Region ' RemoveRawPart #Region "RemoveAllRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RemoveAllRawPart_Command As ICommand Get If m_cmdRemoveAllRawPart Is Nothing Then m_cmdRemoveAllRawPart = New Command(AddressOf RemoveAllRawPart) End If Return m_cmdRemoveAllRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub RemoveAllRawPart() RemoveRawPart(True) End Sub #End Region ' RemoveAllRawPart #Region "MovePartInRawPart" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property MovePartInRawPart_Command As ICommand Get If m_cmdMovePartInRawPart Is Nothing Then m_cmdMovePartInRawPart = New Command(AddressOf MovePartInRawPart) End If Return m_cmdMovePartInRawPart End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub MovePartInRawPart() If IsNothing(ProjectManagerVM.CurrProd) Then Return Dim MovePartInRawPartWndVM As New MovePartInRawPartWndVM() Dim MovePartInRawPartWnd As Object If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then MovePartInRawPartWnd = New OnlyProdMovePartInRawPartWndV(Application.Current.MainWindow, MovePartInRawPartWndVM) Else MovePartInRawPartWnd = New MovePartInRawPartWndV(Application.Current.MainWindow, MovePartInRawPartWndVM) End If If Not MovePartInRawPartWnd.ShowDialog() Then Return End Sub #End Region ' MovePartInRawPart #Region "NewRawPart" Public ReadOnly Property NewRawPart_Command As ICommand Get If m_cmdNewRawPart Is Nothing Then m_cmdNewRawPart = New Command(AddressOf NewRawPartCmd) End If Return m_cmdNewRawPart End Get End Property Public Sub NewRawPartCmd() NewRawPart(False) End Sub Public Sub NewRawPart(bLast As Boolean) If IsNothing(ProjectManagerVM.CurrProd) Then Return Dim SelParts As List(Of BTLPartVM) = Map.refProjectVM.BTLStructureVM.SelBTLParts.ToList() If IsNothing(SelParts) OrElse SelParts.Count <= 0 Then Return ' verifico che abbiano tutti la stessa sezione Dim dHSection As Double = SelParts(0).dH Dim dWSection As Double = SelParts(0).dW For PartIndex = 0 To SelParts.Count - 1 Dim Part As BTLPartVM = SelParts(PartIndex) If Not IsNothing(Part) Then If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then If Part.dH <> dHSection OrElse Part.dW <> dWSection Then MessageBox.Show(EgtMsg(61970), EgtMsg(30007)) Return End If ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then If Part.dH <> dHSection Then MessageBox.Show(EgtMsg(61970), EgtMsg(30007)) Return End If End If Else SelParts.Remove(Part) End If Next ' se pareti e piu' di uno selezionato, esco If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL And SelParts.Count > 1 Then MessageBox.Show(EgtMsg(61971), EgtMsg(30007)) Return End If ' se nessun grezzo, rendo tutti i pezzi visibili If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then Map.refProjectVM.BTLStructureVM.ShowAll(False) End If ' verifico se sono gia' stati messi tutti i pezzi richiesti If Not VerifyPartCount(SelParts) Then Return Dim dRawL As Double = SelParts(0).dL Dim dRawW As Double = SelParts(0).dW Dim dStartOffset As Double = 0 Dim dKerf As Double = 0 Dim dOffset As Double = WarehouseHelper.GetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE) ' se tipo di definizione grezzo esplicito If WarehouseHelper.GetRawPartDef = 1 OrElse ((Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift AndAlso WarehouseHelper.GetWarehouseType = WarehouseType.BASIC) Then ' chiedo lunghezza grezzo Dim sWarehouseIniPath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_BASIC_INI_FILE_NAME If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then dStartOffset = WarehouseHelper.GetStartOffset() dRawL += dStartOffset Else dKerf = WarehouseHelper.GetKerf() dRawL += 2 * dKerf dRawW += 2 * dKerf End If Dim AddRawPartWndVM As New AddRawPartWndVM(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawL, dRawW, dStartOffset) Dim AddRawPartWnd As Object = Nothing If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then AddRawPartWnd = New OnlyProdAddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM) Else AddRawPartWnd = New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM) End If If Not AddRawPartWnd.ShowDialog() Then Return dRawL = AddRawPartWndVM.VariableList(0).dValue dRawW = AddRawPartWndVM.VariableList(1).dValue dStartOffset = AddRawPartWndVM.VariableList(1).dValue ' se altrimenti definizione grezzo da warehouse Else If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then dStartOffset = WarehouseHelper.GetStartOffset() Else dKerf = WarehouseHelper.GetKerf() End If ' se warehouse basic Select Case WarehouseHelper.GetWarehouseType() Case WarehouseType.BASIC WarehouseHelper.GetCurrentDimensions(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawW, dRawL) Case WarehouseType.MEDIUM Dim SectionList As List(Of SParam) = WarehouseHelper.GetSectionList() Dim SParamlist As List(Of SParam) = SectionList.FindAll(Function(x) x.SectXMat = SelParts(0).Section) If bLast Then Dim LastMaterial As SParam = WarehouseHelper.GetLastMaterial(SelParts(0).Section) If Not IsNothing(LastMaterial) Then dRawL = LastMaterial.dL dRawW = LastMaterial.dW ElseIf SParamlist.Count > 0 Then dRawL = SParamlist(0).dL dRawW = SParamlist(0).dW Else MessageBox.Show(EgtMsg(61975), EgtMsg(30007)) Return End If Else If SParamlist.Count = 0 Then ' se pareti aumento dimensioni del kerf If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then dRawW += (2 * dKerf) dRawL += (2 * dKerf) End If ' apro finestra con solo edit If AddRawPartWnd(AddRawPartWndVM.EditTypes.ONLY_TEXT, SParamlist, dRawW, dRawL, dStartOffset, dOffset, dKerf) Then WarehouseHelper.SetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dOffset) If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then WarehouseHelper.SetStartOffset(dStartOffset) Else WarehouseHelper.SetKerf(dKerf) End If Else Return End If ElseIf SParamlist.Count > 0 Then ' imposto finestra con anche edit If AddRawPartWnd(AddRawPartWndVM.EditTypes.TEXT_AND_COMBO, SParamlist, dRawW, dRawL, dStartOffset, dOffset, dKerf) Then WarehouseHelper.SetOffset(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dOffset) If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then WarehouseHelper.SetStartOffset(dStartOffset) Else WarehouseHelper.SetKerf(dKerf) End If Else Return End If End If End If End Select End If If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then ' verifico se lunghezza barra e' maggiore della lunghezza dei pezzi Dim dTotLen As Double = WarehouseHelper.GetStartOffset() For PartIndex = 0 To SelParts.Count - 1 If PartIndex <> 0 Then dTotLen += WarehouseHelper.GetOffset(BWType.BEAM) End If dTotLen += SelParts(PartIndex).dL Next If dTotLen > dRawL Then MessageBox.Show(EgtMsg(61972), EgtMsg(30007)) Return End If End If ' creo nuovo gruppo di lavorazione Map.refMachGroupPanelVM.AddMachGroup() Dim nCurrMachGroup As Integer = EgtGetCurrMachGroup() Dim sCurrMachGroupName As String = "" EgtGetMachGroupName(nCurrMachGroup, sCurrMachGroupName) Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt" ' scrivo dati per variabili P di comunicazione con la macchina in gruppo di lavorazione EgtSetInfo(nCurrMachGroup, MGR_RPT_PRODID, ProjectManagerVM.CurrProd.nProdId) EgtSetInfo(nCurrMachGroup, MGR_RPT_PATTID, nCurrMachGroup) If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then ' ordino i pezzi per lunghezza SelParts = SelParts.OrderBy(Function(x) x.dL).ToList ' creo copie dei pezzi Dim nPartDuploIdList As New List(Of Integer) For Each Part In SelParts Dim nDuploId As Integer = EgtDuploNew(Part.nPartId) ' elimino valori calcolo dell'originale MyMachGroupPanelVM.DuploRemoveProjCalc(nDuploId) ' lo rendo std EgtSetMode(nDuploId, GDB_MD.STD) nPartDuploIdList.Add(nDuploId) Next ' scrivo dati costruzione grezzo in gruppo di lavorazione EgtSetInfo(nCurrMachGroup, MGR_RPT_BARLEN, dRawL) EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelParts(0).sMATERIAL) ' scrivo dati di tutti i pezzi Dim dPosX As Double = WarehouseHelper.GetStartOffset() ' ciclo sui pezzi For nIndex = 0 To nPartDuploIdList.Count - 1 ' se non è primo, aggiungo offset tra barre standard If nIndex <> 0 Then dPosX += WarehouseHelper.GetOffset(BWType.BEAM) End If EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & nIndex + 1, nPartDuploIdList(nIndex) & "," & DoubleToString(dPosX, 3)) ' incremento posizione della sua lunghezza dPosX += SelParts(nIndex).dL Next Dim BeamMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.GetLastMachGroup() ' eseguo script creazione grezzo Dim nERR As Integer = 0 If Not ExecBeam(sLogPath, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdTypes.RAWPART, False) Then ' elimino duplo e gruppo di lavorazione For Each nDuploId In nPartDuploIdList EgtErase(nDuploId) Next BeamMachGroup.DeleteMachGroup() If File.Exists(sLogPath) Then Dim LogFile As String() = File.ReadAllLines(sLogPath) If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then MessageBox.Show(LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) End If Else MessageBox.Show(EgtMsg(61973), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) End If ' se nessun grezzo, rimetto tutti i pezzi invisibili If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then Map.refProjectVM.BTLStructureVM.HideAll() End If Return End If For nDuploIndex = 0 To SelParts.Count - 1 EgtSetInfo(nPartDuploIdList(nDuploIndex), MGR_PRT_ROT, SelParts(nDuploIndex).nROTATED) EgtSetInfo(nPartDuploIdList(nDuploIndex), MGR_PRT_FLIP, SelParts(nDuploIndex).nINVERTED) Next ' aggiorno contatore pezzi usati in Prod For Each SelPart In SelParts SelPart.RefreshPartInProd() Next 'aggiorno lista pezzi BeamMachGroup.MyMachGroupM.RefreshPartList() BeamMachGroup.MyMachGroupM.RefreshGroupData() ' aggiorno dati utilizzo barra BeamMachGroup.UpdateUsage() Core.ViewPanelVM.BWSetView(VT.ISO_SW, False) ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then Dim nPartDuploId As Integer = EgtDuploNew(SelParts(0).nPartId) ' scrivo dati in gruppo di lavorazione Dim dPosX As Double = dKerf Dim dPosY As Double = dKerf EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELLEN, dRawL) EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELWIDTH, dRawW) EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelParts(0).sMATERIAL) EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & 1, nPartDuploId & "," & DoubleToString(dPosX, 3) & "," & DoubleToString(dPosY, 3) & ",0,0") Dim WallMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.MachGroupVMList(Map.refMachGroupPanelVM.MachGroupVMList.Count - 1) ' eseguo script creazione grezzo If Not ExecWall(sLogPath, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdTypes.RAWPART, False, False) Then ' elimino duplo e gruppo di lavorazione EgtErase(nPartDuploId) WallMachGroup.DeleteMachGroup() If File.Exists(sLogPath) Then Dim LogFile As String() = File.ReadAllLines(sLogPath) If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then MessageBox.Show(LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) End If Else MessageBox.Show(EgtMsg(61973), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error) End If ' se nessun grezzo, rimetto tutti i pezzi invisibili If Map.refProjectVM.MachGroupPanelVM.MachGroupVMList.Count = 0 Then Map.refProjectVM.BTLStructureVM.HideAll(True) End If Return End If ' scrivo dati pezzo EgtSetInfo(nPartDuploId, MGR_PRT_POSX, dPosX) EgtSetInfo(nPartDuploId, MGR_PRT_POSY, dPosY) EgtSetInfo(nPartDuploId, MGR_PRT_ROT, SelParts(0).nROTATED) EgtSetInfo(nPartDuploId, MGR_PRT_FLIP, SelParts(0).nINVERTED) ' aggiorno contatore pezzi usati in Prod SelParts(0).RefreshPartInProd() ' aggiorno lista pezzi WallMachGroup.MyMachGroupM.RefreshPartList() WallMachGroup.MyMachGroupM.RefreshGroupData() ' aggiorno dati ultilizzo barra WallMachGroup.UpdateUsage() Core.ViewPanelVM.BWSetView(VT.TOP, False) End If EgtZoom(ZM.ALL) End Sub ' funzione che apre finestra di scelta dimensioni grezzo Private Function AddRawPartWnd(EditType As AddRawPartWndVM.EditTypes, SParamlist As List(Of SParam), ByRef dRawW As Double, ByRef dRawL As Double, ByRef dStartOffset As Double, ByRef dOffset As Double, ByRef dKerf As Double) As Boolean ' apro finestra con solo edit Dim AddRawPartWndVM As New AddRawPartWndVM(EditType, Map.refProjectVM.BTLStructureVM.nPROJTYPE, SParamlist, dRawL, dRawW, dStartOffset, dOffset, dKerf) Dim AddRawPartWndV As Object = Nothing If Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then AddRawPartWndV = New OnlyProdAddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM) Else AddRawPartWndV = New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM) End If If Not AddRawPartWndV.ShowDialog() Then Return False Select Case Map.refProjectVM.BTLStructureVM.nPROJTYPE Case BWType.BEAM dRawL = AddRawPartWndVM.VariableList(0).dValue dStartOffset = AddRawPartWndVM.VariableList(1).dValue dOffset = AddRawPartWndVM.VariableList(2).dValue Case BWType.WALL dRawW = AddRawPartWndVM.VariableList(0).dValue dRawL = AddRawPartWndVM.VariableList(1).dValue dKerf = AddRawPartWndVM.VariableList(2).dValue dOffset = AddRawPartWndVM.VariableList(3).dValue End Select ' verifico se il materiale esiste in magazzino o devo aggiungerlo Dim CurrSParam As SParam = Nothing Select Case EditType Case AddRawPartWndVM.EditTypes.ONLY_TEXT ' lo aggiungo a lista materiali in magazzino CurrSParam = AddRawMaterial(dRawW, dRawL) Case AddRawPartWndVM.EditTypes.ONLY_COMBO ' non faccio nulla Case AddRawPartWndVM.EditTypes.TEXT_AND_COMBO ' verifico se lunghezza testo corrisponde a materiale If Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.BEAM Then CurrSParam = SParamlist.FirstOrDefault(Function(x) x.dL = AddRawPartWndVM.VariableList(0).dValue) Else CurrSParam = SParamlist.FirstOrDefault(Function(x) x.dL = AddRawPartWndVM.VariableList(1).dValue AndAlso x.dW = AddRawPartWndVM.VariableList(0).dValue) End If If IsNothing(CurrSParam) Then ' lo aggiungo a lista materiali in magazzino CurrSParam = AddRawMaterial(dRawW, dRawL) End If End Select ' imposto il materiale selezionato come ultimo utilizzato SetLastMaterial(CurrSParam.SectXMat, CurrSParam) Return True End Function Private Function AddRawMaterial(dRawW As Double, ByRef dRawL As Double) As SParam Dim sWarehousePath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_MEDIUM_INI_FILE_NAME Dim nQuantity As Integer = GetMainPrivateProfileInt(S_WAREHOUSE, K_DEFAULTQUANTITY, 1) Dim CurrSParam = Nothing If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then ' creo sParam If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLParts(0)) Then CurrSParam = New SParam(Map.refProjectVM.BTLStructureVM.SelBTLParts(0).Section, dRawL, nQuantity, False) Dim sL As String = String.Empty sL = LenToString(CurrSParam.dL, 3) ' ricavo l'indice del SecionXMaterial dalla Beam_List Dim SectXMatIndex As Integer = GetSectIndexFromSection(MachineType.BEAM, CurrSParam.SectXMat) ' ricavo nuovo indice materiale Dim ParamIndex As Integer = 1 Dim sParam As String = "" While GetPrivateProfileString(S_BEAM, K_L & ParamIndex, "", sParam, sWarehousePath) > 0 ParamIndex += 1 End While If SectXMatIndex > 0 Then ' lo aggiungo in warehouse WritePrivateProfileString(S_BEAM, K_L & ParamIndex, SectXMatIndex & "," & sL & "," & CurrSParam.nQuantity & "," & If(CurrSParam.bActive, 1, 0), sWarehousePath) Else EgtOutLog("Error in material creation, section not found!") End If Return CurrSParam ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then ' creo sParam If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLParts(0)) Then CurrSParam = New SParam(Map.refProjectVM.BTLStructureVM.SelBTLParts(0).Section, dRawW, dRawL, nQuantity, False) Dim sW As String = String.Empty Dim sL As String = String.Empty sW = LenToString(CurrSParam.dW, 3) sL = LenToString(CurrSParam.dL, 3) ' ricavo l'indice del SecionXMaterial dalla Wall_List Dim SectXMatIndex As Integer = GetSectIndexFromSection(MachineType.WALL, CurrSParam.SectXMat) ' ricavo nuovo indice materiale Dim ParamIndex As Integer = 1 Dim sParam As String = "" While GetPrivateProfileString(S_WALL, K_S & ParamIndex, "", sParam, sWarehousePath) > 0 ParamIndex += 1 End While ' lo aggiungo in warehouse WritePrivateProfileString(S_WALL, K_S & ParamIndex, SectXMatIndex & "," & sW & "," & sL & "," & CurrSParam.nQuantity & "," & If(CurrSParam.bActive, 1, 0), sWarehousePath) Return CurrSParam End If Return Nothing End Function Private Function VerifyPartCount(SelParts As List(Of BTLPartVM)) As Boolean ' verifico se ci sono pezzi da aggiungere Dim ToAddList As New List(Of String) Dim ToAddVM As New List(Of BTLPartVM) For Each SelPart In SelParts If Not SelPart.CanAddPartToCount Then ToAddList.Add(SelPart.nCNT & EgtMsg(61864) & SelPart.nADDED & EgtMsg(61865)) ToAddVM.Add(SelPart) End If Next ' se non ci sono, chiedo se aggiungerne uno nuovo If ToAddList.Count > 0 Then Dim sMessage As String = EgtMsg(61863) & Environment.NewLine For Each sPart In ToAddList sMessage &= " - " & sPart & Environment.NewLine Next If MessageBox.Show(sMessage & EgtMsg(61893), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then For Each PartVM In ToAddVM PartVM.AddNewPartToAdded() Next Else Return False End If End If Return True End Function #End Region ' NewRawPart #Region "VerifyAll" ''' ''' Returns a command that do Open. ''' Public ReadOnly Property VerifyAll_Command As ICommand Get If m_cmdVerifyAll Is Nothing Then m_cmdVerifyAll = New Command(AddressOf VerifyAll) End If Return m_cmdVerifyAll End Get End Property ''' ''' Execute the Open. This method is invoked by the OpenCommand. ''' Friend Sub VerifyAll() If (Map.refMainMenuVM.SelPage = Pages.VIEW AndAlso (IsNothing(ProjectManagerVM.CurrProj) OrElse IsNothing(Map.refProjectVM.BTLStructureVM))) OrElse (Map.refMainMenuVM.SelPage = Pages.MACHINING AndAlso (IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) OrElse (Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE AndAlso (IsNothing(ProjectManagerVM.CurrProj) OrElse IsNothing(Map.refProjectVM.BTLStructureVM)) AndAlso (IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return ' se modalita' assemblato Configuration.AssembledMode(Map.refShowBeamPanelVM.ShowBuilding_IsChecked) Dim BarList() As EgtBEAMWALL.Core.Bar = Nothing Dim ProjType As BWType If Map.refMainMenuVM.SelPage = Pages.VIEW Then ProjType = ProjectManagerVM.CurrProj.nType If Not CreateBarListToVerify(Pages.VIEW, ProjType, BarList) Then Return ' lancio calcolo EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProj.sProjDirPath, AddressOf ManageCalc) ElseIf Map.refMainMenuVM.SelPage = Pages.MACHINING Then ProjType = ProjectManagerVM.CurrProd.nType If Not CreateBarListToVerify(Pages.MACHINING, ProjType, BarList) Then Return ' lancio calcolo EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProd.sProdDirPath, AddressOf ManageCalc) ElseIf Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE Then ProjType = ProjectManagerVM.CurrProd.nType If Map.refProjectVM.LastSelGridType = ProjectVM.GridSelTypes.PART OrElse Map.refProjectVM.LastSelGridType = ProjectVM.GridSelTypes.PARTLIST Then If Not CreateBarListToVerify(Pages.VIEW, ProjType, BarList) Then Return ' lancio calcolo EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProj.sProjDirPath, AddressOf ManageCalc) ElseIf Map.refProjectVM.LastSelGridType = ProjectVM.GridSelTypes.MACHGROUP Then If Not CreateBarListToVerify(Pages.MACHINING, ProjType, BarList) Then Return ' lancio calcolo EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProd.sProdDirPath, AddressOf ManageCalc) End If End If End Sub Private Function CreateBarListToVerify(SelPage As Pages, ProjType As BWType, ByRef BarList As Bar()) As Boolean If SelPage = Pages.VIEW Then Dim TempBarList As New List(Of EgtBEAMWALL.Core.Bar) For PartIndex = 0 To Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1 Dim CurrPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.BTLPartVMList(PartIndex) If Not CurrPart.bDO Then Continue For Dim Bar As New EgtBEAMWALL.Core.Bar With {.nBarId = CurrPart.nPartId, .nProgramPage = ProjectType.PROJ, .nProjType = ProjType, .bBarOk = True, .nMachineName = Map.refMachinePanelVM.SelectedMachine.Name, .nGlobState = CurrPart.nGlobalState} Select Case CurrPart.nGlobalState Case Core.CalcStates.OK, CalcStates.INFO Bar.nCmdType = CalcIntegration.CmdTypes.GENERATE Case Else If CurrPart.nGlobalState = CalcStates.NOTCALCULATED OrElse CurrPart.nFeaturesGlobalState > CalcStates.INFO Then Dim sBTLPartFilePath As String = ProjectManagerVM.CurrProj.sProjDirPath & "\" & CurrPart.nPDN.ToString() & ".ori.bwe" If File.Exists(sBTLPartFilePath) Then File.Delete(sBTLPartFilePath) End If Bar.nCmdType = CalcIntegration.CmdTypes.CHECKGEN End Select TempBarList.Add(Bar) Next BarList = TempBarList.ToArray() ' disabilito interfaccia Map.refProjectVM.SetCalcRunning(True) ElseIf SelPage = Pages.MACHINING Then Dim TempBarList As New List(Of EgtBEAMWALL.Core.Bar) For PartIndex = 0 To Map.refMachGroupPanelVM.MachGroupVMList.Count - 1 Dim CurrMachGroup As MyMachGroupVM = Map.refMachGroupPanelVM.MachGroupVMList(PartIndex) ' se e' gia' stato assegnato a supervisor, la salto e vado alla prossima barra If CurrMachGroup.nProduction_State >= ItemState.Assigned Then Continue For Dim MachineName As String = "" EgtGetMachGroupMachineName(CurrMachGroup.Id, MachineName) Dim Bar As New EgtBEAMWALL.Core.Bar With {.nBarId = CurrMachGroup.Id, .nProgramPage = ProjectType.PROD, .nProjType = ProjType, .bBarOk = True, .nMachineName = MachineName, .nGlobState = CurrMachGroup.nGlobalState} Select Case CurrMachGroup.nGlobalState Case Core.CalcStates.OK, CalcStates.INFO Bar.nCmdType = CalcIntegration.CmdTypes.GENERATE Case Else If CurrMachGroup.nGlobalState = CalcStates.NOTCALCULATED OrElse (CurrMachGroup.nPartsGlobalState > CalcStates.INFO) Then Dim sMachGroupFilePath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\" & CurrMachGroup.Name.ToString() & ".ori.bwe" If File.Exists(sMachGroupFilePath) Then File.Delete(sMachGroupFilePath) End If Bar.nCmdType = CalcIntegration.CmdTypes.CHECKGEN End Select TempBarList.Add(Bar) Next If TempBarList.Count = 0 Then Return False BarList = TempBarList.ToArray() ' disabilito interfaccia Map.refProjectVM.SetCalcRunning(True) End If Return True End Function #End Region ' VerifyAll #End Region ' Commands End Class