From 3cfcb60918292afaced790bfc0fb2f0b3bae40aa Mon Sep 17 00:00:00 2001 From: xxe Date: Fri, 30 Sep 2022 11:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=BF=E5=91=8A=E7=BC=93=E5=AD=98=E5=88=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardOUT/DTO/AdDTO.cs | 10 +--- HKCardOUT/ViewModels/RootViewModel.cs | 71 +++++++++++---------------- HKCardOUT/Views/RootView.xaml | 9 ++-- HKCardOUT/Views/RootView.xaml.cs | 20 ++++---- 4 files changed, 44 insertions(+), 66 deletions(-) diff --git a/HKCardOUT/DTO/AdDTO.cs b/HKCardOUT/DTO/AdDTO.cs index bc7b2f1..f943114 100644 --- a/HKCardOUT/DTO/AdDTO.cs +++ b/HKCardOUT/DTO/AdDTO.cs @@ -6,15 +6,9 @@ using System.Windows.Controls.Primitives; namespace DTO { - public class AdDTO : PropertyChangedBase + public class AdDTO { - public string Device { get; set; } - bool _IsActive; - public bool IsActive - { - get => _IsActive; - set => SetAndNotify(ref _IsActive, value); - } + public string Device { get; set; } public string Ad { get; set; } public string Stalls { get; set; } } diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index c8a052e..3f5822f 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -7,12 +7,18 @@ using NStandard; using Stylet; using StyletIoC; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using System.Threading; +using System.Windows.Documents; using UHFHelper; +using XExten.Advance.InternalFramework.Securities.Common; using XExten.Advance.LinqFramework; +using XExten.Advance.StaticFramework; namespace HKCardOUT.ViewModels { @@ -27,12 +33,12 @@ namespace HKCardOUT.ViewModels public RootViewModel(IContainer Container) { this.Container = Container; + MainThread(); this.Activated += RootViewModel_Activated; this.Closed += RootViewModel_Closed; - MainThread(); } /// /// 关闭页面 @@ -89,16 +95,21 @@ namespace HKCardOUT.ViewModels } else { - DataBus.StoreInfo.Devices.ForEach(item => + if (DataBus.NetWordState) { - var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); - - if (res != null) + DataBus.StoreInfo.Devices.ForEach(item => { - if (!res.ResData.IsMatch(new Regex("0{20}"))) - ReadFunc?.Invoke(res); - } - }); + var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); + + if (res != null) + { + if (!res.ResData.IsMatch(new Regex("0{20}"))) + ReadFunc?.Invoke(res); + } + }); + } + else + HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络,并重启程序!"); } }; timer1.Start(); @@ -109,13 +120,20 @@ namespace HKCardOUT.ViewModels var Init = DataBus.StoreInfo?.Devices.Join(DataBus.StoreInfo?.Stalls, t => t.GateId, x => x.Id, (t, x) => new AdDTO { Ad = x.Remaek, - IsActive = false, Device = t.Name, Stalls = x.Name }).ToList(); if (Init != null) { Ad = new ObservableCollection(Init); + var route = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")); + SyncStatic.WriteFile(Encoding.UTF8.GetBytes(SyncStatic.Compress(Init.ToJson(), SecurityType.Base64)), route); + AdOpen(); + } + else + { + var jsons = SyncStatic.Decompress(SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")), SecurityType.Base64); + Ad = new ObservableCollection(jsons.ToModel>()); AdOpen(); } } @@ -197,37 +215,6 @@ namespace HKCardOUT.ViewModels #endregion #region 命令 - - /// - /// 广告位置 - /// - /// - public void UpdateAction(AdDTO input) - { - input.IsActive = !input.IsActive; - var SC = System.Windows.Forms.Screen.AllScreens.Count(); - if (SC >= 1) - { - if (input.IsActive) - { - if (!DataBus.AdStatus.ContainsKey(input.Device)) - { - var win = new Views.AdWindow(input.Ad); - win.Left = System.Windows.Forms.Screen.AllScreens[1].WorkingArea.Left; - DataBus.AdStatus.Add(input.Device, win); - win.Show(); - } - } - else - { - if (DataBus.AdStatus.ContainsKey(input.Device)) - { - DataBus.AdStatus[input.Device].Close(); - DataBus.AdStatus.Remove(input.Device); - } - } - } - } public void ReadCard(DKoutput input) { lock (locker) @@ -242,7 +229,7 @@ namespace HKCardOUT.ViewModels { CardNo = input.ResData.Substring(1, input.ResData.Length - 1), Location = input.Address.AsInt().ToString(), - IsSync=false + IsSync = false }); } if (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1]) diff --git a/HKCardOUT/Views/RootView.xaml b/HKCardOUT/Views/RootView.xaml index d7ee9ec..0e36a80 100644 --- a/HKCardOUT/Views/RootView.xaml +++ b/HKCardOUT/Views/RootView.xaml @@ -14,8 +14,8 @@ d:DataContext="{d:DesignInstance Type=viewModels:RootViewModel}" ShowMaxButton="False" ShowMinButton="False" - Visibility="Hidden" ShowTitle="True" + Visibility="Hidden" WindowStartupLocation="CenterScreen" WindowState="Maximized" mc:Ignorable="d"> @@ -111,9 +111,6 @@ Width="160" Height="80" Margin="20,20,0,0" - s:View.ActionTarget="{Binding DataContext, ElementName=Main}" - Command="{s:Action UpdateAction}" - CommandParameter="{Binding .}" Style="{StaticResource ButtonDefault}"> @@ -129,13 +126,13 @@ FontSize="18" FontWeight="Bold" Text="{Binding Device, StringFormat=设备:{0}}" /> - + Text="{Binding IsActive, Converter={StaticResource TOC}, StringFormat=广告:{0}}" />--> diff --git a/HKCardOUT/Views/RootView.xaml.cs b/HKCardOUT/Views/RootView.xaml.cs index 565ffa4..ab7fb8f 100644 --- a/HKCardOUT/Views/RootView.xaml.cs +++ b/HKCardOUT/Views/RootView.xaml.cs @@ -15,16 +15,16 @@ namespace HKCardOUT.Views public RootView() { InitializeComponent(); - if (!StartEXE.IsExistKey("HKCardOUT")) - { - var Paths = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HKCardOUT.exe"); - StartEXE.SelfRunning(true, "HKCardOUT", Paths); - } - else if (StartEXE.IsExistKey("HKCardOUT")) - { - var Paths = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HKCardOUT.exe"); - StartEXE.SelfRunning(false, "HKCardOUT", Paths); - } + //if (!StartEXE.IsExistKey("HKCardOUT")) + //{ + // var Paths = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HKCardOUT.exe"); + // StartEXE.SelfRunning(true, "HKCardOUT", Paths); + //} + //else if (StartEXE.IsExistKey("HKCardOUT")) + //{ + // var Paths = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HKCardOUT.exe"); + // StartEXE.SelfRunning(false, "HKCardOUT", Paths); + //} this.Loaded += RootView_Loaded; }