From bf57a6cb97287e91b283665ffd56d2b67c393cf3 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Tue, 12 May 2026 16:54:19 +0800 Subject: [PATCH] =?UTF-8?q?feat=20-=20=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=8F=90=E9=86=92=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.WPF/MainWindow.xaml | 2 +- SlnMesnac.WPF/MainWindow.xaml.cs | 10 +++ .../IndexPage/ProductionLineUserControl.xaml | 28 ++++++- .../IndexPage/ChangeTypeViewModel.cs | 5 +- .../IndexPage/ProductionLineViewModel.cs | 80 ++++++++----------- 5 files changed, 73 insertions(+), 52 deletions(-) diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index bd5522e..3501201 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SlnMesnac.WPF" mc:Ignorable="d" - Title="新宝龙输送带RFID数字化系统" WindowStartupLocation="CenterScreen" WindowState="Maximized" Height="1020" Width="1420" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing" Icon="/NOVOTON.ico"> + Title="新宝龙输送带RFID数字化系统" WindowStartupLocation="CenterScreen" WindowState="Maximized" Height="1080" Width="1920" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing" Icon="/NOVOTON.ico"> diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs index 38c5a40..e330df1 100644 --- a/SlnMesnac.WPF/MainWindow.xaml.cs +++ b/SlnMesnac.WPF/MainWindow.xaml.cs @@ -74,6 +74,16 @@ namespace SlnMesnac.WPF private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { + var result = System.Windows.MessageBox.Show("确认要关闭系统吗?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question); + if (result != MessageBoxResult.OK) + { + e.Cancel = true; + return; + } + else + { + e.Cancel = false; + } Log.Information("系统关闭!"); } diff --git a/SlnMesnac.WPF/Page/IndexPage/ProductionLineUserControl.xaml b/SlnMesnac.WPF/Page/IndexPage/ProductionLineUserControl.xaml index 4e2684b..baffb62 100644 --- a/SlnMesnac.WPF/Page/IndexPage/ProductionLineUserControl.xaml +++ b/SlnMesnac.WPF/Page/IndexPage/ProductionLineUserControl.xaml @@ -92,12 +92,34 @@ + + + + @@ -138,8 +160,10 @@ - - + + + diff --git a/SlnMesnac.WPF/ViewModel/IndexPage/ChangeTypeViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexPage/ChangeTypeViewModel.cs index 29b67ad..93e8d0e 100644 --- a/SlnMesnac.WPF/ViewModel/IndexPage/ChangeTypeViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexPage/ChangeTypeViewModel.cs @@ -136,6 +136,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage if (res) { MessageBox.Show("停止盘点成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + WeakReferenceMessenger.Default.Send("Cancel", "Cancel"); } else { @@ -168,8 +169,8 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage //调用MES接口获取生产订单信息 //MessageBox.Show("MES订单获取成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); List mesOrderInfos = new List(); - //string response = "{\"code\":200,\"msg\":\"success\",\"data\":[{\"OrderNo\":\"SS075\",\"ProductCode\":\"4030502500100006\",\"ProductType\":\"钢丝带-ST-井下阻燃钢丝带\",\"ProductName\":\"输送带-井下阻燃钢丝带-ST\",\"ProductSpec\":\"1400mm;ST/S2500*1;8+8;MT/MT;D7.2;P15;N89\",\"PlanQty\":130.00,\"NextProductNo\":1}]}\r\n"; - string response = await _httpclient.GetMesOrderInfo(lineno, BeginDate.ToString("yyyy-MM-dd")); + string response = "{\"code\":200,\"msg\":\"success\",\"data\":[{\"OrderNo\":\"SS076\",\"ProductCode\":\"4030502500100006\",\"ProductType\":\"钢丝带-ST-井下阻燃钢丝带\",\"ProductName\":\"输送带-井下阻燃钢丝带-ST\",\"ProductSpec\":\"1400mm;ST/S2500*1;8+8;MT/MT;D7.2;P15;N89\",\"PlanQty\":130.00,\"NextProductNo\":2}]}\r\n"; + //string response = await _httpclient.GetMesOrderInfo(lineno, BeginDate.ToString("yyyy-MM-dd")); Console.WriteLine("接收MES接口返回:"+ response); // 反序列化 try diff --git a/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs index 8d8970e..d6f8065 100644 --- a/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs @@ -29,6 +29,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Threading; +using System.Xml.Serialization; using TouchSocket.Core; using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System; using Task = System.Threading.Tasks.Task; @@ -96,12 +97,30 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage } } + /// + /// 当前状态 空闲 盘点中 写入中 + /// + private string _CurrentState = "空闲"; + public string CurrentState + { + get => _CurrentState; + set + { + if (_CurrentState != value) + { + _CurrentState = value; + RaisePropertyChanged(() => CurrentState); + } + } + } + public ProductionLineViewModel() { GetOrderInfoCommand = new RelayCommand(t => RefreshData(t)); ChangeTypeView = App.ServiceProvider.GetService(); // 构造函数里注册 WeakReferenceMessenger.Default.Register(this, RefreshOrderNo); + WeakReferenceMessenger.Default.Register(this, "Cancel", StopMessage); _StringChange = App.ServiceProvider.GetService(); _logger = App.ServiceProvider.GetService(); appConfig = App.ServiceProvider.GetService(); @@ -176,6 +195,15 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).NextProductNo = real_Data.NextProductNo; rfidList.FirstOrDefault(x => x.deviceid == real_Data.Deviceid).Set_BeginIdentify().GetAwaiter().GetResult(); + CurrentState = "盘点中"; + } + + /// + /// 停止盘点消息 + /// + private void StopMessage(object o, string e) + { + CurrentState = "空闲"; } private void LoadDeviceInfo() @@ -208,44 +236,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage } - //Real_DataInfo real_DataInfo = new Real_DataInfo() - //{ - // Name = "1", - // Deviceid = "10001", - // Connectstr = "192.168.0.1:20108", - // LineNo = "6#", - // OrderNo = "123456", - // ProductType = "整芯带", - // WriteCount = "0", - // RfidCount = "20", - // IsOnline = "未连接", - // RfidASCII = "0", - // RfidEPC = "0", - // ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), - // WriteTime = DateTime.Now.AddSeconds(10).ToString("yyyy-MM-dd HH:mm:ss"), - // ProductStatus = "生产中", - // WriteStatus = "写入成功", - //}; - //Real_DataInfo real_DataInfo2 = new Real_DataInfo() - //{ - // Name = "2", - // Deviceid = "10002", - // Connectstr = "127.0.0.1:20108", - // LineNo = "7#", - // OrderNo = "123456", - // ProductType = "整芯带", - // WriteCount = "0", - // RfidCount = "20", - // IsOnline = "未连接", - // RfidASCII = "0", - // RfidEPC = "0", - // ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), - // WriteTime = DateTime.Now.AddSeconds(10).ToString("yyyy-MM-dd HH:mm:ss"), - // ProductStatus = "生产中", - // WriteStatus = "写入成功", - //}; - //real_DataInfos.Add(real_DataInfo); - //real_DataInfos.Add(real_DataInfo2); App.Current.Dispatcher.Invoke(() => { Deviceinfo.Clear(); @@ -283,7 +273,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage /// private async void RecvIdentifyData_Instance(string iCombineId, List tagInfos) { - string info = ""; try { if (string.IsNullOrEmpty(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo)) @@ -314,6 +303,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage + DateTime.Now.ToString("yy") + Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).NextProductNo + Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo; + CurrentState = "写入中"; //写入 三次重写 bool writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData); if (!writeflag) @@ -333,6 +323,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage } } } + Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteStatus = "成功"; LastWriteState = "成功"; @@ -355,27 +346,22 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage }; var a = databaseService._helper.Insert(real_Readdata); - //刷新界面 - //Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidASCII = Encoding.ASCII.GetString(tagInfos[0].EPC); - //Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - //RefreshEventArgs(iCombineId, tagInfos); AddRFIDData(iCombineId, tagInfos); } await Task.Run(async () => { await Task.Delay(1000); await rfidList.FirstOrDefault(x => x.deviceid == iCombineId)!.Set_BeginIdentify(); + CurrentState = "盘点中"; }); } catch (Exception e) { Log.Error($"读结果准备写入时异常:{e.Message}"); - } - finally - { - + CurrentState = "空闲"; } } + public void RefreshEventArgs(string iCombineId, List tagInfos) { try