Facebook
From RL, 4 Years ago, written in PowerShell.
Embed
Download Paste or View Raw
Hits: 229
  1. #==============================================================================================
  2. # XAML Code - Imported from Visual Studio Express WPF Application
  3. #==============================================================================================
  4. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  5. [xml]$XAML = @'
  6. <Window
  7.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  8.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  9.    Title="OS Details" Height="306" Width="525" WindowStartupLocation="CenterScreen" WindowStyle='None' ResizeMode='NoResize'>
  10.    <Grid Margin="0,0,-0.2,0.2">
  11.        <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"/>
  12.        <Label Content="Imie" HorizontalAlignment="Left" Margin="0,27,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
  13.        <Label Content="Nazwisko" HorizontalAlignment="Left" Margin="0,62,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
  14.        <Label Content="Rocznik" HorizontalAlignment="Left" Margin="0,97,0,0" VerticalAlignment="Top" Height="30" Width="170" Background="#FF98D6EB" Foreground="White"/>
  15.        <Button Name="btnExit" Content="Next" HorizontalAlignment="Left" Margin="0,272,0,0" VerticalAlignment="Top" Width="525" Height="34" BorderThickness="0"/>
  16.        <TextBox Name="Imie" HorizontalAlignment="Left" Height="30" Margin="175,27,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
  17.        <TextBox Name="Nazwisko" HorizontalAlignment="Left" Height="30" Margin="175,62,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
  18.        <TextBox Name="Rocznik" HorizontalAlignment="Left" Height="30" Margin="175,97,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="343" IsEnabled="False"/>
  19.    </Grid>
  20. </Window>
  21. '@
  22.  
  23.  
  24. #===========================================================================
  25. # Shows the form
  26. #===========================================================================
  27. #$Form.ShowDialog() | out-null
  28.  
  29.  
  30. $dataSource = ".\SQLEXPRESS"
  31. $user = "sa"
  32. $pwd = "zaq1@WSX"
  33. $database = "Szkolenie"
  34. $connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;"
  35.  
  36. $query = "SELECT * FROM dbo.Person"
  37.  
  38. $connection = New-Object System.Data.SqlClient.SqlConnection
  39. $connection.ConnectionString = $connectionString
  40.  
  41. $connection.Open()
  42. $command = $connection.CreateCommand()
  43. $command.CommandText = $query
  44.  
  45. $result = $command.ExecuteReader()
  46.  
  47. $table = new-object “System.Data.DataTable”
  48. $table.Load($result)
  49.  
  50. $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}
  51.  
  52. #$table | Where-Object {$_.Surname -like "*sson" -and $_.Born -lt 1990} | format-table $format
  53.  
  54. #$table | Where-Object {$_.Surname -like "*sson" -and $_.Born -lt 1990} | format-table $format | Out-GridView
  55.  
  56.  
  57.  
  58. ForEach ($osoba in $table){
  59.  
  60.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  61.     try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  62.     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}
  63.     $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
  64.     $btnExit.Add_Click({$form.Close()})
  65.  
  66.     if ($osoba.id -eq $table.Rows[$table.Rows.Count-1].id){
  67.         $btnExit.Content = "Close"
  68.     }
  69.  
  70.     $Imie.Text = $osoba.Name
  71.     $Nazwisko.Text = $osoba.Surname
  72.     $Rocznik.Text = $osoba.Born
  73.     $Form.ShowDialog() | out-null
  74. }
  75.  
  76.  
  77.  
  78. $connection.Close()