c# 自动生成编号
作者:互联网
/// <summary>
/// 获取编号
/// </summary>
/// <param name="parentCode"></param>
/// <returns></returns>
public string GetCode(string parentCode)
{
string code = "0001";
string d = "D-";
string strcode = "";
BaseService<Sys_Dept> bs = new BaseService<Sys_Dept>();
List<Sys_Dept> list = bs.Query(p => p.Pid == parentCode, 1, " DeptCode Desc ");
if (list.Count > 0)
{
if (parentCode == "0")
{
var model = list.First();
var lastNum = model.DeptCode.Substring(model.DeptCode.Length - 4, 4);
strcode = d + ((Convert.ToInt32(lastNum) + 1).ToString().PadLeft(4, '0'));
}
else
{
var model = list.First();
var lastNum = model.DeptCode.Substring(model.DeptCode.Length - 4, 4);
strcode = parentCode + ((Convert.ToInt32(lastNum) + 1).ToString().PadLeft(4, '0'));
}
}
else
{
//初始化值
if (parentCode == "0")
{
strcode = d + code;
}
else
{
strcode = parentCode + code;
}
}
return strcode;
}
标签:string,c#,list,parentCode,生成,DeptCode,编号,model,strcode 来源: https://blog.csdn.net/qq_39895658/article/details/121167886