Files
egtbeamwall/EgtBEAMWALL.Optimizer/RawPartManager/RawPartManagerVM.vb
T
2026-05-05 10:25:41 +02:00

823 lines
37 KiB
VB.net

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
Private m_CALCPanel_IsEnabled As Boolean = True
Public ReadOnly Property CALCPanel_IsEnabled As Boolean
Get
Return m_CALCPanel_IsEnabled
End Get
End Property
Friend Sub SetCALCPanel_IsEnabled(value As Boolean)
m_CALCPanel_IsEnabled = value
NotifyPropertyChanged(NameOf(CALCPanel_IsEnabled))
End Sub
' Definizione comandi
Private m_cmdProduceAllRawPart As ICommand
Private m_cmdRemoveAllRawPart As ICommand
Private m_cmdMovePartInRawPart As ICommand
Private m_cmdNewRawPart As ICommand
Private m_cmdVerifyAll As ICommand
Private m_cmdResetCalc 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
Public ReadOnly Property ResetCalc_ToolTip As String
Get
Return EgtMsg(61940)
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
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(ProjectType.PROD, CalcIntegration.CmdTypes.CHECKNOSIM)
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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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)
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, String.Format(EgtMsg(62584), {sNewPath}), EgtMsg(15003), MessageBoxButton.OK, MessageBoxImage.Information)
Catch ex As Exception
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, String.Format(EgtMsg(62585), {sSaveCncPath}), EgtMsg(15001), 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
Map.refProdManagerVM.Save()
' 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))
MachGroup.NotifyPropertyChanged(NameOf(MachGroup.ButtonIsEnabled))
Part.NotifyPropertyChanged(NameOf(Part.ButtonIsEnabled))
For Each Feature As BTLFeatureVM In Part.FeatureVMList
Feature.NotifyPropertyChanged(NameOf(Feature.IsEnabled))
Next
' 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
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
' seleziono primo pezzo
If Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count > 0 Then
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList(0))
End If
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 ' Methods
#Region "COMMANDS"
#Region "ProduceAllRawPart"
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
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(ProjectType.PROD, CalcIntegration.CmdTypes.CHECKNOSIM)
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(EgtMsg(62584), {sNewPath}) & Environment.NewLine
Catch ex As Exception
sErrorMessage &= String.Format(EgtMsg(62585), {sSaveCncPath}) & Environment.NewLine
End Try
End If
End If
Next
If Not String.IsNullOrWhiteSpace(sErrorMessage) Then
sErrorMessage = EgtMsg(62587) & Environment.NewLine & sErrorMessage
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, sErrorMessage, If(bErrorMessage, EgtMsg(15001), EgtMsg(15003)), 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})
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, String.Format(EgtMsg(62568), sMachGroups))
End If
End If
End Sub
#End Region ' ProduceAllRawPart
#Region "RemoveAllRawPart"
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
Public Sub RemoveAllRawPart()
RemoveRawPart(True)
End Sub
#End Region ' RemoveAllRawPart
#Region "MovePartInRawPart"
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
Public Sub MovePartInRawPart()
If IsNothing(ProjectManagerVM.CurrProd) Then Return
Dim MovePartInRawPartWndVM As New MovePartInRawPartWndVM()
Dim MovePartInRawPartWnd As New MovePartInRawPartWndV(Application.Current.MainWindow, MovePartInRawPartWndVM)
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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(61970), EgtMsg(30007))
Return
End If
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL Then
If Part.dH <> dHSection Then
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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 = New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM)
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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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, ProjectManagerVM.CurrProd.sMachine, 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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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, ProjectManagerVM.CurrProd.sMachine, 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
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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 New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM)
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 EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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"
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
Friend Sub VerifyAll()
If ((IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return
Map.refCALCPanelVM.SetCalculating(True)
For PartIndex = 0 To Map.refMachGroupPanelVM.MachGroupVMList.Count - 1
DirectCast(Map.refMachGroupPanelVM.MachGroupVMList(PartIndex), MyMachGroupVM).SetIsRowEnabled(False)
Next
Map.refCALCPanelVM.VerifyAll(ProjectType.PROD, CalcIntegration.CmdTypes.CHECKGEN)
Return
End Sub
#End Region ' VerifyAll
#Region "ResetCalc"
Public ReadOnly Property ResetCalc_Command As ICommand
Get
If m_cmdResetCalc Is Nothing Then
m_cmdResetCalc = New Command(AddressOf ResetCalc)
End If
Return m_cmdResetCalc
End Get
End Property
Public Sub ResetCalc()
If IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM) Then Return
Map.refShowBeamPanelVM.ShowBuilding_IsEnabled = True
For Each MachGroup As MyMachGroupVM In Map.refProjectVM.MachGroupPanelVM.MachGroupVMList
If MachGroup.nProduction_State >= ItemState.Assigned Then Continue For
If MachGroup.nGlobalState <> CalcStates.NOTCALCULATED Then
MachGroup.ResetCalcTotalMachGroup()
End If
If Not MachGroup.IsRowEnabled Then MachGroup.SetIsRowEnabled(True)
Next
End Sub
#End Region ' ResetCalc
#End Region ' Commands
End Class