>>
电脑数码世界 >>
【电子政府(E-Government)】 >>
返回 | |||
![]() |
![]() |
![]() | |
| 主题: 根据机构代码本体代码生成效验码 | |
| 作者: danzhou |
楼 主 |
|
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// xym 机构代码效验码 /// 2009-12-28 /// 兆达信息 /// 依据 GB 11714—1997 校验码计算公式 /// </summary> public class XYM { /// <summary> /// 根据机构代码本体代码生成效验码 /// </summary> /// <param name="btdm">8位 本体代码</param> /// <returns>效验码</returns> public string xym(string btdm) { int[] wi ={ 3, 7, 9, 10, 5, 8, 4, 2 }; //Wi一表示第i位置上的加权因子 int[] cc = new int[8]; int DD = 0; int C9 = 0; for (int i = 0; i < 8; i++) { //将字符转换成ASCILL码 cc[i] = (int)btdm[i]; if (47 < cc[i] && cc[i] < 58) cc[i] = cc[i] - 48; //将ASCILL码转换成对应数值 else cc[i] = cc[i] - 65; } for (int i = 0; i < 8; i++) { DD += cc[i] * wi[i]; } //计算校验码 C9 = 11 - DD % 11; //当 MOD函数值为1(C9=10 )时,校验码应用大写拉丁字母X表示. if (C9 == 10) { for (int i = 0; i < 8; i++) return "-X"; } //当MOD函数值为0即(C9=11)时,校验码仍用0表示 else if (C9 == 11) { for (int i = 0; i < 8; i++) return "-" + (char)(48); } else { for (int i = 0; i < 8; i++) return "-" + (char)(C9 + 48); } return ""; } } | |
| 发表时间:2009-12-28 15:48:11 | |
| 快速回复 | |
默认支持UBB,如果你不希望 支持UBB或要其它功能你可 以用 高级回复进行编辑 | |