资源描述:
《ems单号规律与顺丰单号规律(c#)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//////获取EMS物流单号//////当前物流单号///publicstaticstringGetNewEmsNo(stringstrNo){try{stringfri="";intres;intnum3,num4,num5,num6,num7,num8,num9,num0;intmid;stringstrZero="00000000";fri=(Convert.ToUInt32(
2、strNo.Substring(2,8))+1).ToString();//不足零自动补零//if(fri.Length<8)//{//stringstrTmp=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.ToInt
3、32(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
4、+3*num7+5*num8+9*num9+7*num0;res=11-(mid)%(11);if(res==10)res=0;if(res==11)res=5;stringstrHead=strNo.Substring(0,2);if(!IsLetter(strHead)){thrownewException("EMS单号前2位不为字母");}stringstrEnd=strNo.Substring(strNo.Length-2);if(!IsLetter(strEnd)){thrownewException(
5、"EMS单号末2位不为字母");}stringstrEMSres=(strHead+fri+res.ToString()+strEnd);returnstrEMSres;}catch(Exceptionex){MessageForm.Error(ex.Message);returnstring.Empty;}}//////获取顺丰物流单号/////////publicstaticstr
6、ingGetNewShunfengNo(stringstrNo){try{if(strNo.Length!=12){thrownewException("顺丰单号为12位,请检测单号是否正确");}stringfri,Nfri,Yuandanhao,strNewNo;intnum9,num10,num11,num12;intNnum9,Nnum12;intiIndex=8;fri=strNo.Substring(0,11);Yuandanhao=strNo;Nfri=(Convert.ToInt64(fri)+1
7、).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、8;Nnum9=Convert.ToInt32(Nfri.Substring(iIndex++,1));if((Nnum9-num9==1)&&((num9)%(2)==1)){if(num12-8>=0)Nnum12=num12-8;//-8elseNnum12=num12-8+10;}elseif((Nnum9-num9==1)&&((num9)%(2)==0)){i