基础集成平台开发(系统编码生成方案)

在基础集成平台中加入编码生成方案,用户可以通过参数设置来决定该单据是否需要自动生成编码,编码流程如下:


编号生成算法如下:

/// <summary>
        /// 生成下一级编码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static String genNextCode(String code)
        {            

            Encoding unicode = Encoding.GetEncoding("Unicode");
            byte[] bytes = unicode.GetBytes(code);

            int i = bytes.Length - 2;
            bytes = caculate(bytes, i);
            return unicode.GetString(bytes);
        }

        /// <summary>计算进位</summary>
        /// <remarks>
        /// 单纯进位:
        /// 数字进位:1...9,10,11...99,100,101...999...
        /// 字母进位:A...Z,AA,AB...AZ,BA,BB,....BZ,...CZ...DC...ZZ,AAA,AAB...ZZZ
        /// 混合进位:
        /// 基本原理按照以上数字进位
        /// A1...A9,B0,B1...B9...Z9...AA0..AA1.. 
        /// </remarks>
        /// <param name="bytes"></param>
        /// <param name="i"></param>
        private static byte[] caculate(byte[] bytes, int i)
        {
            //0->48;9->57;a->97;z->122;A->65;Z->90
            switch (bytes[i])
            {
                case 57:
                    if (i == 0)
                    {
                        //增一位
                        bytes = new byte[bytes.Length + 2];
                        //第一位为1
                        bytes[0] = 49;
                        //其余为0
                        for (int n = 2; n < bytes.Length; n += 2)
                        {
                            bytes[n] = 48;
                        }
                        return bytes;
                         
                    }
                    else
                    {
                        //设为0,上移一位
                        bytes[i] = 48;
                        return caculate(bytes, i - 2);
                    }; 
                case 122:
                    if (i == 0)
                    {
                        //增一位
                        bytes = new byte[bytes.Length + 2];
                        //全部起始为A
                        for (int n = 0; n < bytes.Length; n += 2)
                        {
                            bytes[n] = 97;
                        }
                        return bytes;
                    }
                    else
                    {
                        //设为A,上移一位
                        bytes[i] = 97;
                        return caculate(bytes, i - 2);
                    }; 
                case 90:
                    if (i == 0)
                    {
                        //增一位
                        //增一位
                        bytes = new byte[bytes.Length + 2];
                        //全部起始为a
                        for (int n = 0; n < bytes.Length; n += 2)
                        {
                            bytes[n] = 65;
                        }
                        return bytes;
                    }
                    else
                    {
                        //设为A,上移一位
                        bytes[i] = 65;
                        return caculate(bytes, i - 2);
                    }; 
                default:
                    bytes[i] += 1;
                    return bytes; 

            } 
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bing Forever

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值