選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AdWindow.xaml.cs 24 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. using HKCardOUT.Helper;
  2. using HKCardOUT.Logic.Service;
  3. using HKCardOUT.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. using BPA.Helper;
  18. using System.Timers;
  19. using DTO;
  20. using HKLib.Dto;
  21. using System.Collections.ObjectModel;
  22. using System.Threading;
  23. using System.Windows.Interop;
  24. using System.Collections.Concurrent;
  25. namespace HKCardOUT.Views
  26. {
  27. /// <summary>
  28. /// AdWindow.xaml 的交互逻辑
  29. /// </summary>
  30. public partial class AdWindow : Window
  31. {
  32. private int BindScreen = -1;
  33. public AdWindow(string input, int bindScreen)
  34. {
  35. InitializeComponent();
  36. this.Loaded += (sender, ev) =>
  37. {
  38. this.WindowState = WindowState.Normal;
  39. this.Width = 1920;
  40. this.Height = 1080;
  41. if (BindScreen != -1)
  42. {
  43. int[] NotchNum = new int[2];
  44. if (bindScreen == 0) { NotchNum[0] = 5; NotchNum[1] = 6; }
  45. if (bindScreen == 1) { NotchNum[0] = 3; NotchNum[1] = 4; }
  46. if (bindScreen == 2) { NotchNum[0] = 1; NotchNum[1] = 2; }
  47. (this.DataContext as AdWindowViewModel).InitData(NotchNum);
  48. ThreadManage.GetInstance().StartLong(new Action(() =>
  49. {
  50. if (DataBus.saleLogDtos.Count > 0)
  51. {
  52. HKLog.HKLogImport.WriteInfo("添加刷卡信息");
  53. if (DataBus.saleLogDtos.TryDequeue(out SaleLogDto info))
  54. {
  55. HKLog.HKLogImport.WriteInfo("取出信息加入队列");
  56. if (!DataBus.SaleLogDtoList.ContainsKey(info.Location))
  57. DataBus.SaleLogDtoList.TryAdd(info.Location, new ConcurrentQueue<SaleLogDto>());
  58. DataBus.SaleLogDtoList[info.Location].Enqueue(info);
  59. }
  60. }
  61. Thread.Sleep(100);
  62. }), "刷卡队列分配");
  63. }
  64. InitView2(input);
  65. //InitControl();
  66. };
  67. this.Closed += (sender, ev) =>
  68. {
  69. App.Current.Shutdown(0);
  70. };
  71. BindScreen = bindScreen;
  72. }
  73. public async void InitView2(string input)
  74. {
  75. var height = this.content.RowDefinitions[1].ActualHeight - 12;
  76. var width = this.content.ActualWidth - 11;
  77. input = input.Replace("style=\"width: 100%;\"", "");
  78. StringBuilder sb = new StringBuilder();
  79. sb.Append("<html><style>body {width: " + width + "px;height: " + height + "px;margin: 0;padding:0;}body p {width: " + width + "px;height: " + height + "px;}body p img {width: 100%;height: 100%;}</style><script>function Set(width, height) { var body = document.getElementsByTagName('body')[0]; body.style.width = width + 'px';body.style.height = height + 'px';var p = document.getElementsByTagName('p')[0]; p.style.width = width + 'px';p.style.height = height + 'px';}</script><body>" + input + "</body></html>");
  80. var html = sb.ToString();
  81. await view2.EnsureCoreWebView2Async(null);
  82. view2.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
  83. view2.CoreWebView2.Settings.AreDevToolsEnabled = false;
  84. view2.CoreWebView2.NavigateToString(html);
  85. }
  86. private void InitControl()
  87. {
  88. ThreadManage.GetInstance().StartLong(() =>
  89. {
  90. if (BindScreen == 0)
  91. {
  92. var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "05" || t.Address == "06").Select(t => t.GateId).FirstOrDefault();
  93. var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
  94. foreach (var item in area)
  95. {
  96. if (item.Key.ToLower().Equals("top"))
  97. {
  98. if (item.IsShow)
  99. {
  100. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  101. var width = this.content.ActualWidth - 9.5;
  102. this.content.Dispatcher.Invoke(async () =>
  103. {
  104. content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
  105. if (view2.CoreWebView2 != null)
  106. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  107. });
  108. }
  109. else
  110. {
  111. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  112. var width = this.content.ActualWidth - 10;
  113. this.content.Dispatcher.Invoke(async () =>
  114. {
  115. content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
  116. if (view2.CoreWebView2 != null)
  117. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  118. });
  119. }
  120. }
  121. if (item.Key.ToLower().Equals("bottom"))
  122. {
  123. if (item.IsShow)
  124. {
  125. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  126. var width = this.content.ActualWidth - 9.5;
  127. this.content.Dispatcher.Invoke(async () =>
  128. {
  129. content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
  130. if (view2.CoreWebView2 != null)
  131. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  132. });
  133. }
  134. else
  135. {
  136. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  137. var width = this.content.ActualWidth - 10;
  138. this.content.Dispatcher.Invoke(async () =>
  139. {
  140. content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
  141. if (view2.CoreWebView2 != null)
  142. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  143. });
  144. }
  145. }
  146. if (item.Key.ToLower().Equals("left"))
  147. {
  148. if (item.IsShow)
  149. {
  150. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  151. var width = this.content.ActualWidth - 9.5;
  152. this.alls.Dispatcher.Invoke(async () =>
  153. {
  154. alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
  155. if (view2.CoreWebView2 != null)
  156. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  157. });
  158. }
  159. else
  160. {
  161. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  162. var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
  163. this.alls.Dispatcher.Invoke(async () =>
  164. {
  165. alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
  166. if (view2.CoreWebView2 != null)
  167. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  168. });
  169. }
  170. }
  171. if (item.Key.ToLower().Equals("right"))
  172. {
  173. if (item.IsShow)
  174. {
  175. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  176. var width = this.content.ActualWidth - 9.5;
  177. this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  178. this.alls.Dispatcher.Invoke(async () =>
  179. {
  180. alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  181. if (view2.CoreWebView2 != null)
  182. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  183. });
  184. }
  185. else
  186. {
  187. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  188. var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
  189. this.alls.Dispatcher.Invoke(async () =>
  190. {
  191. alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
  192. if (view2.CoreWebView2 != null)
  193. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  194. });
  195. }
  196. }
  197. }
  198. }
  199. if (BindScreen == 1)
  200. {
  201. var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "01" || t.Address == "02").Select(t => t.GateId).FirstOrDefault();
  202. var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
  203. foreach (var item in area)
  204. {
  205. if (item.Key.ToLower().Equals("top"))
  206. {
  207. if (item.IsShow)
  208. {
  209. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  210. var width = this.content.ActualWidth - 9.5;
  211. this.content.Dispatcher.Invoke(async () =>
  212. {
  213. content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
  214. if (view2.CoreWebView2 != null)
  215. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  216. });
  217. }
  218. else
  219. {
  220. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  221. var width = this.content.ActualWidth - 10;
  222. this.content.Dispatcher.Invoke(async () =>
  223. {
  224. content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
  225. if (view2.CoreWebView2 != null)
  226. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  227. });
  228. }
  229. }
  230. if (item.Key.ToLower().Equals("bottom"))
  231. {
  232. if (item.IsShow)
  233. {
  234. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  235. var width = this.content.ActualWidth - 9.5;
  236. this.content.Dispatcher.Invoke(async () =>
  237. {
  238. content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
  239. if (view2.CoreWebView2 != null)
  240. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  241. });
  242. }
  243. else
  244. {
  245. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  246. var width = this.content.ActualWidth - 10;
  247. this.content.Dispatcher.Invoke(async () =>
  248. {
  249. content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
  250. if (view2.CoreWebView2 != null)
  251. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  252. });
  253. }
  254. }
  255. if (item.Key.ToLower().Equals("left"))
  256. {
  257. if (item.IsShow)
  258. {
  259. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  260. var width = this.content.ActualWidth - 9.5;
  261. this.alls.Dispatcher.Invoke(async () =>
  262. {
  263. alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
  264. if (view2.CoreWebView2 != null)
  265. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  266. });
  267. }
  268. else
  269. {
  270. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  271. var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
  272. this.alls.Dispatcher.Invoke(async () =>
  273. {
  274. alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
  275. if (view2.CoreWebView2 != null)
  276. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  277. });
  278. }
  279. }
  280. if (item.Key.ToLower().Equals("right"))
  281. {
  282. if (item.IsShow)
  283. {
  284. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  285. var width = this.content.ActualWidth - 9.5;
  286. this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  287. this.alls.Dispatcher.Invoke(async () =>
  288. {
  289. alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  290. if (view2.CoreWebView2 != null)
  291. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  292. });
  293. }
  294. else
  295. {
  296. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  297. var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
  298. this.alls.Dispatcher.Invoke(async () =>
  299. {
  300. alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
  301. if (view2.CoreWebView2 != null)
  302. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  303. });
  304. }
  305. }
  306. }
  307. }
  308. if (BindScreen == 2)
  309. {
  310. var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "05" || t.Address == "06").Select(t => t.GateId).FirstOrDefault();
  311. var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
  312. foreach (var item in area)
  313. {
  314. if (item.Key.ToLower().Equals("top"))
  315. {
  316. if (item.IsShow)
  317. {
  318. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  319. var width = this.content.ActualWidth - 9.5;
  320. this.content.Dispatcher.Invoke(async () =>
  321. {
  322. content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
  323. if (view2.CoreWebView2 != null)
  324. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  325. });
  326. }
  327. else
  328. {
  329. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  330. var width = this.content.ActualWidth - 10;
  331. this.content.Dispatcher.Invoke(async () =>
  332. {
  333. content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
  334. if (view2.CoreWebView2 != null)
  335. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  336. });
  337. }
  338. }
  339. if (item.Key.ToLower().Equals("bottom"))
  340. {
  341. if (item.IsShow)
  342. {
  343. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  344. var width = this.content.ActualWidth - 9.5;
  345. this.content.Dispatcher.Invoke(async () =>
  346. {
  347. content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
  348. if (view2.CoreWebView2 != null)
  349. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  350. });
  351. }
  352. else
  353. {
  354. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  355. var width = this.content.ActualWidth - 10;
  356. this.content.Dispatcher.Invoke(async () =>
  357. {
  358. content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
  359. if (view2.CoreWebView2 != null)
  360. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  361. });
  362. }
  363. }
  364. if (item.Key.ToLower().Equals("left"))
  365. {
  366. if (item.IsShow)
  367. {
  368. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  369. var width = this.content.ActualWidth - 9.5;
  370. this.alls.Dispatcher.Invoke(async () =>
  371. {
  372. alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
  373. if (view2.CoreWebView2 != null)
  374. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  375. });
  376. }
  377. else
  378. {
  379. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  380. var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
  381. this.alls.Dispatcher.Invoke(async () =>
  382. {
  383. alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
  384. if (view2.CoreWebView2 != null)
  385. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  386. });
  387. }
  388. }
  389. if (item.Key.ToLower().Equals("right"))
  390. {
  391. if (item.IsShow)
  392. {
  393. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  394. var width = this.content.ActualWidth - 9.5;
  395. this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  396. this.alls.Dispatcher.Invoke(async () =>
  397. {
  398. alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
  399. if (view2.CoreWebView2 != null)
  400. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  401. });
  402. }
  403. else
  404. {
  405. var height = this.content.RowDefinitions[1].ActualHeight - 10;
  406. var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
  407. this.alls.Dispatcher.Invoke(async () =>
  408. {
  409. alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
  410. if (view2.CoreWebView2 != null)
  411. await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
  412. });
  413. }
  414. }
  415. }
  416. }
  417. Thread.Sleep(5000);
  418. }, $"区域控制{BindScreen}", true);
  419. }
  420. }
  421. }