|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- using HKCardOUT.Helper;
- using HKCardOUT.Logic.Service;
- using HKCardOUT.ViewModels;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using BPA.Helper;
- using System.Timers;
- using DTO;
- using HKLib.Dto;
- using System.Collections.ObjectModel;
- using System.Threading;
- using System.Windows.Interop;
- using System.Collections.Concurrent;
-
- namespace HKCardOUT.Views
- {
- /// <summary>
- /// AdWindow.xaml 的交互逻辑
- /// </summary>
- public partial class AdWindow : Window
- {
- private int BindScreen = -1;
- public AdWindow(string input, int bindScreen)
- {
- InitializeComponent();
-
- this.Loaded += (sender, ev) =>
- {
- this.WindowState = WindowState.Normal;
- this.Width = 1920;
- this.Height = 1080;
- if (BindScreen != -1)
- {
- int[] NotchNum = new int[2];
- if (bindScreen == 0) { NotchNum[0] = 5; NotchNum[1] = 6; }
- if (bindScreen == 1) { NotchNum[0] = 3; NotchNum[1] = 4; }
- if (bindScreen == 2) { NotchNum[0] = 1; NotchNum[1] = 2; }
- (this.DataContext as AdWindowViewModel).InitData(NotchNum);
-
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (DataBus.saleLogDtos.Count > 0)
- {
- HKLog.HKLogImport.WriteInfo("添加刷卡信息");
- if (DataBus.saleLogDtos.TryDequeue(out SaleLogDto info))
- {
- HKLog.HKLogImport.WriteInfo("取出信息加入队列");
- if (!DataBus.SaleLogDtoList.ContainsKey(info.Location))
- DataBus.SaleLogDtoList.TryAdd(info.Location, new ConcurrentQueue<SaleLogDto>());
- DataBus.SaleLogDtoList[info.Location].Enqueue(info);
- }
- }
- Thread.Sleep(100);
- }), "刷卡队列分配");
- }
- InitView2(input);
-
- //InitControl();
- };
- this.Closed += (sender, ev) =>
- {
- App.Current.Shutdown(0);
- };
-
- BindScreen = bindScreen;
- }
-
- public async void InitView2(string input)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 12;
- var width = this.content.ActualWidth - 11;
- input = input.Replace("style=\"width: 100%;\"", "");
-
- StringBuilder sb = new StringBuilder();
- 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>");
- var html = sb.ToString();
- await view2.EnsureCoreWebView2Async(null);
- view2.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
- view2.CoreWebView2.Settings.AreDevToolsEnabled = false;
- view2.CoreWebView2.NavigateToString(html);
- }
-
- private void InitControl()
- {
- ThreadManage.GetInstance().StartLong(() =>
- {
- if (BindScreen == 0)
- {
- var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "05" || t.Address == "06").Select(t => t.GateId).FirstOrDefault();
- var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
-
- foreach (var item in area)
- {
- if (item.Key.ToLower().Equals("top"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("bottom"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("left"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("right"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- }
- }
-
- if (BindScreen == 1)
- {
- var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "01" || t.Address == "02").Select(t => t.GateId).FirstOrDefault();
- var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
-
- foreach (var item in area)
- {
- if (item.Key.ToLower().Equals("top"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("bottom"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("left"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("right"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- }
- }
-
- if (BindScreen == 2)
- {
- var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == "05" || t.Address == "06").Select(t => t.GateId).FirstOrDefault();
- var area = DataBus.RangeCtrl.FirstOrDefault(t => t.GateId == GateId).Locs;
-
- foreach (var item in area)
- {
- if (item.Key.ToLower().Equals("top"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0.239, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[0].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("bottom"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0.5, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 10;
- this.content.Dispatcher.Invoke(async () =>
- {
- content.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("left"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[0].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- if (item.Key.ToLower().Equals("right"))
- {
- if (item.IsShow)
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = this.content.ActualWidth - 9.5;
- this.alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0.2, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- else
- {
- var height = this.content.RowDefinitions[1].ActualHeight - 10;
- var width = alls.ColumnDefinitions[2].ActualWidth + this.content.ActualWidth - 10;
- this.alls.Dispatcher.Invoke(async () =>
- {
- alls.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Star);
- if (view2.CoreWebView2 != null)
- await view2.CoreWebView2.ExecuteScriptAsync($"Set({width},{height})");
- });
- }
- }
- }
- }
-
- Thread.Sleep(5000);
- }, $"区域控制{BindScreen}", true);
- }
- }
- }
|