Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Windows Form App con Powershell
[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