Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

I making one asp.net project for Indian Gas Cylinder Agency. Here A user can book gas


cylinder online. But here is one condition, a user can not book more than 9 cylinders in a year.


If he attempt to book a cylinder after 9th. He should get a message.


How to do this??
Posted

You will need to have these 2 fields in the table in addition to other fields:
1. number_cylinder (int type) assuming user can buy more than one per booking
2. date_of_booking (datetime type)
When a user submits a new booking, run a sql query to sum the number_cylinder by current year, see example:
select sum(number_cylinder) from bookingtable where userid="somevalue" 
and year(date_of_booking) = year(getdate()) 
 
Share this answer
 
v2
Comments
Rahul VB 8-Apr-14 8:58am    
perfect +5
Peter Leow 13-Apr-14 0:08am    
Thank you.
Amiet_Mhaske 13-Apr-14 8:46am    
Thanks a Lot Peter!!! It was really helpful for me..
Peter Leow 13-Apr-14 9:15am    
You are welcome.
Two Solution:
1.If you want new record every time for booking than:
Add a column name like BookingYear. Now every-time user book cylinder new entry will be made with current date's year in this column. Now run following query before saving or booking:

SQL
Select * from table1 where BookingYear = '2014'
(like for the year of 2014).

Now if the Rows.count for this query is greater than equal to 9, than show message.

2.If you want 1 row for a year then add column to table like 'CylinderBookCount'. Every time user make a book uodate this table by increasing the amount in this column.

Now before booking cylinder add check like

SQL
Select CylinderBookCount from table1 where UserID = 'CopyOrAnyUniqueIDOfUser' BookingYear = '2014' 


Now if this return column haveing value then greater than equal to 9, than show message.
 
Share this answer
 
Comments
Amiet_Mhaske 13-Apr-14 8:46am    
Thank You Puneet.. I really appreciated your help.
You should select all booking data from your database table for that user for that year then test the count, like in the next code where I am using EF:

C#
DateTime now = DateTime.Now;
var searchResults = dataContext.UserBookings.Where(c => c.UserID == userID && c.StartDate >= now);
//
if(searchResults.Count  + newAmount <= 9)
  return true; //You can enable the new order! 
 
Share this answer
 
Comments
Amiet_Mhaske 13-Apr-14 8:47am    
Thank you Rahul
Raul Iloc 13-Apr-14 13:54pm    
Welcome!
Hi Amiet_Mhaske,

Add a field in your table having name as BookingCounter.
When user wants to book one more then update this field.
Before update check whether this value is lesthan or equalto (<=) 9
if this condition then do the update.

Thanks,
Sibassis
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900