Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating a personal id for each user
    primarykey
    data
    text
    <p>Is there anyway I can generate a unique sequence number using c#.we are developing a website where we assign a personal id to each user at the time of registration... I need to generate a 14 digit string.</p> <pre><code>For eg. AA 01 201 210 22 AA 02 201 210 22 . . AA 99 201 210 22 then it should start from AB 01 201 210 22 AB 02 201 210 22 and so on... Last 8 digits are current date... Thanks.... private string ConvertDecString(int value) { string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string retVal = string.Empty; int remainder = 0; do { remainder = value % 26; retVal = CHARS.Substring(remainder, 1) + retVal; value = (value / 26) - 1; } while ((value + 1) &gt; 0); return retVal; } public string GetCurrentDate() { string todaydate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString(); return todaydate; } private Random _random = new Random(); public int RadomNum() { return _random.Next(10, 99); } private string GetActualDate() { string Year = System.DateTime.Now.Year.ToString(); string ActualDate1 = Year + GetProperMonth() + GetProperDay(); int n = Convert.ToInt32(ActualDate1); string ActualDate = String.Format("{0:000 000 00}", n); return ActualDate; } private string GetProperMonth() { string Month = System.DateTime.Now.Month.ToString(); string MonthNo = ""; if (Month == "1") { MonthNo = "01"; } else if (Month == "2") { MonthNo = "02"; } else if (Month == "3") { MonthNo = "03"; } else if (Month == "4") { MonthNo = "04"; } else if (Month == "5") { MonthNo = "05"; } else if (Month == "6") { MonthNo = "06"; } else if (Month == "7") { MonthNo = "07"; } else if (Month == "8") { MonthNo = "08"; } else if (Month == "9") { MonthNo = "09"; } else { MonthNo = Month; } return MonthNo; } private string GetProperDay() { string Day = System.DateTime.Now.Day.ToString(); string DayNo = ""; if (Day == "1") { DayNo = "01"; } else if (Day == "2") { DayNo = "02"; } else if (Day == "3") { DayNo = "03"; } else if (Day == "4") { DayNo = "04"; } else if (Day == "5") { DayNo = "05"; } else if (Day == "6") { DayNo = "06"; } else if (Day == "7") { DayNo = "07"; } else if (Day == "8") { DayNo = "08"; } else if (Day == "9") { DayNo = "09"; } else { DayNo = Day; } return DayNo; } public string GeneratePatientNumber(string Alpha) { return ConvertDecString(Convert.ToInt16(Alpha)) + " " + RadomNum() + " " + GetActualDate(); } GeneratePatientNumber(string Alpha) - this method generates 12 digit personal id... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload