当前位置: 首页 > news >正文

刷卡登入数据获取

1.WPF刷卡登入数据获取,防止用户手动输入

//WPF输入框信息及触发命令<StackPanel Orientation="Vertical" VerticalAlignment="Center"  Margin="0 30"  Visibility="{Binding LoginMode,Converter={StaticResource loginModeWithParmVisibilityConverter}, ConverterParameter=IC卡}" ><StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="30"><TextBox hc:InfoElement.TranslateText="{Binding Path=Text,Mode=OneTime,RelativeSource={RelativeSource Mode=Self}}" Text="刷卡卡号" Margin=" 30 0 0 0" Width="101" Padding="10" VerticalAlignment="Center" IsReadOnly="True"></TextBox><TextBox Text="{Binding CardNum,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Focusable="True" Name="t_username1" Width="170"  Padding="10" TabIndex="1"><i:Interaction.Triggers><i:EventTrigger EventName="KeyDown"><i:InvokeCommandAction Command="{Binding DataContext.KeyDownCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" /></i:EventTrigger><i:EventTrigger EventName="KeyUp"><i:InvokeCommandAction Command="{Binding DataContext.KeyUpCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" /></i:EventTrigger></i:Interaction.Triggers></TextBox></StackPanel>

viewmodel代码

//核心命令private DateTime _lastKeyUpTime; // 上次按键弹起时间private const int KeyDownThreshold = 200; // 按键时间间隔阈值(单位:毫秒)private bool IsKeyDown = false;private DateTime KeyUpDateTime = new DateTime();public RelayCommand<object> KeyDownCommand => new RelayCommand<object>((obj) =>{System.Windows.Controls.TextBox textBox = obj as System.Windows.Controls.TextBox;if (IsKeyDown && ((LoginMode)GlobalData.LoginMode) == LoginMode.IC卡 && textBox.Text.Length > 1)//加一个是否是密码输入的判断{textBox.Clear();return;}if (Keyboard.IsKeyDown(Key.Enter)) // 判断是否是 Enter 键{LoginCmd.Execute(null);return;}IsKeyDown = true;//KeyUpDateTime = DateTime.Now;});public RelayCommand<object> KeyUpCommand => new RelayCommand<object>((obj) =>{System.Windows.Controls.TextBox textBox = obj as System.Windows.Controls.TextBox;//var temp = DateTime.Now;判断是否密码输入,密码输入直接return。//if (((LoginMode)GlobalData.LoginMode) == LoginMode.IC卡 && (temp - KeyUpDateTime).TotalMilliseconds > 100  && textBox.Text.Length > 1)//{//    textBox.Clear();//}var currentTime = DateTime.Now;// 计算按键时间间隔var interval = (currentTime - _lastKeyUpTime).TotalMilliseconds;// 如果按键间隔大于阈值,清除输入内容if (textBox.Text.Length > 1 && interval > KeyDownThreshold){textBox.Clear();return;}_lastKeyUpTime = currentTime; // 更新按键时间IsKeyDown = false;});
http://www.xdnf.cn/news/1079695.html

相关文章:

  • MySQL的窗口函数介绍
  • Redis—哨兵模式
  • 相机光学(四十八)——渐晕
  • [自然语言处理]计算语言的熵
  • Qt宝藏库:20+实用开源项目合集
  • ReentrantLock 原理
  • Euler2203安装.NetCore6.0环境操作步骤
  • 前端单元测试覆盖率工具有哪些,分别有什么优缺点
  • Java中的volatile到底是什么来路
  • RAG实战指南 Day 4:LlamaIndex框架实战指南
  • CentOS系统高效部署fastGPT全攻略
  • 21、MQ常见问题梳理
  • 【论】电力-交通融合网协同优化:迎接电动汽车时代的挑战
  • thinkphp8接管异常处理类
  • 【第三章:神经网络原理详解与Pytorch入门】01.神经网络算法理论详解与实践-(2)神经网络整体结构
  • STM32-第二节-GPIO输入(按键,传感器)
  • C盘爆满元凶!WinSxS组件解密
  • JsonCpp的核心类及核心函数使用汇总
  • Web 服务器架构选择深度解析
  • Linux常见指令以及权限理解
  • Flowable12基础流程实战资金申请------------持续更新中
  • 埃及黑白沙漠:2亿年风蚀岩的“外星登陆现场“
  • 未来之窗冥界调试工具—东方仙盟
  • LTspice仿真10——电容
  • A模块 系统与网络安全 第四门课 弹性交换网络-1
  • 在小程序中实现实时聊天:WebSocket最佳实践
  • Verilog 语法介绍 1-1结构
  • Spring Boot + 本地部署大模型实现:基于 Ollama 的集成实践
  • KMP(Kotlin Multiplatform)改造(Android/iOS)老项目
  • PHP语法基础篇(八):超全局变量