powershell

Guess what I did? I wrote CODE! An ITPro crossed into a new land.  Code.

Primal forms Community Edition (*FREE*) from Sapien creates a Powershell Script that creates the Code to produce a form on the screen.

Once you play with the forms and read the basic document on Primal Forms?  You can create a GUI Form launched from Powershell.

So I played with my little script to countdown Techdays.   Once I learned the basics, it wasn’t actually THAT HARD to put that script code INTO the form.

So I present to you humbly my little Script called TechdaysForm.PS1

To get the cool graphic, save the “TechdaysLittleMan” graphic at the bottom of the screen into a folder called C:\Techdays calling it Techdays.Jpg

The Form relies on this.  It’s my first attempt into code, and something to learn from.

Yes you too, the ITPro can safely play with code and make YOUR scripts user friendly, or at the very least “CoOp student Friendly” Open-mouthed smile

The Power of Shell is in YOU!

Sean – The Energized Tech

————–techdaysform.ps1————————

#Generated Form Function
function GenerateForm {

$Locations=@()

$Locations+=("Edmonton","10/6/2010"),("Toronto","10/27/2010"),("Halifax","11/02/2010"), ("Ottawa","11/09/2010"),("Montreal","11/23/2010"),("Winnipeg","12/07/2010"), ("Calgary","12/14/2010")

########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 10/26/2010 11:37 PM
# Generated By: sean.kearney
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$Techdays = New-Object System.Windows.Forms.Form
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$ComboBoxTitle = New-Object System.Windows.Forms.Label
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$saveFileDialog1 = New-Object System.Windows.Forms.SaveFileDialog
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#———————————————-
#Generated Event Script Blocks
#———————————————-
#Provide Custom Code for events specified in PrimalForms.
$handler_comboBox1_SelectedValueChanged=
{
#TODO: Place custom script here
if ($combobox1.SelectedItem) {

$CountdownDate=$Locations | where { $_ -like $ComboBox1.SelectedItem }
$City=$Combobox1.SelectedItem
$RemainingDays=([datetime]$CountdownDate[1]-(GET-DATE)).Days
$CityName=$CountdownDate[0]

$RichTextBox1.Text="It is $RemainingDays Days until Techdays at $City"
$RichTextBox1.Visible=$TRUE

}

}

$handler_label2_Click=
{
#TODO: Place custom script here

}

$handler_pictureBox1_Click=
{
#TODO: Place custom script here

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $Techdays.WindowState = $InitialFormWindowState
}

#———————————————-
#region Generated Form Code
$Techdays.BackColor = [System.Drawing.Color]::FromArgb(255,215,228,242)
$Techdays.Text = "Techdays Countdown"
$Techdays.AccessibleDescription = "Techdays Countdown"
$Techdays.Name = "Techdays"
$Techdays.AccessibleName = "Techdays Countdown"
$Techdays.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 416
$System_Drawing_Size.Height = 175
$Techdays.ClientSize = $System_Drawing_Size

$richTextBox1.Name = "richTextBox1"
$richTextBox1.Text = ""
$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 159
$System_Drawing_Point.Y = 66
$richTextBox1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 243
$System_Drawing_Size.Height = 96
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 4
$richTextBox1.Font= New-Object System.Drawing.Font("Arial",16,2,3,1)

$Techdays.Controls.Add($richTextBox1)

$ComboBoxTitle.TabIndex = 3
$ComboBoxTitle.TextAlign = 32
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 390
$System_Drawing_Size.Height = 23
$ComboBoxTitle.Size = $System_Drawing_Size
$ComboBoxTitle.Text = "How Many Days until Techdays? Select YOUR City from the Pulldown box"
$ComboBoxTitle.Font = New-Object System.Drawing.Font("Arial",8,2,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 9
$ComboBoxTitle.Location = $System_Drawing_Point
$ComboBoxTitle.DataBindings.DefaultDataSourceUpdateMode = 0
$ComboBoxTitle.Name = "ComboBoxTitle"
$ComboBoxTitle.add_Click($handler_label2_Click)

$Techdays.Controls.Add($ComboBoxTitle)

$pictureBox1.TabIndex = 1
$pictureBox1.SizeMode = 4
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 140
$System_Drawing_Size.Height = 125
$pictureBox1.Size = $System_Drawing_Size
$pictureBox1.ImageLocation = "C:\Techdays\Techdays.jpg"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 38
$pictureBox1.Location = $System_Drawing_Point

$pictureBox1.TabStop = $False
$pictureBox1.Name = "pictureBox1"
$pictureBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$pictureBox1.add_Click($handler_pictureBox1_Click)

$Techdays.Controls.Add($pictureBox1)

$comboBox1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 244

$System_Drawing_Size.Height = 21
$comboBox1.Size = $System_Drawing_Size
$comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox1.Name = "comboBox1"
$comboBox1.Items.Add("Calgary")|Out-Null
$comboBox1.Items.Add("Edmonton")|Out-Null
$comboBox1.Items.Add("Halifax")|Out-Null
$comboBox1.Items.Add("Montreal")|Out-Null
$comboBox1.Items.Add("Ottawa")|Out-Null
$comboBox1.Items.Add("Toronto")|Out-Null
$comboBox1.Items.Add("Vancouver")|Out-Null
$comboBox1.Items.Add("Winnipeg")|Out-Null
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 158
$System_Drawing_Point.Y = 38
$comboBox1.Location = $System_Drawing_Point
$comboBox1.Sorted = $True
$comboBox1.TabIndex = 0
$comboBox1.add_SelectedValueChanged($handler_comboBox1_SelectedValueChanged)

$Techdays.Controls.Add($comboBox1)

$saveFileDialog1.ShowHelp = $True
$saveFileDialog1.CreatePrompt = $True

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $Techdays.WindowState
#Init the OnLoad event to correct the initial state of the form
$Techdays.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$Techdays.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

————–techdaysform.ps1————————

Advertisements