#==============================================================================================
# XAML Code - Imported from Visual Studio Express WPF Application
#==============================================================================================
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="OS Details" Height="306" Width="525" WindowStartupLocation="CenterScreen" WindowStyle='None' ResizeMode='NoResize'>
<Grid Margin="0,0,-0.2,0.2">
<TextBox HorizontalAlignment="Center" Height="23" TextWrapping="Wrap" Text="Operating System Details" VerticalAlignment="Top" Width="525" Margin="0,-1,-0.2,0" TextAlignment="Center" Foreground="White" Background="#FF98D6EB"/>
<Label Content="Imie" HorizontalAlignment="Left" Margin="0,27,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
<Label Content="Nazwisko" HorizontalAlignment="Left" Margin="0,62,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
<Label Content="Rocznik" HorizontalAlignment="Left" Margin="0,97,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
<Button Name="btnExit" Content="Next" HorizontalAlignment="Left" Margin="0,272,0,0" VerticalAlignment="Top" Width="525" Height="34" BorderThickness="0"/>
<TextBox Name="Imie" HorizontalAlignment="Left" Height="30" Margin="175,27,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
<TextBox Name="Nazwisko" HorizontalAlignment="Left" Height="30" Margin="175,62,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
<TextBox Name="Rocznik" HorizontalAlignment="Left" Height="30" Margin="175,97,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
</Grid>
</Window>
'@
#===========================================================================
# Shows the form
#===========================================================================
#$Form.ShowDialog() | out-null
$dataSource = ".\SQLEXPRESS"
$user = "sa"
$pwd = "zaq1@WSX"
$database = "Szkolenie"
$connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;"
$query = "SELECT * FROM dbo.Person"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($result)
$format = @{Expression
={$_.Id
};Label
="ID";width
=10},@{Expression
={$_.Name
};Label
="Imie"; width
=15},@{Expression
={$_.Surname
};Label
="Nazwisko"; width
=15},@{Expression
={$_.Born
};Label
="Rocznik"; width
=7}
#$table | Where-Object {$_.Surname -like "*sson" -and $_.Born -lt 1990} | format-table $format
#$table | Where-Object {$_.Surname -like "*sson" -and $_.Born -lt 1990} | format-table $format | Out-GridView
ForEach ($osoba in $table){
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
$xaml.SelectNodes
("//*[@Name]") | %{Set-Variable -Name ($_.Name
) -Value $Form.FindName
($_.Name
)}
$btnExit.Add_Click({$form.Close()})
if ($osoba.id -eq $table.Rows[$table.Rows.Count-1].id){
$btnExit.Content = "Close"
}
$Imie.Text = $osoba.Name
$Nazwisko.Text = $osoba.Surname
$Rocznik.Text = $osoba.Born
$Form.ShowDialog() | out-null
}
$connection.Close()