无论如何我可以使用c#生成一个唯一的序列号。我们正在开发一个网站,我们在注册时为每个用户分配一个个人ID......我需要生成一个14位数字的字符串。
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) > 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...