C#生成顺丰快递单号

#region 获取顺丰下一个单号

/// <summary>

/// 获取顺丰下一个单号

/// </summary>

/// <param name="strCurrentNo">当前顺丰快递单号</param>

/// <returns></returns>

public static string GetSFNxtCode(string strCurrentNo)

{

    if (strCurrentNo.Length == 12)

    {

        string strNewBehindFirstBit = string.Empty;

        string strFrontElevenBits = strCurrentNo.Substring(0, 11);

        string strBehindFirstBit = strCurrentNo.Substring(11, 1);

        string strBehindSecondBit = strCurrentNo.Substring(10, 1);

        string strBehindThirdBit = strCurrentNo.Substring(9, 1);

        if (strBehindSecondBit == "9")

        {

            switch (strBehindThirdBit)

            {

                /*倒数第三位0,1,2,4,5,7,8 跳转 4 */

                case "0":

                case "1":

                case "2":

                case "4":

                case "5":

                case "7":

                case "8":

                    strNewBehindFirstBit = MakeLastBit(strBehindFirstBit, 4);

                    break;

                /*倒数第三位 3,6 跳转 5 */

                case "3":

                case "6":

                    strNewBehindFirstBit = MakeLastBit(strBehindFirstBit, 5);

                    break;

                /*倒数第三位 9 跳转 7 */

                case "9":

                    strNewBehindFirstBit = MakeLastBit(strBehindFirstBit, 7);

                    break;

            }

        }

        else

        {

            strNewBehindFirstBit = MakeLastBit(strBehindFirstBit, 1);

 

        }

        int tempLength = strFrontElevenBits.Length;

        long temp = Convert.ToInt64(strFrontElevenBits) + 1;

        return ((temp.ToString().Length < tempLength) ? "0" + temp.ToString() : temp.ToString()) + strNewBehindFirstBit;

    }

    else

    {

        return string.Empty;

    }

}

 

private static string MakeLastBit(string strLastBit, int step)

{

    int temp = Convert.ToInt16(strLastBit);

    if ((temp - step) >= 0)

        return (temp - step).ToString();

    else

        return (10 + (temp - step)).ToString();

 

}

#endregion

来源: 谢斌个人博客C#生成顺丰快递单号
转载请以链接形式标明本文地址!本文地址:http://www.xb02.com/article/62/
发表评论

发表评论