public void AddSpecValue(SpecValue specValue) { if (specValueList_ == null) { specValueList_ = new List <SpecValue>(); } specValueList_.Add(specValue); }
/// <summary> /// 更新判断方法 /// </summary> /// <param name="compare"></param> /// <param name="specValue"></param> private void UpdateJudgmentResult(string compare, SpecValue specValue) { if (compare.Equals("S==")) { bool pass = specValue.Spec.Equals(specValue.MeasuredValue); specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } else if (compare.Equals("S!=")) { bool pass = specValue.Spec != specValue.MeasuredValue; specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } else if (compare.Equals("S[]")) //正则表达式 { if (!string.IsNullOrEmpty(specValue.MeasuredValue) && !string.IsNullOrEmpty(specValue.Spec)) { bool pass = Regex.IsMatch(specValue.MeasuredValue, specValue.Spec); specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } else { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else if (compare.Equals("D[]")) //上下限 { if (!string.IsNullOrEmpty(specValue.MeasuredValue) && !string.IsNullOrEmpty(specValue.Spec) && specValue.Spec.Contains('~')) { string[] bound = specValue.Spec.Split('~'); double lower = Convert.ToDouble(bound[0]); double upper = Convert.ToDouble(bound[1]); try { double value = Convert.ToDouble(Regex.Replace(specValue.MeasuredValue, @"[^\d\.\-\+]*", string.Empty)); bool pass = lower <= value && value <= upper; specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } catch (Exception) { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else if (compare.Equals("D>=")) //下限 { if (!string.IsNullOrEmpty(specValue.MeasuredValue) && !string.IsNullOrEmpty(specValue.Spec)) { double lower = Convert.ToDouble(specValue.Spec); try { double value = Convert.ToDouble(Regex.Replace(specValue.MeasuredValue, @"[^\d\.\-\+]*", string.Empty)); bool pass = value >= lower; specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } catch (Exception) { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else if (compare.Equals("D<=")) //上限 { if (!string.IsNullOrEmpty(specValue.MeasuredValue) && !string.IsNullOrEmpty(specValue.Spec)) { double upper = Convert.ToDouble(specValue.Spec); try { double value = Convert.ToDouble(Regex.Replace(specValue.MeasuredValue, @"[^\d\.\-\+]*", string.Empty)); bool pass = value <= upper; specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } catch (Exception) { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else if (compare.Equals("D==")) { if (!string.IsNullOrEmpty(specValue.MeasuredValue) && !string.IsNullOrEmpty(specValue.Spec)) { double spec = Convert.ToDouble(specValue.Spec); try { double value = Convert.ToDouble(Regex.Replace(specValue.MeasuredValue, @"[^\d\.\-\+]*", string.Empty)); bool pass = value == spec; specValue.JudgmentResult = pass ? CommonString.RESULT_SUCCEED : CommonString.RESULT_FAILURE; } catch (Exception) { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } else { specValue.JudgmentResult = CommonString.RESULT_FAILURE; } } }