From 7fa019f18eb7dcf15ea6128bc04fd956af285a9a Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 8 Nov 2022 13:54:30 +0800 Subject: [PATCH] 1 --- BPASmartClient.ScreenLib/AppMain.cs | 4 +- BPASmartClient.ScreenLib/Helper/Main.cs | 68 ++++++- .../煮面机/ScreenMorksControlViewModel.cs | 132 ++++++++++++- BPASmartClient.ScreenMaxWok/App.config | 181 +++++++++++++++++- 4 files changed, 368 insertions(+), 17 deletions(-) diff --git a/BPASmartClient.ScreenLib/AppMain.cs b/BPASmartClient.ScreenLib/AppMain.cs index d49e53f5..3624193f 100644 --- a/BPASmartClient.ScreenLib/AppMain.cs +++ b/BPASmartClient.ScreenLib/AppMain.cs @@ -13,6 +13,8 @@ namespace BPASmartClient.ScreenLib { public AppMain(Window window, Type type) { + //启动Redis数据读取 + Main.GetInstance.Start(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; FSystemHelper.GetInstance.CreateDesktopShortcut(); WindowLargeScreen windowLarge = new WindowLargeScreen(); @@ -43,8 +45,6 @@ namespace BPASmartClient.ScreenLib } #endregion window = windowLarge; - Main main = new Main(); - main.Start(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) diff --git a/BPASmartClient.ScreenLib/Helper/Main.cs b/BPASmartClient.ScreenLib/Helper/Main.cs index 83d5f579..171082cf 100644 --- a/BPASmartClient.ScreenLib/Helper/Main.cs +++ b/BPASmartClient.ScreenLib/Helper/Main.cs @@ -1,5 +1,6 @@ using BPA.Communication; using BPA.Helper; +using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace BPASmartClient.ScreenLib /// /// 主函数 /// - public class Main + public class Main { #region 接口继承变量 /// @@ -53,18 +54,26 @@ namespace BPASmartClient.ScreenLib /// private static volatile Main _Instance; public static Main GetInstance => _Instance ?? (_Instance = new Main()); - public Main() { - RedisConnection= System.Configuration.ConfigurationManager.AppSettings["RedisConnection"].ToString(); - Name = System.Configuration.ConfigurationManager.AppSettings["DeviceMC"].ToString(); + public Main() + { + ReadPZ(); + if (PZdic.ContainsKey("RedisConnection")) + RedisConnection = PZdic["RedisConnection"]; + if (PZdic.ContainsKey("DeviceMC")) + Name = PZdic["DeviceMC"]; } /// /// 设备数据 /// - public List reeisDatas { get; set; } = new List(); + public Dictionary> redisDatasDic = new Dictionary>(); /// /// 告警数据 /// - public List reeisDatasAic { get; set; } = new List(); + public Dictionary> redisAicDatasDic = new Dictionary>(); + /// + /// 配置数据 + /// + public Dictionary PZdic=new Dictionary(); #endregion #region 线程处理函数 @@ -80,8 +89,42 @@ namespace BPASmartClient.ScreenLib if (IsRunning && IsRunningReids) { //1.读取Redis变量 - List Values = RedisHelper.GetInstance.Read>($"{Name}[Device]").Content; - List reeisDatasAic = RedisHelper.GetInstance.Read>($"{Name}[Alarm]").Content; + if (!string.IsNullOrEmpty(Name)) + { + redisDatasDic = new Dictionary>(); + redisAicDatasDic = new Dictionary>(); + if (Name.Contains(",")) + { + Name.Split(',')?.ToList().ForEach(x => + { + Dictionary valuePairs = new Dictionary(); + RedisHelper.GetInstance.Read>($"{x}[Device]").Content?.ToList().ForEach(k => { + valuePairs[k.VarName] = k; + }); + redisDatasDic[x]= valuePairs;//设备数据 + + Dictionary valuePairsAic = new Dictionary(); + RedisHelper.GetInstance.Read>($"{x}[Alarm]").Content?.ToList().ForEach(k => { + valuePairsAic[k.VarName] = k; + }); + redisAicDatasDic[x] = valuePairsAic;//告警数据 + }); + } + else + { + Dictionary valuePairs = new Dictionary(); + RedisHelper.GetInstance.Read>($"{Name}[Device]").Content?.ToList().ForEach(k => { + valuePairs[k.VarName] = k; + }); + redisDatasDic[Name] = valuePairs;//设备数据 + + Dictionary valuePairsAic = new Dictionary(); + RedisHelper.GetInstance.Read>($"{Name}[Alarm]").Content?.ToList().ForEach(k => { + valuePairsAic[k.VarName] = k; + }); + redisAicDatasDic[Name] = valuePairsAic;//告警数据 + } + } } } catch (Exception ex) @@ -150,6 +193,15 @@ namespace BPASmartClient.ScreenLib #region 调用事件 /// + /// 读取配置 + /// + public void ReadPZ() + { + System.Configuration.ConfigurationManager.AppSettings.AllKeys?.ToList().ForEach(key => { + PZdic[key]= System.Configuration.ConfigurationManager.AppSettings[key].ToString(); + }); + } + /// /// 初始化连接Redis MQTT /// public void Connection() diff --git a/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs b/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs index 49957813..a6af7f0b 100644 --- a/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs +++ b/BPASmartClient.ScreenLib/煮面机/ScreenMorksControlViewModel.cs @@ -7,12 +7,19 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Newtonsoft.Json; namespace BPASmartClient.ScreenLib { public class ScreenMorksControlViewModel : NotifyBase { #region 变量 + /// + /// 广告地址 + /// + public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } } + private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString()); + /// /// 柱状图显示集合 /// @@ -43,12 +50,6 @@ namespace BPASmartClient.ScreenLib public int YCDdCount { get { return _YCDdCount; } set { _YCDdCount = value; OnPropertyChanged(); } } private int _YCDdCount = 0; - /// - /// 广告地址 - /// - public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } } - private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString()); - /// /// 正在制作订单数据 /// @@ -186,6 +187,125 @@ namespace BPASmartClient.ScreenLib })); Thread.Sleep(5000); }), $"{DateTime.Now},线程服务"); + + + + } + + /// + /// 数据运行器 + /// + public void DataRun() + { + string Dev = "MorkS";//当前设备名称 + string name = Main.GetInstance.PZdic.ContainsKey($"{Dev}_Name") ? Main.GetInstance.PZdic[$"{Dev}_Name"].ToString(): DateTime.Now.ToString(); + ThreadManage.GetInstance().StartLong(new Action(() => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + if (!string.IsNullOrEmpty(name) && Main.GetInstance.redisDatasDic != null && Main.GetInstance.redisDatasDic.ContainsKey(name) && Main.GetInstance.redisDatasDic[name]!=null) + { + List list=new List { "IsRun", "RunStatus", "OrderCount", "ErrorOrderCount", "OrderMakeList", "OrderMakeListOver", "AlarmList" }; + list?.ForEach(x => { + if (Main.GetInstance.PZdic.ContainsKey($"{Dev}_{x}")) + { + if (Main.GetInstance.redisDatasDic[name].ContainsKey(Main.GetInstance.PZdic[$"{Dev}_{x}"])) + { + string _value = Main.GetInstance.redisDatasDic[name][Main.GetInstance.PZdic[$"{Dev}_{x}"]].VarVaule; + #region 执行更新界面数据 + switch (x) + { + case "IsRun"://是否运行 + DevIsRun = _value == "0" ? DevIsRun.停止 : DevIsRun.运行; + break; + case "RunStatus"://运行状态 + DevIsRun = _value == "0" ? DevIsRun.停止 : DevIsRun.运行; + break; + case "OrderCount"://是否运行 + try + { + DdCount = int.Parse(_value); + } + catch (Exception ex) + { + DdCount = 0; + } + break; + case "ErrorOrderCount": + try + { + YCDdCount = int.Parse(_value); + } + catch (Exception ex) + { + YCDdCount = 0; + } + break; + case "OrderMakeList": + try + { + OrderMakeList = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.SortNum)?.ToList().ForEach(par => { + OrderMakeList.Add(par); + }); + } + catch (Exception ex) + { + OrderMakeList = new ObservableCollection(); + } + break; + case "OrderMakeListOver": + try + { + OrderMakeListOver = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.SortNum)?.ToList().ForEach(par => { + OrderMakeListOver.Add(par); + }); + } + catch (Exception ex) + { + OrderMakeListOver = new ObservableCollection(); + } + break; + case "AlarmList": + try + { + AlarmList = new ObservableCollection(); + JsonConvert.DeserializeObject>(_value)?.OrderBy(l => l.AlarmTime)?.ToList().ForEach(par => { + AlarmList.Add(par); + }); + + //Histogram=new + //if (AlarmList.Count > 0) + //{ + + //} + } + catch (Exception ex) + { + OrderMakeListOver = new ObservableCollection(); + } + break; + default: + break; + } + #endregion + + } + } + + }); + } + + //Histogram = new[] { + // new KeyValuePair(name_s[0], new Random().Next(0,400)), + // new KeyValuePair(name_s[1], new Random().Next(0,400)), + // new KeyValuePair(name_s[2], new Random().Next(0,400)), + // new KeyValuePair(name_s[3], new Random().Next(0,400)), + // new KeyValuePair(name_s[4], new Random().Next(0,400))}; + })); + Thread.Sleep(500); + }), $"{name},线程服务"); } } } diff --git a/BPASmartClient.ScreenMaxWok/App.config b/BPASmartClient.ScreenMaxWok/App.config index 04466302..8d057181 100644 --- a/BPASmartClient.ScreenMaxWok/App.config +++ b/BPASmartClient.ScreenMaxWok/App.config @@ -3,7 +3,186 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file