-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUI.ps1
466 lines (409 loc) · 20.3 KB
/
GUI.ps1
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<#
.NAME
ACH Verification Tool
#>
$current_path = [string]$(Split-Path -Parent $PSCommandPath)
. $current_path\HelperFunctions.ps1
. $current_path\Test-ABA\ABAChecker.ps1 -LoadFunctions
Add-Type -AssemblyName System.Windows.Forms
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Application]::EnableVisualStyles()
$ACHVerificationTool = New-Object system.Windows.Forms.Form
$ACHVerificationTool.ClientSize = '1200,725'
$ACHVerificationTool.MinimumSize = '1210,745'
$ACHVerificationTool.text = "ACH NACHA Verification Tool"
$ACHVerificationTool.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$ACHVerificationTool.TopMost = $false
$ACHVerificationTool.MaximizeBox = $False
$ACHVerificationTool.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ACHVerificationTool.Icon = "$(Split-Path -Parent $PSCommandPath)\img\bank-icon.ico"
$Title = New-Object system.Windows.Forms.Label
$Title.text = "ACH NACHA Verification Tool"
$Title.AutoSize = $true
$Title.width = 25
$Title.height = 10
$Title.location = New-Object System.Drawing.Point(25,15)
$Title.Font = 'Segoe UI,18'
#region File Input/Output Panel
# Panel definition
$FilePanel = New-Object system.Windows.Forms.Groupbox
$FilePanel.height = 225
$FilePanel.width = 360
$FilePanel.text = "File Input/Output"
$FilePanel.location = New-Object System.Drawing.Point(25,65)
# ACH File Input Textbox and Browse handling
$ACHInputFilePathLabel = New-Object system.Windows.Forms.Label
$ACHInputFilePathLabel.text = "ACH Input File Path:"
$ACHInputFilePathLabel.AutoSize = $true
$ACHInputFilePathLabel.width = 25
$ACHInputFilePathLabel.height = 10
$ACHInputFilePathLabel.location = New-Object System.Drawing.Point(15,23)
$ACHInputFilePathLabel.Font = 'Microsoft Sans Serif,10'
$ACHInputFilePath = New-Object system.Windows.Forms.TextBox
$ACHInputFilePath.multiline = $false
$ACHInputFilePath.width = 250
$ACHInputFilePath.height = 27
$ACHInputFilePath.location = New-Object System.Drawing.Point(15,45)
$ACHInputFilePath.Font = 'Microsoft Sans Serif,11'
$ACHInputFilePathButton = New-Object system.Windows.Forms.Button
$ACHInputFilePathButton.text = "Browse"
$ACHInputFilePathButton.width = 60
$ACHInputFilePathButton.height = 25
$ACHInputFilePathButton.location = New-Object System.Drawing.Point(285,45)
$ACHInputFilePathButton.Font = 'Microsoft Sans Serif,10'
# Working directory textbox and browse handling
$WorkingDirectoryLabel = New-Object system.Windows.Forms.Label
$WorkingDirectoryLabel.text = "Working Directory:"
$WorkingDirectoryLabel.AutoSize = $true
$WorkingDirectoryLabel.width = 25
$WorkingDirectoryLabel.height = 10
$WorkingDirectoryLabel.location = New-Object System.Drawing.Point(15,80)
$WorkingDirectoryLabel.Font = 'Microsoft Sans Serif,10'
$WorkingDirectory = New-Object system.Windows.Forms.TextBox
$WorkingDirectory.multiline = $false
$WorkingDirectory.width = 250
$WorkingDirectory.height = 26
$WorkingDirectory.location = New-Object System.Drawing.Point(15,100)
$WorkingDirectory.Font = 'Microsoft Sans Serif,11'
$WorkingDirectoryButton = New-Object system.Windows.Forms.Button
$WorkingDirectoryButton.text = "Browse"
$WorkingDirectoryButton.width = 60
$WorkingDirectoryButton.height = 25
$WorkingDirectoryButton.location = New-Object System.Drawing.Point(285,100)
$WorkingDirectoryButton.Font = 'Microsoft Sans Serif,10'
#region File Handling
$ACHInputFilePathButton.Add_Click( {
if ($ACHInputFilePath.Text) {
if (Test-Path $ACHInputFilePath.Text) {
$ACHInputFilePath.Text = Get-FileName -InitialDirectory $ACHInputFilePath.Text
}
} else {
$ACHInputFilePath.Text = Get-FileName
}
})
$ACHInputFilePath.Add_TextChanged( {
if (-not $ACHInputFilePath.Text) {
$SuccessProvider.SetError($ACHInputFilePath, "")
$ErrorProvider.SetError($ACHInputFilePath, "")
}
elseif (Test-Path -Path $ACHInputFilePath.Text) {
$SuccessProvider.SetError($ACHInputFilePath, "OK")
$ErrorProvider.SetError($ACHInputFilePath, "")
}
else {
$ErrorProvider.SetError($ACHInputFilePath, "Check path, not found or no access")
$SuccessProvider.SetError($ACHInputFilePath, "")
}
})
$WorkingDirectoryButton.Add_Click( {
$WorkingDirectory.Text = Get-Folder
})
$WorkingDirectory.Add_TextChanged( {
if (-not $WorkingDirectory.Text) {
$SuccessProvider.SetError($WorkingDirectory, "")
$ErrorProvider.SetError($WorkingDirectory, "")
}
elseif (Test-Path -Path $WorkingDirectory.Text) {
$SuccessProvider.SetError($WorkingDirectory, "OK")
$ErrorProvider.SetError($WorkingDirectory, "")
}
else {
$ErrorProvider.SetError($WorkingDirectory, "Check path, not found or no access")
$SuccessProvider.SetError($WorkingDirectory, "")
}
})
#endregion
# Tool Options (Patching and Logigng Options)
$PatchFile = New-Object system.Windows.Forms.CheckBox
$PatchFile.text = "Patch File?"
$PatchFile.AutoSize = $false
$PatchFile.width = 95
$PatchFile.height = 20
$PatchFile.location = New-Object System.Drawing.Point(15,145)
$PatchFile.Font = 'Microsoft Sans Serif,11'
$PatchFile.Checked = $true
$LogBasic = New-Object system.Windows.Forms.RadioButton
$LogBasic.text = "Basic Logging"
$LogBasic.AutoSize = $true
$LogBasic.width = 104
$LogBasic.height = 20
$LogBasic.location = New-Object System.Drawing.Point(125,145)
$LogBasic.Font = 'Microsoft Sans Serif,11'
$LogFull = New-Object system.Windows.Forms.RadioButton
$LogFull.text = "Full Logging"
$LogFull.AutoSize = $true
$LogFull.width = 104
$LogFull.height = 20
$LogFull.location = New-Object System.Drawing.Point(125,170)
$LogFull.Font = 'Microsoft Sans Serif,11'
$LogFull.Checked = $True
$LogNone = New-Object system.Windows.Forms.RadioButton
$LogNone.text = "No Logging"
$LogNone.AutoSize = $true
$LogNone.width = 104
$LogNone.height = 20
$LogNone.location = New-Object System.Drawing.Point(125,195)
$LogNone.Font = 'Microsoft Sans Serif,11'
#endregion
#region ACH Control Settings Panel
$ACHControlSettingsPanel = New-Object system.Windows.Forms.Groupbox
$ACHControlSettingsPanel.height = 265
$ACHControlSettingsPanel.width = 360
$ACHControlSettingsPanel.text = "ACH Control Settings"
$ACHControlSettingsPanel.location = New-Object System.Drawing.Point(25,315)
# Immediate Origin
$ImmediateOriginLabel = New-Object system.Windows.Forms.Label
$ImmediateOriginLabel.text = "Imm. Origin Routing Number:"
$ImmediateOriginLabel.AutoSize = $true
$ImmediateOriginLabel.width = 25
$ImmediateOriginLabel.height = 10
$ImmediateOriginLabel.location = New-Object System.Drawing.Point(15,23)
$ImmediateOriginLabel.Font = 'Microsoft Sans Serif,10'
$ImmediateOrigin = New-Object system.Windows.Forms.TextBox
$ImmediateOrigin.multiline = $false
$ImmediateOrigin.width = 165
$ImmediateOrigin.height = 27
$ImmediateOrigin.location = New-Object System.Drawing.Point(15,45)
$ImmediateOrigin.Font = 'Microsoft Sans Serif,11'
$ODFILabel = New-Object system.Windows.Forms.Label
$ODFILabel.text = "Imm. Origin DFI:"
$ODFILabel.AutoSize = $true
$ODFILabel.width = 25
$ODFILabel.height = 10
$ODFILabel.location = New-Object System.Drawing.Point(200,23)
$ODFILabel.Font = 'Microsoft Sans Serif,10'
$ODFI = New-Object system.Windows.Forms.TextBox
$ODFI.multiline = $false
$ODFI.width = 140
$ODFI.height = 27
$ODFI.location = New-Object System.Drawing.Point(200,45)
$ODFI.Font = 'Microsoft Sans Serif,11'
$ImmediateOriginNameLabel = New-Object system.Windows.Forms.Label
$ImmediateOriginNameLabel.text = "Imm. Origin Name:"
$ImmediateOriginNameLabel.AutoSize = $true
$ImmediateOriginNameLabel.width = 25
$ImmediateOriginNameLabel.height = 10
$ImmediateOriginNameLabel.location = New-Object System.Drawing.Point(15,80)
$ImmediateOriginNameLabel.Font = 'Microsoft Sans Serif,10'
$ImmediateOriginName = New-Object system.Windows.Forms.TextBox
$ImmediateOriginName.multiline = $false
$ImmediateOriginName.width = 325
$ImmediateOriginName.height = 27
$ImmediateOriginName.location = New-Object System.Drawing.Point(15,100)
$ImmediateOriginName.Font = 'Microsoft Sans Serif,11'
#region Immediate Origin Handlers
$ImmediateOrigin.Add_TextChanged( {
if ($ImmediateOrigin.Text -match "\d{8}") {
$result = Test-ABA -RoutingNumber $ImmediateOrigin.Text
if ($result.code -ne 200) {
# Invalid
$ErrorProvider.SetError($ImmediateOrigin, "$($result.code): $($result.message)");
$SuccessProvider.SetError($ImmediateOrigin, "")
} else {
# Valid
$SuccessProvider.SetError($ImmediateOrigin, $($result.customer_name))
$ErrorProvider.SetError($ImmediateOrigin, "")
$ImmediateOriginName.Text = $result.customer_name
$ODFI.Text = ($result.rn).substring(0,8)
}
} else {
# Invalid
$ErrorProvider.SetError($ImmediateOrigin, "Please use 9 Digit ABA routing number")
$SuccessProvider.SetError($ImmediateOrigin, "")
}
})
#endregion
# Immediate Destination
$ImmediateDestinationLabel = New-Object system.Windows.Forms.Label
$ImmediateDestinationLabel.text = "Imm. Destination Routing Number:"
$ImmediateDestinationLabel.AutoSize = $true
$ImmediateDestinationLabel.width = 25
$ImmediateDestinationLabel.height = 10
$ImmediateDestinationLabel.location = New-Object System.Drawing.Point(15,137)
$ImmediateDestinationLabel.Font = 'Microsoft Sans Serif,10'
$ImmediateDestination = New-Object system.Windows.Forms.TextBox
$ImmediateDestination.multiline = $false
$ImmediateDestination.width = 325
$ImmediateDestination.height = 27
$ImmediateDestination.location = New-Object System.Drawing.Point(15,160)
$ImmediateDestination.Font = 'Microsoft Sans Serif,11'
$ImmediateDestinationNameLabel = New-Object system.Windows.Forms.Label
$ImmediateDestinationNameLabel.text = "Imm. Destination Name:"
$ImmediateDestinationNameLabel.AutoSize = $true
$ImmediateDestinationNameLabel.width = 25
$ImmediateDestinationNameLabel.height = 10
$ImmediateDestinationNameLabel.location = New-Object System.Drawing.Point(15,197)
$ImmediateDestinationNameLabel.Font = 'Microsoft Sans Serif,10'
$ImmediateDestinationName = New-Object system.Windows.Forms.TextBox
$ImmediateDestinationName.multiline = $false
$ImmediateDestinationName.width = 325
$ImmediateDestinationName.height = 27
$ImmediateDestinationName.location = New-Object System.Drawing.Point(15,220)
$ImmediateDestinationName.Font = 'Microsoft Sans Serif,11'
#region Immediate Destination Handlers
$ImmediateDestination.Add_TextChanged( {
if ($ImmediateDestination.Text -match "\d{8}") {
$result = Test-ABA -RoutingNumber $ImmediateDestination.Text
if ($result.code -ne 200) {
# Invalid
$ErrorProvider.SetError($ImmediateDestination, "$($result.code): $($result.message)");
$SuccessProvider.SetError($ImmediateDestination, "")
}
else {
# Valid
$SuccessProvider.SetError($ImmediateDestination, $($result.customer_name))
$ErrorProvider.SetError($ImmediateDestination, "")
$ImmediateDestinationName.Text = $result.customer_name
}
}
else {
# Invalid
$ErrorProvider.SetError($ImmediateDestination, "Please use 9 Digit ABA routing number");
$SuccessProvider.SetError($ImmediateDestination, "")
}
})
#endregion
#endregion
#region Console Output Objects
$ConsoleOutput = New-Object system.Windows.Forms.TextBox
$ConsoleOutput.Multiline = $true
$ConsoleOutput.ReadOnly = $true
$ConsoleOutput.WordWrap = $false
$ConsoleOutput.ScrollBars = "Vertical"
$ConsoleOutput.width = 785 # 557
$ConsoleOutput.height = 645
$ConsoleOutput.Anchor = 'top,right'
$ConsoleOutput.location = New-Object System.Drawing.Point(400, 15)
$ConsoleOutput.Font = 'Consolas,10'
$ConsoleOutputSelectAllButton = New-Object System.Windows.Forms.Label
$ConsoleOutputSelectAllButton.Text = "Select All"
$ConsoleOutputSelectAllButton.Width = 75
$ConsoleOutputSelectAllButton.Height = 20
$ConsoleOutputSelectAllButton.location = New-Object System.Drawing.Point(1115, 662)
$ConsoleOutputSelectAllButton.Font = 'Microsoft Sans Serif,11'
$ConsoleOutputSelectAllButton.ForeColor = 'Gray'
$ConsoleOutputSelectAllButton.Add_Click( {
# Set focus to console output box
$ConsoleOutput.Focus();
# Select all text
$ConsoleOutput.SelectAll()
})
# Event Handlers for select all button underline style
$ConsoleOutputSelectAllButton.Add_MouseEnter( {
$ConsoleOutputSelectAllButton.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 11, [System.Drawing.FontStyle]::Underline)
})
$ConsoleOutputSelectAllButton.Add_MouseLeave( {
$ConsoleOutputSelectAllButton.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 11, [System.Drawing.FontStyle]::Regular)
})
#endregion
#region Progress Bar Objects
$ProgressLabel = New-Object system.Windows.Forms.Label
$ProgressLabel.text = "Progress"
$ProgressLabel.AutoSize = $true
$ProgressLabel.width = 25
$ProgressLabel.height = 10
$ProgressLabel.location = New-Object System.Drawing.Point(15,688)
$ProgressLabel.Anchor = 'left,bottom'
$ProgressLabel.Font = 'Microsoft Sans Serif,10'
$ProgressBar = New-Object system.Windows.Forms.ProgressBar
$ProgressBar.text = "Progress"
$ProgressBar.width = 1085
$ProgressBar.height = 22
$ProgressBar.Anchor = 'right,bottom'
$ProgressBar.location = New-Object System.Drawing.Point(98,688)
$ProgressBar.Value = 0
#endregion
#region Verify and Logfile action buttons
$VerifyButton = New-Object system.Windows.Forms.Button
$VerifyButton.text = "Verify"
$VerifyButton.width = 170
$VerifyButton.height = 50
$VerifyButton.location = New-Object System.Drawing.Point(25,610)
$VerifyButton.Font = 'Microsoft Sans Serif,10'
$VerifyButton.Add_Click({
if (-not $ACHInputFilePath.Text) {
$ErrorProvider.SetError($ACHInputFilePath, "Field required")
$SuccessProvider.SetError($ACHInputFilePath, "")
} else {
$verifyACHParams = @{
ACHFileName = $ACHInputFilePath.Text
OutputFolder = $WorkingDirectory.Text
FileHeader = @{
immediate_destination = $ImmediateDestination.Text
immediate_destination_name = $ImmediateDestinationName.Text
immediate_origin = $ImmediateOrigin.Text
immediate_origin_name = $ImmediateOriginName.Text
}
RunFromGUI = $true
}
if ($PatchFile.Checked) {
$verifyACHParams.Patch = $True
}
$verifyACHParams
.\Verify-ACH.ps1 @verifyACHParams
$ach_file_object = Get-ChildItem $ACHInputFilePath.Text | Select *
$ConsoleOutput.Lines = (Get-Content $([string]$WorkingDirectory.Text + '\' + [string]$ach_file_object.basename + '_Fixed.ach'))
$ShowLogfileButton.Enabled = $true
$ProgressBar.Value = 0
}
})
$ShowLogfileButton = New-Object system.Windows.Forms.Button
$ShowLogfileButton.text = "Show Logfile"
$ShowLogfileButton.width = 170
$ShowLogfileButton.height = 50
$ShowLogfileButton.enabled = $false
$ShowLogfileButton.location = New-Object System.Drawing.Point(215,610)
$ShowLogfileButton.Font = 'Microsoft Sans Serif,10'
#endregion
$ACHVerificationTool.controls.AddRange(@($ProgressBar, $Title, $FilePanel, $ConsoleOutput, $ACHControlSettingsPanel, $VerifyButton, $ProgressLabel, $ShowLogfileButton, $ConsoleOutputSelectAllButton))
$FilePanel.controls.AddRange(@($ACHInputFilePathLabel,$ACHInputFilePath,$WorkingDirectoryLabel,$WorkingDirectory,$ACHInputFilePathButton,$WorkingDirectoryButton,$PatchFile,$LogBasic,$LogFull,$LogNone))
$ACHControlSettingsPanel.controls.AddRange(@($ImmediateOriginNameLabel, $ImmediateOriginName, $ODFILabel, $ODFI, $ImmediateOriginLabel, $ImmediateOrigin, $ImmediateDestinationNameLabel, $ImmediateDestinationName, $ImmediateDestinationLabel, $ImmediateDestination))
#region Error Validation Controls
# Add Validation Control
$ErrorProvider = New-Object System.Windows.Forms.ErrorProvider
$ErrorProvider.BlinkStyle = [System.Windows.Forms.ErrorBlinkStyle]::NeverBlink;
$ErrorProvider.Icon = "$(Split-Path -Parent $PSCommandPath)\img\Papirus-Team-Papirus-Status-Dialog-warning.ico"
$SuccessProvider = New-Object System.Windows.Forms.ErrorProvider
$SuccessProvider.BlinkStyle = [System.Windows.Forms.ErrorBlinkStyle]::NeverBlink;
$SuccessProvider.Icon = "$(Split-Path -Parent $PSCommandPath)\img\Paomedia-Small-N-Flat-Sign-check.ico"
#endregion
$ACHVerificationTool.Add_FormClosing( {
[xml]$ConfigFile = Get-SettingsFile
$application_path = "$env:userprofile\AppData\Local\POSHTools\Verify-ACH\config"
$config_path = $application_path + '\PreviousParameters.xml'
# FILE SETTINGS
$ConfigFile.Settings.Files.Input = '' # Set-NullString $ACHInputFilePath.Text
$ConfigFile.Settings.Files.Output = Set-NullString $WorkingDirectory.Text
$ConfigFile.Settings.Files.Patch = if ($PatchFile.Checked -eq $true) { '1' } else { '0' }
$ConfigFile.Settings.Files.Logging = if ($LogFull.Checked -eq $true) { 'Full' } elseif ($LogBasic.Checked -eq $true) { 'Basic' } else { 'None' } # 'Full'
# ACH CONTROL SETTINGS
# Originator
$ConfigFile.Settings.ACH.Origin.Routing = Set-NullString $ImmediateOrigin.Text
$ConfigFile.Settings.ACH.Origin.Name = Set-NullString $ImmediateOriginName.Text
$ConfigFile.Settings.ACH.Origin.DFI = Set-NullString $ODFI.Text
# Destination
$ConfigFile.Settings.ACH.Destination.Routing = Set-NullString $ImmediateDestination.Text
$ConfigFile.Settings.ACH.Destination.Name = Set-NullString $ImmediateDestinationName.Text
# SAVE FILE
$ConfigFile.Save($config_path) | Out-Null
})
$ACHVerificationTool.Add_Load({
[xml]$ConfigFileLoad = Get-SettingsFile
$ACHInputFilePath.Text = $ConfigFileLoad.Settings.Files.Input
$WorkingDirectory.Text = $ConfigFileLoad.Settings.Files.Output
$PatchFile.Checked = if ($ConfigFileLoad.Settings.Files.Patch -eq '1') { $true } else { $false }
if ($ConfigFileLoad.Settings.Files.Logging -eq 'Full') {
$LogFull.Checked = $true
} elseif ($ConfigFileLoad.Settings.Files.Logging -eq 'Basic') {
$LogBasic.Checked = $true
} else {
$LogNone.Checked = $true
}
$ImmediateOrigin.Text = $ConfigFileLoad.Settings.ACH.Origin.Routing
$ImmediateOriginName.Text = $ConfigFileLoad.Settings.ACH.Origin.Name
$ODFI.Text = $ConfigFileLoad.Settings.ACH.Origin.DFI
$ImmediateDestination.Text = $ConfigFileLoad.Settings.ACH.Destination.Routing
$ImmediateDestinationName.Text = $ConfigFileLoad.Settings.ACH.Destination.Name
})
$ACHVerificationTool.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true })) | Out-Null