123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728 |
- using MeterVision.db;
- using MeterVision.FreeAi;
- using MeterVision.Util;
- using System;
- using System.ComponentModel;
- using System.Linq;
- using System.Windows;
- namespace MeterVision.model
- {
- public class SingleDetailItem : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- // 触发属性变更通知
- protected virtual 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 _singleDetailId;
- public string SingleDetailId
- {
- get => _singleDetailId;
- set
- {
- if (_singleDetailId != value)
- {
- _singleDetailId = value;
- OnPropertyChanged(nameof(SingleDetailId));
- }
- }
- }
- private string _createTime;
- public string CreateTime
- {
- get => _createTime;
- set
- {
- if (_createTime != value)
- {
- _createTime = value;
- OnPropertyChanged(nameof(CreateTime));
- }
- }
- }
- private string _srcImage;
- public string SrcImage
- {
- get => _srcImage;
- set
- {
- if (_srcImage != value)
- {
- _srcImage = value;
- OnPropertyChanged(nameof(SrcImage));
- }
- }
- }
- private int _runFlag;
- public int RunFlag
- {
- get => _runFlag;
- set
- {
- if (_runFlag != value)
- {
- _runFlag = value;
- OnPropertyChanged(nameof(RunFlag));
- OnPropertyChanged(nameof(ResultVisiable)); // 依赖 RunFlag 更新 ResultVisiable
- }
- }
- }
- 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
- OnPropertyChanged(nameof(FeatureRegionName));
- OnPropertyChanged(nameof(MeterRegionName));
- OnPropertyChanged(nameof(NumInUpper));
- OnPropertyChanged(nameof(LastUnitName2));
- OnPropertyChanged(nameof(FinalValueName2));
- }
- }
- }
- 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 double _lastUnit;
- public double LastUnit
- {
- get => _lastUnit;
- set
- {
- if (_lastUnit != value)
- {
- _lastUnit = value;
- OnPropertyChanged(nameof(LastUnit));
- OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
- OnPropertyChanged(nameof(FinalValueName2));
- OnPropertyChanged(nameof(LastUnitName2));
- }
- }
- }
- public string LastUnitName
- {
- get
- {
- if(MeterType > 0)
- {
- return $"尾数: {LastUnit}m³";
- }
- else
- {
- return "";
- }
- }
- }
- public string LastUnitName2
- {
- get
- {
- if(LastUnit == double.MaxValue)
- {
- return "";
- }
- return LastUnit.ToString();
- }
- }
- public int _numInUpper;
- public int NumInUpper
- {
- get => _numInUpper;
- set
- {
- if(_numInUpper != value)
- {
- _numInUpper = value;
- OnPropertyChanged(nameof(NumInUpper));
- OnPropertyChanged(nameof(NumInUpperName));
- }
- }
- }
- public string NumInUpperName
- {
- get
- {
- if (MeterType == 1 || MeterType == 3)
- {
- return $"数字在上: {(NumInUpper == 1 ? "是" : "否")}";
- }
- 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 string ResultTypeColor => Get_ResultTypeColor();
- private long _rawValue;
- public long RawValue
- {
- get => _rawValue;
- set
- {
- if (_rawValue != value)
- {
- _rawValue = value;
- if (MeterType == 0)
- {
- _rawValue = -1;
- }
- OnPropertyChanged(nameof(RawValue));
- }
- }
- }
- private long _finalValue;
- public long FinalValue
- {
- get => _finalValue;
- set
- {
- if (_finalValue != value)
- {
- _finalValue = value;
- //if(MeterType == 0)
- //{
- // _finalValue = "";
- //}
- OnPropertyChanged(nameof(FinalValue));
- OnPropertyChanged(nameof(FinalValue2));
- OnPropertyChanged(nameof(FinalValueName2));
- OnPropertyChanged(nameof(LastUnitName2));
- }
- }
- }
- //public double FinalValue2 => (double)(FinalValue / (double)10000);
- public string FinalValue2
- {
- get
- {
- if(FinalValue == long.MaxValue)
- {
- return "";
- }
- else
- {
- return ((double)(FinalValue / (double)10000)).ToString();
- }
- }
- }
- public string FinalValueName2
- {
- get
- {
- if (FinalValue == long.MaxValue)
- {
- return "";
- }
- else
- {
- if (LastUnit != double.MaxValue)
- {
- 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;
- }
- int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
- double dValue = iValue * LastUnit;
- return dValue.ToString($"F{decimalPlaces}");
- }
- else
- {
- return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
- }
- }
- }
- }
- private long _completeValue;
- public long CompleteValue
- {
- get => _completeValue;
- set
- {
- if(_completeValue != value)
- {
- _completeValue = value;
- OnPropertyChanged(nameof(CompleteValue));
- }
- }
- }
- //AI识别出的水表类型
- private int _resultMeter;
- public int ResultMeter
- {
- get => _resultMeter;
- set
- {
- if (_resultMeter != value)
- {
- _resultMeter = value;
- OnPropertyChanged(nameof(ResultMeter));
- }
- }
- }
- 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));
- }
- }
- }
- 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
- {
- get => $"最大流量: {FlowRate}";
- }
- private 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 double _lastValue;
- public double LastValue
- {
- get => _lastValue;
- set
- {
- if(_lastValue != value)
- {
- _lastValue = value;
- OnPropertyChanged(nameof(LastValue));
- OnPropertyChanged(nameof(LastValueName));
- }
- }
- }
- public string LastValueName => $"初值: {LastValue}";
- private string _lastTime;
- public string LastTime
- {
- get => _lastTime;
- set
- {
- if(_lastTime != value)
- {
- _lastTime = value;
- OnPropertyChanged(nameof(LastTime));
- OnPropertyChanged(nameof(LastTimeName1));
- OnPropertyChanged(nameof(LastTimeName2));
- }
- }
- }
- public string LastTimeName1 => ThisApp.ConvertDateFormat_Date(LastTime);
- public string LastTimeName2 => ThisApp.ConvertDateFormat_Time(LastTime);
- private string _deviceSn;
- public string DeviceSn
- {
- get => _deviceSn;
- set
- {
- if(_deviceSn != value)
- {
- _deviceSn = value;
- OnPropertyChanged(nameof(DeviceSn));
- }
- }
- }
- private string _sampleTime;
- public string SampleTime
- {
- get => _sampleTime;
- set
- {
- if(_sampleTime != value)
- {
- _sampleTime = value;
- OnPropertyChanged(nameof(SampleTime));
- }
- }
- }
- public Visibility ResultVisiable => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
- public SingleDetailItem() { }
- public SingleDetailItem(TSingleDetail singleDetail)
- {
- ObjectHelper.CopyMatchingFields(singleDetail, this);
- }
- private string Get_MeterTypeName()
- {
- switch (MeterType)
- {
- case 0:
- return "未识别出";
- case 1:
- return "数字+指针";
- case 2:
- return "全指针";
- case 3:
- return "全数字";
- case 4:
- return "LED表";
- case 5:
- return "压力表";
- case 88:
- return "无法摆正";
- case 90:
- return "概率太低";
- default:
- if(MeterType == int.MaxValue)
- {
- return "";
- }
- else
- {
- return "未知值";
- }
- //return "";
- //return "非水表";
- }
- }
- 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_ResultTypeColor()
- {
- switch (ResultType)
- {
- case 1:
- case 2:
- case 7:
- case 8:
- return "#67c23a"; // 绿色
- default:
- return "#e6a23c"; // 橙色
- }
- }
- private string[] Get_DebugInfoArray()
- {
- string[] sInfos = DebugInfo.Split(',');
- if (sInfos.Length != 24)
- {
- sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
- }
- return sInfos.ToArray();
- //return sInfos.Select(s => s == "88" ? "" : s).ToArray();
- }
- // complete_value = @CompleteValue,
- // result_meter = @ResultMeter,
- // new SQLiteParameter("@CompleteValue", detail.CompleteValue),
- // new SQLiteParameter("@ResultMeter", detail.ResultMeter),
- //CompleteValue = reader.GetString(reader.GetOrdinal("complete_value")),
- //ResultMeter = reader.GetInt32(reader.GetOrdinal("result_meter")),
- //DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
- //SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
- //-------------------------------------------------
- }
- }
|