/// <summary> /// 获取新身份证最后一位校验位 /// </summary> public void GetIdCardCheckCodeTest() { var idCardRightNumber = "632802197803272788"; var checkCode = IdCardValidatorHelper.GetIdCardCheckCode(idCardRightNumber); checkCode.IsEqualTo("1"); }
/// <summary> /// 获取身份证生日时间 /// </summary> public void GetBirthdayTest() { var idCardRightNumber = "632802197803272788"; var resulte = IdCardValidatorHelper.GetBirthday(idCardRightNumber); resulte.IsEqualTo("19780327"); }
/// <summary> /// 根据身份证号获得性别 /// </summary> public void GetSexByIdCardTest() { var idCardRightNumber = "632802197803272788"; DateTime brityday; var resulte = IdCardValidatorHelper.GetSexByIdCard(idCardRightNumber, out brityday); resulte.IsEqualTo(0); }
/// <summary> /// 验证身份证合理性 /// </summary> public void CheckIdCardTest() { var idCardRightNumber = "632802197803272788"; var resulte = IdCardValidatorHelper.CheckIdCard(idCardRightNumber); resulte.IsTrue(); var idCardErrorNumber = "6328021978032727"; var errorResulte = IdCardValidatorHelper.CheckIdCard(idCardErrorNumber); errorResulte.IsFalse(); }
/// <summary> /// 添加信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult SaveIdCardNumberInfo(SysIdCardContentModel model) { var resultMode = new ResponseBaseModel <SysIdCardContentModel> { ResultCode = ResponceCodeEnum.Fail }; if (model == null) { return(Json(resultMode, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.Name)) { resultMode.Message = "姓名不能为空"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.CardNumber)) { resultMode.Message = "身份证号不能为空"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrEmpty(model.Remarks)) { var introduction = FilterHtmlHelper.NoHtml(model.Remarks); model.Remarks = introduction != null && introduction.Length > 200 ? introduction.Substring(0, 200) : introduction; } if (!IdCardValidatorHelper.CheckIdCard(model.CardNumber)) { resultMode.Message = "身份证号有效性验证不通过"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } var cardModel = new IdCardNumber(model.CardNumber); var newModel = new SysIdCardContentModel { Id = model.Id, Age = cardModel.Age, CardNumber = cardModel.CardNumber, Name = model.Name, Remarks = model.Remarks, City = cardModel.City, Area = cardModel.Area, CreateTime = DateTime.Now, Province = cardModel.Province, Sex = cardModel.Sex == 1 ? SexEnum.Boy : SexEnum.Grill }; var server = new SysIdCardContentService(); if (model.Id > 0) { var oldModel = server.Get(model.Id); if (oldModel == null) { resultMode.Message = "不存在该内容记录"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } newModel.CreateTime = oldModel.CreateTime; } else { var hadAdd = server.GetByCardNumber(model.CardNumber); if (hadAdd != null && hadAdd.CardNumber == model.CardNumber) { resultMode.Message = "已经存在该身份证号码"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } } try { server.SaveModel(newModel); resultMode.ResultCode = ResponceCodeEnum.Success; resultMode.Message = "处理成功"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e); resultMode.Message = "处理失败"; return(Json(resultMode, JsonRequestBehavior.AllowGet)); } }