用户提交请求后重置 Powershell 表单
Reset Powershell Form after User Submits Request
在用户成功提交他们的请求后,我如何才能获得 reset/close 的表单?我正在使用 Powershell ise 进行测试,在我真正退出之前,脚本永远不会关闭。这是我当前的功能。
多亏了这个论坛上的人们,我的表格才能正常工作。我还有另一个问题正在努力解决。如何在用户点击提交按钮后重置表单?我目前必须退出表单才能结束脚本。
#region gui events {
$btn1.Add_Click({ sendRequest; thankyou })
#endregion events }
#endregion GUI }
function sendRequest()
{
# API Key
$FDApiKey="api key"
#################################################
# Force TLS1.2 as Powershell defaults to TLS 1.0 and Freshdesk will fail connections
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
# Prep
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
##################################################
$Body = @{
description = $description.Text
email = $email.Text
subject = $subject.Text
type = $request.Text
priority = 1
status = 2
}
Invoke-WebRequest "https://clasd.freshdesk.com/api/v2/tickets/" `
-Headers $FDHeaders `
-ContentType "application/json" `
-Method Post `
-Body ($Body | ConvertTo-JSON)
}
function thankyou ()
{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
}
#Write your logic code here
[void]$Form.ShowDialog()
如果没有看到表单上的所有控件,就不可能真正为您提供完整的代码,但这应该能为您提供基本的思路。
function thankyou{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
$description.Text = ''
$email.Text = ''
$subject.Text = ''
$request.Text = ''
}
这是单击按钮后关闭表单的简单示例。
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({$form.Close()}) #add any other logic you require to the button click's anonymous function
$form.Controls.Add($button)
$form.ShowDialog()
要动态访问按钮的表单,而不是传递对表单的实际引用,您可以这样做:
function OnButtonClick {
$theForm = $this.Parent
$theForm.DialogResult = [System.Windows.Forms.DialogResult]::OK
$theForm.Close()
}
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({OnButtonClick})
$form.Controls.Add($button)
$form.ShowDialog()
在用户成功提交他们的请求后,我如何才能获得 reset/close 的表单?我正在使用 Powershell ise 进行测试,在我真正退出之前,脚本永远不会关闭。这是我当前的功能。
多亏了这个论坛上的人们,我的表格才能正常工作。我还有另一个问题正在努力解决。如何在用户点击提交按钮后重置表单?我目前必须退出表单才能结束脚本。
#region gui events {
$btn1.Add_Click({ sendRequest; thankyou })
#endregion events }
#endregion GUI }
function sendRequest()
{
# API Key
$FDApiKey="api key"
#################################################
# Force TLS1.2 as Powershell defaults to TLS 1.0 and Freshdesk will fail connections
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
# Prep
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
##################################################
$Body = @{
description = $description.Text
email = $email.Text
subject = $subject.Text
type = $request.Text
priority = 1
status = 2
}
Invoke-WebRequest "https://clasd.freshdesk.com/api/v2/tickets/" `
-Headers $FDHeaders `
-ContentType "application/json" `
-Method Post `
-Body ($Body | ConvertTo-JSON)
}
function thankyou ()
{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
}
#Write your logic code here
[void]$Form.ShowDialog()
如果没有看到表单上的所有控件,就不可能真正为您提供完整的代码,但这应该能为您提供基本的思路。
function thankyou{
[System.Windows.Forms.MessageBox]::Show("Your ticket has been submitted!" , "Status")
$description.Text = ''
$email.Text = ''
$subject.Text = ''
$request.Text = ''
}
这是单击按钮后关闭表单的简单示例。
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({$form.Close()}) #add any other logic you require to the button click's anonymous function
$form.Controls.Add($button)
$form.ShowDialog()
要动态访问按钮的表单,而不是传递对表单的实际引用,您可以这样做:
function OnButtonClick {
$theForm = $this.Parent
$theForm.DialogResult = [System.Windows.Forms.DialogResult]::OK
$theForm.Close()
}
$form = [System.Windows.Forms.Form]::new()
$button = [System.Windows.Forms.Button]::new()
$button.Text = "click me quick"
$button.Add_Click({OnButtonClick})
$form.Controls.Add($button)
$form.ShowDialog()