CODE to auto generate an alpha numeric id in C#
public string GetLatestOrderId()
{
string ReceivedId = string.Empty;
string displayString = string.Empty;
String query = "SELECT MAX(OrderReceivedNo) FROM [Order_Received]";
String data = DataManager.RunExecuteScalar(ConnectionString.Constr, query);
ReceivedId = data;
if (string.IsNullOrEmpty(ReceivedId))
{
ReceivedId = "OR0000";
}
int len = ReceivedId.Length;
string splitNo = ReceivedId.Substring(2, len - 2);
int num = Convert.ToInt32(splitNo);
num++;
displayString = ReceivedId.Substring(0, 2) + num.ToString("0000");
return displayString;
}
OR
public static IEnumerable<string> Numbers()
{
return Enumerable.Range(0xA0000, 0xFFFF9 - 0xA0000 + 1)
.Select(x => x.ToString("X"));
}
You could also have an id generator class:
public class IdGenerator
{
private const int Min = 0xA0000;
private const int Max = 0xFFFF9;
private int _value = Min - 1;
public string NextId()
{
if (_value < Max)
{
_value++;
}
else
{
_value = Min;
}
return _value.ToString("X");
}
}