我有一个文本框,其值来自用于生成随机数的 jquery 函数。现在我要做的是检查复选框的值(随机数)是否存在于数据库中。如果它存在于数据库生成的随机数不会发布在文本框中,而是会重新生成新的随机数,直到它产生一个尚未保存在数据库中的数字..
这是我的标记:
<p>
<label>Reference Code:</label>
<span class="field">
<asp:TextBox ID="GenerateCode" runat="server" CssClass="smallinput random" CausesValidation="True" Enabled="False"></asp:TextBox>
<asp:HiddenField ID="txthidden" runat="server" />
<br /><small style="color: red">Please write the code at the back of yours check</small>
</span>
</p>
这是我的jQuery函数:
function randomString()
{
var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var result = '';
for (var i = 8; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
function generateRandomNumber() {
var rndStr = randomString();
$("#<%=GenerateCode.ClientID%>").val(rndStr);
$("#<%=txthidden.ClientID%>").val(rndStr);
}
window.onload = function () {
generateRandomNumber();
}
这是我将其保存到数据库的方法:
string EchequeMaster = ClassEmailCheque.InsertEmailCheque(SenderID, Convert.ToInt32(ddlCurrency.SelectedIndex), Convert.ToDecimal(Amount.Text), ChequeNumber.Text, code2, PendingStatus, DateTime.Now);
这是 InsertEmailCheque 的代码:
string retEcheque = "";
string EchequeSQL = "INSERT INTO ServiceVirtualAccountEmailCheck (SenderID, CurrencyID, Amount, ChequeNo, ReferenceNo, Status, DateCreated) "
+ "VALUES (@SenderID, @CurrencyID, @Amount, @ChequeNo, @ReferenceNo, @Status, @DateCreated)";
string[] param = { "@SenderID", "@CurrencyID", "@Amount", "ChequeNo", "@ReferenceNo", "@Status", "@DateCreated" };
object[] paramVal = { SenderID, CurrencyID, Amount, ChequeNo, ReferenceNo, Status, DateCreated };
try
{
ClassDBQuery.ExecNonQuery(EchequeSQL, param, paramVal);
}
catch (Exception ex)
{
retEcheque = ex.Message;
}
return retEcheque;
请帮忙。。谢谢。。