Hi All,
I want to generate a number series which contains both letters and digits. And it should be generated automatically.
Ex:- Assume we have 3 codes--> APR BDL JAF
Then number series should be APR000001, APR00002, APR00003...........
BDL00001,BDL00002.........
It's like a receipting number series. Under these numbers, records will be saved. And I want to save this series in the sql database.
How can I do this......???
Should I do this in coding or can I do this using SQL....???
I'm using VS2008, C# language, SQL 2005
It's a big help if u can help me....
Loading
Manoj KieanPosted Jun 25, 2009, 6:47 AM
{
char[] c = input.ToCharArray();
string output;
string sDigitValue = new string(c);
string sDefineValue = sDigitValue.Substring(1, 3);
string sFirstChar = sDigitValue.Substring(0, 1);
int i = c.Length - 1;
bool overflow = false;
bool nextdigit = false;
do
{
if (i < 0)
{
nextdigit = true;
overflow = false;
}
else if (sDefineValue.ToString().ToUpper() == "9ZZ")
{
lblMessage.Text = "Code Limit Exceeds...Consult System Admin.";
break;
}
else
{
int isIntValue;
bool isNumeric = int.TryParse(sDefineValue, out isIntValue);
if (isNumeric == true)
{
if (Convert.ToInt32(sDefineValue) == 999)
{
sDefineValue = "9A0";
output = sFirstChar + sDefineValue;
return output;
}
else
{
isIntValue = Convert.ToInt32(sDefineValue) + 1;
output = sFirstChar + isIntValue.ToString("000");
return output;
}
}
else
{
c[i]++;
if (c[i] == ':')
{
c[i] = 'A'; // jump from ":" to "A" in ascii table
}
if (c[i] > 'Z')
{
// roll over to next digit
c[i] = '0';
overflow = true;
i--;
}
else
{
overflow = false;
}
}
}
}
while (overflow);
if (nextdigit)
{
output = String.Concat("1", new string(c));
}
else
{
output = new string(c);
}
return output;
}
In Button Click Call this Function