Skip to content

Commit

Permalink
- Renamed FileTab.ErpItem to FileTab.ErpMaterial to be consistent wit…
Browse files Browse the repository at this point in the history
…h variable naming, used in the script

- Added logging initialization to erpmaterial tabs and edit/save pg config menues
- Removed Default.ps1
- Added ItemTab.ErpMaterial.ps1
  • Loading branch information
ThomasRossmeisl committed Nov 24, 2022
1 parent b3464bc commit 24e24ef
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 59 deletions.
33 changes: 0 additions & 33 deletions Files/DataStandard/Vault.Custom/addinVault/Default.ps1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
try {
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange
try {
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange

$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
[xml]$cfg = Get-PowerGateConfigFromVault
New-Item -Path "c:\temp\powerGateCfg" -ItemType Directory -Force
$cfg.Save($cfgPath)
$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log"
Set-LogFilePath -Path $logPath

Start-Process -FilePath C:\Windows\explorer.exe -ArgumentList "/select, ""$cfgPath"""
$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
[xml]$cfg = Get-PowerGateConfigFromVault
New-Item -Path "c:\temp\powerGateCfg" -ItemType Directory -Force
$cfg.Save($cfgPath)

Start-Process -FilePath C:\Windows\explorer.exe -ArgumentList "/select, ""$cfgPath"""
}
catch {
($null = ShowMessageBox -Message $_.Exception.Message -Button "OK" -Icon "Error")
($null = ShowMessageBox -Message $_.Exception.Message -Button "OK" -Icon "Error")
}
finally {
Remove-CoolOrangeLogging
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
try {
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange
try {
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange

$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
$testPath = Test-Path $cfgPath
if ($testPath -eq $false) {
$null = ShowMessageBox -Message "No config file found in '$cfgPath' `n Please download/edit the config file first and then save it back to the Vault server!" -Button "OK" -Icon "Warning"
return
}
[byte[]]$cfg = [System.IO.File]::ReadAllBytes($cfgPath)
Set-PowerGateConfigFromVault -Content $cfg
$null = ShowMessageBox -Message "Config file saved to Vault server" -Button "OK" -Icon "Information"

$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log"
Set-LogFilePath -Path $logPath

Remove-Item $cfgPath -Force
$cfgPath = "c:\temp\powerGateCfg\powerGateConfiguration.xml"
$testPath = Test-Path $cfgPath
if ($testPath -eq $false) {
$null = ShowMessageBox -Message "No config file found in '$cfgPath' `n Please download/edit the config file first and then save it back to the Vault server!" -Button "OK" -Icon "Warning"
return
}
[byte[]]$cfg = [System.IO.File]::ReadAllBytes($cfgPath)
Set-PowerGateConfigFromVault -Content $cfg
$null = ShowMessageBox -Message "Config file saved to Vault server" -Button "OK" -Icon "Information"


Remove-Item $cfgPath -Force
}
catch {
($null = ShowMessageBox -Message $_.Exception.Message -Button "OK" -Icon "Error")
($null = ShowMessageBox -Message $_.Exception.Message -Button "OK" -Icon "Error")
}
finally {
Remove-CoolOrangeLogging
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# return
#region TO BE REMOVED
if((Get-Process -Id $PID).ProcessName -eq 'powershell' -and $host.Name.StartsWith('powerEvents')){
return
Expand All @@ -19,7 +18,8 @@ Connect-ERP -Service 'http://thomas-rossi:8080/PGS/ErpServices'
$global:addinPath = $PSScriptRoot
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange

$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log"
Set-LogFilePath -Path $logPath

# 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!"
Expand Down
134 changes: 134 additions & 0 deletions Files/powerEvents/Events/ItemTab.ErpMaterial.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#region TO BE REMOVED
if((Get-Process -Id $PID).ProcessName -eq 'powershell' -and $host.Name.StartsWith('powerEvents')){
return
}
if([System.Threading.Thread]::CurrentThread.GetApartmentState() -eq 'MTA' -and (Get-Process -Id $PID).ProcessName -ne 'powershell'){
Start-Process powershell.exe -ArgumentList "-STA",$MyInvocation.InvocationName -WindowStyle hidden
return
}

Import-Module powerEvents
Open-VaultConnection -Server $env:Computername -Vault Vault -User Administrator -Password ""
$selectedItem = Get-VaultItem -Number 'co-00000'

Import-Module powergate
Connect-ERP -Service 'http://thomas-rossi:8080/PGS/ErpServices'
#endregion

$global:addinPath = $PSScriptRoot
Import-Module "C:\ProgramData\coolOrange\powerGate\Modules\Initialize.psm1" -Global
Initialize-CoolOrange
$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.log"
Set-LogFilePath -Path $logPath



# 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))")
# }

#region Initialize material tab
Add-Type -AssemblyName PresentationFramework
[xml]$erpMaterialTabXaml = Get-Content -LiteralPath "C:\ProgramData\coolOrange\powerEvents\Events\ErpTab.Item.xaml"
$xamlReader = [System.Xml.XmlNodeReader]::new($erpMaterialTabXaml)
$erpMaterialTab = [Windows.Markup.XamlReader]::Load($xamlReader)
#endregion Initialize material tab


#region Initialize viewmodel
$materialTabContext = New-Object -Type PsObject -Property @{
ErpEntity = $null
VaultEntity = $selectedItem
IsCreate = $false

Lists = @{
UomList = @(GetUnitOfMeasuresList)
MaterialTypeList = @(GetMaterialTypeList)
CategoryList = @(GetCategoryList)
}
}
#endregion Initialize viewmodel


#region Initialize UI Components
#region Register Validate tab events
$erpMaterialTab_Description = $erpMaterialTab.FindName('Description')
$erpMaterialTab_Description.Add_TextChanged({
param($Sender)

ValidateErpMaterialTab -MaterialTabContext $Sender.DataContext
})

$erpMaterialTab_MaterialTypeList = $erpMaterialTab.FindName('MaterialTypeList')
$erpMaterialTab_MaterialTypeList.Add_SelectionChanged({
param($Sender)

ValidateErpMaterialTab -MaterialTabContext $Sender.DataContext
})
#endregion Register Validate tab events

$erpMaterialTab_LinkMaterialButton = $erpMaterialTab.FindName("LinkMaterialButton")
$erpMaterialTab_LinkMaterialButton.IsEnabled = (IsEntityUnlocked -Entity $selectedItem)
$erpMaterialTab_LinkMaterialButton.Add_Click({
param($Sender)

LinkErpMaterial -MaterialTabContext $Sender.DataContext
})

$erpMaterialTab_CreateOrUpdateMaterialButton = $erpMaterialTab.FindName("CreateOrUpdateMaterialButton")
$erpMaterialTab_CreateOrUpdateMaterialButton.Add_Click({
param($Sender)

CreateOrUpdateErpMaterial -MaterialTabContext $Sender.DataContext
})

$erpMaterialTab_GoToMaterialButton = $erpMaterialTab.FindName("GoToMaterialButton")
$erpMaterialTab_GoToMaterialButton.IsEnabled = $true
$erpMaterialTab_GoToMaterialButton.Add_Click({
param($Sender)

GoToErpMaterial -MaterialTabContext $Sender.DataContext
})
#endregion Initialize UI Components


$erpServices = Get-ERPServices -Available
if (-not $erpServices) {
$erpMaterialTab.FindName("lblStatusMessage").Content = "One or more services are not available!"
$erpMaterialTab.FindName("lblStatusMessage").Foreground = "Red"
$erpMaterialTab.IsEnabled = $false
$erpMaterialTab.ShowDialog()
return
}

$number = GetEntityNumber -entity $selectedItem
$erpMaterial = Get-ERPObject -EntitySet "Materials" -Keys @{ Number = $number }
if(-not $?) {
$erpMaterialTab.FindName("lblStatusMessage").Content = $Error[0]
$erpMaterialTab.FindName("lblStatusMessage").Foreground = "Red"
$erpMaterialTab.IsEnabled = $false
$tab_control.ShowDialog()
return
}

if (-not $erpMaterial) {
$erpMaterial = NewErpMaterial
$erpMaterial = PrepareErpMaterialForCreate -erpMaterial $erpMaterial -vaultEntity $selectedItem
$materialTabContext.IsCreate = $true
$materialTabContext.ErpEntity = $erpMaterial
$erpMaterialTab.FindName("GoToMaterialButton").IsEnabled = $false
}
else {
$materialTabContext.ErpEntity = $erpMaterial
$erpMaterialTab.FindName("GoToMaterialButton").IsEnabled = $true
}

$erpMaterialTab.DataContext = $materialTabContext
ValidateErpMaterialTab
$erpMaterialTab.ShowDialog()

0 comments on commit 24e24ef

Please sign in to comment.