/// <summary> /// 根据段ID获取段中元素实体 /// </summary> /// yand 16.07.04 /// zouql 16.09.20 新增RuleType /// <param name="DataSegmentId">段ID</param> /// <returns></returns> public List <ComponentInfo> ComponentList(int DataSegmentId) { List <ComponentInfo> componentList = new List <ComponentInfo>(); // 获取数据段规则 List <SegmentRulesInfo> segmentRulesList = segmentRuleMapper.List(DataSegmentId); List <MetaInfo> metaList = new List <MetaInfo>(); for (int i = 0; i < segmentRulesList.Count; i++) { // 获取数据元 MetaInfo metaInfo = metaMapper.Find(segmentRulesList[i].MetaCode); metaInfo.RuleType = new RuleType().Get(metaInfo.RuleType.RuleTypeId); // 获取HTML标签 List <HtmlElementInfo> htmlElementList = new DAL.BankCredit.HtmlElementMapper().Find(segmentRulesList[i].MetaCode); MetaComponentsInfo GetMetaComponentsInfoByCode = new DataRule().GetMetaComponentsInfoByCode(segmentRulesList[i].MetaCode); // 一个数据元可能对应多个标签 for (int j = 0; j < htmlElementList.Count; j++) { ComponentInfo componentInfo = new ComponentInfo(); componentInfo.HtmlElement = htmlElementList[j].Html; componentInfo.HtmlelementId = htmlElementList[j].HtmlElementID; componentInfo.Type = GetMetaComponentsInfoByCode.Type; componentInfo.IsRequired = segmentRulesList[i].IsRequired; componentInfo.Length = metaInfo.DatasLength; componentInfo.MetaName = metaInfo.Name; componentInfo.DataType = metaInfo.DataType; componentInfo.MetaCode = metaInfo.MetaCode; componentInfo.SegmentRulesId = segmentRulesList[i].SegmentRulesId; componentInfo.Description = segmentRulesList[i].Description; componentInfo.RuleType = metaInfo.RuleType ?? new RuleTypeInfo(); componentList.Add(componentInfo); } } return(componentList); }
/// <summary> /// 查找单个 /// </summary> /// yangj 16.07.05 /// <param name="metaCode">数据元标识</param> /// <returns></returns> public MetaInfo Find(int metaCode) { return(metaMapper.Find(metaCode)); }
/// <summary> /// 数据类型校验 /// </summary> /// zouql 16.09.28 /// <param name="data"></param> private void BaseTypeComare(MessageInfo data) { // 基础段必填验证 if (data.A.Count == 0) { ShowError(message: "基础段必填"); } // 段规则Code集合 var paragraphCodes = new List <string>() { "A", "B", "C", "D", "E", "G", "H", "I", "J", "K" }; // 同一metaCode对应的不同段的值的集合 var values = new List <string>(); // Meta访问实例 var metaMapper = new DAL.BankCredit.MetaMapper(); // RuleType访问实例 var ruleTypeMapper = new DAL.BankCredit.RuleTypeMapper(); // 段规则校验实例 var comPare = new DataAndRuleComPare(); // 遍历metaCode foreach (var metaCode in PData.Mates.Keys) { foreach (var item in dataDic) { // 必填项 if (item.Value.Substring(0, 1).Equals("M") && item.Value.Substring(1, item.Value.Length - 1).Equals(metaCode)) { var value = GetValue(Convert.ToInt32(metaCode), item.Key.Substring(0, 1), data); var paragraphData = SearchParegraphCode(item.Key.Substring(0, 1), data); if (string.IsNullOrEmpty(value) && paragraphData != null && paragraphData.Count > 0) { ShowError(message: item.Key + "必填"); } } } // 清空values values.Clear(); // 获取同一metaCode对应的不同段的值的集合 paragraphCodes.ForEach(delegate(string item) { var value = GetValue(Convert.ToInt32(metaCode), item, data); if (!string.IsNullOrEmpty(value)) { values.AddRange(value.Split('.')); } } ); // 值存在,进一步校验 if (values.Count > 0) { // 获取MetaInfo var metaInfo = metaMapper.Find(Convert.ToInt32(metaCode)) ?? new MetaInfo(); // 获取RuleType var ruleTypeInfo = ruleTypeMapper.Find(Convert.ToInt32(metaCode)) ?? new RuleTypeInfo(); for (var i = 0; i < values.Count; i++) { #region 校验类型 if (!comPare.VarificationData(metaInfo, values[i])) { ShowError(message: "类型校验未通过"); } #endregion #region 贷款卡编码、组织机构代码校验 if (metaCode.Equals("7503") && metaCode.Equals("7505")) { if (!ValidFn.IdCard_Valid(values[i])) { ShowError(message: "贷款卡编码校验未通过"); } } else if (metaCode.Equals("6507") && metaCode.Equals("6511")) { if (!ValidFn.IdCard_Valid(values[i])) { ShowError(message: "组织机构代码校验未通过"); } } #endregion else { #region 金额、时间、整数校验 var valueInt = -1; if (ruleTypeInfo.MoneyType) { // 验证金额 if (!int.TryParse(values[i], out valueInt) && valueInt <= 0) { ShowError(message: "金额校验未通过"); } } else if (ruleTypeInfo.TimeType) { // 验证时间 if (!int.TryParse(values[i], out valueInt) && valueInt <19000101 && valueInt> Convert.ToInt32(string.Format("{0:yyyyMMdd}", DateTime.Now))) { ShowError(message: "时间校验未通过"); } } else if (ruleTypeInfo.TimeType) { // 验证整数 if (!int.TryParse(values[i], out valueInt) && valueInt < 0) { ShowError(message: "整数校验未通过"); } } #endregion } } } } }