/// <summary> /// 执行检查 /// </summary> /// <param name="pPropertyValue">待检查的数据值</param> /// <param name="pPropertyText">此数据的属性名称(列描述)</param> /// <param name="pRowData">当前数据项的信息</param> /// <param name="oResult">检查结果</param> /// <returns>TRUE:通过检查,FALSE:未通过检查。</returns> public bool Process(object pPropertyValue, string pPropertyText, IETCLDataItem pRowData, ref IETCLResultItem oResult) { bool isPass = true; if (pPropertyValue == null || string.IsNullOrWhiteSpace(pPropertyValue.ToString())) {//无效 isPass = false; oResult.OPType = OperationType.DataValidaty; oResult.Message = string.Format("数据项:【{0}】的数据值不能为空.", pPropertyText); } return(isPass); }
/// <summary> /// 根据指定的正则表达式执行检查 /// </summary> /// <param name="pPropertyValue">待检查的数据值</param> /// <param name="pPropertyText">此数据的属性名称(列描述)</param> /// <param name="pRowData">当前数据项的信息</param> /// <param name="oResult">检查结果</param> /// <returns>TRUE:通过检查,FALSE:未通过检查。</returns> public bool Process(object pPropertyValue, string pPropertyText, IETCLDataItem pRowData, ref IETCLResultItem oResult) { bool isPass = true; if (pPropertyValue != null && !string.IsNullOrWhiteSpace(pPropertyValue.ToString())) { if (!this._reg.IsMatch(pPropertyValue.ToString())) { isPass = false; oResult.OPType = OperationType.DataValidaty; oResult.Message = string.Format("数据项:【{0}】 的数据不是一个合法的【{1}】格式.", pPropertyText, _regexName); } } return(isPass); }
/// <summary> /// 执行检查 /// </summary> /// <param name="pPropertyValue">待检查的数据值</param> /// <param name="pPropertyText">此数据的属性名称(列描述)</param> /// <param name="pRowData">当前数据项的信息</param> /// <param name="oResult">检查结果</param> /// <returns>TRUE:通过检查,FALSE:未通过检查。</returns> public bool Process(object pPropertyValue, string pPropertyText, IETCLDataItem pRowData, ref IETCLResultItem oResult) { bool isPass = true; if (pPropertyValue == null || string.IsNullOrWhiteSpace(pPropertyValue.ToString()))//空值不检查依赖项 { return(true); } //检查当前XLS中是否有此依赖表 ETCLTable referenceTable = this._etclWorksheet.GetTableByName(this._etclColumn.ReferenceTableName); if (referenceTable == null) { throw new ETCLException(200, string.Format("未找到关联表的相关定义,请修改XML配置。列名:{0},关联表:{1}", this._etclColumn.ColumnName, this._etclColumn.ReferenceTableName)); } //通过反射从数据库中读取此依赖表信息 if (!_dictCachedReference.ContainsKey(this._etclColumn.ReferenceTableName)) { object[] oTempEntities = Reflection.DynamicReflectionHandler.QueryAll(referenceTable, new object[] { this._userInfo }); _dictCachedReference.Add(this._etclColumn.ReferenceTableName, oTempEntities); } object[] oEntities = _dictCachedReference[this._etclColumn.ReferenceTableName]; foreach (var entityItem in oEntities) { object oTempValue = Reflection.DynamicReflectionHandler.GetProperty(entityItem, this._etclColumn.ReferenceTextColumnName); if (oTempValue.Equals(pPropertyValue)) { isPass = false; oResult = new ETCLCommonResultItem(); oResult.OPType = OperationType.ForeignKeyDependence; oResult.Message = string.Format("[{数据项:{0}}]的数据在关联表中不存在.", pPropertyText); } } return(isPass); }
/// <summary> /// 执行取值范围检查 /// </summary> /// <param name="pPropertyValue">待检查的数据值</param> /// <param name="pPropertyText">此数据的属性名称(列描述)</param> /// <param name="pRowData">当前数据项的信息</param> /// <param name="oResult">检查结果</param> /// <returns>TRUE:通过检查,FALSE:未通过检查。</returns> public bool Process(object pPropertyValue, string pPropertyText, IETCLDataItem pRowData, ref IETCLResultItem oResult) { bool isPass = true; if (pPropertyValue == null) { return(isPass); } switch (pPropertyValue.GetType().ToString()) { case "System.DateTime": case "System.DateTime?": //校验时间有效性 if (!string.IsNullOrWhiteSpace(this._etclColumn.MaxValue)) { DateTime maxDate = Convert.ToDateTime(this._etclColumn.MaxValue); if (((DateTime)pPropertyValue) > maxDate) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值超过了允许的最大值:[" + this._etclColumn.MaxValue + "]"); } } if (!string.IsNullOrWhiteSpace(this._etclColumn.MinValue)) { DateTime minDate = Convert.ToDateTime(this._etclColumn.MinValue); if (((DateTime)pPropertyValue) < minDate) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值低于了允许的最小值:[" + this._etclColumn.MinValue + "]"); } } break; case "System.Int32": //校验数值有效性 case "System.Int32?": case "System.Decimal": case "System.Decimal?": case "System.Single": case "System.Single?": case "System.Double": case "System.Double?": if (!string.IsNullOrWhiteSpace(this._etclColumn.MaxValue)) { Double maxValue = Convert.ToDouble(this._etclColumn.MaxValue); if (Convert.ToDouble(pPropertyValue) > maxValue) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值超过了允许的最大值:[" + this._etclColumn.MaxValue + "]"); } } if (!string.IsNullOrWhiteSpace(this._etclColumn.MinValue)) { Double minValue = Convert.ToDouble(this._etclColumn.MinValue); if (Convert.ToDouble(pPropertyValue) < minValue) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值低于了允许的最小值:[" + this._etclColumn.MinValue + "]"); } } break; case "System.String": //字符串的长度 case "string": if (!string.IsNullOrWhiteSpace(this._etclColumn.MaxValue)) { int maxValue = Convert.ToInt32(this._etclColumn.MaxValue); if (pPropertyValue.ToString().Length > maxValue) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值长度超过了允许的最大长度:[" + this._etclColumn.MaxValue + "]"); } } if (!string.IsNullOrWhiteSpace(this._etclColumn.MinValue)) { int minValue = Convert.ToInt32(this._etclColumn.MinValue); if (pPropertyValue.ToString().Length < minValue) { isPass = false; oResult.Message = string.Format("列【" + this._etclColumn.ColumnText + "】中的值长度低于了允许的最小长度:[" + this._etclColumn.MinValue + "]"); } } break; case "System.DBNull": isPass = true; break; default: throw new ETCLException(400, string.Format("未处理的数据类型:{0}", pPropertyValue.GetType().ToString())); } return(isPass); }
/// <summary> /// 执行检查 /// </summary> /// <param name="pPropertyValue">待检查的数据值</param> /// <param name="pPropertyText">此数据的属性名称(列描述)</param> /// <param name="pRowData">当前数据项的信息</param> /// <param name="oResult">检查结果</param> /// <returns>TRUE:通过检查,FALSE:未通过检查。</returns> public bool Process(object pPropertyValue, string pPropertyText, IETCLDataItem pRowData, ref IETCLResultItem oResult) { //int rowIndex =pRowData _etclTable.Entities.IndexOf((CommonExcelDataItem)pRowData); bool isPass = true; if (pPropertyValue == null || string.IsNullOrWhiteSpace(pPropertyValue.ToString()))//空值不检查是否重复 { return(isPass); } int currentIndex = 0; List <int> listDuplicateItemIndex = new List <int>(); if (isPass) { if (pPropertyValue != null && this._etclColumn.ValueCountCache.ContainsKey(pPropertyValue) && this._etclColumn.ValueCountCache[pPropertyValue] > 1) { isPass = false; listDuplicateItemIndex.Add(currentIndex - 1); } } string duplicatedRowIndex = string.Empty; //检测数据库中是否已存在此值 if (isPass) { object[] oAllEntities; if (dictDBTableCache.ContainsKey(this._etclTable.TableName)) { oAllEntities = dictDBTableCache[this._etclTable.TableName]; } else { oAllEntities = Reflection.DynamicReflectionHandler.QueryAll(this._etclTable, new object[] { _userInfo }); dictDBTableCache.Add(this._etclTable.TableName, oAllEntities); } object[] cellValues = new object[oAllEntities.Length]; if (dictDBTableColumnValueCache.ContainsKey(this._etclTable.TableName + "|" + this._etclColumn.ColumnName)) { cellValues = dictDBTableColumnValueCache[this._etclTable.TableName + "|" + this._etclColumn.ColumnName]; } else { cellValues = new object[oAllEntities.Length]; for (int i = 0; i < oAllEntities.Length; i++) { object entityItem = oAllEntities[i]; cellValues[i] = Reflection.DynamicReflectionHandler.GetProperty(entityItem, this._etclColumn.ColumnName); } dictDBTableColumnValueCache.Add(this._etclTable.TableName + "|" + this._etclColumn.ColumnName, cellValues); } if (pPropertyValue != null && cellValues.Contains(pPropertyValue)) { duplicatedRowIndex = "-1"; isPass = false; } } if (!isPass) {//此单元格的值与其它单元格有重复,记录错误信息. oResult.OPType = OperationType.DataRepeatly; if (duplicatedRowIndex == string.Empty) { foreach (var item in listDuplicateItemIndex) { duplicatedRowIndex += (item + 2).ToString() + ",";//序号应从2开始(第一行是列头,item为0序号应为1) } if (duplicatedRowIndex.Length > 0) { duplicatedRowIndex = duplicatedRowIndex.Substring(0, duplicatedRowIndex.Length - 1); } } if (duplicatedRowIndex == "-1") { oResult.Message = string.Format("[检测到重复项(在数据库表中).列:【{0}】].", pPropertyText); } else { oResult.Message = string.Format("[检测到重复项(在当前工作表中).列:【{0}】,行号:【{1}】].", pPropertyText, duplicatedRowIndex); } } return(isPass); }