using System;
namespace NewsDataTransceiver
{
/// <summary>
/// MakeCode 的摘要说明。
/// 根据输入的数字计算 4 位数的标识串,本函数保证输入数字在 0 - 1500625(5位:60466175) 之内不出现重复串
/// 输入的数字,最好使用自动增加的ID,或者随机数.
/// 使用的时候应该修改命名空间 NewsDataTransceiver
/// </summary>
public class MakeCode
{
public static string MakeCodeStr(long Num)
{
//
// TODO: 在此处添加构造函数逻辑
//
long Num1,Num2,Num3,Num4;
Num1 = Num % 35;
Num2 = ((int)(Num / 35)) % 35 ;
Num3 = ((int)(Num / 1225)) % 35;
Num4 = ((int)(Num / 42875)) % 35;
//Num5=(Num \ 1500625) Mod 35
return GetNumStr(Num4) + GetNumStr(Num3) + GetNumStr(Num2) + GetNumStr(Num1);
}
public static string GetNumStr(long Num)
{
switch(Num)
{
case 0:
return "K";
case 1:
return "Z";
case 2:
return "S";
case 3:
return "5";
case 4:
return "H";
case 5:
return "A";
case 6:
return "P";
case 7:
return "9";
case 8:
return "N";
case 9:
return "7";
case 10:
return "6";
case 11:
return "2";
case 12:
return "G";
case 13:
return "0";
case 14:
return "B";
case 15:
return "D";
case 16:
return "C";
case 17:
return "F";
case 18:
return "1";
case 19:
return "J";
case 20:
return "I";
case 21:
return "W";
case 22:
return "E";
case 23:
return "3";
case 24:
return "R";
case 25:
return "V";
case 26:
return "X";
case 27:
return "L";
case 28:
return "4";
case 29:
return "M";
case 30:
return "Y";
case 31:
return "Q";
case 32:
return "8";
case 33:
return "T";
case 34:
return "U";
default:
return "Z";
}
}
}
}
namespace NewsDataTransceiver
{
/// <summary>
/// MakeCode 的摘要说明。
/// 根据输入的数字计算 4 位数的标识串,本函数保证输入数字在 0 - 1500625(5位:60466175) 之内不出现重复串
/// 输入的数字,最好使用自动增加的ID,或者随机数.
/// 使用的时候应该修改命名空间 NewsDataTransceiver
/// </summary>
public class MakeCode
{
public static string MakeCodeStr(long Num)
{
//
// TODO: 在此处添加构造函数逻辑
//
long Num1,Num2,Num3,Num4;
Num1 = Num % 35;
Num2 = ((int)(Num / 35)) % 35 ;
Num3 = ((int)(Num / 1225)) % 35;
Num4 = ((int)(Num / 42875)) % 35;
//Num5=(Num \ 1500625) Mod 35
return GetNumStr(Num4) + GetNumStr(Num3) + GetNumStr(Num2) + GetNumStr(Num1);
}
public static string GetNumStr(long Num)
{
switch(Num)
{
case 0:
return "K";
case 1:
return "Z";
case 2:
return "S";
case 3:
return "5";
case 4:
return "H";
case 5:
return "A";
case 6:
return "P";
case 7:
return "9";
case 8:
return "N";
case 9:
return "7";
case 10:
return "6";
case 11:
return "2";
case 12:
return "G";
case 13:
return "0";
case 14:
return "B";
case 15:
return "D";
case 16:
return "C";
case 17:
return "F";
case 18:
return "1";
case 19:
return "J";
case 20:
return "I";
case 21:
return "W";
case 22:
return "E";
case 23:
return "3";
case 24:
return "R";
case 25:
return "V";
case 26:
return "X";
case 27:
return "L";
case 28:
return "4";
case 29:
return "M";
case 30:
return "Y";
case 31:
return "Q";
case 32:
return "8";
case 33:
return "T";
case 34:
return "U";
default:
return "Z";
}
}
}
}
ASP 的实现方法:
<%
' 根据输入的数字计算 4 位数的标识串,本函数保证输入数字在 0 - 1500625(5位:60466175) 之内不出现重复串
PUBLIC FUNCTION MakeCode4(Num)
DIM Num1,Num2,Num3,Num4,Num5,Num6,Num7
Num1=Num Mod 35
Num2=(Num \ 35) Mod 35
Num3=(Num \ 1225) Mod 35
Num4=(Num \ 42875) Mod 35
' Num5=(Num \ 1500625) Mod 35
MakeCode4=GetNumStr(Num4) & GetNumStr(Num3) & GetNumStr(Num2) & GetNumStr(Num1)
END FUNCTION
PUBLIC FUNCTION GetNumStr(Num)
Select case Num
case 0
GetNumStr="K"
case 1
GetNumStr="Z"
case 2
GetNumStr="S"
case 3
GetNumStr="5"
case 4
GetNumStr="H"
case 5
GetNumStr="A"
case 6
GetNumStr="P"
case 7
GetNumStr="9"
case 8
GetNumStr="N"
case 9
GetNumStr="7"
case 10
GetNumStr="6"
case 11
GetNumStr="2"
case 12
GetNumStr="G"
case 13
GetNumStr="0"
case 14
GetNumStr="B"
case 15
GetNumStr="D"
case 16
GetNumStr="C"
case 17
GetNumStr="F"
case 18
GetNumStr="1"
case 19
GetNumStr="J"
case 20
GetNumStr="I"
case 21
GetNumStr="W"
case 22
GetNumStr="E"
case 23
GetNumStr="3"
case 24
GetNumStr="R"
case 25
GetNumStr="V"
case 26
GetNumStr="X"
case 27
GetNumStr="L"
case 28
GetNumStr="4"
case 29
GetNumStr="M"
case 30
GetNumStr="Y"
case 31
GetNumStr="Q"
case 32
GetNumStr="8"
case 33
GetNumStr="T"
case 34
GetNumStr="U"
END SELECT
END FUNCTION
%>
' 根据输入的数字计算 4 位数的标识串,本函数保证输入数字在 0 - 1500625(5位:60466175) 之内不出现重复串
PUBLIC FUNCTION MakeCode4(Num)
DIM Num1,Num2,Num3,Num4,Num5,Num6,Num7
Num1=Num Mod 35
Num2=(Num \ 35) Mod 35
Num3=(Num \ 1225) Mod 35
Num4=(Num \ 42875) Mod 35
' Num5=(Num \ 1500625) Mod 35
MakeCode4=GetNumStr(Num4) & GetNumStr(Num3) & GetNumStr(Num2) & GetNumStr(Num1)
END FUNCTION
PUBLIC FUNCTION GetNumStr(Num)
Select case Num
case 0
GetNumStr="K"
case 1
GetNumStr="Z"
case 2
GetNumStr="S"
case 3
GetNumStr="5"
case 4
GetNumStr="H"
case 5
GetNumStr="A"
case 6
GetNumStr="P"
case 7
GetNumStr="9"
case 8
GetNumStr="N"
case 9
GetNumStr="7"
case 10
GetNumStr="6"
case 11
GetNumStr="2"
case 12
GetNumStr="G"
case 13
GetNumStr="0"
case 14
GetNumStr="B"
case 15
GetNumStr="D"
case 16
GetNumStr="C"
case 17
GetNumStr="F"
case 18
GetNumStr="1"
case 19
GetNumStr="J"
case 20
GetNumStr="I"
case 21
GetNumStr="W"
case 22
GetNumStr="E"
case 23
GetNumStr="3"
case 24
GetNumStr="R"
case 25
GetNumStr="V"
case 26
GetNumStr="X"
case 27
GetNumStr="L"
case 28
GetNumStr="4"
case 29
GetNumStr="M"
case 30
GetNumStr="Y"
case 31
GetNumStr="Q"
case 32
GetNumStr="8"
case 33
GetNumStr="T"
case 34
GetNumStr="U"
END SELECT
END FUNCTION
%>