123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- using MeterVision.db;
- 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));
- }
- }
- }
- //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 _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 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 string _lastUnit;
- public string 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 "";
- }
- }
- }
- 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 string _rawValue;
- public string RawValue
- {
- get => _rawValue;
- set
- {
- if (_rawValue != value)
- {
- _rawValue = value;
- if (MeterType == 0)
- {
- _rawValue = "";
- }
- OnPropertyChanged(nameof(RawValue));
- }
- }
- }
- private string _finalValue;
- public string FinalValue
- {
- get => _finalValue;
- set
- {
- if (_finalValue != value)
- {
- _finalValue = value;
- if (MeterType == 0)
- {
- _finalValue = "";
- }
- OnPropertyChanged(nameof(FinalValue));
- }
- }
- }
- public string FinalValueColor => GetFinalValueColor();
- //0不等,1相等 2:整数相等
- 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));
- }
- }
- }
- 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 Visibility ResultVisiable
- {
- get => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
- }
- public PatchDetailItem() { }
- public PatchDetailItem(TPatchDetail patchDetail)
- {
- ObjectHelper.CopyMatchingFields(patchDetail, this);
- }
- public string GetEqualFlagName()
- {
- if (string.IsNullOrWhiteSpace(StandValue))
- {
- return "-";
- }
- else
- {
- if(EqualFlag == 1)
- {
- //return "✔️";
- return "√";
- }
- else
- {
- //return "✖️";
- return "×";
- }
- }
- }
- public string GetEqualFlagColor()
- {
- if (string.IsNullOrWhiteSpace(StandValue))
- {
- //flag = 2
- return "#666666";
- }
- else
- {
- if (EqualFlag == 1)
- {
- //flag = 1
- return "#28a745 ";
- }
- else
- {
- //flag = 0
- return "#dc3545 ";
- }
- }
- }
- 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}";
- 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[] Get_DebugInfoArray()
- {
- //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 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;
- }
- /////////////////////////////
- }
- }
|