Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friend,
i have number that is generate for every users when user open the page
1st one is IMP-20120505-1(imp(any word)+now-a day+ 1(last record or when table is empity or days first entry))
i want to that id is generate different for users on this page when user open the page
like
IMP-20120505-1
IMP-20120505-2
IMP-20120505-3
IMP-20120505-4
next day
IMP-20120506-1
IMP-20120506-2
like this
if u have any idea about that plz ans me..
Posted

1 solution

create any class in your project.
put this static member in this class

C#
public class AnyClass
    {
        public static int ind = 0;
        public static string lastDay = "";
    }


add your asp.net project a global.asax file

and configure your application_start and session_start area

C#
protected void Application_Start(object sender, EventArgs e)
       {
           AnyClass.lastDay = DateTime.Now.ToShortDateString();
       }

       protected void Session_Start(object sender, EventArgs e)
       {
           string toDay = DateTime.Now.ToShortDateString();

           // this will work only one times in a day. hour check the time after a new day. AnyClass.lastDay != toDay check if your computer time is am and pm. i didnt test clearly but i hope this will help you.
           if (DateTime.Now.Hour == 0 && (AnyClass.lastDay != toDay) && AnyClass.ind != 0)
           {
               AnyClass.ind = 0;
               AnyClass.lastDay = toDay;
           }
           AnyClass.ind++;
       }

dont forget this will took in session. you can manage your sessions time in web.config file or under iis.

call your AnyClass.ind in your project anywhere
 
Share this answer
 
v2

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