From a61542489c49508598eb6ac375d3d2b2b65ecb21 Mon Sep 17 00:00:00 2001 From: xxe Date: Tue, 20 Sep 2022 15:29:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8D=A1=E5=86=99=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardIN/COM/COMHelper.cs | 36 -------------------- HKCardIN/HKCardIN.csproj | 2 +- HKCardIN/ViewModels/RootViewModel.cs | 46 ++++++++++++++++++++++++-- HKCardIN/Views/CardView.xaml | 49 ++++++++++++++++++++++++++++ HKCardIN/Views/CardView.xaml.cs | 35 ++++++++++++++++++++ HKCardIN/Views/RootView.xaml | 10 ++++-- HKCardOUT/COM/COMHelper.cs | 34 ------------------- HKCardOUT/HKCardOUT.csproj | 1 - HKLog/HKLog.csproj | 2 +- 9 files changed, 138 insertions(+), 77 deletions(-) delete mode 100644 HKCardIN/COM/COMHelper.cs create mode 100644 HKCardIN/Views/CardView.xaml create mode 100644 HKCardIN/Views/CardView.xaml.cs delete mode 100644 HKCardOUT/COM/COMHelper.cs diff --git a/HKCardIN/COM/COMHelper.cs b/HKCardIN/COM/COMHelper.cs deleted file mode 100644 index b51c08e..0000000 --- a/HKCardIN/COM/COMHelper.cs +++ /dev/null @@ -1,36 +0,0 @@ -using HKCardIN.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.IO.Ports; -using System.Text; -using System.Threading.Tasks; - -namespace COM -{ - public class COMHelper : Singleton - { - public SerialPort serialPort; - public void OpenCOM(string input) - { - serialPort = new SerialPort(input, 9600, Parity.None, 8, StopBits.One); - //数据接收 - serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); - serialPort.ReceivedBytesThreshold = 1; - serialPort.RtsEnable = true; - try - { - if (serialPort.IsOpen) return; - serialPort.Open(); - } - catch { } - } - /// 数据接收事件 - private void DataReceived(object sender, SerialDataReceivedEventArgs e) - { - byte[] readBuffer = new byte[serialPort.ReadBufferSize]; - serialPort.Read(readBuffer, 0, readBuffer.Length); - string str = Encoding.Default.GetString(readBuffer); - } - } -} diff --git a/HKCardIN/HKCardIN.csproj b/HKCardIN/HKCardIN.csproj index 73c723f..8e122f9 100644 --- a/HKCardIN/HKCardIN.csproj +++ b/HKCardIN/HKCardIN.csproj @@ -33,13 +33,13 @@ - + diff --git a/HKCardIN/ViewModels/RootViewModel.cs b/HKCardIN/ViewModels/RootViewModel.cs index 02fcb06..fc3a272 100644 --- a/HKCardIN/ViewModels/RootViewModel.cs +++ b/HKCardIN/ViewModels/RootViewModel.cs @@ -1,11 +1,16 @@ -using HKCardIN.Helper; +using HandyControl.Data; +using HKCardIN.Helper; using HKCardIN.Logic; using HKCardIN.Logic.Model; +using HKCardIN.Views; +using HKLog; using Stylet; using System; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows; +using UHFHelper; namespace HKCardIN.ViewModels { @@ -64,6 +69,44 @@ namespace HKCardIN.ViewModels #endregion #region 命令 + + public void ReadAction() + { + if (!UHFCardHelper.GetInstance().ComOpen) + { + var res = UHFCardHelper.GetInstance().OpenPort(); + HKLogImport.WriteInfo(res.ResMes); + } + var RCardNo = UHFCardHelper.GetInstance().ReadCard(); + if (!Regex.IsMatch(RCardNo, "\\d{19}")) + { + var res = HandyControl.Controls.MessageBox.Show(new MessageBoxInfo + { + Button = MessageBoxButton.YesNo, + IconKey = "InfoGeometry", + IconBrushKey = "InfoBrush", + YesContent = "是", + NoContent = "否", + Message = "此卡是新卡,前往制卡", + Caption = "提示!" + }); + if (res == MessageBoxResult.Yes) + { + CardView view = new CardView(); + if (view.ShowDialog().Value) HandyControl.Controls.Growl.InfoGlobal("制卡成功"); + else HandyControl.Controls.Growl.InfoGlobal("制卡失败"); + } + Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo); + UHFCardHelper.GetInstance().ClosePort(); + } + else + { + CardNo = RCardNo; + Info = BaseLogic.GetInstance().PullUserAndCardInfo(CardNo); + UHFCardHelper.GetInstance().ClosePort(); + } + + } public void InputAction(string input) { if (IsLocker) return; @@ -110,7 +153,6 @@ namespace HKCardIN.ViewModels protected override void OnViewLoaded() { MainThread(); - //Info = BaseLogic.GetInstance().PullUserAndCardInfo("1569245210230263808"); } private void MainThread() { diff --git a/HKCardIN/Views/CardView.xaml b/HKCardIN/Views/CardView.xaml new file mode 100644 index 0000000..4cfe333 --- /dev/null +++ b/HKCardIN/Views/CardView.xaml @@ -0,0 +1,49 @@ + + + + + + + +