Skip to content

Commit

Permalink
- Update ERPBOM_Tab.xaml to work with bomTabContext
Browse files Browse the repository at this point in the history
- Added new script to create bom tab
- Removed references to datastandard
  • Loading branch information
ThomasRossmeisl committed Nov 28, 2022
1 parent 61a3bb1 commit 34bdce2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 30 deletions.
29 changes: 14 additions & 15 deletions Files/powerEvents/Events/ERPBOM_Tab.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviours="clr-namespace:Common.Wpf;assembly=Common" behaviours:TabTitleBehavior.TabTitle="ERP BOM" x:Name="MainWindow">
<UserControl.Resources>
<ScrollViewer xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ScrollViewer.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />

<Style TargetType="{x:Type UserControl}">
<Style TargetType="{x:Type ScrollViewer}">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Background" Value="#FFFDFDFD" />
</Style>
Expand Down Expand Up @@ -77,7 +76,7 @@
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
</ScrollViewer.Resources>

<Grid Height="auto">
<Grid.RowDefinitions>
Expand All @@ -101,8 +100,8 @@
</Style>
</Label.Style>
</Label>
<Button Grid.Row="0" Grid.Column="1" x:Name="CreateOrUpdateMaterialButton" Content="BOM Transfer..." Command="{Binding PsCmd[ShowBomWindow]}" DataContext="{Binding DataContext, ElementName=MainWindow}" Width="136" Margin="0,0,14,0" />
<Button Grid.Row="0" Grid.Column="2" x:Name="GoToBomButton" Content="Open BOM in ERP..." Command="{Binding PsCmd[GoToErpBom]}" DataContext="{Binding DataContext, ElementName=MainWindow}" Width="136" Margin="0,0,14,0" />
<Button Grid.Row="0" Grid.Column="1" x:Name="ShowBomWindowButton" Content="BOM Transfer..." Width="136" Margin="0,0,14,0" />
<Button Grid.Row="0" Grid.Column="2" x:Name="GoToBomButton" Content="Open BOM in ERP..." Width="136" Margin="0,0,14,0" />
</Grid>

<Rectangle Grid.Row="1">
Expand Down Expand Up @@ -132,17 +131,17 @@
<ColumnDefinition MinWidth="100" Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Number" Grid.Row="0" Grid.Column="0" />
<TextBox Text="{Binding Number}" Grid.Row="0" Grid.Column="1" IsReadOnly="True" />
<TextBox Text="{Binding ErpEntity.Number}" Grid.Row="0" Grid.Column="1" IsReadOnly="True" />
<Label Content="Description" Grid.Column="0" Grid.Row="1" />
<TextBox Text="{Binding Description}" Grid.Column="1" Grid.Row="1" IsReadOnly="True"/>
<TextBox Text="{Binding ErpEntity.Description}" Grid.Column="1" Grid.Row="1" IsReadOnly="True"/>
<Label Content="State" Grid.Row="0" Grid.Column="3" />
<ComboBox Grid.Row="0" Grid.Column="4" SelectedValue="{Binding State}" DisplayMemberPath="Value" SelectedValuePath="Key" IsEnabled="False" ItemsSource="{Binding DataContext.PsList[GetBOMStateList], ElementName=MainWindow}" />
<ComboBox Grid.Row="0" Grid.Column="4" SelectedValue="{Binding ErpEntity.State}" DisplayMemberPath="Value" SelectedValuePath="Key" IsEnabled="False" ItemsSource="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext.Lists[BomStatesList]}" />
<Label Content="Last Modified Date" Grid.Column="3" Grid.Row="1" />
<TextBox Text="{Binding ModifiedDate}" Grid.Column="4" Grid.Row="1" IsReadOnly="True" />
<TextBox Text="{Binding ErpEntity.ModifiedDate}" Grid.Column="4" Grid.Row="1" IsReadOnly="True" />
</Grid>
</GroupBox>

<DataGrid Grid.Row="1" ItemsSource="{Binding BomRows}" AutoGenerateColumns="False" ScrollViewer.CanContentScroll="False" HorizontalGridLinesBrush="WhiteSmoke" VerticalGridLinesBrush="WhiteSmoke" Background="White" Margin="6" Focusable="False" SelectionMode="Single" IsReadOnly="True">
<DataGrid Grid.Row="1" ItemsSource="{Binding ErpEntity.BomRows}" AutoGenerateColumns="False" ScrollViewer.CanContentScroll="False" HorizontalGridLinesBrush="WhiteSmoke" VerticalGridLinesBrush="WhiteSmoke" Background="White" Margin="6" Focusable="False" SelectionMode="Single" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Position}" Header="Position" Width="60" IsReadOnly="True" SortDirection="Ascending">
<DataGridTextColumn.HeaderStyle>
Expand Down Expand Up @@ -176,7 +175,7 @@
<DataGridComboBoxColumn SelectedValueBinding="{Binding Path=UnitOfMeasure}" Header="Base UOM" Width="80" IsReadOnly="True" DisplayMemberPath="Value" SelectedValuePath="Key">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.PsList[GetUnitOfMeasuresList]}"/>
<Setter Property="ItemsSource" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext.Lists[UomList]}"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
</DataGridComboBoxColumn>
Expand All @@ -202,4 +201,4 @@
<Image Grid.Column="2" Source="C:\ProgramData\coolOrange\powerGate\UI\powerGate.ico" Width="16" Height="16" Margin="0,0,16,0" Opacity="0.5" />
</Grid>
</Grid>
</UserControl>
</ScrollViewer>
109 changes: 109 additions & 0 deletions Files/powerEvents/Events/TransferERPBomViaFileTab.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#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 -Properties @{Name = 'FlcRootItem.iam'}

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()
}


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

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


Add-VaultTab -Name 'ERP BOM' -EntityType 'File' -Action {
param($selectedFile)

$Script:erpBomTab_control = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::new([xml](Get-Content "$PSScriptRoot\ERPBOM_Tab.xaml")))

#region Initialize viewmodel
$bomTabContext = New-Object -Type PsObject -Property @{
ErpEntity = $null
VaultEntity = $selectedFile

Lists = @{
BomStatesList = @(GetBOMStateList)
UomList = @(GetUnitOfMeasuresList)
}
}
#endregion Initialize viewmodel


#region Initialize UI Components
$erpItemTab_ShowBomWindowButton = $Script:erpBomTab_control.FindName("ShowBomWindowButton")
$erpItemTab_ShowBomWindowButton.Add_Click({
param($Sender, $EventArgs)

ShowBomWindow -VaultEntity $Sender.DataContext.VaultEntity
})

$erpItemTab_GoToBomButton = $Script:erpBomTab_control.FindName("GoToBomButton")
$erpItemTab_GoToBomButton.Add_Click({
param($Sender)

GoToErpBom -ErpEntity $Sender.DataContext.ErpEntity
})
#endregion Initialize UI Components

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

$number = GetEntityNumber -entity $selectedFile
$erpBomHeader = Get-ERPObject -EntitySet "BomHeaders" -Keys @{Number = $number } -Expand "BomRows"
if(-not $?) {
$Script:erpBomTab_control.FindName("lblStatusMessage").Content = $Error[0]
$Script:erpBomTab_control.FindName("lblStatusMessage").Foreground = "Red"
$Script:erpBomTab_control.IsEnabled = $false
return $Script:erpBomTab_control
}

if(-not $erpBomHeader) {
$Script:erpBomTab_control.FindName("GoToBomButton").IsEnabled = $false
}
else {
$bomTabContext.ErpEntity = $erpBomHeader
$Script:erpBomTab_control.FindName("GoToBomButton").IsEnabled = $true
}

$Script:erpBomTab_control.DataContext = $bomTabContext
return $Script:erpBomTab_control
}
27 changes: 12 additions & 15 deletions Files/powerEvents/Modules/ErpTabs.Bom.psm1
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
function InitBomTab {
$entity = GetSelectedObject
$number = GetEntityNumber -entity $entity
$getErpBomHeaderResult = Get-ERPObject -EntitySet "BomHeaders" -Keys @{Number = $number } -Expand "BomRows"
function ShowBomWindow {
param(
$VaultEntity
)

if(-not $getErpBomHeaderResult) {
$goToEnabled = $false
}
else {
$goToEnabled = $true
}
$dswindow.FindName("DataGrid").DataContext = $getErpBomHeaderResult
$dswindow.FindName("GoToBomButton").IsEnabled = $goToEnabled
Show-BomWindow -Entity $VaultEntity
[System.Windows.Forms.SendKeys]::SendWait("{F5}")
}

function GoToErpBom {
$bom = $dswindow.FindName("DataGrid").DataContext
if ($bom.Link) {
Start-Process -FilePath $bom.Link
param(
$ErpEntity
)

if ($ErpEntity.Link) {
Start-Process -FilePath $ErpEntity.Link
}
}

0 comments on commit 34bdce2

Please sign in to comment.