/// <summary>根据pbh生成下级的bh,自动+1,超过限制则返回文本
///
/// </summary>
/// <param name="pbh">父编号</param>
/// <param name="x">每一级编号的位数</param>
/// <returns></returns>
public string GenBH(string pbh, int x)
{
string sql = "select right(max(bh)," + x + ") from jfs_category where pbh=" + pbh;
MSSQLHelper h = new MSSQLHelper();
h.CreateCommand(sql);
string res = h.ExecuteScalar();
if (string.IsNullOrEmpty(res))
{
int a = 1;
if (pbh != "0")
{
return pbh + a.ToString("d" + x);
}
return a.ToString("d" + x);
}
else
{
int a = int.Parse(res) + 1;
int b = (int)Math.Pow(10, x);
if (a >= b)
{
return "编号超过限制!";
}
if (pbh != "0")
{
return pbh + a.ToString("d" + x);
}
return a.ToString("d" + x);
}
}
网友评论