gpt4 book ai didi

powershell - Powershell错误验证

转载 作者:行者123 更新时间:2023-12-03 07:54:12 25 4
gpt4 key购买 nike

Function Button_Click()
{
Param([Parameter(Mandatory=$True)]

$telephone,
$calledtoSee,
$wantstoSeeyou,
$pleaseCall,
$willcallAgain,
$returningYourCall,
$ToSelection,
$from,
$telephoneNumber,
$message)


[boolean]$okayContinue=$true
[string]$radioSelectedText
[string]$comboBoxSectionText
[string]$persontoEmail
$callType
$messageCount

$comboBoxSectionText = $ToSelection.GetItemText($ToSelection.SelectedItem)


if($okayContinue){

if($comboBoxSectionText -eq "Please Select Contact"){
[System.Windows.Forms.MessageBox]::Show("Please Select Recipient")
$okayContinue=$false

}

}

if($okayContinue){

if([string]::IsNullOrWhiteSpace($from.Text)){
[System.Windows.Forms.MessageBox]::Show("Please Enter Who The Message is From")
$from.focus()
$okayContinue=$false
}
}

if($okayContinue){

if([string]::IsNullOrWhiteSpace($telephoneNumber.Text)){
[System.Windows.Forms.MessageBox]::Show("Please Enter Telephone Number")
$telephoneNumber.focus()
$okayContinue=$false
}
}
#######################################################################################################################################################

if($okayContinue){

if($telephone.Checked){
$callType = $telephone.Text
}
elseif($calledtoSee.Checked){
$callType = $calledtoSee.Text
}
elseif($wantstoSeeyou.Checked){
$callType = $wantstoSeeyou.Text
}
elseif($pleaseCall.Checked){
$callType= $pleaseCall.Text
}
elseif($willcallAgain.Checked){
$callType = $willcallAgain.Text
}
elseif($returningYourCall.Checked){
$callType = $returningYourCall.Text
}
else{
[System.Windows.Forms.MessageBox]::Show("Please Select Call Type")
$okayContinue=$false
}

}

if($okayContinue){

if([string]::IsNullOrWhiteSpace($message.Text)){

[System.Windows.Forms.MessageBox]::Show("Please Enter Message")
$okayContinue=$false
}


}





if($okayContinue){

$buildPerson=$comboBoxSectionText.Split(',')

$personObject = [pscustomobject]@{

FirstName = $buildPerson[0]
LastName = $buildPerson[1]
Email = $buildPerson[2]
}

$messageObject = [pscustomobject]@{

Message = $message.Text
MessageFor = $personObject
From = $from.Text
CallType = $callType
Telephone = $telephoneNumber.Text
}
}

我有一个带有6个单选按钮,2个文本框和一个组合框的表单。现在,在错误验证方面,我决定使用 bool(boolean) 值,并检查是否正确填充了文本框以及是否已选择收件人。填满所有内容后,将创建一个对象。

关于错误验证,我是否走上了正确的轨道?我可以更好地处理它吗?

最佳答案

如果要对验证进行完全编程控制,或者需要执行复杂的验证检查,则应使用大多数Windows窗体控件中内置的验证事件。每个接受自由格式用户输入的控件都有一个Validating事件,该事件在控件需要数据验证时发生。在“验证事件处理”方法中,您可以通过多种方式验证用户输入。看看Event-Driven Validation。还有更多的解释在这里:Extending Windows Forms with a Custom Validation

关于powershell - Powershell错误验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30460612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com