zoukankan      html  css  js  c++  java
  • 生成分类编号的方法

    用到了dapper,分类表结构:id,createtime,caname,bh,pbh,remark    

        /// <summary>生成分类表中分类编号</summary> 

            /// <param name="pbh">父编号</param>

            /// <param param name="x">每一级编号的位数</param>

            /// <returns></returns>

            public string GenBH(string pbh, int x)

            {

                string sql = "select right(max(bh)," + x + ") from category where pbh='" + pbh+"'";

                using (var connection = ConnectionFactory.GetOpenConnection())

                { 

                    string res = connection.QuerySingle<string>(sql);

                    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)

                        {

                            throw new Exception("编号超过限制!");

                        }

                        if (pbh != "0")

                        {

                            return pbh + a.ToString("d" + x);

                        }

                        return a.ToString("d" + x);

                    }

                } 

            }

  • 相关阅读:
    BZOJ 3505: [Cqoi2014]数三角形 数学
    BZOJ 3931: [CQOI2015]网络吞吐量 最大流
    BZOJ 4236: JOIOJI MAP
    BZOJ 4247 挂饰 背包DP
    hihocoder #1224 : 赛车 dfs
    hihocoder #1223 : 不等式 水题
    BZOJ 3224: Tyvj 1728 普通平衡树 treap
    uoj #31. 【UR #2】猪猪侠再战括号序列 贪心
    BZOJ 1005: [HNOI2008]明明的烦恼 Purfer序列 大数
    心跳回忆4 攻略
  • 原文地址:https://www.cnblogs.com/niunan/p/6889882.html
Copyright © 2011-2022 走看看