Hi All
I have a piece of code to create document numbers featuring, 4 variables.
Prefix, Suffix, NextNum and Length.
The first 3 are rather simple. In the past the 4th one I have hard coded but now it needs improvement. One answer is to use a switch statement to use one of a few options the user may have selected but that seems like bad coding.
Code:
list = fa.SelectList("select Prefix, Suffix, NextNum, Length from docnumbers where Form = 'Invoice' limit 1", list);
t0.Text = String.Format("{0}{2:000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]), list[3][0]);
I have hardcoded that 6 characters must be displayed but now I want it to get it from the Length variable in the database.
Any ideas?
Many thanks
Andrew
Edit: Switch would look like
list = fa.SelectList("select Prefix, Suffix, NextNum, Length from docnumbers where Form = 'Invoice' limit 1", list);
switch (list[3][0])
{
case 1:
t0.Text = String.Format("{0}{2:0}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 2:
t0.Text = String.Format("{0}{2:00}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 3:
t0.Text = String.Format("{0}{2:000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 4:
t0.Text = String.Format("{0}{2:0000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 5:
t0.Text = String.Format("{0}{2:00000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 6:
t0.Text = String.Format("{0}{2:000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 7:
t0.Text = String.Format("{0}{2:0000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 8:
t0.Text = String.Format("{0}{2:00000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 9:
t0.Text = String.Format("{0}{2:000000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
case 10:
t0.Text = String.Format("{0}{2:0000000000}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
default:
t0.Text = String.Format("{0}{2}{1}", list[0][0], list[1][0], Convert.ToInt32(list[2][0]));
break;
}