Skip to content

Commit

Permalink
PG-1260
Browse files Browse the repository at this point in the history
  -> moved datatrigger functionalities from Item Tab xaml file into Add-VaultTab Action which now fully controls the ui behavior

   -> moved TO BE REMOVED content into a Debugging Section that gets executed only in powershell in ISE processes
  • Loading branch information
coolOrange-Public committed Nov 30, 2022
1 parent 34bdce2 commit 28b0f7a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 182 deletions.
94 changes: 14 additions & 80 deletions Files/powerEvents/Events/ERPItem_Tab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,10 @@
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Label x:Name="lblStatusMessage" Margin="14,0,0,0" FontSize="14" FontWeight="Medium" VerticalAlignment="Center">
<Label.Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
<Setter Property="Content" Value="ERP: Create Material"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="Label.Content" Value="ERP: View/Update Material" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<Label x:Name="lblStatusMessage" Margin="14,0,0,0" FontSize="14" FontWeight="Medium" VerticalAlignment="Center" />

<Button Grid.Row="0" Grid.Column="1" x:Name="LinkMaterialButton" Content="Link ERP Item..." Width="136" Margin="0,0,14,0" />
<Button Grid.Row="0" Grid.Column="2" x:Name="CreateOrUpdateMaterialButton" IsEnabled="False" Width="136" Margin="0,0,14,0">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Content" Value="Create ERP Item"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="Button.Content" Value="Update ERP Item" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Grid.Row="0" Grid.Column="2" x:Name="CreateOrUpdateMaterialButton" IsEnabled="False" Width="136" Margin="0,0,14,0" />
<Button Grid.Row="0" Grid.Column="3" x:Name="GoToMaterialButton" Content="Open Item in ERP..." Width="136" Margin="0,0,14,0" />
</Grid>
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto">
Expand All @@ -120,65 +98,21 @@
<ColumnDefinition MinWidth="100" Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Number" Grid.Row="0" Grid.Column="0" />
<TextBox Text="{Binding ErpEntity.Number}" Grid.Row="0" Grid.Column="1" IsReadOnly="True" />
<TextBox Text="{Binding Number}" Grid.Row="0" Grid.Column="1" IsReadOnly="True" />
<Label Content="Description" Grid.Column="0" Grid.Row="1" />
<TextBox x:Name="Description" Text="{Binding ErpEntity.Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" />

<Label Content="Blocked" Grid.Column="0" Grid.Row="2" >
<Label.Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="Label.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<CheckBox Grid.Column="1" Grid.Row="2" IsChecked="{Binding ErpEntity.IsBlocked}" IsEnabled="False" >
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="CheckBox.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
<TextBox Text="{Binding Description}" Grid.Column="1" Grid.Row="1" />

<Label Content="Blocked" Grid.Column="0" Grid.Row="2" />
<CheckBox IsChecked="{Binding IsBlocked}" Grid.Column="1" Grid.Row="2" IsEnabled="False" />

<Label Content="Type" Grid.Column="3" Grid.Row="1"/>
<ComboBox x:Name="MaterialTypeList" SelectedValue="{Binding ErpEntity.Type}" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="4" Grid.Row="1" IsEnabled="{Binding IsCreate}" ItemsSource="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext.Lists[MaterialTypeList]}" />
<ComboBox x:Name="MaterialTypeList" SelectedValue="{Binding Type}" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="4" Grid.Row="1" />

<Label Content="Base Unit of Measure" Grid.Column="3" Grid.Row="0" />
<ComboBox Name="UomList" SelectedValue="{Binding ErpEntity.UnitOfMeasure}" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="4" Grid.Row="0" IsEnabled="{Binding IsCreate}" ItemsSource="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext.Lists[UomList]}" />
<ComboBox Name="UomList" SelectedValue="{Binding UnitOfMeasure}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="4" Grid.Row="0" />

<Label Content="Last Modified Date" Grid.Column="3" Grid.Row="2" >
<Label.Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="Label.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<TextBox Text="{Binding ErpEntity.ModifiedDate}" Grid.Column="4" Grid.Row="2" IsEnabled="False" >
<TextBox.Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsCreate, ElementName=DataGrid}" Value="False">
<Setter Property="TextBox.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label x:Name="ModifiedDateLabel" Content="Last Modified Date" Grid.Column="3" Grid.Row="2" />
<TextBox x:Name="ModifiedDateTextBox" Text="{Binding ModifiedDate}" Grid.Column="4" Grid.Row="2" IsEnabled="False" />
</Grid>
</GroupBox>
<GroupBox Header="Inventory Data" Grid.Row="1">
Expand All @@ -196,13 +130,13 @@
</Grid.ColumnDefinitions>

<Label Content="Item Category Code" Grid.Column="0" Grid.Row="0" />
<ComboBox Name="CategoryList" SelectedValue="{Binding ErpEntity.Category}" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="1" Grid.Row="0" ItemsSource="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext.Lists[CategoryList]}" />
<ComboBox Name="CategoryList" SelectedValue="{Binding Category}" DisplayMemberPath="Value" SelectedValuePath="Key" Grid.Column="1" Grid.Row="0" />

<Label Content="Search Description" Grid.Column="0" Grid.Row="1" />
<TextBox Text="{Binding ErpEntity.SearchDescription}" Grid.Column="1" Grid.Row="1" />
<TextBox Text="{Binding SearchDescription}" Grid.Column="1" Grid.Row="1" />

<Label Content="Storage Area / Shelf" Grid.Column="3" Grid.Row="0" />
<TextBox Text="{Binding ErpEntity.Shelf}" Grid.Column="4" Grid.Row="0" />
<TextBox Text="{Binding Shelf}" Grid.Column="4" Grid.Row="0" />
</Grid>
</GroupBox>
</Grid>
Expand Down
196 changes: 94 additions & 102 deletions Files/powerEvents/Events/TransferERPItemViaFileTab.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 ""
$selectedFile = Get-VaultFile -File '$/Designs/MultipageInv.idw'

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 ""
$selectedFile = Get-VaultFile -File '$/Designs/MultipageInv.idw'

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($selectedFile))
$debugERPTab_window.ShowDialog()
}
$debugERPTab_window = [Windows.Markup.XamlReader]::Load($xamlReader)
$debugERPTab_window.Title = "powerGate Debug Window for Tab: $name"
$debugERPTab_window.AddChild($action.InvokeReturnAsIs($selectedFile))
$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 @@ -48,97 +43,94 @@ Set-LogFilePath -Path $logPath
Add-VaultTab -Name 'ERP Item' -EntityType 'File' -Action {
param($selectedFile)

$Script:erpItemTab_control = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::new([xml](Get-Content "$PSScriptRoot\ERPItem_Tab.xaml")))
$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)

$materialTypes_combobox = $erpItemTab_control.FindName('MaterialTypeList')
$materialTypes_combobox.ItemsSource = @(GetMaterialTypeList)

$categories_combobox = $erpItemTab_control.FindName('CategoryList')
$categories_combobox.ItemsSource = @(GetCategoryList)

$erpItemTab_CreateOrUpdateMaterialButton = $erpItemTab_control.FindName('CreateOrUpdateMaterialButton')
$erpItemTab_GoToMaterialButton = $erpItemTab_control.FindName('GoToMaterialButton')

#region Initialize viewmodel
$materialTabContext = New-Object -Type PsObject -Property @{
ErpEntity = $null
VaultEntity = $selectedFile
IsCreate = $false
$number = GetEntityNumber -entity $selectedFile
$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
}

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

$erpItemTab_CreateOrUpdateMaterialButton.Content = 'Create ERP Item'

$erpItemTab_GoToMaterialButton.IsEnabled = $false

Lists = @{
UomList = @(GetUnitOfMeasuresList)
MaterialTypeList = @(GetMaterialTypeList)
CategoryList = @(GetCategoryList)
}
$erpMaterial = NewErpMaterial
$erpMaterial = PrepareErpMaterialForCreate -erpMaterial $erpMaterial -vaultEntity $selectedFile
}
#endregion Initialize viewmodel
else {
$statusMessage_label.Content = 'ERP: View/Update Material'

$erpItemTab_CreateOrUpdateMaterialButton.Content = 'Update ERP Item'

#region Initialize UI Components
#region Register Validate tab events
$erpItemTab_Description = $erpItemTab_control.FindName('Description')
$erpItemTab_Description.Add_TextChanged({
param($Sender)
$erpItemTab_control.FindName('ModifiedDateLabel').Visibility = 'Visible'
$erpItemTab_control.FindName('ModifiedDateTextBox').Visibility = 'Visible'

ValidateErpMaterialTab -ErpItemTab $Script:erpItemTab_control
})
$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 $selectedFile)
$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 $selectedFile
$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 $selectedFile
$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 28b0f7a

Please sign in to comment.