delphi 实现顺丰单号、EMS 单号算法  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 实现顺丰单号、EMS 单号算法


//delphi 实现顺丰单号、EMS 单号算法(规则 规律)

function TForm1.EMS(EMSNo: string;num:integer):TStringList;

var

        fri:string;

        res:Integer;

        num3,num4,num5,num6,num7,num8,num9,num0:Integer;

        mid:Integer;

        I:integer;

        EMSres:TStringList;

begin

        EMSres:=TStringList.Create;

        fri:=Copy(EMSNo,3,8)  ;

        for i:=1 to  num do

        begin

          num3:=StrToInt(Copy(fri,1,1));

          num4:=StrToInt(Copy(fri,2,1));

          num5:=StrToInt(Copy(fri,3,1));

          num6:=StrToInt(Copy(fri,4,1));

          num7:=StrToInt(Copy(fri,5,1));

          num8:=StrToInt(Copy(fri,6,1));

          num9:=StrToInt(Copy(fri,7,1));

          num0:=StrToInt(Copy(fri,8,1));

          mid:= 8*num3+6*num4+4*num5+2*num6+3*num7+5*num8+9*num9+7*num0 ;

          res:=11-(mid)mod(11);

          if res=10 then

                res:=0;

          if res=11 then

                res:=5;

          EMSres.Add('EI'+fri+IntToStr(res)+'CN');

          fri:=IntToStr(strtoint(fri)+1);

        end;

        result:=EMSres;

end;


function TForm1.ShunFeng(ShunFengNo: string;num:integer):TStringList;

var

        fri,Nfri,Yuandanhao:string;

        res:Double;

        num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12:Integer;

        Nnum1,Nnum2,Nnum3,Nnum4,Nnum5,Nnum6,Nnum7,Nnum8,Nnum9,Nnum10,Nnum11,Nnum12:Integer;

        mid:Integer;

        I:integer;

        ShunFengres:TStringList;

begin

        ShunFengres:=TStringList.Create;

        fri:=Copy(ShunFengNo,1,11)  ;

        ShunFengres.Add(ShunFengNo);

        Yuandanhao:=ShunFengNo;

        for i:=1 to  num-1 do

        begin

          Nfri:=FloatToStr(StrToFloat(fri)+1);

          num1:=StrToInt(Copy(Yuandanhao,1,1));

          num2:=StrToInt(Copy(Yuandanhao,2,1));

          num3:=StrToInt(Copy(Yuandanhao,3,1));

          num4:=StrToInt(Copy(Yuandanhao,4,1));

          num5:=StrToInt(Copy(Yuandanhao,5,1));

          num6:=StrToInt(Copy(Yuandanhao,6,1));

          num7:=StrToInt(Copy(Yuandanhao,7,1));

          num8:=StrToInt(Copy(Yuandanhao,8,1));

          num9:=StrToInt(Copy(Yuandanhao,9,1));

          num10:=StrToInt(Copy(Yuandanhao,10,1));

          num11:=StrToInt(Copy(Yuandanhao,11,1));

          num12:=StrToInt(Copy(Yuandanhao,12,1));  //12????óD£??í11??£?ìí?óá???±?á?′?′¢?-ê??±


          Nnum1:=StrToInt(Copy(Nfri,1,1));

          Nnum2:=StrToInt(Copy(Nfri,2,1));

          Nnum3:=StrToInt(Copy(Nfri,3,1));

          Nnum4:=StrToInt(Copy(Nfri,4,1));

          Nnum5:=StrToInt(Copy(Nfri,5,1));

          Nnum6:=StrToInt(Copy(Nfri,6,1));

          Nnum7:=StrToInt(Copy(Nfri,7,1));

          Nnum8:=StrToInt(Copy(Nfri,8,1));

          Nnum9:=StrToInt(Copy(Nfri,9,1));

          Nnum10:=StrToInt(Copy(Nfri,10,1));

          Nnum11:=StrToInt(Copy(Nfri,11,1));

          if (Nnum9-num9=1) and ((num9)mod(2)=1)  then

          begin

            if   num12-8 >=0 then

               Nnum12:=num12-8             // -8

            else

               Nnum12:= num12-8 +10

          end

          else if (Nnum9-num9=1) and ((num9)mod(2)=0)  then

          begin

            if   num12-7 >=0 then

               Nnum12:=num12-7             // -7

            else

               Nnum12:= num12-7 +10

          end

          else

          begin

            if ((num10=3)or(num10=6))and(num11=9) then

            begin

              if   num12-5 >=0 then

                 Nnum12:=num12-5             // -5

              else

                 Nnum12:= num12-5 +10

            end

            else if   (num11=9) then

            begin

              if   num12-4 >=0 then

                 Nnum12:=num12-4             // -4

              else

                 Nnum12:= num12-4 +10

            end

            else

            begin

              if   num12-1 >=0 then

                 Nnum12:=num12-1            // -1

              else

                 Nnum12:= num12-1 +10

            end;

          end;

          ShunFengres.Add(Nfri+IntToStr(Nnum12));

          Yuandanhao:=Nfri+IntToStr(Nnum12);

          fri:=FloatToStr(StrToFloat(fri)+1);

        end;

        result:=ShunFengres;

end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.037439107894897 seconds