using CCDCount.DLL;
using CCDCount.MODEL.ConfigModel;
using CCDCount.MODEL.SqlDataModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace CCDCountWpf
{
    public class CameraCoboxItem
    {
        public string Name { get; set; }  // 显示的名称
        public string SNValue { get; set; }  // 对应的编号
    }

    public class ShowBindingClass : INotifyPropertyChanged
    {
        /// <summary>
        /// 累计数量
        /// </summary>
        private string allActiveNum = "0";
        public string AllActiveNum
        {
            get { return allActiveNum; }
            set
            {
                allActiveNum = value;
                OnPropertyChanged("AllActiveNum");
            }
        }

        /// <summary>
        /// 累计OK
        /// </summary>
        private string allOkNum = "0";
        public string AllOkNum
        {
            get { return allOkNum; }
            set
            {
                allOkNum = value;
                OnPropertyChanged("AllOkNum");
            }
        }

        /// <summary>
        /// 累计NG
        /// </summary>
        private string allNgNum = "0";
        public string AllNgNum
        {
            get { return allNgNum; }
            set
            {
                allNgNum = value;
                OnPropertyChanged("AllNgNum");
            }
        }

        /// <summary>
        /// 数粒速度
        /// </summary>
        private string shuLiSpeed = "0";
        public string ShuLiSpeed
        {
            get { return shuLiSpeed; }
            set
            {
                shuLiSpeed = value;
                OnPropertyChanged("ShuLiSpeed");
            }
        }

        /// <summary>
        /// 内存监控
        /// </summary>
        private string ramMonitor = "";
        public string RamMonitor
        {
            get { return ramMonitor; }
            set
            {
                ramMonitor = value;
                OnPropertyChanged("RamMonitor");
            }
        }

        /// <summary>
        /// CPU监控
        /// </summary>
        private string _CPUMonitor = "";
        public string CPUMonitor
        {
            get { return _CPUMonitor; }
            set
            {
                _CPUMonitor = value;
                OnPropertyChanged("CPUMonitor");
            }
        }

        /// <summary>
        /// 相机运行状态
        /// </summary>
        private string camRunStatic = "未运行";
        public string CamRunStatic
        {
            get { return camRunStatic; }
            set
            {
                camRunStatic = value;
                OnPropertyChanged("CamRunStatic");
            }
        }

        /// <summary>
        /// 历史结果当前图像编号
        /// </summary>
        private int historyImageNum = 1;
        public int HistoryImageNum
        {
            get { return historyImageNum; }
            set
            {
                historyImageNum = value;
                OnPropertyChanged("HistoryImageNum");
            }
        }

        /// <summary>
        /// 历史结果图像数量
        /// </summary>
        private int historyImageCount = 0;
        public int HistoryImageCount
        {
            get { return historyImageCount; }
            set
            {
                historyImageCount = value;
                OnPropertyChanged("HistoryImageCount");
            }
        }

        /// <summary>
        /// 历史结果图像
        /// </summary>
        private BitmapImage historyImage;
        public BitmapImage HistoryImage
        {
            get { return historyImage; }
            set
            {
                historyImage = value;
                OnPropertyChanged("HistoryImage");
            }
        }

        /// <summary>
        /// 结果图像
        /// </summary>
        private BitmapImage bitmapImage;
        public BitmapImage BitmapImage
        {
            get { return bitmapImage; }
            set
            {
                bitmapImage = value;
                OnPropertyChanged("BitmapImage");
            }
        }

        /// <summary>
        /// 结果图像
        /// </summary>
        private BitmapImage _DebugImage;
        public BitmapImage DebugImage
        {
            get { return _DebugImage; }
            set
            {
                _DebugImage = value;
                OnPropertyChanged("DebugImage");
            }
        }

        /// <summary>
        /// 相机运行状态字体颜色
        /// </summary>
        private SolidColorBrush cameraStaticColor = Brushes.Red;
        public SolidColorBrush CameraStaticColor
        {
            get { return cameraStaticColor; }
            set
            {
                cameraStaticColor = value;
                OnPropertyChanged("CameraStaticColor");
            }
        }

        /// <summary>
        /// 配方名称
        /// </summary>
        public string FormulationName
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.FormulationName;
                }
                return "";
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    string oldValue = MessageBus.NowSettingLoadMainThread.FormulationName;
                    MessageBus.NowSettingLoadMainThread.FormulationName = value;
                    MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"配方名称从{ oldValue }修改为{value}");
                    OnPropertyChanged("FormulationName");
                }
            }
        }

        /// <summary>
        /// 相机曝光时间
        /// </summary>
        public string ExposureTimeValue
        {
            get
            {
                // 从MessageBus获取最新值（保证读取时同步）
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.ExposureTimeValue.ToString();
                }
                return "";
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null && float.TryParse(value, out float newValue))
                {
                    // 同步更新到MessageBus
                    float oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.ExposureTimeValue;
                    MessageBus.NowSettingLoadMainThread.cameraConfig.ExposureTimeValue = newValue;
                    MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                    MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                    if (oldValue != newValue)
                        FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的曝光时间已从{oldValue}修改为{newValue}");
                    OnPropertyChanged("ExposureTimeValue");
                }
            }
        }

        /// <summary>
        /// 相机行频
        /// </summary>
        public string AcquistionLineRate
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.AcquistionLineRateValue.ToString();
                }
                else
                {
                    return "";
                }
            }
            set 
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        float oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.AcquistionLineRateValue;
                        MessageBus.NowSettingLoadMainThread.cameraConfig.AcquistionLineRateValue = int.Parse(value);
                        MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                        MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的行频从{oldValue}修改为{value}");
                        OnPropertyChanged("AcquistionLineRate");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("AcquistionLineRate-SetError");
                    }
                    
                }
            }
        }

        /// <summary>
        /// 图像宽度
        /// </summary>
        public string ImageWidth
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.Width.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.Width;
                        MessageBus.NowSettingLoadMainThread.cameraConfig.Width = int.Parse(value);
                        MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                        MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的图像宽从{oldValue}修改为{value}");
                        OnPropertyChanged("ImageWidth");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("ImageWidth-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 相机名称（用户自定义）
        /// </summary>
        public string CamUserName
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.CameraName;
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        string oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.CameraName == "" ? "null" : MessageBus.NowSettingLoadMainThread.cameraConfig.CameraName;
                        MessageBus.NowSettingLoadMainThread.cameraConfig.CameraName = value;
                        MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                        MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                        if (oldValue != value)
                            FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的用户自定义名从{oldValue}修改为{value}");
                        OnPropertyChanged("CamUserName");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("CamUserName-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 图像偏移X
        /// </summary>
        public string CamOffsetX
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.OffsetX.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.OffsetX;
                        MessageBus.NowSettingLoadMainThread.cameraConfig.OffsetX = int.Parse(value);
                        MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                        MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的图像X偏移从{oldValue}修改为{value}");
                        OnPropertyChanged("CamOffsetX");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("CamOffsetX-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 相机列表
        /// </summary>
        public ObservableCollection<CameraCoboxItem> CameraItems { get; } = new ObservableCollection<CameraCoboxItem>();

        public ObservableCollection<string> FormulationItems { get; } = new ObservableCollection<string>();

        public ObservableCollection<string> BatchItems { get; } = new ObservableCollection<string>();

        public ObservableCollection<string> ValueChangeItems { get; } = new ObservableCollection<string>();

        public ObservableCollection<string> ErrorMessItems { get; } = new ObservableCollection<string>();

        /// <summary>
        /// 当前选择的相机SN
        /// </summary>
        public string CameraSNNum
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        string oldValue = MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum;
                        MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum = value;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.CameraSN = value;
                        MessageBus.NowSettingLoadMainThread.CameraConfigIsChange = true;
                        FaultLog.RecordValueChangeMessage($"相机{MessageBus.NowSettingLoadMainThread.cameraConfig.CamerNo}的SN从{oldValue}修改为{value}");
                        OnPropertyChanged("CameraSNNum");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("CameraSNNum-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 预处理阈值
        /// </summary>
        public string RegionThreshold
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.RegionThreshold.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.RegionThreshold;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.RegionThreshold = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的预处理阈值从{oldValue}修改为{value}");
                        OnPropertyChanged("RegionThreshold");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("RegionThreshold-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 数粒通道数
        /// </summary>
        public string Channel
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.Channel.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.Channel;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.Channel = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的通道数从{oldValue}修改为{value}");
                        OnPropertyChanged("Channel");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Channel-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 噪声滤波阈值
        /// </summary>
        public string NoiseFilter
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.NoiseFilter_Threshold.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.NoiseFilter_Threshold;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.NoiseFilter_Threshold = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的噪声滤波阈值从{oldValue}修改为{value}");
                        OnPropertyChanged("NoiseFilter");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("NoiseFilter-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最小宽
        /// </summary>
        public string MIN_OBJECT_WIDTH
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_WIDTH.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_WIDTH;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_WIDTH = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最小宽从{oldValue}修改为{value}");
                        OnPropertyChanged("MIN_OBJECT_WIDTH");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MIN_OBJECT_WIDTH-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最大宽
        /// </summary>
        public string MAX_OBJECT_WIDTH
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_WIDTH.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_WIDTH;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_WIDTH = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最大宽从{oldValue}修改为{value}");
                        OnPropertyChanged("MAX_OBJECT_WIDTH");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MAX_OBJECT_WIDTH-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最小高
        /// </summary>
        public string MIN_OBJECT_HEIGHT
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_HEIGHT.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_HEIGHT;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_OBJECT_HEIGHT = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最小高从{oldValue}修改为{value}");
                        OnPropertyChanged("MIN_OBJECT_HEIGHT");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MIN_OBJECT_HEIGHT-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最大高
        /// </summary>
        public string MAX_OBJECT_HEIGHT
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_HEIGHT.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_HEIGHT;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_OBJECT_HEIGHT = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最大高从{oldValue}修改为{value}");
                        OnPropertyChanged("MAX_OBJECT_HEIGHT");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MAX_OBJECT_HEIGHT-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最长长度
        /// </summary>
        public string MAX_OBJECT_LENGTH
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_Object_LENGTH.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_Object_LENGTH;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MAX_Object_LENGTH = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的合格粒最长长度从{oldValue}修改为{value}");
                        OnPropertyChanged("MAX_Object_LENGTH");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MAX_Object_LENGTH-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最短长度
        /// </summary>
        public string MIN_OBJECT_LENGTH
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_Object_LENGTH.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_Object_LENGTH;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MIN_Object_LENGTH = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的合格粒的最短长度从{oldValue}修改为{value}");
                        OnPropertyChanged("MIN_Object_LENGTH");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MIN_Object_LENGTH-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最小面积
        /// </summary>
        public string MinArea
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MinArea.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MinArea;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MinArea = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最小面积从{oldValue}修改为{value}");
                        OnPropertyChanged("MinArea");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MinArea-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 合格粒最大面积
        /// </summary>
        public string MaxArea
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MaxArea.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.MaxArea;
                        MessageBus.NowSettingLoadMainThread.shuLiConfig.MaxArea = int.Parse(value);
                        if (oldValue != int.Parse(value))
                            FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的异常粒最大面积从{oldValue}修改为{value}");
                        OnPropertyChanged("MaxArea");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("MaxArea-SetError");
                    }

                }
            }
        }


        /// <summary>
        /// 异常粒识别码
        /// </summary>
        public string PandingCode
        {
            get
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    return MessageBus.NowSettingLoadMainThread.shuLiConfig.MaxArea.ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                if (MessageBus.NowSettingLoadMainThread != null)
                {
                    try
                    {
                        int oldValue = MessageBus.NowSettingLoadMainThread.shuLiConfig.PandingCode;
                        if(oldValue != int.Parse(value))
                        {
                            MessageBus.NowSettingLoadMainThread.shuLiConfig.PandingCode = int.Parse(value);
                            if (oldValue != int.Parse(value))
                                FaultLog.RecordValueChangeMessage($"数粒识别{MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum}的判断标准识别码从{oldValue}修改为{value}");
                        }
                        OnPropertyChanged("PandingCode");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("PandingCode-SetError");
                    }

                }
            }
        }

        /// <summary>
        /// 错误信息列表
        /// </summary>
        private List<ErroeMesDataModelClass> errMessageList = new List<ErroeMesDataModelClass>();
        public List<ErroeMesDataModelClass> ErrMessageShowList
        {
            get { return errMessageList; }
            set
            {
                errMessageList = value;
                OnPropertyChanged("errMessageList");
            }
        }

        private string showErrMessage = "";
        public string ShowErrMessage
        {
            get { return showErrMessage; }
            set
            {
                showErrMessage = value;
                OnPropertyChanged("showErrMessage");
            }
        }

        /// <summary>
        /// 用户数据信息列表
        /// </summary>
        private List<UserMesDataModelClass> userMesDataModels = new List<UserMesDataModelClass>();
        public List<UserMesDataModelClass> UserMesDataModels
        {
            get { return userMesDataModels; }
            set
            {
                userMesDataModels = value;
                OnPropertyChanged("userMesDataModels");
            }
        }

        private string batchNumber = "";
        public string BatchNumber
        {
            get { return batchNumber; }
            set
            {
                batchNumber = value;
                OnPropertyChanged("BatchNumber");
            }
        }

        private int bottingCount;
        public int BottingCount
        {
            get { return bottingCount; }
            set
            {
                bottingCount = value;
                OnPropertyChanged("BottingCount");
            }
        }

        private ushort bottingSpeed;
        public ushort BottingSpeed
        {
            get { return bottingSpeed; }
            set
            {
                bottingSpeed = value;
                OnPropertyChanged("BottingSpeed");
            }
        }

        //数据绑定核心实现
        public event PropertyChangedEventHandler PropertyChanged;

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