this is a good application for a windows service. you would have 3 (maybe 4) projects for your solution.
1. Web
2. Logic
3. Windows Service
4. Tests (if you run unit tests)
all the application and business logic is located in the Logic assembly. Web and Windows Service reference the Logic assembly.
add a timer to the windows service to fire every so many minutes/hours tracking the current date. when the date changes. roll the incrementing number.
thinking about the problem some more. you may be able to use a math equation to generate the ticket number instead of needing to reset the next number.
1st is significance required for the ticket number, or is this for convience? the system should track the timestamp of the ticket in a seperate property/object/column anyway. could you substitute either an autogenerated number or GUID instead of year-month_day-n_ticket_of_the_day. if you wanted to build some significance into the ticket number could you use seconds/milliseconds as yyyy-mmdd-XXXX? if so the following code would work.
Code:
public string GenerateTicketNumber()
{
DateTime today = DateTime.Today;
int millisecondsElaspsedToday = (DateTime.Now - today).TotalMilliseconds();
return string.Format("{0:yyyy}-{0:mmdd}-{1:000000000}", today, millisecondsElaspsedToday);
}
depending on how large of a system you have you may be able to use seconds. this assumes 2 tickets are not entered at the same time. low to moderate volume.
if this is viable. taking it one step further you wouldn't need to store the ticket number in the database, only the timestamp, the ticket number would be generated from the timestamp property.
Code:
public DateTime TimeStamp { get; set; }
public TicketNumber()
{
int millisecondsElaspsedThatDay = (TimeStamp - TimeStamp.Date).TotalMilliseconds();
return string.Format("{0:yyyy}-{0:mmdd}-{1:000000000}", TimeStamp, millisecondsElaspsedThatDay);
}
I may be way off the mark, not understanding the full requirements of the system. But I figured it's worth noting. no sense making the system more complicated than it needs to be.
Jason Meckley
Programmer
Specialty Bakers, Inc.