-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCallWizard.ps1
More file actions
150 lines (129 loc) · 5.27 KB
/
CallWizard.ps1
File metadata and controls
150 lines (129 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
# CREATED BY ANDREW TANNER IN OCTOBER 2018
# VERSION 1.0
#
PowerShell.exe -windowstyle hidden {
#Generated Form Function
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#Initialize Form Objects
$HelpDeskForm = New-Object System.Windows.Forms.Form
$CallStoreButton = New-Object System.Windows.Forms.Button
$GetNumButton = New-Object System.Windows.Forms.Button
$EnterLabel = New-Object System.Windows.Forms.Label
$madeBy = New-Object System.Windows.Forms.Label
$textBox1 = New-Object System.Windows.Forms.TextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
$path = 'C:\Users\' + $env:UserName + '\AppData\vanmar.mdb'
#Custom Keylistener for Enter to run the button event handler
$textbox1_KeyDown = [System.Windows.Forms.KeyEventHandler]{
if ($_.KeyCode -eq 'Enter')
{
$handler_GetNumButton_Click.Invoke()
#Suppress sound from unexpected use of enter on keyPress/keyUp
$_.SuppressKeyPress = $true
}
}
$textbox1.add_KeyDown($textbox1_KeyDown)
#Event Handler that gets store number and copies to clipboard
$handler_CallStoreButton_Click=
{
$text = $textBox1.Text
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = $path")
$objRecordset.Open("Select * from StoreData", $objConnection,$adOpenStatic,$adLockOptimistic)
$objRecordset.MoveFirst()
do {$objRecordset.Fields.Item("PhoneNumber").Value; if($objRecordset.Fields.Item("StoreID").Value -eq $text){$number = $objRecordset.Fields.Item("PhoneNumber").Value;} $objRecordset.MoveNext()} until
($objRecordset.EOF -eq $True)
$objRecordset.Close()
$objConnection.Close()
Set-Clipboard $number
$IE= new-object -ComObject "InternetExplorer.Application"
$IE.navigate2(“CISCOTEL://" + $number)
}
$handler_GetNumButton_Click=
{
$text = $textBox1.Text
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\axt3962\AppData\vanmar.mdb")
$objRecordset.Open("Select * from StoreData", $objConnection,$adOpenStatic,$adLockOptimistic)
$objRecordset.MoveFirst()
do {$objRecordset.Fields.Item("PhoneNumber").Value; if($objRecordset.Fields.Item("StoreID").Value -eq $text){$number = $objRecordset.Fields.Item("PhoneNumber").Value;} $objRecordset.MoveNext()} until
($objRecordset.EOF -eq $True)
$objRecordset.Close()
$objConnection.Close()
Set-Clipboard $number
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$HelpDeskForm.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#Form Style Code
$HelpDeskForm.Text = "Phone Wizard"
$HelpDeskForm.Name = "HelpDeskForm"
$HelpDeskForm.DataBindings.DefaultDataSourceUpdateMode = 0
$HelpDeskForm.TopMost = $true
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 250
$System_Drawing_Size.Height = 80
$HelpDeskForm.ClientSize = $System_Drawing_Size
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 240
$System_Drawing_Size.Height = 23
#Number Button Attributes
$CallStoreButton.TabIndex = 0
$CallStoreButton.Name = "Call Store"
$CallStoreButton.UseVisualStyleBackColor = $True
$CallStoreButton.Text = "Call Store"
$CallStoreButton.Location = '5,57'
$CallStoreButton.Size = '240,20'
$CallStoreButton.DataBindings.DefaultDataSourceUpdateMode = 0
$CallStoreButton.add_Click($handler_CallStoreButton_Click)
$CallStoreButton.BackColor = 'darkred'
$CallStoreButton.ForeColor = 'white'
$CallStoreButton.Font = 'Segoe UI, style=bold'
$GetNumButton.Name = "GetNum"
$GetNumButton.add_Click($handler_GetNumButton_Click)
#TextBox Attributes
$textBox1.Location = '5,30'
$textBox1.Size = '240,20'
$textBox1.Font = 'Segoe UI, style=bold'
$textBox1.TextAlign = 'Center'
$textbox1.MaxLength = '7'
#EnterLable Attributes
$EnterLabel.Text = "Enter the Store ID:"
$EnterLabel.Font = 'Segoe UI, style=bold'
$EnterLabel.Location = '5,5'
$EnterLabel.Size = '240,40'
#madeBy Attributes
$madeBy.Text = "Made by Andrew Tanner 2018"
$madeBy.Font = 'Segoe UI'
$madeBy.Location = '5,81'
$madeBy.Size = '240,40'
#Add the elements to the window
$HelpDeskForm.Controls.Add($CallStoreButton)
$HelpDeskForm.Controls.Add($textBox1)
$HelpDeskForm.Controls.Add($EnterLabel)
$HelpDeskForm.Controls.Add($madeBy)
#endregion Form Code
#Save the initial state of the form
$InitialFormWindowState = $HelpDeskForm.WindowState
#Init the OnLoad event to correct the initial state of the form
$HelpDeskForm.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$HelpDeskForm.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
}