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);

                    }

                } 

            }

  • 相关阅读:
    php对象 构造方法的使用
    php面向对象 类常量的介绍
    php面向对象 $this的使用
    php 对象里面的属性 ||增删改查
    php实现图片上传完整版
    php 下载文件的例子
    php 学生信息表小项目 扩展模仿百度分页的完全实现
    前后端分离 解读
    java Class.forName() 方法详解
    spring MVC 注解详解
  • 原文地址:https://www.cnblogs.com/niunan/p/6889882.html
Copyright © 2011-2022 走看看