
using CCDCount.DLL;
using CCDCount.DLL.SqlDataClass;
using CCDCount.MODEL.AuditTrailModel;
using CCDCount.MODEL.ConfigModel;
using LogClass;
using MvCameraControl;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static System.Net.Mime.MediaTypeNames;

namespace CCDCountWpf.WpfPage
{
    /// <summary>
    /// MainPage.xaml 的交互逻辑
    /// </summary>
    public partial class MainPage : Page
    {
        #region 变量与实例
        #endregion
        public MainPage()
        {
            InitializeComponent();
            DataContext  = ShowMessageBus.ShowBinding;
            InitFormationItems();
        }

        private void DataClear_Click(object sender, RoutedEventArgs e)
        {
            if(MessageBus.NowSettingLoadMainThread == null)
                return;
            MessageBus.NowSettingLoadMainThread.ClearHistoryActive();
            MessageBus.NowSettingLoadMainThread.ClearSendQueue();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            this.Width = double.NaN; // 等效于 Auto
            this.Height = double.NaN;

            StopIdentifyBtn.IsEnabled = false;
            StopIdentifyBtn.Opacity = 0.5;

            if(MessageBus.NowSettingLoadMainThread != null)
            {
                if (MessageBus.NowSettingLoadMainThread.CameraRunStatic)
                {
                    StartIdentifyBtn.IsEnabled = false;
                    StartIdentifyBtn.Opacity = 0.5;
                    StopIdentifyBtn.IsEnabled = true;
                    StopIdentifyBtn.Opacity = 1;
                }
                else
                {
                    StartIdentifyBtn.IsEnabled = true;
                    StartIdentifyBtn.Opacity = 1;
                    StopIdentifyBtn.IsEnabled = false;
                    StopIdentifyBtn.Opacity = 0.5;
                }
            }
        }

        /// <summary>
        /// 启动相机识别
        /// </summary>
        private bool RunCameraIdentify()
        {
            if(MessageBus.NowSettingLoadMainThread != null)
            {
                MessageBus.NowSettingLoadMainThread.BatchNumber = ShowMessageBus.ShowBinding.BatchNumber;
                if (MessageBus.NowSettingLoadMainThread.CameraConfigIsChange)
                {
                    MessageBus.NowSettingLoadMainThread.ReLoadCameraConfig();
                }
                //启动单相机实例的全部线程
                if (!MessageBus.NowSettingLoadMainThread.StartMianThread())
                {
                    FaultLog.RecordErrorMessage(MessageBus.NowSettingLoadMainThread.cameraConfig.DeviceName + "_" + MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum + "启动失败", "CCDCountWpf:MainPage-RunCameraIdentify");
                    //LOG.error(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "启动失败");
                    MessageBox.Show(MessageBus.NowSettingLoadMainThread.cameraConfig.DeviceName + "_" + MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum + "启动失败");
                    return false;
                }
            }
            MessageBus.NowLoadCammeraSN = MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum;
            return true;
        }

        /// <summary>
        /// 停止相机识别
        /// </summary>
        private void StopCameraIdentify()
        {
            if(MessageBus.NowSettingLoadMainThread != null)
            {
                //启动单相机实例的全部线程
                if (!MessageBus.NowSettingLoadMainThread.StopMianThread())
                {
                    FaultLog.RecordErrorMessage(MessageBus.NowSettingLoadMainThread.cameraConfig.DeviceName + "_" + MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum + "关闭失败", "CCDCountWpf:MainPage-StopCameraIdentify");
                    MessageBox.Show(MessageBus.NowSettingLoadMainThread.cameraConfig.DeviceName + "_" + MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum + "关闭失败");
                }
            }
        }

        private bool RunBatchIsRun =false;

        /// <summary>
        /// 运行批次记录
        /// </summary>
        /// <param name="BatchNumber"></param>
        private void RunBatchRecord(string BatchNumber)
        {
            if (RunBatchIsRun)
            {
                return;
            }
            List<BatchRecordModel> batchRecordModels = new List<BatchRecordModel>();
            Stopwatch stopwatch = new Stopwatch();
            BatchMessSqliteDataClass batchMessSqliteData = new BatchMessSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData\\BatchData_{BatchNumber}.db");
            RunBatchIsRun = true;
            Task.Run(() =>
            {
                while (RunBatchIsRun)
                {
                    stopwatch.Restart();
                    DateTime RecordTime = DateTime.Now;
                    var OutTimeBatch = batchRecordModels.Where(x => x.RecordTime.AddMinutes(1) < RecordTime).ToList();
                    OutTimeBatch.ForEach(x => batchRecordModels.Remove(x));
                    PlcSettingMessageBus.pLCManagement.ReadBottingVibrationTableHighSpeedValue(out ushort BottingVibrationTableHighSpeedValue, out ushort FilterVibrationTableHighSpeedValue, out ushort CountVibrationTableHighSpeedValue);
                    PlcSettingMessageBus.pLCManagement.ReadBottingCount(out ushort BottingCount);
                    ushort CountSPeed = (ushort)(batchRecordModels.Count() > 0 ? (BottingCount - batchRecordModels.Min(o => o.BottingCount)) > 0 ? BottingCount - batchRecordModels.Min(o => o.BottingCount) : 0 : 0);
                    ShowMessageBus.ShowBinding.BottingSpeed = CountSPeed;
                    BatchRecordModel batchRecordModel = new BatchRecordModel
                    {
                        BatchNunber = BatchNumber,
                        MaterialCylinderVibrationTableSpeed = BottingVibrationTableHighSpeedValue,
                        FilterVibrationTableSpeed = FilterVibrationTableHighSpeedValue,
                        CountVibrationTableSpeed = CountVibrationTableHighSpeedValue,
                        BottingCount = BottingCount,
                        BottingSpeed = CountSPeed,
                        RecordTime = RecordTime
                    };
                    batchMessSqliteData.InsertBatchMessage(batchRecordModel);
                    batchRecordModels.Add(batchRecordModel);
                    stopwatch.Stop();
                    int SleepTime = 998 - (int)stopwatch.ElapsedMilliseconds;
                    if(SleepTime > 0)
                    {
                        Thread.Sleep(SleepTime);
                    }
                }
            });
        }

        private void StopBatchRecord()
        {
            RunBatchIsRun = false;
        }

        private void StartIdentifyBtn_Click(object sender, RoutedEventArgs e)
        {
            if(String.IsNullOrWhiteSpace(ShowMessageBus.ShowBinding.BatchNumber))
            {
                MessageBox.Show("请输入批次号！");
                return;
            }
            RunBatchRecord(ShowMessageBus.ShowBinding.BatchNumber);
            if(!RunCameraIdentify())
            {
                return;
            }
            StartIdentifyBtn.IsEnabled = false;
            StartIdentifyBtn.Opacity = 0.5;
            StopIdentifyBtn.IsEnabled = true;
            StopIdentifyBtn.Opacity = 1;
            if(PlcSettingMessageBus.pLCManagement.IsConnect)
            {
                PlcSettingMessageBus.pLCManagement.MachineRunToTrue();
            }
        }

        private void StopIdentifyBtn_Click(object sender, RoutedEventArgs e)
        {
            StopCameraIdentify();
            StopBatchRecord();
            StartIdentifyBtn.IsEnabled = true;
            StartIdentifyBtn.Opacity = 1;
            StopIdentifyBtn.IsEnabled = false;
            StopIdentifyBtn.Opacity = 0.5;
            if (PlcSettingMessageBus.pLCManagement.IsConnect)
            {
                PlcSettingMessageBus.pLCManagement.MachineStopToTrue();
            }
        }

        private void BottingMaterialCylinderVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed + 10) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed += 10;
            }
        }

        private void BottingMaterialCylinderVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed + 1) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed += 1;
            }
        }

        private void BottingMaterialCylinderVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed - 1) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed -= 1;
            }
        }

        private void BottingMaterialCylinderVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed - 10) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed -= 10;
            }
        }

        private void BottingFilterVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed + 10) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed += 10;
            }
        }

        private void BottingFilterVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed + 1) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed += 1;
            }
        }

        private void BottingFilterVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed - 1) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed -= 1;
            }
        }

        private void BottingFilterVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed - 10) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed -= 10;
            }
        }

        private void BottingCountVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed + 10) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed += 10;
            }
        }

        private void BottingCountVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed + 1) >
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed += 1;
            }
        }

        private void BottingCountVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed - 1) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed -= 1;
            }
        }

        private void BottingCountVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed - 10) <
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed -= 10;
            }
        }

        private void BottValueSetUpUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 5) >
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 5;
            }
        }

        private void BottValueSetUpBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 1) >
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 1;
            }
        }

        private void BottValueSetDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet - 1) <
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet -= 1;
            }
        }

        private void BottValueSetDownDownBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet - 5) <
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
            {
                PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet -= 5;
            }
        }

        private void TextBox_KeyDown(object sender,KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                TextBox textBox = sender as TextBox;
                if (textBox != null)
                {
                    // 强制更新源数据
                    BindingExpression bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty);
                    bindingExpression.UpdateSource();
                }
            }
        }

        /// <summary>
        /// 初始化配方列表
        /// </summary>
        private void InitFormationItems()
        {
            string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
            if (!Directory.Exists(folderPath))
            {
                // 创建文件夹
                Directory.CreateDirectory(folderPath);
            }
            try
            {
                // 获取文件列表（包含子目录）
                string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
                ShowMessageBus.ShowBinding.FormulationItems.Clear();
                foreach (string file in files)
                {
                    ShowMessageBus.ShowBinding.FormulationItems.Add(Path.GetFileNameWithoutExtension(file));
                }
                if (ShowMessageBus.ShowBinding.FormulationName != null && ShowMessageBus.ShowBinding.FormulationName != string.Empty)
                {
                    try
                    {
                        FormulationCoBox.SelectedItem = ShowMessageBus.ShowBinding.FormulationName;
                    }
                    catch { }
                }
            }
            catch
            { }
        }

        private void SaveFormulationBtn_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(ShowMessageBus.ShowBinding.FormulationName))
            {
                MessageBox.Show("请输入配方名称！");
                return;
            }
            var ParaValue = PlcSettingMessageBus.pLCManagement.ReadAllPara();
            FormulationConfigClass formulationConfigClass = FormulationClass.InitFormulation(
                MessageBus.NowSettingLoadMainThread.cameraConfig, MessageBus.NowSettingLoadMainThread.shuLiConfig,ParaValue);
            if (formulationConfigClass == null)
            {
                MessageBox.Show("获取参数失败，请检查与PLC的连接");
                return;
            }
            formulationConfigClass.FormulationName = ShowMessageBus.ShowBinding.FormulationName;
            string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
            string FilePath = folderPath + "\\" + ShowMessageBus.ShowBinding.FormulationName + ".xml";
            if (File.Exists(FilePath))
            {
                var confirmResult = MessageBox.Show("配方已存在，是否覆盖？",
                                  "保存确认", MessageBoxButton.YesNo);
                if (confirmResult == MessageBoxResult.No)
                {
                    return;
                }
            }
            if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
            {
                XmlStorage.SerializeToXml(formulationConfigClass, FilePath);
                InitFormationItems();
                MessageBus.NowSettingLoadMainThread.FormulationName = formulationConfigClass.FormulationName;
                MessageBus.NowSettingLoadMainThread.IsLoadFormulation = true;
                MessageBox.Show("保存成功");
            }
        }

        private void ReadFormulationBtn_Click(object sender, RoutedEventArgs e)
        {
            string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations\\{FormulationCoBox.SelectedItem}.xml";
            if (!File.Exists(folderPath))
            {
                MessageBox.Show("指定文件不存在，请选择一个正确的配方");
                return;
            }
            try
            {
                FormulationConfigClass formulationConfigClass = null;
                formulationConfigClass = XmlStorage.DeserializeFromXml<FormulationConfigClass>(folderPath);
                LoadFormulation(formulationConfigClass);
                MessageBus.NowSettingLoadMainThread.FormulationName = formulationConfigClass.FormulationName;
                MessageBus.NowSettingLoadMainThread.IsLoadFormulation = true;
                MessageBox.Show("加载成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"读取文件时出错：{ex.Message}");
            }
        }

        /// <summary>
        /// 加载配方
        /// </summary>
        /// <param name="FormulationConfig"></param>
        private void LoadFormulation(FormulationConfigClass FormulationConfig)
        {
            ShowMessageBus.ShowBinding.AcquistionLineRate = FormulationConfig.AcquistionLineRateValue.ToString();
            ShowMessageBus.ShowBinding.ExposureTimeValue = FormulationConfig.ExposureTimeValue.ToString();
            ShowMessageBus.ShowBinding.Channel = FormulationConfig.Channel.ToString();
            ShowMessageBus.ShowBinding.FormulationName = FormulationConfig.FormulationName;
            ShowMessageBus.ShowBinding.MAX_OBJECT_LENGTH = FormulationConfig.MAX_Object_LENGTH.ToString();
            ShowMessageBus.ShowBinding.MIN_OBJECT_LENGTH = FormulationConfig.MIN_Object_LENGTH.ToString();
            ShowMessageBus.ShowBinding.PandingCode = FormulationConfig.PandingCode.ToString();
            ShowMessageBus.ShowBinding.RegionThreshold = FormulationConfig.RegionThreshold.ToString();

            PlcSettingMessageBus.PlcMessageShowBindage.FillingModel =
                FormulationConfig.FillingMode;
            PlcSettingMessageBus.PlcMessageShowBindage.BeltsSpeed =
                FormulationConfig.BeltsSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_FillingSpeed =
                FormulationConfig.ShakeTable1H_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_FillingSpeed =
                FormulationConfig.ShakeTable2H_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_FillingSpeed =
                FormulationConfig.ShakeTable3H_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1M_FillingSpeed =
                FormulationConfig.ShakeTable1M_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2M_FillingSpeed =
                FormulationConfig.ShakeTable2M_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3M_FillingSpeed =
                FormulationConfig.ShakeTable3M_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1L_FillingSpeed =
                FormulationConfig.ShakeTable1L_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2L_FillingSpeed =
                FormulationConfig.ShakeTable2L_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3L_FillingSpeed =
                FormulationConfig.ShakeTable3L_FillingSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1H_CacheSpeed =
                FormulationConfig.ShakeTable1H_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2H_CacheSpeed =
                FormulationConfig.ShakeTable2H_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3H_CacheSpeed =
                FormulationConfig.ShakeTable3H_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1M_CacheSpeed =
                FormulationConfig.ShakeTable1M_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2M_CacheSpeed =
                FormulationConfig.ShakeTable1M_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3M_CacheSpeed =
                FormulationConfig.ShakeTable3M_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable1L_CacheSpeed =
                FormulationConfig.ShakeTable1L_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable2L_CacheSpeed =
                FormulationConfig.ShakeTable1L_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.ShakeTable3L_CacheSpeed =
                FormulationConfig.ShakeTable3L_CacheSpeed;
            PlcSettingMessageBus.PlcMessageShowBindage.FillingValveCloseSpeed =
                FormulationConfig.FillingValveCloseSpeed.ToString();
            PlcSettingMessageBus.PlcMessageShowBindage.FillingValveClosePosition =
                FormulationConfig.FillingValveClosePosition.ToString();
            PlcSettingMessageBus.PlcMessageShowBindage.ValveDelytime =
                FormulationConfig.ValveDelytime;
            PlcSettingMessageBus.PlcMessageShowBindage.ScrewJogSpeed =
                FormulationConfig.ScrewJogSpeed.ToString();
            PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet =
                FormulationConfig.BottValueSet;
            PlcSettingMessageBus.PlcMessageShowBindage.FillingValveOpenSpeed =
                FormulationConfig.FillingValveOpenSpeed.ToString();
            PlcSettingMessageBus.PlcMessageShowBindage.FillingValveOpenPosition =
                FormulationConfig.FillingValveOpenPosition.ToString();
            PlcSettingMessageBus.PlcMessageShowBindage.CacheShutdownValue =
                FormulationConfig.CacheShutdownValue;
        }
    }
}
