Last active
October 6, 2017 15:50
-
-
Save mvillegascuellar/4ec2b5a46439150c70c09821805ba970 to your computer and use it in GitHub Desktop.
Windows Form App con Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
[void] [System.Windows.Forms.Application]::EnableVisualStyles() | |
$button_click = { | |
$SQLServer = "NombreDelServidor" | |
$SQLDBName = "AdventureWorks" | |
$uid ="Usuario" | |
$pwd = "Password" | |
$SqlQuery = "SELECT * from [Production].[vProductAndDescription];" | |
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection | |
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = False; User ID = $uid; Password = $pwd;" | |
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand | |
$SqlCmd.CommandText = $SqlQuery | |
$SqlCmd.Connection = $SqlConnection | |
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter | |
$SqlAdapter.SelectCommand = $SqlCmd | |
$DataSet = New-Object System.Data.DataSet | |
$SqlAdapter.Fill($DataSet) | |
$SqlConnection.close() | |
$DataSet.tables[0] | Out-GridView | |
} | |
$Form = New-Object system.Windows.Forms.Form | |
$Form.Size = New-Object System.Drawing.Size(300,200) | |
$form.MaximizeBox = $false | |
$Form.StartPosition = "CenterScreen" | |
$Form.FormBorderStyle = 'Fixed3D' | |
$Form.Text = "App Dummy AdventureWorks" | |
$Label = New-Object System.Windows.Forms.Label | |
$Label.Text = "Escoja la accion" | |
$Label.AutoSize = $true | |
$Label.Location = New-Object System.Drawing.Size(75,50) | |
$Font = New-Object System.Drawing.Font("Arial",15,[System.Drawing.FontStyle]::Bold) | |
$Label.Font = $Font | |
$Form.Controls.Add($Label) | |
$Okbutton = New-Object System.Windows.Forms.Button | |
$Okbutton.Location = New-Object System.Drawing.Size(40,80) | |
$Okbutton.Size = New-Object System.Drawing.Size(100,30) | |
$Okbutton.Text = "Query" | |
$Okbutton.Add_Click($button_click) | |
$Form.Controls.Add($Okbutton) | |
$Closebutton = New-Object System.Windows.Forms.Button | |
$Closebutton.Location = New-Object System.Drawing.Size(150,80) | |
$Closebutton.Size = New-Object System.Drawing.Size(100,30) | |
$Closebutton.Text = "Close" | |
$Closebutton.Add_Click({$Form.Close()}) | |
$Form.Controls.Add($Closebutton) | |
$Form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment