Browse Source

修改相等的判断

djs 4 months ago
parent
commit
91fde872f2
2 changed files with 67 additions and 22 deletions
  1. 58 4
      MeterVision/db/TPatchDetail.cs
  2. 9 18
      MeterVision/model/PatchDetailItem.cs

+ 58 - 4
MeterVision/db/TPatchDetail.cs

@@ -219,7 +219,7 @@ namespace MeterVision.db
             return isEqual;
         }
 
-        public int GetEqualFlag(double standValue, long finalValue)
+        public int GetEqualFlag2(string strStandValue,double standValue, long finalValue)
         {
             bool isEqual = false;
             //比较结果值与标准值是否相等
@@ -256,15 +256,33 @@ namespace MeterVision.db
                     //全指针
                     //数字+指针(只比较数字部分)
                     //获取真正数据部分的值
-                    int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
-                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
-                    isEqual = (standValue1 == finalValue1);
+                    int standValue1;    // = (int)Math.Ceiling(standValue / LastUnit);
+                    int finalValue1;    // = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+
+                    //isEqual = (standValue1 == finalValue1);
+
                     //isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
 
                     /*if(finalValue == 22066060)
                     {
                         Console.WriteLine("测试");
                     }*/
+
+                    if (strStandValue.Contains("."))
+                    {
+                        //标准值带有小数则全比较
+                        standValue1 = (int)Math.Ceiling(standValue / LastUnit);
+                        finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                        isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+                    }
+                    else
+                    {
+                        //标准值没有小数则只比较整数部分    
+                        standValue1 = (int)standValue;
+                        finalValue1 = (int)(finalValue / FaConstant.CUBE_VALUE);
+                        isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+                    }
+
                     return isEqual ? 1 : 0;
                 }
                 else if (MeterType == 3)
@@ -286,6 +304,42 @@ namespace MeterVision.db
         }
 
 
+        public int GetEqualFlag(double standValue, long finalValue)
+        {
+            bool isEqual = false;
+            //比较结果值与标准值是否相等
+            if (MeterType == ResultMeter)
+            {
+                if (MeterType == 1 || MeterType == 3)
+                {
+                    //数字+指针(只比较数字部分)
+                    //获取真正数据部分的值
+                    int standValue1 = (int)Math.Ceiling(standValue / LastUnit);
+                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
+                    //isEqual = (standValue1 == finalValue1);
+
+                    //判断如何按最后一个单位差1,也认为正确(比如0.1单位,则差0.1是正确的,10单位的,差10也是正确的)
+
+                    //上面的值,也就规划为数字的整数
+                    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+
+                    return isEqual ? 1 : 0;
+                }
+                else if (MeterType == 2)
+                {
+                    int standValue1 = (int)standValue;
+                    int finalValue1 = (int)(finalValue / FaConstant.CUBE_VALUE);
+
+                    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
+                    return isEqual ? 1 : 0;
+                }
+            }
+            return 2;
+        }
+
+
         //恢复运行时的默认值
         public void ResetRunValue()
         {

+ 9 - 18
MeterVision/model/PatchDetailItem.cs

@@ -1100,7 +1100,7 @@ namespace MeterVision.model
             //比较结果值与标准值是否相等
             if (MeterType == ResultMeter)
             {
-                if (MeterType == 1)
+                if (MeterType == 1 || MeterType == 3)
                 {
                     //数字+指针(只比较数字部分)
                     //获取真正数据部分的值
@@ -1113,31 +1113,22 @@ namespace MeterVision.model
                     //上面的值,也就规划为数字的整数
                     isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
 
+
                     return isEqual ? 1 : 0;
                 }
                 else if (MeterType == 2)
                 {
-                    //全指针
-                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
-                    return isEqual ? 1 : 0;
-                }
-                else if (MeterType == 3)
-                {
-                    //全数字
-                    //return (standValue * FaConstant.CUBE_VALUE) == finalValue;
-                    isEqual = (standValue * FaConstant.CUBE_VALUE) == finalValue;
+                    int standValue1 = (int)standValue;
+                    int finalValue1 = (int)(finalValue / FaConstant.CUBE_VALUE);
+
+                    isEqual = (Math.Abs(standValue1 - finalValue1) <= 1);
+
                     return isEqual ? 1 : 0;
                 }
-                else
-                {
-                    return 2;
-                }
-            }
-            else
-            {
-                return 2;
             }
+            return 2;
         }
+
         /////////////////////////////
     }
 }