| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
-
- using CCDCount.DLL;
- using CCDCount.DLL.AlarmTools;
- using CCDCount.DLL.SqlDataClass;
- using CCDCount.DLL.Tools;
- using CCDCount.MODEL.AuditTrailModel;
- using CCDCount.MODEL.ConfigModel;
- using CCDCountWpf.Language;
- 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();
- PlcSettingMessageBus.pLCManagement.ClearBottSpeed();
- }
- private void Page_Loaded(object sender, RoutedEventArgs e)
- {
- this.Width = double.NaN; // 等效于 Auto
- this.Height = double.NaN;
- LOG.log("生产界面初始化语言切换事件", 6);
- LanguageManager.LanguageChangeEvent += ChangeLanguage;
- LOG.log("生产界面运行一次语言切换", 6);
- ChangeLanguage(null, EventArgs.Empty);
- StopIdentifyBtn.IsEnabled = false;
- StopIdentifyBtn.Opacity = 0.5;
- LOG.log("运行状态初始化", 6);
- 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 + "Failed to open", "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 + "Failed to open");
- 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 + "Failed to close", "CCDCountWpf:MainPage-StopCameraIdentify");
- MessageBox.Show(MessageBus.NowSettingLoadMainThread.cameraConfig.DeviceName + "_" + MessageBus.NowSettingLoadMainThread.cameraConfig.CameraSNNum + "Failed to close");
- }
- }
- }
- 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)
- {
- try
- {
- stopwatch.Restart();
- DateTime RecordTime = DateTime.Now;
- var OutTimeBatch = batchRecordModels.Where(x => x.RecordTime.AddMinutes(1) < RecordTime).ToList();
- OutTimeBatch.ForEach(x => batchRecordModels.Remove(x));
- if(!PlcSettingMessageBus.pLCManagement.ReadBottingVibrationTableHighSpeedValue(out ushort BottingVibrationTableHighSpeedValue, out ushort FilterVibrationTableHighSpeedValue, out ushort CountVibrationTableHighSpeedValue))
- {
- continue ;
- }
- if(!PlcSettingMessageBus.pLCManagement.ReadBottingCount(out ushort BottingCount))
- {
- continue ;
- }
- 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);
- }
- }
- catch(Exception ex)
- {
- LOG.error("MianPage-RunBatchRecord:Error:" + ex.Message);
- }
- }
- });
- }
- 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();
- PlcSettingMessageBus.pLCManagement.WriteCameraRunState(1);
- }
- }
- private void StopIdentifyBtn_Click(object sender, RoutedEventArgs e)
- {
- StopCameraIdentify();
- LOG.log("停止相机成功",6);
- StopBatchRecord();
- StartIdentifyBtn.IsEnabled = true;
- StartIdentifyBtn.Opacity = 1;
- StopIdentifyBtn.IsEnabled = false;
- StopIdentifyBtn.Opacity = 0.5;
- if (PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- PlcSettingMessageBus.pLCManagement.MachineStopToTrue();
- PlcSettingMessageBus.pLCManagement.WriteCameraRunState(0);
- }
- }
- private void BottingMaterialCylinderVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
- {
- if (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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 (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 5) >
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
- {
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 5;
- }
- }
- }
- private void BottValueSetUpBtn_Click(object sender, RoutedEventArgs e)
- {
- if (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 1) >
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
- {
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 1;
- }
- }
- }
- private void BottValueSetDownBtn_Click(object sender, RoutedEventArgs e)
- {
- if (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet - 1) <
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
- {
- PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet -= 1;
- }
- }
- }
- private void BottValueSetDownDownBtn_Click(object sender, RoutedEventArgs e)
- {
- if (SystemAlarm.CheckAlarmStatic(AlarmMessageList.PLC连接中))
- {
- MessageBox.Show("PLC Connecting,Please Wait");
- return;
- }
- if (PlcSettingMessageBus.pLCManagement != null && PlcSettingMessageBus.pLCManagement.IsConnect)
- {
- 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;
- }
- private void ChangeLanguage(object o, EventArgs e)
- {
- DataGridTextColumn MessageTypeColumn = FindName("DataGridMessageTypeColumn") as DataGridTextColumn;
- var MessageTypeHeard = MessageTypeColumn?.Header as TextBlock;
- //if (MessageTypeHeard.Text.ToString().Contains("类型"))
- //{
- // //修改绑定路径到本地化属性
- // MessageTypeColumn.Binding = new Binding("AlarmChType");
- //}
- //else if (MessageTypeHeard.Text.ToString().Contains("MessageType"))
- //{
- // MessageTypeColumn.Binding = new Binding("AlarmEnType");
- //}
- DataGridTextColumn MessageColumn = FindName("DataGridMessageColumn") as DataGridTextColumn;
- var MessageHeard = MessageColumn?.Header as TextBlock;
- if (MessageHeard.Text.ToString().Contains("信息"))
- {
- // 修改绑定路径到本地化属性
- MessageColumn.Binding = new Binding("AlarmChMess");
- }
- else if (MessageHeard.Text.ToString().Contains("Message"))
- {
- MessageColumn.Binding = new Binding("AlarmEnMess");
- }
- }
- private void BatchNumberTbx_GotFocus(object sender, RoutedEventArgs e)
- {
- OnScreenKeyboard.KeyBoardShow();
- }
- private void FormulationName_GotFocus(object sender, RoutedEventArgs e)
- {
- OnScreenKeyboard.KeyBoardShow();
- }
- }
- }
|