添加前重复检查
本文关键字:检查 添加 | 更新日期: 2023-09-27 18:06:45
我向大家道歉。
谢谢大家。
似乎我漏掉了一个愚蠢的变量,我甚至没有注意到。我以为是我的检查坏了,但是没有,我在上面的方法中错过了一个变量,所以它只是不断地说,是的,这是真的-。-谢谢大家的帮助
您必须在每次检查后添加return;
。因为现在你做了检查,但之后没有什么能阻止你的代码执行。你必须这样做:
protected void BoxReceivedClick(object sender, EventArgs e)
{
if (lblSupporterId.Text == "")
{
lblNotRawConsignmentNumber.Text = "Cannot Insert! Missing SupporterId";
return;
}
else if (lblConsignmentNumber.Text == "")
{
lblNotRawConsignmentNumber.Text = "Cannot Insert! Missing Consignment Number";
return;
}
else if (lblCollectionRequestId.Text == "")
{
lblNotRawConsignmentNumber.Text = "Cannot Insert! Missing Collection Request ID";
return;
}
else if (Istest())
{
return;
}
InsertItemIntoReceivedBoxesTable(lblSupporterId.Text, txtReferenceNumber.Text, lblCollectionRequestId.Text);
BindReceivedBoxes();
ClearLabels();
}
实际上您的Istest()
方法在没有发现重复时返回true
,而false
否则:
return !isDuplicate;
从return语句中删除!
Dennis_E的回答是正确的。代码"lblNotRawConsignmentNumber"周围应该有大括号。Text = "BLAH";打破;"。方法IeTest()
将在第一次返回true,然后一直返回false。
在您的程序中,您检查单元格是否不匹配新值,然后将true
分配给isDuplicate
。然后将Dupe Test值分配给lblNotRawConsignmentNumber
if (lblConsignmentNumber.Text != gvReceivedBoxes.Rows[i].Cells[3].Text)
{
isDuplicate = true;
lblNotRawConsignmentNumber.Text = "Dupe Teset";
break;
}
尝试如下:
if (lblConsignmentNumber.Text == gvReceivedBoxes.Rows[i].Cells[3].Text)
{
isDuplicate = true;
lblNotRawConsignmentNumber.Text = "Dupe Teset";
break;
}