瀏覽代碼

读卡写卡

Lishi
xxe 2 年之前
父節點
當前提交
a61542489c
共有 9 個檔案被更改,包括 138 行新增77 行删除
  1. +0
    -36
      HKCardIN/COM/COMHelper.cs
  2. +1
    -1
      HKCardIN/HKCardIN.csproj
  3. +44
    -2
      HKCardIN/ViewModels/RootViewModel.cs
  4. +49
    -0
      HKCardIN/Views/CardView.xaml
  5. +35
    -0
      HKCardIN/Views/CardView.xaml.cs
  6. +8
    -2
      HKCardIN/Views/RootView.xaml
  7. +0
    -34
      HKCardOUT/COM/COMHelper.cs
  8. +0
    -1
      HKCardOUT/HKCardOUT.csproj
  9. +1
    -1
      HKLog/HKLog.csproj

+ 0
- 36
HKCardIN/COM/COMHelper.cs 查看文件

@@ -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<COMHelper>
{
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);
}
}
}

+ 1
- 1
HKCardIN/HKCardIN.csproj 查看文件

@@ -33,13 +33,13 @@
<PackageReference Include="HandyControls" Version="3.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HKLog\HKLog.csproj" />
<ProjectReference Include="..\UHFHelper\UHFHelper.csproj" />
</ItemGroup>
<ItemGroup>
<Resource Include="HKResouces\头像.png" />


+ 44
- 2
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()
{


+ 49
- 0
HKCardIN/Views/CardView.xaml 查看文件

@@ -0,0 +1,49 @@
<Window
x:Class="HKCardIN.Views.CardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:HKCardIN.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="海科智慧一卡通平台"
Width="300"
Height="200"
ResizeMode="CanMinimize"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Background>
<ImageBrush ImageSource="/HKResouces/背景.jpg" />
</Window.Background>
<WrapPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical">
<TextBox
x:Name="Phone"
Width="200"
hc:InfoElement.Placeholder="请输入手机号"
Style="{StaticResource TextBoxExtend}" />
<WrapPanel Margin="0,10,0,0" HorizontalAlignment="Center">
<Button
x:Name="Query"
Width="80"
Height="50"
Margin="0,0,10,0"
Click="QueryClick"
Content="查询"
FontSize="18"
Style="{StaticResource ButtonDefault}" />
<Button
x:Name="Create"
Width="80"
Height="50"
Margin="10,0,0,0"
Click="CreateClick"
Content="制卡"
FontSize="18"
IsEnabled="False"
Style="{StaticResource ButtonDefault}" />
</WrapPanel>
</WrapPanel>
</Window>

+ 35
- 0
HKCardIN/Views/CardView.xaml.cs 查看文件

@@ -0,0 +1,35 @@
using HKLog;
using System.Text.RegularExpressions;
using System.Windows;
using UHFHelper;
using XExten.Advance.LinqFramework;

namespace HKCardIN.Views
{
/// <summary>
/// CardView.xaml 的交互逻辑
/// </summary>
public partial class CardView : System.Windows.Window
{
public CardView()
{
InitializeComponent();
}

private void QueryClick(object sender, RoutedEventArgs e)
{
if (this.Phone.Text.IsNullOrEmpty()) HandyControl.Controls.Growl.InfoGlobal("手机号不能为空!");
if (!Regex.IsMatch(this.Phone.Text, "\\d{11}")) HandyControl.Controls.Growl.InfoGlobal("请输入正确的手机号!");
//查询接口
Create.IsEnabled = true;
}

private void CreateClick(object sender, RoutedEventArgs e)
{
var res = UHFCardHelper.GetInstance().WriteCard("1569245210230263808");
HKLogImport.WriteInfo(res.ResMes);
DialogResult = true;
Close();
}
}
}

+ 8
- 2
HKCardIN/Views/RootView.xaml 查看文件

@@ -10,8 +10,8 @@
xmlns:viewModels="clr-namespace:HKCardIN.ViewModels"
x:Name="Root"
Title="海科智慧一卡通平台"
Width="800"
Height="460"
Width="900"
Height="480"
d:DataContext="{d:DesignInstance Type=viewModels:RootViewModel}"
ResizeMode="CanMinimize"
WindowStartupLocation="CenterScreen"
@@ -52,6 +52,7 @@
Key="E"
Command="{s:Action UnLockAction}"
CommandParameter="{Binding ., ElementName=Pwd}" />
<KeyBinding Key="R" Command="{s:Action ReadAction}" />
<KeyBinding
Key="F1"
Command="{s:Action InputAction}"
@@ -301,6 +302,11 @@
FontWeight="Bold"
Foreground="WhiteSmoke" />
<WrapPanel HorizontalAlignment="Center">
<Button
Command="{s:Action ReadAction}"
Content="读卡[R]"
IsDefault="True"
Style="{StaticResource 操作}" />
<Button
Command="{s:Action SaveAction}"
Content="确定[Enter]"


+ 0
- 34
HKCardOUT/COM/COMHelper.cs 查看文件

@@ -1,34 +0,0 @@
using HKCardOUT.Helper;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;

namespace COM
{
public class COMHelper : Singleton<COMHelper>
{
public SerialPort serialPort;
public void OpenCOM()
{
serialPort = new SerialPort("COM3", 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);
}
}
}

+ 0
- 1
HKCardOUT/HKCardOUT.csproj 查看文件

@@ -38,7 +38,6 @@
<PackageReference Include="Quartz" Version="3.4.0" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
</ItemGroup>
<ItemGroup>


+ 1
- 1
HKLog/HKLog.csproj 查看文件

@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x86</Platforms>
<Platforms>x86</Platforms>
</PropertyGroup>

<ItemGroup>


Loading…
取消
儲存