Created
July 26, 2023 01:55
-
-
Save dedSyn4ps3/976443086d198facd981c04b348bea15 to your computer and use it in GitHub Desktop.
Definitions for a small PowerShell GUI
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
# - SNIP - # | |
. .\ResponseCore.ps1 | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
Add-Type -AssemblyName PresentationCore, PresentationFramework | |
# Enable Visual Styles | |
[Windows.Forms.Application]::EnableVisualStyles() | |
###################################### | |
# Callback Functions # | |
###################################### | |
function New-ComboBoxResponse { | |
try { | |
# Pass selected location and retrieve details | |
$_location = $comboBox.SelectedItem | |
$_comboDetails = Get-LocationDetails -Location $_location | |
$_tech = Get-TechName | |
$_text = New-ResponseGeneratorText -Tech $_tech -Phone $_comboDetails.Phone -Email $_comboDetails.Email -Title $_comboDetails.Title | |
Write-ResponseGeneratorText -Text $_text | |
Invoke-ConfirmationMessage | |
} | |
catch { | |
Invoke-FailMessage($_.Exception.Message) | |
} | |
} | |
function New-ShortcutResponse { | |
param( | |
[parameter(Mandatory = $true)] | |
[String]$Selection | |
) | |
try { | |
$_tech = Get-TechName | |
# Pass selected location and retrieve details | |
$_shortcutDetails = Get-LocationDetails -Location $Selection | |
$_text = New-ResponseGeneratorText -Tech $_tech -Phone $_shortcutDetails.Phone -Email $_shortcutDetails.Email -Title $_shortcutDetails.Title | |
Write-ResponseGeneratorText -Text $_text | |
Invoke-ConfirmationMessage | |
} | |
catch { | |
Invoke-FailMessage($_.Exception.Message) | |
} | |
} | |
# - SNIP - # | |
function Initialize-FormUI { | |
# Base form | |
$form = New-Object System.Windows.Forms.Form | |
$form.Text = 'Response Generator' | |
$form.Size = New-Object System.Drawing.Size(600, 400) | |
$form.StartPosition = 'CenterScreen' | |
######################################## | |
# Form Header # | |
######################################## | |
# Image | |
$banner = New-Object System.Windows.Forms.PictureBox | |
$banner.ImageLocation = "https://i1.wp.com/www.trendmut.com/wp-content/uploads/2018/01/humss-tech-support-banner.jpg" | |
$banner.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::StretchImage | |
$banner.Size = New-Object System.Drawing.Size(600, 80) | |
$banner.Dock = [System.Windows.Forms.DockStyle]::Top | |
$form.Controls.Add($banner) | |
# Label | |
$label = New-Object System.Windows.Forms.Label | |
$label.Location = New-Object System.Drawing.Point(150, 85) | |
$label.Size = New-Object System.Drawing.Size(325, 25) | |
$label.Text = 'IT Support Response Generator' | |
$label.Font = New-Object System.Drawing.Font("Cooper Black", 12, [System.Drawing.FontStyle]::Bold) | |
$form.Controls.Add($label) | |
######################################## | |
# Customer Dropdown # | |
######################################## | |
$customer_label = New-Object System.Windows.Forms.Label | |
$customer_label.Location = New-Object System.Drawing.Point(10, 125) | |
$customer_label.Size = New-Object System.Drawing.Size(280, 20) | |
$customer_label.Font = New-Object System.Drawing.Font("Arial", 11, [System.Drawing.FontStyle]::Bold) | |
$customer_label.Text = 'Customer Selection:' | |
$form.Controls.Add($customer_label) | |
# Add Items | |
$comboBox = New-Object System.Windows.Forms.ComboBox | |
$comboBox.Location = New-Object System.Drawing.Point(12, 150) | |
$comboBox.Width = 300 | |
[void] $comboBox.Items.Add('SFV') | |
[void] $comboBox.Items.Add('WWC') | |
[void] $comboBox.Items.Add('MIDW') | |
[void] $comboBox.Items.Add('EAST') | |
$form.Controls.Add($comboBox) | |
# Generate response for selection | |
$generateButton = New-Object System.Windows.Forms.Button | |
$generateButton.Location = New-Object System.Drawing.Point(315, 150) | |
$generateButton.Size = New-Object System.Drawing.Size(75, 25) | |
$generateButton.Text = 'GENERATE' | |
$generateButton.Add_Click({ New-ComboBoxResponse }) | |
$form.Controls.Add($generateButton) | |
####################################### | |
# Shortcut Buttons # | |
####################################### | |
$shortcuts_label = New-Object System.Windows.Forms.Label | |
$shortcuts_label.Location = New-Object System.Drawing.Point(10, 190) | |
$shortcuts_label.Size = New-Object System.Drawing.Size(280, 20) | |
$shortcuts_label.Font = New-Object System.Drawing.Font("Arial", 11, [System.Drawing.FontStyle]::Bold) | |
$shortcuts_label.Text = 'Quick Select:' | |
$form.Controls.Add($shortcuts_label) | |
# SFV | |
$sfvButton = New-Object System.Windows.Forms.Button | |
$sfvButton.Location = New-Object System.Drawing.Point(60, 215) | |
$sfvButton.Size = New-Object System.Drawing.Size(100, 50) | |
$sfvButton.Text = 'SFV' | |
$sfvButton.Font = New-Object System.Drawing.Font("Arial", 12, [System.Drawing.FontStyle]::Regular) | |
$sfvButton.Add_Click({ New-ShortcutResponse -Selection "SFV" }) | |
$form.Controls.Add($sfvButton) | |
# - SNIP - # | |
$form.ShowDialog() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment