取单据编号
string djbh="";
var data = db.z_ygzz.OrderByDescending(zz => zz.ygzzid).Take(1);
djbh = data.Select(d => d.djbh).FirstOrDefault();
先从数据库中查找最大id号,再找对应的djbh,最后调用方法NextNumber找下一位单据编号
public static string NextNumber(string BaseNumber,string firstValue)
{
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 = firstValue ;
return NewNumber;
}