From 8559abbd28b3ca5f91f07d461f04f45cb3ff3b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Thu, 3 Mar 2022 18:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Business/APIHelper.cs | 53 ++++++ .../HBLConsole.Business.csproj | 5 + HBLConsole.Business/MORKS.cs | 19 ++ HBLConsole.Business/MessageServerBase.cs | 22 ++- HBLConsole.Business/ServerData.cs | 56 ++++++ .../HBLConsole.Communication.csproj | 1 + HBLConsole.Communication/M2MQTT/MqttM2.cs | 9 - HBLConsole.Communication/ModbusTcpHelper.cs | 26 +++ HBLConsole.Factory/HBLConsole.Factory.csproj | 7 + HBLConsole.Factory/SimpleFactory.cs | 10 +- HBLConsole.GVL/GeneralConfig.cs | 20 +++ HBLConsole.GVL/HBLConsole.GVL.csproj | 3 + HBLConsole.GVL/InternetInfo.cs | 30 +++- .../HBLConsole.MainConsole.csproj | 7 + HBLConsole.MainConsole/HeartbeatReport.cs | 63 +++++++ HBLConsole.MainConsole/Main.cs | 34 +++- HBLConsole.Model/HBLConsole.Model.csproj | 6 + .../KeepParameter/BatchingInfoPar.cs | 16 ++ HBLConsole.Service/HBLConsole.Service.csproj | 1 + HBLConsole.Service/Sqlite.cs | 36 ++++ HBLConsole.sln | 10 +- HBLConsole/App.config | 4 +- HBLConsole/App.xaml.cs | 15 +- .../DialogWindow/View/ListDialogView.xaml | 7 +- .../ViewModel/ListDialogViewModel.cs | 169 +++++++----------- HBLConsole/HBLConsole.csproj | 3 +- HBLConsole/Model/MorkOrderPushPar.cs | 14 ++ HBLConsole/Model/OrderData.cs | 25 +++ HBLConsole/Server/SystemHelper.cs | 109 ----------- HBLConsole/Service/InitService.cs | 46 +++++ HBLConsole/View/MainView.xaml | 12 ++ HBLConsole/ViewModel/MainViewModel.cs | 12 +- HBLConsole/ViewModel/OrderStatusViewModel.cs | 2 +- HBLConsole/ViewModel/ViewModelBase.cs | 18 +- 34 files changed, 612 insertions(+), 258 deletions(-) create mode 100644 HBLConsole.Business/APIHelper.cs create mode 100644 HBLConsole.Business/MORKS.cs create mode 100644 HBLConsole.Business/ServerData.cs create mode 100644 HBLConsole.Communication/ModbusTcpHelper.cs create mode 100644 HBLConsole.GVL/GeneralConfig.cs create mode 100644 HBLConsole.MainConsole/HeartbeatReport.cs create mode 100644 HBLConsole.Model/KeepParameter/BatchingInfoPar.cs create mode 100644 HBLConsole.Service/Sqlite.cs create mode 100644 HBLConsole/Model/MorkOrderPushPar.cs create mode 100644 HBLConsole/Model/OrderData.cs delete mode 100644 HBLConsole/Server/SystemHelper.cs create mode 100644 HBLConsole/Service/InitService.cs diff --git a/HBLConsole.Business/APIHelper.cs b/HBLConsole.Business/APIHelper.cs new file mode 100644 index 0000000..311acef --- /dev/null +++ b/HBLConsole.Business/APIHelper.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using BPA.Utility; +using HBLConsole.GVL; + +namespace HBLConsole.Business +{ + public class APIHelper + { + + private volatile static APIHelper _Instance; + public static APIHelper GetInstance => _Instance ?? (_Instance = new APIHelper()); + private APIHelper() { } + + public void OrderStatusChange(string suborderId, int orderStatus) + { + var m = $"[/api/RobotOrder]_[{DateTime.Now.Ticks}]".AESEncrypt(); + WebApiHelper.GetInstance().HttpPost(InternetInfo.GetInstance.OrderStatusChange, ""); + } + + public void GetBatchingInfo() + { + + //string serviceAddress = "http://1.14.74.54:7001/api/Advertisement/htmlurl?storeId=3b007e32-f1cc-4021-b4e0-f4764fa90f12"; + //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress); + //request.Method = "GET"; + //request.ContentType = "text/html;charset=UTF-8"; + //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + //Stream myResponseStream = response.GetResponseStream(); + //StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); + //string retString = myStreamReader.ReadToEnd(); + //myStreamReader.Close(); + //myResponseStream.Close(); + ////Response.Write(retString); + //JObject obj = JObject.Parse(retString); + //string Data1 = obj["data"].ToString(); + //string Data = string.Empty; + //if (Data1.Length > 0) + // Data = obj["data"]["data"].ToString();//获取连接 + //GVL_VAR.GetInstance.SorbetesAddress = Data; + //if (SorbetesAddressNoti != null) SorbetesAddressNoti(Data); + //MessageLogOut.GetInstance.Show($"广告连接:={Data}"); + + } + + } +} diff --git a/HBLConsole.Business/HBLConsole.Business.csproj b/HBLConsole.Business/HBLConsole.Business.csproj index 5310c9f..7df6e4d 100644 --- a/HBLConsole.Business/HBLConsole.Business.csproj +++ b/HBLConsole.Business/HBLConsole.Business.csproj @@ -7,6 +7,8 @@ + + @@ -16,6 +18,9 @@ ..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll + + ..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll + diff --git a/HBLConsole.Business/MORKS.cs b/HBLConsole.Business/MORKS.cs new file mode 100644 index 0000000..fe07f1c --- /dev/null +++ b/HBLConsole.Business/MORKS.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Business +{ + public class MORKS + { + + private volatile static MORKS _Instance; + public static MORKS GetInstance => _Instance ?? (_Instance = new MORKS()); + private MORKS() { } + + + + } +} diff --git a/HBLConsole.Business/MessageServerBase.cs b/HBLConsole.Business/MessageServerBase.cs index dbca51b..4d55aa4 100644 --- a/HBLConsole.Business/MessageServerBase.cs +++ b/HBLConsole.Business/MessageServerBase.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using HBLConsole.Abstract; +using BPA.Message; +using HBLConsole.Model; +using HBLConsole.Service; +using BPA.Message.Enum; namespace HBLConsole.Business { @@ -11,7 +15,11 @@ namespace HBLConsole.Business { public override void AddOrder(T orderInfo) { - throw new NotImplementedException(); + if (orderInfo == null) return; + if (orderInfo is MorkOrderPush morkOrderpush) + { + ActionManagerment.GetInstance.Send("orderSend", morkOrderpush); + } } public override void BatchingCountInfo() @@ -21,12 +29,20 @@ namespace HBLConsole.Business public override void GetBatchingInfo(T batchingInfo) { - throw new NotImplementedException(); + if (batchingInfo == null) return; + if (batchingInfo is OrderMaterialDelivery BatchingInfos) + { + Json.GetInstance.Base.orderMaterialDelivery = BatchingInfos; + } } public override void GetRecipeBom(T recipeBomInfo) { - throw new NotImplementedException(); + if (recipeBomInfo == null) return; + if (recipeBomInfo is RecipeBoms recipeBom) + { + Json.GetInstance.Base.recipeBoms = recipeBom; + } } } } diff --git a/HBLConsole.Business/ServerData.cs b/HBLConsole.Business/ServerData.cs new file mode 100644 index 0000000..6a42d06 --- /dev/null +++ b/HBLConsole.Business/ServerData.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using HBLConsole.Service; +using System.Collections.Concurrent; +using BPA.Message; +using HBLConsole.GVL; +using HBLConsole.Interface; +using HBLConsole.Factory; + +namespace HBLConsole.Business +{ + public class ServerData + { + + private volatile static ServerData _Instance; + public static ServerData GetInstance => _Instance ?? (_Instance = new ServerData()); + private ServerData() { } + + ConcurrentQueue receives = new ConcurrentQueue(); + + IServerMessage serverMessage = new ServerMessage(); + + public void Init() + { + ThreadManagerment.GetInstance.StartLong(new Action(() => + { + while (receives.Count > 0) + { + if (receives.TryDequeue(out string msg)) + { + var package = BPAPackage.Deserialize(msg); + if (package.ClientId == InternetInfo.GetInstance.ClientId) + { + if (package.Message != null) + { + serverMessage.Universal(SimpleFactory.GetInstance.GetAbsMessageServer, package.Message); + } + } + } + } + Thread.Sleep(100); + }), ""); + } + + + public void ReceiveData(string info) + { + receives.Enqueue(info); + } + + } +} diff --git a/HBLConsole.Communication/HBLConsole.Communication.csproj b/HBLConsole.Communication/HBLConsole.Communication.csproj index b0c5653..90341c7 100644 --- a/HBLConsole.Communication/HBLConsole.Communication.csproj +++ b/HBLConsole.Communication/HBLConsole.Communication.csproj @@ -6,6 +6,7 @@ + diff --git a/HBLConsole.Communication/M2MQTT/MqttM2.cs b/HBLConsole.Communication/M2MQTT/MqttM2.cs index c2d5e8d..54d2913 100644 --- a/HBLConsole.Communication/M2MQTT/MqttM2.cs +++ b/HBLConsole.Communication/M2MQTT/MqttM2.cs @@ -10,16 +10,7 @@ using System.Threading.Tasks; using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt.Messages; using Newtonsoft.Json; -using Communication.Model; using System.Collections.Concurrent; -using Alarm.Enums; -using Alarm.Models; -using Alarm.Service; -using ServiceModel; -using GVL; -using BPA.Message; -using BPA.Utility; -using Communication.MQTT; using System.Drawing; using HBLConsole.Model; using HBLConsole.Service; diff --git a/HBLConsole.Communication/ModbusTcpHelper.cs b/HBLConsole.Communication/ModbusTcpHelper.cs new file mode 100644 index 0000000..97649f4 --- /dev/null +++ b/HBLConsole.Communication/ModbusTcpHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ModbusTcp; + +namespace HBLConsole.Communication +{ + public class ModbusTcpHelper + { + + private volatile static ModbusTcpHelper _Instance; + public static ModbusTcpHelper GetInstance => _Instance ?? (_Instance = new ModbusTcpHelper()); + private ModbusTcpHelper() { } + + ModbusClient modbusClient; + + public void Connect(string ip, int port) + { + modbusClient = new ModbusClient(ip, port); + + } + + } +} diff --git a/HBLConsole.Factory/HBLConsole.Factory.csproj b/HBLConsole.Factory/HBLConsole.Factory.csproj index c1f3a16..e10c7c5 100644 --- a/HBLConsole.Factory/HBLConsole.Factory.csproj +++ b/HBLConsole.Factory/HBLConsole.Factory.csproj @@ -6,7 +6,14 @@ + + + + ..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll + + + diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index 0bdd13c..ffc77ec 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -2,6 +2,8 @@ using HBLConsole.Interface; using System; using System.Reflection; +using BPA.Message.Enum; +using HBLConsole.GVL; namespace HBLConsole.Factory { @@ -15,14 +17,14 @@ namespace HBLConsole.Factory public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer()); private AbstractMessageServer _GetAbsMessageServer; - public IServerMessage GetIServerMessage => _GetIServerMessage ?? (_GetIServerMessage = new ServerMessage()); - private IServerMessage _GetIServerMessage; + //public IServerMessage GetIServerMessage => _GetIServerMessage ?? (_GetIServerMessage = new ServerMessage()); + //private IServerMessage _GetIServerMessage; private AbstractMessageServer GetAbstractMessageServer() { - Type type = Assembly.Load("MqttMessageServer").GetType($"MqttMessageServer.{GVL_VAR.GetInstance.StartDeviceType.ToString()}"); + Type type = Assembly.Load("HBLConsole.Business").GetType($"HBLConsole.Business.{GeneralConfig.GetInstance.DeviceType.ToString()}"); if (type == null) - type = Assembly.Load("MqttMessageServer").GetType($"MqttMessageServer.Base"); + type = Assembly.Load("HBLConsole.Business").GetType($"HBLConsole.Business.MessageServerBase"); return (AbstractMessageServer)Activator.CreateInstance(type); } } diff --git a/HBLConsole.GVL/GeneralConfig.cs b/HBLConsole.GVL/GeneralConfig.cs new file mode 100644 index 0000000..f6940ab --- /dev/null +++ b/HBLConsole.GVL/GeneralConfig.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Message.Enum; + +namespace HBLConsole.GVL +{ + public class GeneralConfig + { + + private volatile static GeneralConfig _Instance; + public static GeneralConfig GetInstance => _Instance ?? (_Instance = new GeneralConfig()); + private GeneralConfig() { } + + public DeviceClientType DeviceType { get; set; } + + } +} diff --git a/HBLConsole.GVL/HBLConsole.GVL.csproj b/HBLConsole.GVL/HBLConsole.GVL.csproj index b0ec00a..abc8fab 100644 --- a/HBLConsole.GVL/HBLConsole.GVL.csproj +++ b/HBLConsole.GVL/HBLConsole.GVL.csproj @@ -17,6 +17,9 @@ + + ..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll + ..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll diff --git a/HBLConsole.GVL/InternetInfo.cs b/HBLConsole.GVL/InternetInfo.cs index 6b0760d..e89238a 100644 --- a/HBLConsole.GVL/InternetInfo.cs +++ b/HBLConsole.GVL/InternetInfo.cs @@ -8,6 +8,8 @@ using BPA.Utility.Consul.YT; using System.IO; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Consul; +using System.Threading; +using HBLConsole.Service; namespace HBLConsole.GVL { @@ -22,17 +24,30 @@ namespace HBLConsole.GVL public void Init() { + NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); + while (!NetworkConnectState) + { + NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); + Thread.Sleep(2000); + } + ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"]; ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); - IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/BQLControl/app.json", false, 5_000); + IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000); IConfiguration config = configurationBuilder.Build(); - MqttUserName = config["Server:MqttUserName"]; - MqttAddress = config["Server:MqttAddress"]; - MqttPassword = config["Server:MqttPassword"]; - MqttPort = int.Parse(config["Server:MqttPort"]); + MqttUserName = config["MQTT:TcpAccount"]; + MqttPassword = config["MQTT:TcpPwd"]; + MqttAddress = config["MQTT:MqttAddress"]; + MqttPort = int.Parse(config["MQTT:MqttPort"]); + OrderStatusChange = config["API:robotstatuschange"]; } + /// + /// 订单状态更改接口地址 + /// + public string OrderStatusChange { get; set; } + /// /// Consul 地址 /// @@ -43,6 +58,11 @@ namespace HBLConsole.GVL /// public bool NetworkConnectState { get; set; } + /// + /// 广告地址 + /// + public Uri SorbetesAddress { get; set; } + /// /// 客户端ID /// diff --git a/HBLConsole.MainConsole/HBLConsole.MainConsole.csproj b/HBLConsole.MainConsole/HBLConsole.MainConsole.csproj index ea65f04..a3bf676 100644 --- a/HBLConsole.MainConsole/HBLConsole.MainConsole.csproj +++ b/HBLConsole.MainConsole/HBLConsole.MainConsole.csproj @@ -5,10 +5,17 @@ + + + + ..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll + + + diff --git a/HBLConsole.MainConsole/HeartbeatReport.cs b/HBLConsole.MainConsole/HeartbeatReport.cs new file mode 100644 index 0000000..8534524 --- /dev/null +++ b/HBLConsole.MainConsole/HeartbeatReport.cs @@ -0,0 +1,63 @@ +//using BPA.Message; +//using BPA.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +//using GVL; +//using BPA.Message.Enum; +//using BPA.Communication; +using System.Threading; +using HBLConsole.Service; +using HBLConsole.GVL; +using BPA.Message; +using HBLConsole.Communication; +using BPA.Message.Enum; +//using Communication.MQTT; +//using BPA.Message.Kafka; +//using Model.Enums; +//using ServiceModel; +//using Communication.SerialPortComm; + +namespace HBLConsole.MainConsole +{ + public class HeartbeatReport + { + + private volatile static HeartbeatReport _Instance; + public static HeartbeatReport GetInstance => _Instance ?? (_Instance = new HeartbeatReport()); + private HeartbeatReport() { } + + /// + /// 消息包 + /// + public BPAPackage MessagePackage { get; set; } = new BPAPackage(); + + public Func GetMessage { get; set; } + + DeviceStatus deviceStatus = new DeviceStatus(); + string Topic = string.Empty; + + public void Init() + { + deviceStatus.DeviceType = GeneralConfig.GetInstance.DeviceType; + deviceStatus.BatchingInfo = new List(); + deviceStatus.Healthy = DeviceHealthy.UnHealth; + Topic = TOPIC.GetInstance.GetHeatbeatTopic(GeneralConfig.GetInstance.DeviceType); + + ThreadManagerment.GetInstance.StartLong(new Action(() => + { + MessagePackage.ClientId = InternetInfo.GetInstance.ClientId; + MessagePackage.ClientType = GeneralConfig.GetInstance.DeviceType; + MessagePackage.MessageId = MessageID.MORK_HEART_BEAT; + MessagePackage.MessageVersion = 0x01; + MessagePackage.Timestamp = DateTime.Now; + MessagePackage.Message = GetMessage == null ? deviceStatus : GetMessage(); + MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize()); + Thread.Sleep(1000); + }), "设备心跳上报"); + + } + } +} diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 919ad6f..8b61932 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -3,6 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using HBLConsole.Model; +using HBLConsole.Service; +using HBLConsole.GVL; +using HBLConsole.Communication; +using BPA.Message; +using HBLConsole.Business; namespace HBLConsole.MainConsole { @@ -13,9 +19,35 @@ namespace HBLConsole.MainConsole public static Main GetInstance => _Instance ?? (_Instance = new Main()); private Main() { } - public void Init() + List Topics = new List(); + + public void BusinessInit() { + Topics.Clear(); + Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId)); + Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId)); + ThreadManagerment.GetInstance.Start(new Action(() => + { + InternetInfo.GetInstance.Init(); + MqttHelper.GetInstance.ConnectOk = new Action(() => + { + MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); + HeartbeatReport.GetInstance.Init(); + MqttHelper.GetInstance.MqttReceive = new Action((receivce) => + { + ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload)); + }); + }); + + MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); }); + + MqttHelper.GetInstance.MqttInitAsync(InternetInfo.GetInstance.MqttUserName, + InternetInfo.GetInstance.MqttPassword, + InternetInfo.GetInstance.MqttAddress, + InternetInfo.GetInstance.MqttPort, + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); + }), "业务逻辑初始化"); } } diff --git a/HBLConsole.Model/HBLConsole.Model.csproj b/HBLConsole.Model/HBLConsole.Model.csproj index f208d30..6b64af0 100644 --- a/HBLConsole.Model/HBLConsole.Model.csproj +++ b/HBLConsole.Model/HBLConsole.Model.csproj @@ -4,4 +4,10 @@ net5.0 + + + ..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll + + + diff --git a/HBLConsole.Model/KeepParameter/BatchingInfoPar.cs b/HBLConsole.Model/KeepParameter/BatchingInfoPar.cs new file mode 100644 index 0000000..0a7c6ba --- /dev/null +++ b/HBLConsole.Model/KeepParameter/BatchingInfoPar.cs @@ -0,0 +1,16 @@ +using BPA.Message; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Model +{ + public class BatchingInfoPar + { + public OrderMaterialDelivery orderMaterialDelivery { get; set; } = new OrderMaterialDelivery(); + + public RecipeBoms recipeBoms { get; set; } = new RecipeBoms(); + } +} diff --git a/HBLConsole.Service/HBLConsole.Service.csproj b/HBLConsole.Service/HBLConsole.Service.csproj index 5db1cf0..25f57f2 100644 --- a/HBLConsole.Service/HBLConsole.Service.csproj +++ b/HBLConsole.Service/HBLConsole.Service.csproj @@ -17,6 +17,7 @@ + diff --git a/HBLConsole.Service/Sqlite.cs b/HBLConsole.Service/Sqlite.cs new file mode 100644 index 0000000..3b3d07a --- /dev/null +++ b/HBLConsole.Service/Sqlite.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Sqlite; + +namespace HBLConsole.Service +{ + public class Sqlite : DbContext where T : class, new() + { + + private volatile static Sqlite _Instance; + public static Sqlite GetInstance => _Instance ?? (_Instance = new Sqlite()); + private Sqlite() { } + + public DbSet Base { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite($"FileName={path}"); + } + + static string path + { + get + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile")); + return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{typeof(T).Name}.db"; + } + } + + } +} diff --git a/HBLConsole.sln b/HBLConsole.sln index cf2470a..6bcc062 100644 --- a/HBLConsole.sln +++ b/HBLConsole.sln @@ -23,7 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Interface", "HBL EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Abstract", "HBLConsole.Abstract\HBLConsole.Abstract.csproj", "{366CA88C-D690-4669-9AB8-1948D3CBF127}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Factory", "Factory\HBLConsole.Factory.csproj", "{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Factory", "HBLConsole.Factory\HBLConsole.Factory.csproj", "{1B19BE8D-AFB9-4635-B114-8648B0C8BDF7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -71,10 +71,10 @@ Global {366CA88C-D690-4669-9AB8-1948D3CBF127}.Debug|Any CPU.Build.0 = Debug|Any CPU {366CA88C-D690-4669-9AB8-1948D3CBF127}.Release|Any CPU.ActiveCfg = Release|Any CPU {366CA88C-D690-4669-9AB8-1948D3CBF127}.Release|Any CPU.Build.0 = Release|Any CPU - {A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Release|Any CPU.Build.0 = Release|Any CPU + {1B19BE8D-AFB9-4635-B114-8648B0C8BDF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B19BE8D-AFB9-4635-B114-8648B0C8BDF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B19BE8D-AFB9-4635-B114-8648B0C8BDF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B19BE8D-AFB9-4635-B114-8648B0C8BDF7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HBLConsole/App.config b/HBLConsole/App.config index cf3bea9..70eb11a 100644 --- a/HBLConsole/App.config +++ b/HBLConsole/App.config @@ -4,10 +4,10 @@ - + - + diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index a0cd1d9..d8c6957 100644 --- a/HBLConsole/App.xaml.cs +++ b/HBLConsole/App.xaml.cs @@ -10,6 +10,8 @@ using HBLConsole.View; using HBLConsole.Server; using System.Diagnostics; using HBLConsole.Service; +using HBLConsole.Model; +using HBLConsole.MainConsole; namespace HBLConsole { @@ -19,24 +21,33 @@ namespace HBLConsole public partial class App : Application { MainView mainView = new MainView(); - ListDialogView listDialogView = new ListDialogView(); + ListDialogView listDialogView; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); - ActionManagerment.GetInstance.Register(new Func((o) => { return new object(); }), "aa"); SystemHelper.GetInstance.AutoStart(false); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + InitService.GetInstance.Register(); + InitService.GetInstance.DataInit(); mainView.Show(); + if (Json.GetInstance.Base.morkOrderPushes.Count > 0) + { + listDialogView = new ListDialogView(); + listDialogView.ShowDialog(); + } + MainConsole.Main.GetInstance.BusinessInit(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { + InitService.GetInstance.DataSave(); Process.Start($"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName}.exe"); } protected override void OnExit(ExitEventArgs e) { base.OnExit(e); + InitService.GetInstance.DataSave(); } } } diff --git a/HBLConsole/DialogWindow/View/ListDialogView.xaml b/HBLConsole/DialogWindow/View/ListDialogView.xaml index 93ef68b..849a319 100644 --- a/HBLConsole/DialogWindow/View/ListDialogView.xaml +++ b/HBLConsole/DialogWindow/View/ListDialogView.xaml @@ -204,7 +204,7 @@ Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> - + @@ -230,16 +230,15 @@ + Text="{Binding OrderPush.SortNum}" /> - + Text="{Binding OrderPush.GoodsName}" /> goodBatchings = new List(); - //for (int i = 0; i < 5; i++) - //{ - // goodBatchings.Add(new GoodBatchings() - // { - // BatchingCount = i, - // BatchingId = i, - // BatchingType = i, - // }); - //} - - //for (int i = 0; i < 10; i++) - //{ - // Json.GetInstance.Base.morksOrderPushes.Add(new MorksOrderPush() - // { - // Bowl = i, - // GoodBatchings = goodBatchings, - // RecipeId = i, - // SortNum = i, - // SuborderId = i.ToString(), - // }); - - // Json.GetInstance.Base.orderStatusLists.Add(new OrderStatusList() - // { - // SortNo = i.ToString(), - // OrderStatus = BPA.Message.ORDER_STATUS.WAIT, - // GoodName = i.ToString(), - // SubOrderId = i.ToString(), - // }); - //} - - - //Json.GetInstance.Save(); - - - //CloseCommand = new RelayCommand(() => { WeakReferenceMessenger.Default.Send("false", "Close"); }); - - //CancelCommand = new RelayCommand(() => - //{ - // Json.GetInstance.Base.morksOrderPushes.Clear(); - // Json.GetInstance.Base.orderStatusLists.Clear(); - // WeakReferenceMessenger.Default.Send("false", "Close"); - //}); - - //ConfirmCommand = new RelayCommand(() => - //{ - // foreach (var item in OrderLists) - // { - // if (!item.IsSelected) - // { - // var reslut = Json.GetInstance.Base.orderStatusLists.FirstOrDefault(p => p.SubOrderId == item.SubOrderId); - // if (reslut != null) Json.GetInstance.Base.orderStatusLists.Remove(reslut); - - // var OrderPushe = Json.GetInstance.Base.morksOrderPushes.FirstOrDefault(p => p.SuborderId == item.SubOrderId); - // if (OrderPushe != null) Json.GetInstance.Base.morksOrderPushes.Remove(OrderPushe); - // } - // } - // WeakReferenceMessenger.Default.Send("true", "Close"); - //}); - - //Json.GetInstance.Read(); - //foreach (var item in Json.GetInstance.Base.morksOrderPushes) - //{ - // var result = Json.GetInstance.Base.orderStatusLists.FirstOrDefault(p => p.SubOrderId == item.SuborderId); - // if (result != null) - // { - // orderStatusLists.Add(result); - // OrderLists.Add(new OrderList() - // { - // GoodName = result.GoodName, - // IsSelected = false, - // OrderStatus = result.OrderStatus, - // SortNo = result.SortNo, - // SubOrderId = result.SubOrderId, - // }); - // } - //} - - //if (Json.GetInstance.Base.morksOrderPushes.Count > 0) - //{ - // ThreadManagerment.GetInstance.Start(new Action(() => - // { - // Thread.Sleep(10000); - // if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); - // }), "延时退出"); - //} - //AllSelected = true; + CloseCommand = new RelayCommand(() => + { + Json.GetInstance.Base.morkOrderPushes.Clear(); + orderStatusLists.Clear(); + WeakReferenceMessenger.Default.Send("false", "Close"); + }); + + CancelCommand = new RelayCommand(() => + { + Json.GetInstance.Base.morkOrderPushes.Clear(); + orderStatusLists.Clear(); + WeakReferenceMessenger.Default.Send("false", "Close"); + }); + + ConfirmCommand = new RelayCommand(() => + { + foreach (var item in orderStatusLists) + { + if (!item.IsSelected) + { + var reslut = Json.GetInstance.Base.morkOrderPushes.FirstOrDefault(p => p.OrderPush.SuborderId == item.OrderPush.SuborderId); + if (reslut != null) Json.GetInstance.Base.morkOrderPushes.Remove(reslut); + } + } + foreach (var item in Json.GetInstance.Base.morkOrderPushes) + { + orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); + } + WeakReferenceMessenger.Default.Send("true", "Close"); + }); + + foreach (var item in Json.GetInstance.Base.morkOrderPushes) + { + orderStatusLists.Add(new OrderData() { IsSelected = true, OrderPush = item.OrderPush, OrderStatus = item.OrderStatus }); + } + + if (Json.GetInstance.Base.morkOrderPushes.Count > 0) + { + ThreadManagerment.GetInstance.Start(new Action(() => + { + Thread.Sleep(10000); + if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); + }), "延时退出"); + } + AllSelected = true; } - //public ObservableCollection OrderLists { get; set; } = new ObservableCollection(); - /// /// 全选标志 /// - //public bool AllSelected - //{ - // get { return _mAllSelected; } - // set - // { - // _mAllSelected = value; - // OnPropertyChanged(); - // for (int i = 0; i < OrderLists.Count; i++) - // { - // OrderLists.ElementAt(i).IsSelected = value; - // } - // } - //} - private bool _mAllSelected; + public bool AllSelected + { + get { return _mAllSelected; } + set + { + _mAllSelected = value; + OnPropertyChanged(); + for (int i = 0; i < orderStatusLists.Count; i++) + { + orderStatusLists.ElementAt(i).IsSelected = value; + } + } + } + private bool _mAllSelected = true; public RelayCommand CloseCommand { get; set; } @@ -139,5 +96,7 @@ namespace HBLConsole.DialogWindow.ViewModel + + } } diff --git a/HBLConsole/HBLConsole.csproj b/HBLConsole/HBLConsole.csproj index c68be84..b9209a3 100644 --- a/HBLConsole/HBLConsole.csproj +++ b/HBLConsole/HBLConsole.csproj @@ -191,11 +191,12 @@ - + + diff --git a/HBLConsole/Model/MorkOrderPushPar.cs b/HBLConsole/Model/MorkOrderPushPar.cs new file mode 100644 index 0000000..d8280b7 --- /dev/null +++ b/HBLConsole/Model/MorkOrderPushPar.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Message; + +namespace HBLConsole +{ + public class MorkOrderPushPar + { + public List morkOrderPushes = new List(); + } +} diff --git a/HBLConsole/Model/OrderData.cs b/HBLConsole/Model/OrderData.cs new file mode 100644 index 0000000..62dc091 --- /dev/null +++ b/HBLConsole/Model/OrderData.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Message; +using BPA.Message.Enum; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; + +namespace HBLConsole +{ + public class OrderData : ObservableObject + { + public bool IsSelected { get { return _mIsSelected; } set { _mIsSelected = value; OnPropertyChanged(); } } + private bool _mIsSelected; + + public MorkOrderPush OrderPush { get { return _mOrderPush; } set { _mOrderPush = value; OnPropertyChanged(); } } + private MorkOrderPush _mOrderPush = new MorkOrderPush(); + + public ORDER_STATUS OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; OnPropertyChanged(); } } + private ORDER_STATUS _mOrderStatus; + + } +} diff --git a/HBLConsole/Server/SystemHelper.cs b/HBLConsole/Server/SystemHelper.cs deleted file mode 100644 index 0d1aa1a..0000000 --- a/HBLConsole/Server/SystemHelper.cs +++ /dev/null @@ -1,109 +0,0 @@ -//using IWshRuntimeLibrary; -//using Microsoft.Win32; -//using System; -//using System.Collections.Generic; -//using System.Diagnostics; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; -//using System.Windows.Forms; - -//namespace HBLConsole.Server -//{ -// /// -// /// 系统操作类 -// /// -// public class SystemHelper -// { -// private volatile static SystemHelper _Instance; -// public static SystemHelper GetInstance => _Instance ?? (_Instance = new SystemHelper()); -// private SystemHelper() { } - -// /// -// /// 获取当前应用程序名称,包括后缀名 -// /// -// public string GetApplicationName => Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf(@"\") + 1); - -// /// -// /// 获取当前应用程序完整路径 -// /// -// public string GetApplicationPath => Application.ExecutablePath; - -// /// -// /// 创建桌面快捷方式 -// /// -// /// 成功或失败 -// public bool CreateDesktopShortcut() -// { -// //1、在COM对象中找到 Windows Script Host Object Model -// //2、添加引用 using IWshRuntimeLibrary; -// string deskTop = string.Empty; -// try -// { -// deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\"; -// if (System.IO.File.Exists(deskTop + GetApplicationName + ".lnk")) // -// { -// return true; -// //System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式 -// } -// WshShell shell = new WshShell(); - -// //快捷键方式创建的位置、名称 -// IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + GetApplicationName + ".lnk"); -// shortcut.TargetPath = GetApplicationPath; //目标文件 -// //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 -// shortcut.WorkingDirectory = System.Environment.CurrentDirectory; -// shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】 -// shortcut.Description = GetApplicationName; //描述 -// //shortcut.IconLocation = exePath + "\\logo.ico"; //快捷方式图标 -// shortcut.Arguments = ""; -// //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键 -// shortcut.Save(); //必须调用保存快捷才成创建成功 -// return true; -// } -// catch (Exception) -// { -// return false; -// } -// } - -// /// -// /// 设置开机自启动 -// /// -// /// true:开机启动,false:不开机自启 -// public void AutoStart(bool isAuto = true) -// { -// if (isAuto == true) -// { -// RegistryKey R_local = Registry.CurrentUser; -// RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); -// R_run.SetValue(GetApplicationName, Application.ExecutablePath); -// R_run.Close(); -// R_local.Close(); -// } -// else -// { -// RegistryKey R_local = Registry.CurrentUser; -// RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); -// R_run.DeleteValue(GetApplicationName, false); -// R_run.Close(); -// R_local.Close(); -// } -// } - -// /// -// /// 判断是否是自动启动 -// /// -// /// -// public bool IsAutoStart() -// { -// //RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"); -// RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"); -// return registryKey.GetValueNames().Contains(GetApplicationName); -// } - - - - -// } -//} diff --git a/HBLConsole/Service/InitService.cs b/HBLConsole/Service/InitService.cs new file mode 100644 index 0000000..ae6ba97 --- /dev/null +++ b/HBLConsole/Service/InitService.cs @@ -0,0 +1,46 @@ +using BPA.Message; +using BPA.Message.Enum; +using HBLConsole.Service; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole +{ + public class InitService + { + + private volatile static InitService _Instance; + public static InitService GetInstance => _Instance ?? (_Instance = new InitService()); + private InitService() { } + + public void DataInit() + { + Json.GetInstance.Read(); + } + + public void DataSave() + { + Json.GetInstance.Save(); + } + + public void Register() + { + ActionManagerment.GetInstance.Register(new Action((o) => + { + if (o is MorkOrderPush morkOrderPush) + { + Json.GetInstance.Base.morkOrderPushes.Add(new OrderData() + { + OrderStatus = ORDER_STATUS.WAIT, + IsSelected = true, + OrderPush = morkOrderPush + }); + } + }), "orderSend"); + } + + } +} diff --git a/HBLConsole/View/MainView.xaml b/HBLConsole/View/MainView.xaml index f604eb3..5d54888 100644 --- a/HBLConsole/View/MainView.xaml +++ b/HBLConsole/View/MainView.xaml @@ -24,6 +24,8 @@ + +