Skip to content

Commit

Permalink
Merge branch 'powerGate_rework' of https://github.com/coolOrangeLabs/…
Browse files Browse the repository at this point in the history
…powerGateTemplate into powerGate_rework
  • Loading branch information
coolOrange-Public committed Nov 24, 2022
2 parents 0d79e35 + b3464bc commit ed4b13d
Show file tree
Hide file tree
Showing 16 changed files with 1,275 additions and 1,733 deletions.
58 changes: 36 additions & 22 deletions Files/DataStandard/CAD.Custom/addins/powerGateMain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
$matrix = $Application.TransientGeometry.CreateMatrix()
$occur = $Document.ComponentDefinition.Occurrences
$occur.AddVirtual($number, $matrix)
$null = ShowMessageBox -Message "Virtual Component '$number' successfully inserted." -Title "powerGate ERP - Virtual Component" -Icon "Information"
ShowMessageBox -Message "Virtual Component '$number' successfully inserted." -Title "powerGate ERP - Virtual Component" -Icon "Information" | Out-Null
}
catch {
$null = ShowMessageBox -Message "'$number' already exists. Please choose another ERP item." -Title "powerGate ERP - Virtual Component" -Icon "Warning"
ShowMessageBox -Message "'$number' already exists. Please choose another ERP item." -Title "powerGate ERP - Virtual Component" -Icon "Warning" | Out-Null
}
}
if ($prop["_FileExt"].Value -eq ".IPT") {
$prop["Raw_Number"].Value = $number
$prop["Raw_Quantity"].Value = 1
$null = ShowMessageBox -Message "Raw Material '$number' successfully inserted." -Title "powerGate ERP - Raw Material" -Icon "Information"
ShowMessageBox -Message "Raw Material '$number' successfully inserted." -Title "powerGate ERP - Raw Material" -Icon "Information" | Out-Null
}
}
}
Expand All @@ -27,7 +27,7 @@ function OpenErpMaterialWindow {
$reader = (New-Object System.Xml.XmlNodeReader $windowXaml)
$global:window = [Windows.Markup.XamlReader]::Load($reader)

[xml]$userControlXaml = Get-Content $PSScriptRoot.Replace('\CAD.Custom\addins', '\Vault.Custom\Configuration\File\ERP Item.xaml')
[xml]$userControlXaml = Get-Content $PSScriptRoot.Replace('\addins', '\Configuration\ERP Item.xaml')
$reader = (New-Object System.Xml.XmlNodeReader $userControlXaml)
$global:userControl = [Windows.Markup.XamlReader]::Load($reader)

Expand All @@ -36,7 +36,7 @@ function OpenErpMaterialWindow {

$userControl.DataContext = $dsWindow.DataContext

InitErpMaterialTab -number $prop["Part Number"].Value
InitErpMaterialTab_Ds4Inv -number $prop["Part Number"].Value

if ($window.ShowDialog() -eq "OK") {
$materialTabContext = $userControl.FindName("DataGrid").DataContext
Expand All @@ -50,7 +50,7 @@ function CloseErpMaterialWindow {
$window.Close()
}

function InitErpMaterialTab($number) {
function InitErpMaterialTab_Ds4Inv($number) {
$getErpMaterialResult = Get-ERPObject -EntitySet "Materials" -Keys @{ Number = $number }

$materialTabContext = New-Object -Type PsObject -Property @{
Expand All @@ -69,7 +69,7 @@ function InitErpMaterialTab($number) {
$goToEnabled = $true
}
$userControl.FindName("DataGrid").DataContext = $materialTabContext
$userControl.FindName("LinkMaterialButton").IsEnabled = IsEntityUnlocked
$userControl.FindName("LinkMaterialButton").IsEnabled = IsEntityUnlocked_Ds4Inv
$userControl.FindName("GoToMaterialButton").IsEnabled = $goToEnabled
}

Expand All @@ -81,7 +81,7 @@ function PrepareErpMaterial($erpMaterial) {
return $erpMaterial
}

function IsEntityUnlocked {
function IsEntityUnlocked_Ds4Inv {
$fullFileName = $prop["_FilePath"].Value + "\" + $prop["_FileName"].Value
if (Test-Path -Path $fullFileName) {
$status = Get-ChildItem $fullFileName
Expand All @@ -92,14 +92,14 @@ function IsEntityUnlocked {
}
}

function ValidateErpMaterialTab {
function ValidateErpMaterialTab_Ds4Inv {
$materialTabContext = $userControl.FindName("DataGrid").DataContext
$erpMaterial = $materialTabContext.Entity
if ($erpMaterial.Number) {
$entityUnlocked = $true
}
else {
$entityUnlocked = IsEntityUnlocked
$entityUnlocked = IsEntityUnlocked_Ds4Inv
}

#TODO: Setup obligatory fields that need to be filled out to activate the 'Create' button
Expand All @@ -114,37 +114,37 @@ function ValidateErpMaterialTab {
$userControl.FindName("CreateOrUpdateMaterialButton").IsEnabled = $enabled
}

function CreateOrUpdateErpMaterial {
function CreateOrUpdateErpMaterial_Ds4Inv {
$materialTabContext = $userControl.FindName("DataGrid").DataContext

if($materialTabContext.IsCreate) {
$createErpMaterialResult = Add-ErpObject -EntitySet "Materials" -Properties $materialTabContext.Entity
if ($? -eq $false) {
return
}
$null = ShowMessageBox -Message "$($createErpMaterialResult.Number) successfully created" -Title "powerGate ERP - Create Material" -Icon "Information"
SetEntityProperties -erpMaterial $createErpMaterialResult
ShowMessageBox -Message "$($createErpMaterialResult.Number) successfully created" -Title "powerGate ERP - Create Material" -Icon "Information" | Out-Null
SetEntityProperties_Ds4Inv -erpMaterial $createErpMaterialResult
}
else {
$updateErpMaterialResult = Update-ERPObject -EntitySet "Materials" -Key $materialTabContext.Entity._Keys -Properties $materialTabContext.Entity._Properties
if ($? -eq $false) {
return
}
$null = ShowMessageBox -Message "$($updateErpMaterialResult.Number) successfully updated" -Title "powerGate ERP - Update Material" -Icon "Information"
ShowMessageBox -Message "$($updateErpMaterialResult.Number) successfully updated" -Title "powerGate ERP - Update Material" -Icon "Information" | Out-Null
}

RefreshView
RefreshView_Ds4Inv
}

function GoToErpMaterial {
function GoToErpMaterial_Ds4Inv {
$materialTabContext = $userControl.FindName("DataGrid").DataContext
$erpMaterial = $materialTabContext.Entity
if ($erpMaterial.Link) {
Start-Process -FilePath $erpMaterial.Link
}
}

function LinkErpMaterial {
function LinkErpMaterial_Ds4Inv {
$erpMaterial = OpenErpSearchWindow

#TODO: Rename "Part Number" on a german system to "Teilenummer"
Expand All @@ -159,18 +159,19 @@ function LinkErpMaterial {
}

$answer = ShowMessageBox -Message ($message + "Do you really want to link the item '$($erpMaterial.Number)'?") -Title "powerGate ERP - Link Item" -Button "YesNo" -Icon "Question"

if ($answer -eq "Yes") {
SetEntityProperties -erpMaterial $erpMaterial -vaultEntity $vaultEntity
RefreshView
SetEntityProperties_Ds4Inv -erpMaterial $erpMaterial -vaultEntity $vaultEntity
RefreshView_Ds4Inv
}
}

function RefreshView {
function RefreshView_Ds4Inv {
[System.Windows.Forms.SendKeys]::SendWait("{F5}")
InitErpMaterialTab -number $prop["Part Number"].Value
InitErpMaterialTab_Ds4Inv -number $prop["Part Number"].Value
}

function SetEntityProperties($erpMaterial) {
function SetEntityProperties_Ds4Inv($erpMaterial) {
#TODO: Update Inventor iProperties with values from ERP
$prop["Part Number"].Value = $erpMaterial.Number
$prop["Description"].Value = $erpMaterial.Description
Expand All @@ -185,6 +186,19 @@ function InitializeWindow
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange

#todo: remove
Connect-ERP -Service 'http://thomas-rossi:8080/PGS/ErpServices'

# if ($vaultConnection.Vault -notin $vaultToPgsMapping.Keys) {
# throw "The currently connected Vault '$($vaultConnection.Vault)' is not mapped to any powerGateServer URL. Please extend the configuration and re-submit the job!"
# }

# Write-Host "Connecting to powerGateServer on: $($vaultToPgsMapping[$vaultConnection.Vault])"
# $connected = Connect-ERP -Service "http://$($vaultToPgsMapping[$vaultConnection.Vault]):8080/PGS/ErpServices"
# if(-not $connected) {
# throw("Connection to ERP could not be established! Reason: $($Error[0]) (Source: $($Error[0].Exception.Source))")
# }

$erpServices = Get-ERPServices -Available
if (-not $erpServices -or $erpServices.Count -le 0) {
$dswindow.FindName("lblStatusMessage").Content = "One or more services are not available!"
Expand Down

0 comments on commit ed4b13d

Please sign in to comment.