终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

378 wiersze
15 KiB

  1. using BPA.Message;
  2. using BPASmartClient.Business;
  3. using BPASmartClient.Control;
  4. using BPASmartClient.CustomResource.UserControls;
  5. using BPASmartClient.CustomResource.UserControls.MessageShow;
  6. using BPASmartClient.Device;
  7. using BPA.Helper;
  8. using BPASmartClient.IoT;
  9. using BPASmartClient.Model;
  10. using BPASmartClient.Model.冰淇淋.Enum;
  11. using BPASmartClient.Model.咖啡机.Enum;
  12. using BPASmartClient.Peripheral;
  13. using BPASmartClient.ViewModel;
  14. using Newtonsoft.Json;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Reflection;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using System.Windows.Controls;
  25. using System.Windows.Data;
  26. using System.Windows.Documents;
  27. using System.Windows.Input;
  28. using System.Windows.Media;
  29. using System.Windows.Media.Imaging;
  30. using System.Windows.Navigation;
  31. using System.Windows.Shapes;
  32. namespace BPASmartClient
  33. {
  34. /// <summary>
  35. /// Interaction logic for MainWindow.xaml
  36. /// </summary>
  37. public partial class MainWindow : Window
  38. {
  39. public MainConsole mainConsole;
  40. public MainWindow()
  41. {
  42. InitializeComponent();
  43. MainViewModel.GetInstance().window = this;
  44. this.DataContext = MainViewModel.GetInstance();
  45. ActionManage.GetInstance.Register(new Action(() =>
  46. {
  47. myMenu.Visibility = Visibility.Visible;
  48. myPanel.Visibility = Visibility.Collapsed;
  49. MenuItem_Click(new MenuItem() { Tag = "LogView", Header = "日志监视" }, null);
  50. }), "LoginSuccess");
  51. Initialize();
  52. }
  53. #region 私有
  54. /// <summary>
  55. /// 初始化
  56. /// </summary>
  57. private void Initialize()
  58. {
  59. this.ButClose.Click += (o, e) =>
  60. {
  61. MessageBoxResult res = MessageBox.Show("确定关闭上位机软件?", "警告", MessageBoxButton.OKCancel);
  62. if (res == MessageBoxResult.OK)
  63. {
  64. this.Close();
  65. Application.Current.Shutdown();
  66. }
  67. };
  68. this.br.MouseLeftButtonDown += (o, e) =>
  69. {
  70. if (e.ClickCount > 1)
  71. {
  72. if (this.WindowState == WindowState.Maximized)
  73. this.WindowState = WindowState.Normal;
  74. else if (this.WindowState == WindowState.Normal)
  75. this.WindowState = WindowState.Maximized;
  76. }
  77. if (e.LeftButton == MouseButtonState.Pressed) this.DragMove();
  78. };
  79. MenuItem_Click(new MenuItem() { Tag = "LogView", Header = "日志监视" }, null);
  80. TaskManage.GetInstance.Start(new Action(() =>
  81. {
  82. GetDevices();
  83. mainConsole = new MainConsole();
  84. mainConsole.Start();
  85. }), "启动主控制台", isRestart: false);
  86. ActionManage.GetInstance.Register(new Action(() =>
  87. {
  88. TaskManage.GetInstance.Start(new Action(() =>
  89. {
  90. try
  91. {
  92. DataVClient.GetInstance().Initialize();
  93. DataVClient.GetInstance().Start();
  94. }
  95. catch (Exception ex)
  96. {
  97. MessageLog.GetInstance.ShowEx(ex.ToString());
  98. }
  99. }), "启动主IoT", isRestart: false);
  100. }), "配置初始化完成Iot启动");
  101. ActionManage.GetInstance.Register(new Action<object>((o) =>
  102. {
  103. App.Current.Dispatcher.Invoke(new Action(() =>
  104. {
  105. if (o is IOTCommandModel iot)
  106. {
  107. switch (iot.CommandName)
  108. {
  109. case 0://控制类
  110. if (iot.CommandValue != null && iot.CommandValue.Count > 0)
  111. {
  112. switch (iot.CommandValue.Keys.ToList()[0])
  113. {
  114. case "程序启动":
  115. //mainConsole.Start();
  116. break;
  117. //mainConsole.Stop();
  118. case "程序停止":
  119. break;
  120. case "程序复位":
  121. //mainConsole.Stop();
  122. //mainConsole.Start();
  123. break;
  124. default:
  125. break;
  126. }
  127. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏控制", iot.CommandValue.Keys.ToList()[0]);
  128. }
  129. break;
  130. case 1://设置类
  131. break;
  132. case 2://通知类
  133. if (iot.CommandValue != null && iot.CommandValue.ContainsKey("text"))
  134. {
  135. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏通知", iot.CommandValue["text"]);
  136. }
  137. break;
  138. default:
  139. break;
  140. }
  141. }
  142. }));
  143. }), "IotBroadcast");
  144. }
  145. /// <summary>
  146. /// 获取设备集合
  147. /// </summary>
  148. private void GetDevices()
  149. {
  150. //List<string> IDevices = new List<string>();
  151. //List<string> IPeripherals = new List<string>();
  152. DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
  153. var files = directoryInfo.GetFiles().Where(p => p.FullName.Contains("BPASmartClient.") && p.FullName.Contains("dll")).ToList();
  154. List<string> fileList = new List<string>();
  155. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  156. var dlls = assemblies?.Where(p => p.FullName.Contains("BPASmartClient.")).ToList();
  157. List<string> dllList = new List<string>();
  158. if (files != null)
  159. {
  160. foreach (var item in files)
  161. {
  162. var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName);
  163. if (res != null && res.Length > 0 && res.Contains(".") && !res.Contains("dll")) fileList.Add(res);
  164. }
  165. }
  166. if (dlls != null)
  167. {
  168. dlls.ForEach((item) =>
  169. {
  170. item.GetTypes().ToList().ForEach((type) =>
  171. {
  172. if (type.GetInterfaces().Contains(typeof(IDevice)))
  173. {
  174. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  175. }
  176. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  177. {
  178. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  179. }
  180. });
  181. dllList.Add(System.IO.Path.GetFileNameWithoutExtension(item.EscapedCodeBase));
  182. });
  183. }
  184. dllList.ForEach((item) => { if (fileList.Contains(item)) fileList.Remove(item); });
  185. fileList.ForEach((item) =>
  186. {
  187. Assembly.Load(item).GetTypes().ToList().ForEach((type) =>
  188. {
  189. if (type.GetInterfaces().Contains(typeof(IDevice)))
  190. {
  191. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  192. }
  193. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  194. {
  195. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  196. }
  197. });
  198. });
  199. }
  200. /// <summary>
  201. /// 菜单切换栏
  202. /// </summary>
  203. private void MenuItem_Click(object sender, RoutedEventArgs e)
  204. {
  205. try
  206. {
  207. if (sender is MenuItem)
  208. {
  209. Type type = Type.GetType($"BPASmartClient.Control.{(sender as MenuItem).Tag?.ToString()}");
  210. if (type == null) { MenuClick((sender as MenuItem).Tag?.ToString()); return; }
  211. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  212. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  213. Title.Text = (sender as MenuItem).Header?.ToString() + "界面";
  214. }
  215. else if (sender is Button)
  216. {
  217. Type type = Type.GetType($"BPASmartClient.Control.{(sender as Button).Tag?.ToString()}");
  218. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  219. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  220. Title.Text = (sender as Button).Content?.ToString() + "界面";
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  226. }
  227. }
  228. private void Debug_Click(object sender, RoutedEventArgs e)
  229. {
  230. try
  231. {
  232. if (sender is MenuItem)
  233. {
  234. // Type type = Assembly.Load("BPASmartClient.MorkT").GetType("BPASmartClient.MorkT.View.DebugView");
  235. // Type type = Assembly.Load("BPASmartClient.MorkF").GetType("BPASmartClient.MorkF.View.DebugView");
  236. Type type = Assembly.Load("BPASmartClient.MorkM").GetType("BPASmartClient.MorkM.View.DebugView");
  237. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  238. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  239. Title.Text = (sender as MenuItem).Header?.ToString() + "界面";
  240. }
  241. }
  242. catch (Exception ex)
  243. {
  244. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  245. }
  246. }
  247. #endregion
  248. #region 公用
  249. /// <summary>
  250. /// 菜单点击
  251. /// </summary>
  252. /// <param name="name"></param>
  253. public void MenuClick(string name)
  254. {
  255. try
  256. {
  257. switch (name)
  258. {
  259. case "Close":
  260. this.Close();
  261. break;
  262. case "IOT":
  263. BrowserHelper.OpenDefaultBrowserUrl("http://iot.black-pa.com");
  264. break;
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuClick(),描述:[{ex.Message}]");
  270. }
  271. }
  272. #endregion
  273. #region 临时测试代码
  274. /// <summary>
  275. /// 测试按钮
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void Button_Click(object sender, RoutedEventArgs e)
  280. {
  281. //new Demo_MakeCoffeeEvent() { Id = 1 }.Publish();
  282. //new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish();
  283. //new DRCoffee_CoffeeCommCmdEvent() { Id = 1,CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish();
  284. MorkOrderPush morkOrderPush = new MorkOrderPush() { DeviceId = 2 };
  285. var temp = BPAPackage.Make(morkOrderPush, 12, BPA.Message.Enum.DeviceClientType.MORKS);
  286. Plugin.GetInstance().GetPlugin<MQTTMgr>().Publish("DOWN/MORKS/ORDER/12", temp.Serialize());
  287. }
  288. /// <summary>
  289. /// 初始化
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. private void init_Click(object sender, RoutedEventArgs e)
  294. {
  295. ActionManage.GetInstance.Send("InitDevice");
  296. }
  297. /// <summary>
  298. /// 登录
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void Button_Login(object sender, RoutedEventArgs e)
  303. {
  304. try
  305. {
  306. Type type = Type.GetType($"BPASmartClient.Control.AdminstratorsView");
  307. if (type == null) { MenuClick((sender as MenuItem).Tag?.ToString()); return; }
  308. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  309. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  310. Title.Text = "管理员登录界面";
  311. }
  312. catch (Exception ex)
  313. {
  314. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  315. }
  316. }
  317. /// <summary>
  318. /// 注销
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void Button_LogOut(object sender, RoutedEventArgs e)
  323. {
  324. myMenu.Visibility = Visibility.Hidden;
  325. myPanel.Visibility = Visibility.Visible;
  326. }
  327. #endregion
  328. private void DeviceMonitor_Click(object sender, RoutedEventArgs e)
  329. {
  330. string deviceName = string.Empty;
  331. var result = Plugin.GetInstance().GetPlugin<ConfigMgr>()?.deviceConfigModelJsons;
  332. if (result != null)
  333. {
  334. foreach (var shop in result)//店铺集合
  335. {
  336. deviceName = shop.deviceModels[0].DeviceName;
  337. }
  338. }
  339. if (deviceName != null)
  340. {
  341. Type type = Assembly.Load($"BPASmartClient.{deviceName}").GetType($"BPASmartClient.{deviceName}.View.DebugView");
  342. if (type == null) return;
  343. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  344. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  345. Title.Text = "设备监控界面";
  346. }
  347. }
  348. }
  349. }