下面,我给出一段代码。里面具有完整的注释。
using System;
namespace BaseLayer
{
///
/// 单据编号,产生自增编号,如:入参为"DJ000002",将返回"DJ000003"
///
public class SheetNumber
{
///
/// 单据编号,产生自增编号,如:入参为"DJ000002",将返回"DJ000003"
///
///
///
public string NextNumber(string BaseNumber)
{
string NewNumber = "";//新值
int InNumber = 1;//进位
int PlaceValue;//位值
char[] No = BaseNumber.ToCharArray();
for(int i=BaseNumber.Length-1;i>=0;i--)
{
if(No[i]=='9' && InNumber==1)
{
InNumber=1;
NewNumber="0"+NewNumber;
}
else
if(InNumber==1 && No[i]>='0' && No[i]<'9')
{
PlaceValue=Int32.Parse(No[i].ToString());
PlaceValue=(InNumber+PlaceValue);
InNumber=0;
NewNumber=PlaceValue.ToString()+NewNumber;
}
else
{
InNumber=0;
NewNumber=No[i]+NewNumber;
}
}
if(BaseNumber==NewNumber)
NewNumber="0000000001";
return NewNumber;
}
}
}
OK。如果以后遇到要自己追加单据号码的话。这一段代码应该可能实现你的要求了吧?'