EMS單號規律與順豐單號規律(C#)

來源:互聯網
上載者:User
 /// <summary>        /// 擷取EMS物流單號        /// </summary>        /// <param name="strNo">當前物流單號</param>        /// <returns></returns>        public static string GetNewEmsNo(string strNo)        {            try            {                string fri = "";                int res;                int num3, num4, num5, num6, num7, num8, num9, num0;                int mid;                string strZero = "00000000";                fri = (Convert.ToUInt32(strNo.Substring(2, 8)) + 1).ToString();                //不足零自動補零                //if (fri.Length < 8)                //{                //    string strTmp = strZero + fri;                //    fri = strTmp.Substring(strTmp.Length - 8);                //}                fri=fri.PadLeft(8, '0');                num3 = Convert.ToInt32(fri.Substring(0, 1));                num4 = Convert.ToInt32(fri.Substring(1, 1));                num5 = Convert.ToInt32(fri.Substring(2, 1));                num6 = Convert.ToInt32(fri.Substring(3, 1));                num7 = Convert.ToInt32(fri.Substring(4, 1));                num8 = Convert.ToInt32(fri.Substring(5, 1));                num9 = Convert.ToInt32(fri.Substring(6, 1));                num0 = Convert.ToInt32(fri.Substring(7, 1));                mid = 8 * num3 + 6 * num4 + 4 * num5 + 2 * num6 + 3 * num7 + 5 * num8 + 9 * num9 + 7 * num0;                res = 11 - (mid) % (11);                if (res == 10)                    res = 0;                if (res == 11)                    res = 5;                string strHead = strNo.Substring(0, 2);                if (!IsLetter(strHead))                {                    throw new Exception("EMS單號前2位不為字母");                }                string strEnd = strNo.Substring(strNo.Length - 2);                if (!IsLetter(strEnd))                {                    throw new Exception("EMS單號末2位不為字母");                }                string strEMSres = (strHead + fri + res.ToString() + strEnd);                return strEMSres;            }            catch (Exception ex)            {                MessageForm.Error(ex.Message);                return string.Empty;            }        }    /// <summary>        /// 擷取順豐物流單號        /// </summary>        /// <param name="strNo"></param>        /// <returns></returns>        public static string GetNewShunfengNo(string strNo)        {            try            {                if (strNo.Length != 12)                {                    throw new Exception("順豐單號為12位,請檢測單號是否正確");                }                string fri, Nfri, Yuandanhao, strNewNo;                int num9, num10, num11, num12;                int Nnum9, Nnum12;                int iIndex = 8;                fri = strNo.Substring(0, 11);                Yuandanhao = strNo;                Nfri = (Convert.ToInt64(fri) + 1).ToString().PadLeft(11,'0');                num9 = Convert.ToInt32(Yuandanhao.Substring(iIndex++, 1));                num10 = Convert.ToInt32(Yuandanhao.Substring(iIndex++, 1));                num11 = Convert.ToInt32(Yuandanhao.Substring(iIndex++, 1));                num12 = Convert.ToInt32(Yuandanhao.Substring(iIndex++, 1));                iIndex = 8;                Nnum9 = Convert.ToInt32(Nfri.Substring(iIndex++, 1));                if ((Nnum9 - num9 == 1) && ((num9) % (2) == 1))                {                    if (num12 - 8 >= 0)                        Nnum12 = num12 - 8;          // -8                    else                        Nnum12 = num12 - 8 + 10;                }                else if ((Nnum9 - num9 == 1) && ((num9) % (2) == 0))                {                    if (num12 - 7 >= 0)                        Nnum12 = num12 - 7;         // -7                    else                        Nnum12 = num12 - 7 + 10;                }                else                {                    if (((num10 == 3) || (num10 == 6)) && (num11 == 9))                    {                        if (num12 - 5 >= 0)                            Nnum12 = num12 - 5;            // -5                        else                            Nnum12 = num12 - 5 + 10;                    }                    else if (num11 == 9)                    {                        if (num12 - 4 >= 0)                            Nnum12 = num12 - 4;          // -4                        else                            Nnum12 = num12 - 4 + 10;                    }                    else                    {                        if (num12 - 1 >= 0)                            Nnum12 = num12 - 1;           // -1                        else                            Nnum12 = num12 - 1 + 10;                    }                }                return strNewNo = Nfri + Nnum12.ToString();            }            catch (Exception ex)            {                throw ex;                            }                    }  public static bool IsLetter(string str)        {            foreach (char c in str)            {                if (!char.IsLetter(c))                {                    return false;                }            }            return true;        }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.