/// <summary> /// 检查数字录入是否正确 /// </summary> /// <param name="strData">要检查的字符串</param> /// <returns>正确返回true</returns> private bool CheckNumericInfo(string strData) { int index = strData.IndexOf('='); int nextIndex = -1; string strValue; Regex r = new Regex(@"(^[+-]?(\d+)(\.\d+)?$)|(^[+-]?\d+(\.\d+)?[+]\d+(\.\d+)?$)"); // 同时匹配 +0.18 or +0.18+0.20 while (index != -1) { nextIndex = strData.IndexOf(',', index); if (nextIndex == -1) { nextIndex = strData.Length - 1; } if (nextIndex == index + 1) { return(false); } else { if (StapleFunction.IsChineseCharacters(strData.Substring(nextIndex - 1, 1))) { strValue = strData.Substring(index + 1, nextIndex - index - 2); } else { strValue = strData.Substring(index + 1, nextIndex - index - 1); } //Regex r = new Regex(@"^[+-]?(\d+)(\.\d+)?$"); // 匹配浮点数 //Regex r = new Regex(@"^[+-]?\d+(\.\d+)?[+]\d+(\.\d+)?$"); // 匹配 +0.18+0.20 if (!r.IsMatch(strValue)) { return(false); } } index = strData.IndexOf('=', nextIndex + 1); } index = strData.IndexOf(':'); while (index != -1) { nextIndex = strData.IndexOf(',', index); if (nextIndex == -1) { nextIndex = strData.Length; } if (nextIndex == index + 1) { return(false); } else { if (StapleFunction.IsChineseCharacters(strData.Substring(nextIndex - 1, 1))) { strValue = strData.Substring(index + 1, nextIndex - index - 2); } else { strValue = strData.Substring(index + 1, nextIndex - index - 1); } if (!r.IsMatch(strValue)) { return(false); } } index = nextIndex == strData.Length ? -1 : strData.IndexOf(':', nextIndex + 1); } return(true); }
/// <summary> /// 产品总成编码校验 /// </summary> /// <param name="goodsID">总成ID</param> /// <param name="productCode">产品编码</param> /// <param name="barCodeType">编码类型</param> /// <param name="error">出错时返回的错误信息</param> /// <returns>检验通过返回true, 失败返回false</returns> public bool VerifyProductCodesInfo(int goodsID, string productCode, GlobalObject.CE_BarCodeType barCodeType, out string error) { error = ""; productCode = productCode.ToUpper(); View_F_GoodsPlanCost goodsInfo = UniversalFunction.GetGoodsInfo(goodsID); if (!Convert.ToBoolean(BasicInfo.BaseSwitchInfo[(int)GlobalObject.CE_SwitchName.检测钢印码及条形码])) { return(true); } if (StapleFunction.IsChineseCharacters(productCode)) { error = "请不要在产品编号中包含中文字符"; return(false); } Dictionary <CE_GoodsAttributeName, object> dic = UniversalFunction.GetGoodsInfList_Attribute_AttchedInfoList(goodsID); if (!dic.Keys.ToList().Contains(CE_GoodsAttributeName.流水码)) { throw new Exception(UniversalFunction.GetGoodsMessage(goodsID) + "基础属性未设置【流水码】"); } List <F_ProductWaterCode> lstWaterCode = dic[CE_GoodsAttributeName.流水码] as List <F_ProductWaterCode>; if (lstWaterCode.Count == 0) { error = "产品类型不正确,无法找到对应的编码规则"; return(false); } else { foreach (var item in lstWaterCode) { //条形码检测 if (barCodeType == CE_BarCodeType.出厂条形码) { if (productCode.Length == item.BarcodeExample.Length && Regex.IsMatch(productCode, @item.BarcodeRole)) { return(true); } }//钢印码检测 else if (barCodeType == CE_BarCodeType.内部钢印码) { if (productCode.Length == item.SteelSealExample.Length && Regex.IsMatch(productCode, @item.SteelSealRole)) { return(true); } } else { return(false); } } if (barCodeType == CE_BarCodeType.出厂条形码) { error = "编码规则不符,条形码正确格式为"; foreach (var item in lstWaterCode) { error += "【" + item.BarcodeExample.Trim() + "】"; } } else if (barCodeType == CE_BarCodeType.内部钢印码) { error = "编码规则不符,钢印码正确格式为"; foreach (var item in lstWaterCode) { error += "【" + item.SteelSealExample.Trim() + "】"; } } return(false); } }