using MeterVision.db;
using MeterVision.FreeAi;
using MeterVision.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace MeterVision.model
{
    public class PatchDetailItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private int _index;
        public int Index
        {
            get => _index;
            set
            {
                if (_index != value)
                {
                    _index = value;
                    OnPropertyChanged(nameof(Index));
                }
            }
        }

        private string _patchDetailId;
        public string PatchDetailId
        {
            get => _patchDetailId;
            set
            {
                if (_patchDetailId != value)
                {
                    _patchDetailId = value;
                    OnPropertyChanged(nameof(PatchDetailId));
                }
            }
        }

        private string _patchId;
        public string PatchId
        {
            get => _patchId;
            set
            {
                if(_patchId != value)
                {
                    _patchId = value;
                    OnPropertyChanged(nameof(PatchId));
                }
            }
        }

        private string _createTime;
        public string CreateTime
        {
            get => _createTime;
            set
            {
                if (_createTime != value)
                {
                    _createTime = value;
                    OnPropertyChanged(nameof(CreateTime));
                }
            }
        }

        private string _standDetailId;
        public string StandDetailId
        {
            get => _standDetailId;
            set
            {
                if(_standDetailId != value)
                {
                    _standDetailId = value;
                    OnPropertyChanged(nameof(StandDetailId));
                }
            }
        }

        private string _standResult;
        public string StandValue
        {
            get => _standResult;
            set
            {
                if (_standResult != value)
                {
                    _standResult = value;
                    OnPropertyChanged(nameof(StandValue));
                }
            }
        }

        private string _srcImage;
        public string SrcImage
        {
            get => _srcImage;
            set
            {
                if (_srcImage != value)
                {
                    _srcImage = value;
                    OnPropertyChanged(nameof(SrcImage));
                }
            }
        }

        public string SampleTime { get; set; }

        public string SampleTimePart1 => ThisApp.ConvertDateFormat_Date2(SampleTime);
        public string SampleTimePart2 => ThisApp.ConvertDateFormat_Time2(SampleTime);


        //1: 已识别处理 0:还未识别
        private int _runFlag;
        public int RunFlag
        {
            get => _runFlag;
            set
            {
                if (_runFlag != value)
                {
                    _runFlag = value;
                    OnPropertyChanged(nameof(RunFlag));
                    OnPropertyChanged(nameof(ResultVisiable));
                    OnPropertyChanged(nameof(RunFlagName));
                    OnPropertyChanged(nameof(RunFlagColor));
                }
            }
        }

        public string RunFlagName
        {
            get => RunFlag == 1 ? "🚩":"";
        }

        public string RunFlagColor
        {
            //get => RunFlag == 1 ? "#007bff" : "Tranparent";
            get => RunFlag == 1 ? "Black" : "Transparent";
        }


        private string _runTime;
        public string RunTime
        {
            get => _runTime;
            set
            {
                if (_runTime != value)
                {
                    _runTime = value;
                    OnPropertyChanged(nameof(RunTime));
                    OnPropertyChanged(nameof(RunTime_date)); // 依赖 RunTime 更新 RunTIme_date
                    OnPropertyChanged(nameof(RunTime_time)); // 依赖 RunTime 更新 RunTIme_time
                }
            }
        }

        public string RunTime_date => ThisApp.ConvertDateFormat_Date(RunTime);

        public string RunTime_time => ThisApp.ConvertDateFormat_Time(RunTime);

        private string _dstIamge;
        public string DstImage
        {
            get => _dstIamge;
            set
            {
                if (_dstIamge != value)
                {
                    _dstIamge = value;
                    OnPropertyChanged(nameof(DstImage));
                }
            }
        }

        private int _resultType;
        public int ResultType
        {
            get => _resultType;
            set
            {
                if (_resultType != value)
                {
                    _resultType = value;
                    OnPropertyChanged(nameof(ResultType));
                    OnPropertyChanged(nameof(ResultTypeColor)); // 依赖 ResultType 更新 ResultTypeColor
                }
            }
        }

        public Color ResultTypeColor
        {
            //=> Get_ResultTypeColor();
            get
            {
                return (Color)ColorConverter.ConvertFromString(Get_ResultTypeColor());
            }
        }
            
            

        private long _rawValue;
        public long RawValue
        {
            get => _rawValue;
            set
            {
                if (_rawValue != value)
                {
                    _rawValue = value;
                    OnPropertyChanged(nameof(RawValue));
                    OnPropertyChanged(nameof(RawValueName));
                }
            }
        }

        public string RawValueName
        {
            get
            {
                if(RawValue >= 0)
                {
                    return ((double)RawValue / FaConstant.CUBE_VALUE).ToString();                    
                }
                return "";
            }
        }

        private long _finalValue;
        public long FinalValue
        {
            get => _finalValue;
            set
            {
                if (_finalValue != value)
                {
                    _finalValue = value;
                    OnPropertyChanged(nameof(FinalValue));
                    OnPropertyChanged(nameof(FinalValueName));
                    OnPropertyChanged(nameof(FinalValueName2));
                }
            }
        }

        public string FinalValueName
        {
            get
            {
                if(FinalValue >= 0)
                {
                    return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
                }
                return "";
            }
        }

        //按LastUnit来截取小数
        public string FinalValueName2
        {
            get
            {
                if(MeterType == ResultMeter)
                {
                    string valueStr = LastUnit.ToString(); //LastUnit.ToString("G17");
                    int decimalIndex = valueStr.IndexOf('.');
                    int decimalPlaces = 0;
                    if (decimalIndex == -1)
                    {
                        decimalPlaces = 0;
                    }
                    else
                    {
                        decimalPlaces = valueStr.Length - decimalIndex - 1;
                    }
                    //double dValue = (double)FinalValue / (FaConstant.CUBE_VALUE * LastUnit);
                    //return dValue.ToString($"F{decimalPlaces}");
                    //return dValue.ToString()
                    int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
                    double dValue = iValue * LastUnit;

                    return dValue.ToString($"F{decimalPlaces}");
                }
                return "";
                //if (FinalValue >= 0)
                //{
                //    return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
                //}
                //return "";
            }
        }


        public string FinalValueColor => GetFinalValueColor();

        private long _completeValue;
        public long CompleteValue
        {
            get => _completeValue;
            set
            {
                if(_completeValue != value)
                {
                    _completeValue = value;
                    OnPropertyChanged(nameof(CompleteValue));
                }
            }
        }

        private int _valueChanged;
        public int ValueChanged
        {
            get => _valueChanged;
            set
            {
                if(_valueChanged != value)
                {
                    _valueChanged = value;
                    OnPropertyChanged(nameof(ValueChanged));
                }
            }
        }

        private int _resultMeter;
        public int ResultMeter
        {
            get => _resultMeter;
            set
            {
                if(_resultMeter != value)
                {
                    _resultMeter = value;
                    OnPropertyChanged(nameof(ResultMeter));
                    OnPropertyChanged(nameof(ResultMeterName));
                }
            }
        }

        public string ResultMeterName => GetMeterTypeName(ResultMeter);

        
        //0不等，1相等 2:无效，3无标准值，无法比较
        private int _equalFlag;
        public int EqualFlag
        {
            get => _equalFlag;
            set
            {
                if(_equalFlag != value)
                {
                    _equalFlag = value;
                    OnPropertyChanged(nameof(EqualFlag));
                    OnPropertyChanged(nameof(EqaulFlagName));
                    OnPropertyChanged(nameof(EqualFlagColor));
                    OnPropertyChanged(nameof(FinalValueColor));
                    OnPropertyChanged(nameof(FinalValueName2));
                }
            }
        }

        public string EqaulFlagName => GetEqualFlagName();

        public string EqualFlagColor => GetEqualFlagColor();

        private string _aiVer;
        public string AiVer
        {
            get => _aiVer;
            set
            {
                if (_aiVer != value)
                {
                    _aiVer = value;
                    OnPropertyChanged(nameof(AiVer));
                }
            }
        }

        private string _debugInfo;
        public string DebugInfo
        {
            get => _debugInfo;
            set
            {
                if (_debugInfo != value)
                {
                    _debugInfo = value;
                    OnPropertyChanged(nameof(DebugInfo));
                    OnPropertyChanged(nameof(AI_result_array)); // 依赖 DebugInfo 更新 AI_result_array
                }
            }
        }
        //--------------------------------

        public string[] AI_result_array => Get_DebugInfoArray();

        private string _logPath;
        public string LogPath
        {
            get => _logPath;
            set
            {
                if (_logPath != value)
                {
                    _logPath = value;
                    OnPropertyChanged(nameof(LogPath));
                }
            }
        }

        private string _memo;
        public string Memo
        {
            get => _memo;
            set
            {
                if(_memo != value)
                {
                    _memo = value;
                    OnPropertyChanged(nameof(Memo));
                }
            }
        }

        public string StationId { get; set; }
        public string StationIdName => $"站点: {StationId}";
        
        public string StationKey { get; set; }


        //--改动的地方
        private int _meterType;
        public int MeterType
        {
            get => _meterType;
            set
            {
                if (_meterType != value)
                {
                    _meterType = value;
                    OnPropertyChanged(nameof(MeterType));
                    OnPropertyChanged(nameof(MeterTypeName)); // 依赖 MeterType 更新 MeterTypeName
                }
            }
        }

        public string MeterTypeName => Get_MeterTypeName();


        private double _brightVal;
        public double BrightVal
        {
            get => _brightVal;
            set
            {
                if(_brightVal != value)
                {
                    _brightVal = value;
                    OnPropertyChanged(nameof(BrightVal));
                    OnPropertyChanged(nameof(BrightValName));
                }
            }
        }

        public string BrightValName => $"亮度: {BrightVal}";


        private int _flowRate;
        public int FlowRate
        {
            get => _flowRate;
            set
            {
                if(_flowRate != value)
                {
                    _flowRate = value;
                    OnPropertyChanged(nameof(FlowRate));
                    OnPropertyChanged(nameof(FlowRateName));
                }
            }
        }
        public string FlowRateName => $"小时流量: {FlowRate}";



        private int _digitCount;
        public int DigitCount
        {
            get => _digitCount;
            set
            {
                if (_digitCount != value)
                {
                    _digitCount = value;
                    OnPropertyChanged(nameof(DigitCount));
                    OnPropertyChanged(nameof(NumCountName)); // 依赖 DigitCount 更新 NumCountName
                }
            }
        }
        private int _pointerCount;
        public int PointerCount
        {
            get => _pointerCount;
            set
            {
                if (_pointerCount != value)
                {
                    _pointerCount = value;
                    OnPropertyChanged(nameof(PointerCount));
                    OnPropertyChanged(nameof(NumCountName)); // 依赖 PointerCount 更新 NumCountName
                }
            }
        }
        public string NumCountName => Get_NumCountName();

        private double _lastUnit;
        public double LastUnit
        {
            get => _lastUnit;
            set
            {
                if (_lastUnit != value)
                {
                    _lastUnit = value;
                    OnPropertyChanged(nameof(LastUnit));
                    OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
                }
            }
        }

        public string LastUnitName
        {
            get
            {
                if (MeterType > 0)
                {
                    return $"尾数: {LastUnit}m³";
                }
                else
                {
                    return "";
                }
            }
        }

        public int _numInUpper;
        public int NumInUpper
        {
            get => _numInUpper;
            set
            {
                if (_numInUpper != value)
                {
                    _numInUpper = value;
                    OnPropertyChanged(nameof(NumInUpper));
                }
            }
        }

        public string NumInUpperName
        {
            get
            {
                if(MeterType == 1 || MeterType == 3)
                {
                    return $"数字在上: {(NumInUpper == 1 ? "是":"否")}";
                }
                return "";
            }
        }

        public string _meterRegion;
        public string MeterRegion
        {
            get => _meterRegion;
            set
            {
                if(_meterRegion != value)
                {
                    _meterRegion = value;
                    OnPropertyChanged(nameof(MeterRegion));
                    OnPropertyChanged(nameof(MeterRegionName));
                }
            }
        }
        public string MeterRegionName {
            get
            {
                if (!string.IsNullOrEmpty(MeterRegion))
                {
                    return $"表盘: {MeterRegion}";
                }
                return "";
            }
        }

        private string _featureRegion;
        public string FeatureRegion
        {
            get => _featureRegion;
            set
            {
                if(_featureRegion != value)
                {
                    _featureRegion = value;
                    OnPropertyChanged(nameof(FeatureRegion));
                    OnPropertyChanged(nameof(FeatureRegionName));
                }
            }
        }
        public string FeatureRegionName
        {
            get
            {
                if (!string.IsNullOrEmpty(FeatureRegion))
                {
                    if (MeterType == 1 || MeterType == 3)
                    {
                        return "数字区域: \n" + FeatureRegion;
                    }
                    else if (MeterType == 2)
                    {
                        return "首位指针: \n" + FeatureRegion;
                    }
                    else
                    {
                        return "";
                    }
                }
                else
                {
                    return "";
                }
            }
        }

        private int _lastCompress;
        public int LastCompress
        {
            get => _lastCompress;
            set
            {
                if(_lastCompress != value)
                {
                    _lastCompress = value;
                    OnPropertyChanged(nameof(LastCompress));
                    OnPropertyChanged(nameof(LastCompressName));
                }
            }
        }

        public string LastCompressName
        {
            get
            {
                if(LastCompress >= 0)
                {
                    return "上次压缩: " + LastCompress;
                }
                return "";
            }
        }

        public long _latestValue;
        public long LatestValue
        {
            get => _latestValue;
            set
            {
                if(_latestValue != value)
                {
                    _latestValue = value;
                    OnPropertyChanged(nameof(LatestValue));
                    OnPropertyChanged(nameof(LatestValueName));
                }
            }
        }

        public string LatestValueName
        {
            get
            {
                if (LatestValue >= 0)
                {
                    return $"上次值: {LatestValue / 10000}";
                }
                return string.Empty;
            }
        }

        public string _latestTime;
        public string LatestTime
        {
            get => _latestTime;
            set
            {
                if(_latestTime != value)
                {
                    _latestTime = value;
                    OnPropertyChanged(nameof(LatestTime));
                }
            }
        }

        public long _latestComplete;
        public long LatestComplete
        {
            get => _latestComplete;
            set
            {
                if(_latestComplete!= value)
                {
                    _latestComplete = value;
                    OnPropertyChanged(nameof(LatestComplete));
                    OnPropertyChanged(nameof(LatestCompleteName));
                }
            }
        }

        public string LatestCompleteName
        {
            get
            {
                if (LatestComplete >= 0)
                {
                    return $"完整值: {LatestComplete}";
                }
                return string.Empty;
            }
        }


        public Visibility ResultVisiable
        {
            get => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
        }


        public PatchDetailItem() { }

        public PatchDetailItem(TPatchDetail patchDetail)
        {
            ObjectHelper.CopyMatchingFields(patchDetail, this);
        }


        //public string GetEqualFlagName()
        //{
        //    if(RunFlag == 1)
        //    {
        //        if (string.IsNullOrWhiteSpace(StandValue))
        //        {
        //            return "-";
        //        }
        //        else
        //        {
        //            if (EqualFlag == 1)
        //            {
        //                return "√";
        //            }
        //            else
        //            {
        //                if(MeterType == ResultMeter  && MeterType > 0)
        //                {
        //                    return "×";
        //                }
        //                else
        //                {
        //                    return "∅";
        //                }
        //            }
        //        }
        //    }
        //    else
        //    {
        //        return "a";
        //    }
        //}

        public string GetEqualFlagName()
        {
            if (RunFlag == 1)
            {
                if (EqualFlag == 1)
                {
                    return "√";
                }
                else if(EqualFlag == 0)
                {
                    //错误的
                    return "×";
                }
                else if(EqualFlag == 2)
                {
                    //无效的
                    return "∅";
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return "";
            }
        }

        //public string GetEqualFlagColor()
        //{
        //    if(RunFlag == 1)
        //    {
        //        if (string.IsNullOrWhiteSpace(StandValue))
        //        {
        //            //flag = 2
        //            return "#666666";
        //        }
        //        else
        //        {
        //            if (EqualFlag == 1)
        //            {
        //                //flag = 1
        //                return "#28a745 ";
        //            }
        //            else
        //            {
        //                if(MeterType == ResultMeter && MeterType > 0)
        //                {
        //                    return "#dc3545 ";
        //                }
        //                else
        //                {
        //                    return "#FFA500";
        //                }
        //            }
        //        }
        //    }
        //    else
        //    {
        //        return "666666";
        //    }
        //}

        public string GetEqualFlagColor()
        {
            if (RunFlag == 1)
            {
                if (string.IsNullOrWhiteSpace(StandValue))
                {
                    return "#666666";
                }
                else
                {
                    if (EqualFlag == 1)
                    {                 
                        return "#28a745 ";
                    }
                    else if(EqualFlag == 2)
                    {
                        return "#FFA500";
                    }
                    else if(EqualFlag == 0)
                    {
                        return "#dc3545 ";
                    }
                    else
                    {
                        return "#666666";
                    }
                }
            }
            else
            {
                return "#666666";
            }
        }

        private string Get_ResultTypeColor()
        {
            switch (ResultType)
            {
                case 1:
                case 2:
                case 7:
                case 8:
                    return "#67c23a"; // 绿色
                default:
                    return "#e6a23c"; // 橙色
            }
        }

        private string GetFinalValueColor()
        {
            if (EqualFlag == 1)
            {
                return "Green";

            }else if(EqualFlag == 2)
            {
                return "#000000";
            }
            else
            {
                return "#FF4C4C";   //淡红色
            }

            //            if (string.IsNullOrWhiteSpace(StandValue))
            //{
            //    return "#666666";
            //}
            //else
            //{
            //    if (EqualFlag == 1)
            //    {
            //        return "#28a745 ";
            //    }
            //    else
            //    {
            //        return "#dc3545 ";
            //    }
            //}
        }

        private string Get_NumCountName()
        {
            switch (MeterType)
            {
                case 1:
                    return $"数字: {DigitCount} 指针{PointerCount}";
                case 2:
                    return $"指针: {PointerCount}";
                case 3:
                    return $"数字: {DigitCount}";

                default:
                    return string.Empty;
            }
        }


        private string Get_MeterTypeName()
        {
            switch (MeterType)
            {
                case 1:
                    return "数字+指针";
                case 2:
                    return "全指针";
                case 3:
                    return "全数字";
                case 4:
                    return "LED表";
                case 5:
                    return "压力表";
                default:
                    return "";
            }
        }

        //
        private string GetMeterTypeName(int meterType)
        {
            switch (meterType)
            {
                case 0:
                    return "0: 非水表";
                case 1:
                    return "1: 数字+指针表";
                case 2:
                    return "2: 全指针表";
                case 3:
                    return "3: 全数字表";
                case 88:
                    return "88: 没有配置";
                case 89:
                    return "89: 角度变化";
                case 90:
                    return "90: 概率太低";
                case 91:
                    return "91: 不符合最大水流";
                case 92:
                    return "92: 非递增或倒转";
            }
            return $"{meterType}: 未知";


        }


        private string[] Get_DebugInfoArray()
        {

            string[] sInfos = DebugInfo.Split(',');
            if (sInfos.Length != 24)
            {
                sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
            }

            return sInfos.ToArray();


            ////string[] sInfos = DebugInfo.Split(',');
            ////if (sInfos.Length != 24)
            ////{
            ////    sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
            ////}

            ////return sInfos.Select(s => s == "88" ? "" : s).ToArray();

            //// 将 DebugInfo 按逗号分割成字符串数组
            //string[] sInfos = DebugInfo.Split(',');

            //// 如果数组长度不等于24，则创建一个新的长度为24的数组并初始化为空字符串
            //if (sInfos.Length != 24)
            //{
            //    sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
            //}

            //// 对每个字符串进行处理：如果它是 "88" 则转为空字符串，
            //// 如果它是单个数字，则在前面补零
            //return sInfos.Select(s =>
            //{
            //    // 如果是 "88" 返回空字符串
            //    if (s == "88") return "";

            //    // 如果字符串长度为1，则在前面补零
            //    if (s.Length == 1)
            //    {
            //        return "0" + s;
            //    }

            //    // 否则返回原字符串
            //    return s;
            //}).ToArray();
        }

        public string GetValueByLastUnit(long value)
        {
            if(MeterType!= ResultMeter)
            {
                return (value / FaConstant.CUBE_VALUE).ToString();
            }

            double dValue = (double)value / FaConstant.CUBE_VALUE;
            return dValue.ToString();
        }

        //public static bool CheckEquailityWithStandValue(string standValue,string finalValue)
        //{
        //    ////return standValue.Equals(FinalValue);
        //    //string finalValue = FinalValue;

        //    // 获取整数部分
        //    string standIntegerPart = standValue.Split('.')[0];
        //    string finalIntegerPart = finalValue.Split('.')[0];

        //    // 比较整数部分
        //    if (standIntegerPart != finalIntegerPart)
        //    {
        //        return false;
        //    }

        //    // 获取小数部分，若没有小数部分，则默认为空字符串
        //    string standDecimalPart = standValue.Contains(".") ? standValue.Split('.')[1] : "";
        //    string finalDecimalPart = finalValue.Contains(".") ? finalValue.Split('.')[1] : "";

        //    // 如果standValue有小数部分，则根据其小数位数调整finalValue的小数部分
        //    if (!string.IsNullOrEmpty(standDecimalPart))
        //    {
        //        // 获取standValue小数部分的位数
        //        int decimalPlaces = standDecimalPart.Length;

        //        // 截取FinalValue的小数部分，或者补充零
        //        if (finalDecimalPart.Length > decimalPlaces)
        //        {
        //            // 截取多余的小数位
        //            finalDecimalPart = finalDecimalPart.Substring(0, decimalPlaces);
        //        }
        //        else if (finalDecimalPart.Length < decimalPlaces)
        //        {
        //            // 补充零
        //            finalDecimalPart = finalDecimalPart.PadRight(decimalPlaces, '0');
        //        }

        //        // 比较调整后的小数部分
        //        return standDecimalPart == finalDecimalPart;
        //    }

        //    // 如果standValue没有小数部分，只比较整数部分
        //    return true;

        //}


        public bool CheckEquailityWithStandValue(int standValue, long finalValue)
        {
            bool isEqual = false;
            //比较结果值与标准值是否相等
            if(MeterType == ResultMeter)
            {
                if(MeterType == 1)
                {
                    //数字+指针(只比较数字部分)
                    //获取真正数据部分的值
                    int standValue1 = (int)(standValue / LastUnit);
                    int finalValue1 = (int)(finalValue / (FaConstant.CUBE_VALUE * LastUnit));
                    return (standValue1 == finalValue1);
                }
                else if(MeterType == 2)
                {
                    //全指针
                    return (standValue * FaConstant.CUBE_VALUE) == finalValue;
                }
                else if(MeterType == 3)
                {
                    //全数字
                    return (standValue * FaConstant.CUBE_VALUE) == finalValue;
                }
            }
            return isEqual;
        }


        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;
        }

        /////////////////////////////
    }
}
