Skip to content

Commit

Permalink
PG-1260
Browse files Browse the repository at this point in the history
  + adapted TransferERPItemViaItemTab script with duplicated logic from similar File Tab script
  • Loading branch information
coolOrange-Public committed Nov 30, 2022
1 parent aab2485 commit 674f655
Showing 1 changed file with 94 additions and 103 deletions.
197 changes: 94 additions & 103 deletions Files/powerEvents/Events/TransferERPItemViaItemTab.ps1
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
#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'

function Add-VaultTab($name, $EntityType, $Action){
Add-Type -AssemblyName PresentationFramework

$xamlReader = New-Object System.Xml.XmlNodeReader ([xml]@'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<Style TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Background" Value="#FFFDFDFD" />
</Style>
</Window.Resources>
</Window>
#region Debugging
if((Get-Process -Id $PID).ProcessName -in @('powershell','powershell_ise')){
Import-Module powerEvents

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

function Add-VaultTab($name, $EntityType, $Action){
Add-Type -AssemblyName PresentationFramework

$xamlReader = New-Object System.Xml.XmlNodeReader ([xml]@'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<Style TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Background" Value="#FFFDFDFD" />
</Style>
</Window.Resources>
</Window>
'@)
$debugERPTab_window = [Windows.Markup.XamlReader]::Load($xamlReader)
$debugERPTab_window.Title = "powerGate Debug Window for Tab: $name"
$debugERPTab_window.AddChild($action.InvokeReturnAsIs($selectedItem))
$debugERPTab_window.ShowDialog()
}
$debugERPTab_window = [Windows.Markup.XamlReader]::Load($xamlReader)
$debugERPTab_window.Title = "powerGate Debug Window for Tab: $name"
$debugERPTab_window.AddChild($action.InvokeReturnAsIs($selectedItem))
$debugERPTab_window.ShowDialog()
}


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

$global:addinPath = $PSScriptRoot
Expand All @@ -45,100 +40,96 @@ $logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\VDS_Vault-powerGate.
Set-LogFilePath -Path $logPath


Add-VaultTab -Name 'ERP Item' -EntityType 'File' -Action {
Add-VaultTab -Name 'ERP Item' -EntityType 'Item' -Action {
param($selectedItem)
$erpItemTab_control = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::new([xml](Get-Content "$PSScriptRoot\ERPItem_Tab.xaml")))

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

$unitOfMeasure_combobox = $erpItemTab_control.FindName('UomList')
$unitOfMeasure_combobox.ItemsSource = @(GetUnitOfMeasuresList)

$Script:erpItemTab_control = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::new([xml](Get-Content "$PSScriptRoot\ERPItem_Tab.xaml")))
$materialTypes_combobox = $erpItemTab_control.FindName('MaterialTypeList')
$materialTypes_combobox.ItemsSource = @(GetMaterialTypeList)

#region Initialize viewmodel
$materialTabContext = New-Object -Type PsObject -Property @{
ErpEntity = $null
VaultEntity = $selectedItem
IsCreate = $false
$categories_combobox = $erpItemTab_control.FindName('CategoryList')
$categories_combobox.ItemsSource = @(GetCategoryList)

Lists = @{
UomList = @(GetUnitOfMeasuresList)
MaterialTypeList = @(GetMaterialTypeList)
CategoryList = @(GetCategoryList)
}
$erpItemTab_CreateOrUpdateMaterialButton = $erpItemTab_control.FindName('CreateOrUpdateMaterialButton')
$erpItemTab_GoToMaterialButton = $erpItemTab_control.FindName('GoToMaterialButton')

$number = GetEntityNumber -entity $selectedItem
$erpMaterial = Get-ERPObject -EntitySet "Materials" -Keys @{ Number = $number }
if(-not $?) {
$statusMessage_label.Content = $Error[0]
$statusMessage_label.Foreground = "Red"
$erpItemTab_control.IsEnabled = $false
return $erpItemTab_control
}
#endregion Initialize viewmodel

if (-not $erpMaterial) {
$statusMessage_label.Content = 'ERP: Create Material'

$erpItemTab_CreateOrUpdateMaterialButton.Content = 'Create ERP Item'

$erpItemTab_GoToMaterialButton.IsEnabled = $false

#region Initialize UI Components
#region Register Validate tab events
$erpItemTab_Description = $erpItemTab_control.FindName('Description')
$erpItemTab_Description.Add_TextChanged({
param($Sender)
$erpMaterial = NewErpMaterial
$erpMaterial = PrepareErpMaterialForCreate -erpMaterial $erpMaterial -vaultEntity $selectedItem
}
else {
$statusMessage_label.Content = 'ERP: View/Update Material'

ValidateErpMaterialTab -ErpItemTab $Script:erpItemTab_control
})
$erpItemTab_CreateOrUpdateMaterialButton.Content = 'Update ERP Item'

$erpItemTab_control.FindName('ModifiedDateLabel').Visibility = 'Visible'
$erpItemTab_control.FindName('ModifiedDateTextBox').Visibility = 'Visible'

$erpItemTab_GoToMaterialButton.Add_Click({
param($Sender)

GoToErpMaterial -MaterialTabContext $erpMaterial
})

$erpItemTab_MaterialTypeList = $Script:erpItemTab_control.FindName('MaterialTypeList')
$erpItemTab_MaterialTypeList.Add_SelectionChanged({
$unitOfMeasure_combobox.IsEnabled = $false
$materialTypes_combobox.IsEnabled = $false
}
$erpItemTab_control.DataContext = $erpMaterial

$erpItemTab_CreateOrUpdateMaterialButton.Add_Click({
param($Sender)

ValidateErpMaterialTab -ErpItemTab $Script:erpItemTab_control
CreateOrUpdateErpMaterial -MaterialTabContext $erpMaterial
})
#endregion Register Validate tab events

$erpItemTab_LinkMaterialButton = $Script:erpItemTab_control.FindName("LinkMaterialButton")
$erpItemTab_LinkMaterialButton = $erpItemTab_control.FindName('LinkMaterialButton')
$erpItemTab_LinkMaterialButton.IsEnabled = (IsEntityUnlocked -Entity $selectedItem)
$erpItemTab_LinkMaterialButton.Add_Click({
param($Sender, $EventArgs)

LinkErpMaterial -ErpItemTab $Script:erpItemTab_control
LinkErpMaterial -ErpItemTab $erpItemTab_control
})

$erpItemTab_CreateOrUpdateMaterialButton = $Script:erpItemTab_control.FindName("CreateOrUpdateMaterialButton")
$erpItemTab_CreateOrUpdateMaterialButton.Add_Click({
$materialTypes_combobox.Add_SelectionChanged({
param($Sender)

CreateOrUpdateErpMaterial -MaterialTabContext $Sender.DataContext
ValidateErpMaterialTab -ErpItemTab $erpItemTab_control
})

$erpItemTab_GoToMaterialButton = $Script:erpItemTab_control.FindName("GoToMaterialButton")
$erpItemTab_GoToMaterialButton.IsEnabled = $true
$erpItemTab_GoToMaterialButton.Add_Click({
$erpItemTab_Description = $erpItemTab_control.FindName('Description')
$erpItemTab_Description.Add_TextChanged({
param($Sender)

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


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

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

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

$Script:erpItemTab_control.DataContext = $materialTabContext
ValidateErpMaterialTab -ErpItemTab $Script:erpItemTab_control
#$materialTabContext.IsCreate = $true
return $Script:erpItemTab_control

}
ValidateErpMaterialTab -ErpItemTab $erpItemTab_control
return $erpItemTab_control
}

0 comments on commit 674f655

Please sign in to comment.