终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

MainWindow.xaml.cs 9.1 KiB

vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using BPASmartClient.Business;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Device;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.IoT;
  7. using BPASmartClient.Message;
  8. using BPASmartClient.Peripheral;
  9. using BPASmartClient.ViewModel;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Animation;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Navigation;
  26. using System.Windows.Shapes;
  27. namespace BPASmartClient.MilkWithTea
  28. {
  29. /// <summary>
  30. /// Interaction logic for MainWindow.xaml
  31. /// </summary>
  32. public partial class MainWindow : Window
  33. {
  34. public MainConsole mainConsole;
  35. public MainWindow()
  36. {
  37. InitializeComponent();
  38. Initialize();
  39. }
  40. Storyboard sb = new Storyboard();
  41. DoubleAnimation yd1 = new DoubleAnimation();//实例化浮点动画
  42. DoubleAnimation yd2 = new DoubleAnimation();
  43. private void Initialize()
  44. {
  45. ThreadManage.GetInstance().Start(new Action(() =>
  46. {
  47. GetDevices();
  48. mainConsole = new MainConsole();
  49. mainConsole.Start();
  50. }), "启动主控制台", false);
  51. ActionManage.GetInstance.Register(new Action(() =>
  52. {
  53. ThreadManage.GetInstance().Start(new Action(() =>
  54. {
  55. try
  56. {
  57. DataVClient.GetInstance().Initialize();
  58. DataVClient.GetInstance().Start();
  59. }
  60. catch (Exception ex)
  61. {
  62. MessageLog.GetInstance.ShowEx(ex.ToString());
  63. }
  64. }), "启动主IoT", false);
  65. }), "配置初始化完成Iot启动");
  66. ActionManage.GetInstance.Register(new Action<object>((o) =>
  67. {
  68. App.Current.Dispatcher.Invoke(new Action(() =>
  69. {
  70. if (o is IOTCommandModel iot)
  71. {
  72. switch (iot.CommandName)
  73. {
  74. case 0://控制类
  75. if (iot.CommandValue != null && iot.CommandValue.Count > 0)
  76. {
  77. switch (iot.CommandValue.Keys.ToList()[0])
  78. {
  79. case "程序启动":
  80. //mainConsole.Start();
  81. break;
  82. //mainConsole.Stop();
  83. case "程序停止":
  84. break;
  85. case "程序复位":
  86. //mainConsole.Stop();
  87. //mainConsole.Start();
  88. break;
  89. default:
  90. break;
  91. }
  92. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏控制", iot.CommandValue.Keys.ToList()[0]);
  93. }
  94. break;
  95. case 1://设置类
  96. break;
  97. case 2://通知类
  98. if (iot.CommandValue != null && iot.CommandValue.ContainsKey("text"))
  99. {
  100. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "大屏通知", iot.CommandValue["text"]);
  101. }
  102. break;
  103. default:
  104. break;
  105. }
  106. }
  107. }));
  108. }), "IotBroadcast");
  109. NavButton_Click(new Button() { Tag = "MainControlView" },null);
  110. }
  111. /// <summary>
  112. /// 获取设备集合
  113. /// </summary>
  114. private void GetDevices()
  115. {
  116. //List<string> IDevices = new List<string>();
  117. //List<string> IPeripherals = new List<string>();
  118. DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
  119. var files = directoryInfo.GetFiles().Where(p => p.FullName.Contains("BPASmartClient.") && p.FullName.Contains("dll")).ToList();
  120. List<string> fileList = new List<string>();
  121. var assemblies = AppDomain.CurrentDomain.GetAssemblies();
  122. var dlls = assemblies?.Where(p => p.FullName.Contains("BPASmartClient.")).ToList();
  123. List<string> dllList = new List<string>();
  124. if (files != null)
  125. {
  126. foreach (var item in files)
  127. {
  128. var res = System.IO.Path.GetFileNameWithoutExtension(item.FullName);
  129. if (res != null && res.Length > 0 && res.Contains(".") && !res.Contains("dll")) fileList.Add(res);
  130. }
  131. }
  132. if (dlls != null)
  133. {
  134. dlls.ForEach((item) =>
  135. {
  136. item.GetTypes().ToList().ForEach((type) =>
  137. {
  138. if (type.GetInterfaces().Contains(typeof(IDevice)))
  139. {
  140. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  141. }
  142. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  143. {
  144. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  145. }
  146. });
  147. dllList.Add(System.IO.Path.GetFileNameWithoutExtension(item.EscapedCodeBase));
  148. });
  149. }
  150. dllList.ForEach((item) => { if (fileList.Contains(item)) fileList.Remove(item); });
  151. fileList.ForEach((item) =>
  152. {
  153. Assembly.Load(item).GetTypes().ToList().ForEach((type) =>
  154. {
  155. if (type.GetInterfaces().Contains(typeof(IDevice)))
  156. {
  157. if (!type.FullName.Contains("BaseDevice")) ShopDeviceConfigViewModel.IDevices.Add(type.FullName);
  158. }
  159. else if (type.GetInterfaces().Contains(typeof(IPeripheral)))
  160. {
  161. if (!type.FullName.Contains("BasePeripheral")) ShopDeviceConfigViewModel.IPeripherals.Add(type.FullName);
  162. }
  163. });
  164. });
  165. }
  166. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  167. {
  168. this.DragMove();
  169. }
  170. private void CloseButton_Click(object sender, RoutedEventArgs e)
  171. {
  172. this.Close();
  173. }
  174. private void NavButton_Click(object sender, RoutedEventArgs e)
  175. {
  176. FadeInOut(0, 1, 750, 0);
  177. try
  178. {
  179. if (sender is Button bt )
  180. {
  181. Type type = Type.GetType($"BPASmartClient.MilkWithTea.View.{bt.Tag?.ToString()}");
  182. ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
  183. contentRegion.Content = (FrameworkElement)cti.Invoke(null);
  184. sb.Begin();
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]");
  190. }
  191. }
  192. private void FadeInOut(double opactityFrom ,double opactityTo,double yForm,double yTo)
  193. {
  194. contentRegion.RenderTransform = new TranslateTransform();
  195. yd1.From = opactityFrom;//动画的起始值
  196. yd1.To = opactityTo;//动画的结束值
  197. yd1.Duration = TimeSpan.FromSeconds(0.8);
  198. Storyboard.SetTarget(yd1, contentRegion);//给故事板绑定动画
  199. Storyboard.SetTargetProperty(yd1, new PropertyPath("Opacity"));//动画的依赖属性
  200. yd2.From = yForm;//动画的起始值
  201. yd2.To = yTo;//动画的结束值
  202. yd2.Duration = TimeSpan.FromSeconds(0.5);
  203. Storyboard.SetTarget(yd2, contentRegion);//给故事板绑定动画
  204. Storyboard.SetTargetProperty(yd2, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));//动画的依赖属性
  205. sb.Children.Add(yd1);//故事板添加动画
  206. sb.Children.Add(yd2);
  207. }
  208. }
  209. }