美文网首页
树形菜单编号生成方法

树形菜单编号生成方法

作者: niunan | 来源:发表于2017-02-27 23:36 被阅读126次
   /// <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);
        }
    }

相关文章

网友评论

      本文标题:树形菜单编号生成方法

      本文链接:https://www.haomeiwen.com/subject/sjitgttx.html