|
- 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);
- }
- }
- }
|