If User cancel the ticket within one week of textbox2 (i.e Booking Date) date then 5% charge will be applicable of total ticket cost
I m working with Visual Studio 2008 ASp.NEt 3.5 VB
i have 2 textboxes in my VB.NET webform ..
textbox1 showing the todays date, time as 22-Dec-2010, 06:00:00 PM
Textbox2 showing the Booking Date, time of client assume 30-Dec-21010, 07:00:00 PM
I want ....
when user cancel the ticket before one week of textbox2 (i.e Booking Date) then no charge will be applicable
when user cancel the ticket within one week of textbox2 (i.e Booking Date) date then 5% charge will be applicable of total ticket cost
when user cancel the ticket within 3 Days of textbox2 (i.e Booking Date) date then 10% charge will be applicable of total ticket cost
开发者_JAVA百科How to do this using Vb.NET ?
This should get you started
Function CalcAmt(pDate1 As Date, pDate2 As Date,TicketPrice as Currency) As Currency
NumDays = DateDiff("d", pDate1, pDate2)
if NumDays >=7 then
CalcAmt = 0
elseif NumDays > 3 then
CalcAmt = 0.05 * TicketPrice
else
CalcAmt = 0.10 * TicketPrice
end if
End Function
Are you just asking how to compare dates in VB .NET? (I assume so, since the act of "charging the user" is kind of beyond the scope of what we can help you with.)
Try something like this (this was free-hand, I don't have a VB compiler handy, so it may not be completely perfect):
Dim currentDate As Date = DateTime.Parse(textbox1.Text)
Dim bookingDate As Date = DateTime.Parse(textbox2.Text)
Dim difference As Integer = bookingDate.Subtract(currentDate).Days
You can then check how many days difference
is to apply your logic. Keep in mind a few things:
- This is fragile code. Look into using
DateTime.TryParse
if you're not already familiar with it. What I have above is open to exceptions. - Please DO NOT rely on the values of the text boxes from the form for your date calculations. You can get the current date on the server, and you should have the booking date in a database or something on the server. Use those. The client can post any dates he or she feels like posting to avoid charges. User-submitted data is NEVER to be implicitly trusted.
精彩评论