Private Function StoreCouponCode() As String
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString)
Dim sql As New SqlCommand("", con)
Dim sqlGetSlNo As New SqlCommand("SELECT MAX(SlNo) FROM Coupons WHERE CustID=" & Convert.ToInt16(HFCustID.Value) & " AND BusiID=" & Convert.ToInt16(HFBusiID.Value) & " AND OfferID=" & Convert.ToInt16(HFOfferID.Value), con)
Dim sNo, UserID, couponCode, offerCheck As String
Dim slNo As Int16
Try
UserID = getCurrentUserID()
con.Open()
sNo = Convert.ToString(sqlGetSlNo.ExecuteScalar) 'fteches latest serial no for the coupon
If sNo = "" Then
slNo = 0
Else
slNo = Convert.ToInt16(sNo) + 1
End If
couponCode = MakeCouponCode(slNo)
offerCheck = couponCode.Substring(13, 3)
sql.CommandText = "INSERT INTO Coupons VALUES (" & _
HFCustID.Value & "," & HFBusiID.Value & "," & HFOfferID.Value & ",'" & _
Today.Date & "'," & Convert.ToString(slNo) & "," & offerCheck & ",'" & couponCode & "','" & _
UserID & "'," & LblPayInAdv.Text & "," & LblPayLater.Text & ",'" & Convert.ToString(Date.Now) & "')"
sql.ExecuteNonQuery()
con.Close()
Catch ex As Exception
couponCode = "N/A"
Finally
con.Dispose()
sql.Dispose()
End Try
Return couponCode
End Function
Protected Sub CmdGetCoupon_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CmdGetCoupon.Click
If User.Identity.Name = "" Then
LblMessage.Text = "You need to login first!"
Exit Sub
End If
Dim couponCode As String = StoreCouponCode()
Response.Redirect("~/Coupon.aspx?CouponCode=" & couponCode, True)
End Sub
Run Code Online (Sandbox Code Playgroud)
当用户点击CmdGetCoupon它时需要一些时间来重定向CmdGetCoupon.. 所以用户点击多次,这导致从单个用户帐户生成多个优惠券.
我想显示一条消息"请等待你的优惠券正在生成"并禁用,CmdGetCoupon以便用户不能多次点击....任何想法??如何做到这一点?
在javascript中执行此操作 - 使用OnClientClick调用禁用传入的表单元素的函数.
// On button
... OnClientClick="DisableMe(this);" ...
// Javascript
function DisableMe(elem)
{
elem.disabled = true;
// more code to show message
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2690 次 |
| 最近记录: |