using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using POSV.Component; using POSV.Utils; namespace POSV { public partial class LockForm : BusinessForm { private const int TIMER_INTERVAL = 1000; /// /// 强制保留焦点的计时器 /// private System.Timers.Timer _timer = null; private bool _isStart = false; public LockForm() { InitializeComponent(); this.DialogResult = DialogResult.None; stylishAnalogClock1.ClockTime = DateTime.Now; _timer = new System.Timers.Timer(TIMER_INTERVAL); this._timer.Interval = TIMER_INTERVAL; this._timer.Elapsed += OnTimerElapsed; TimerStart(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); //工作区自动居中 this.mainPanel.Location = new Point((this.Width - this.mainPanel.Width) / 2 , (this.Height - this.mainPanel.Height) / 2); this.txtPasswd.GotFocus += OnInputGotFocus; this.txtPasswd.Multiline = false; this.txtPasswd.Focus(); this.lblInfo.Text = string.Format(this.lblInfo.Tag.ToString() , Global.Instance.Worker.No); } private bool ValidateInputValue() { if (string.IsNullOrEmpty(txtPasswd.Text.Trim())) { this.ShowMessage(this.lblInfo , "密码不能为空..." , false); this.txtPasswd.Focus(); return false; } return true; } private void OnTouchClick(object sender , TouchEventArgs e) { switch (e.Value) { case "clear": //如果当前焦点控件是输入框 if (this.ActiveControl is NumericTextBox) { var activeControl = this.ActiveControl as NumericTextBox; activeControl.Text = string.Empty; } break; case "accept": //验证通过 { var valid = ValidateInputValue(); if (valid) { this.Verify(); } } break; default: { InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]); } break; } } private void OnCloseTouchClick(object sender , EventArgs e) { //先关闭父窗体 this.Owner?.Close(); //再关闭当前窗体 this.Close(); } protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); e.Cancel = (this.DialogResult != DialogResult.OK); } private void OnInputValueChanged(object sender , Component.EnterEventArg e) { this.BeginInvoke(new MethodInvoker(() => { this.lblInfo.Text = String.Format(this.lblInfo.Tag.ToString() , Global.Instance.Worker.No); })); } public void TimerStart() { if (!_isStart) { this._timer.Start(); } } public void TimerStop() { this._timer.Stop(); _isStart = false; } private void OnTimerElapsed(object sender , System.Timers.ElapsedEventArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(() => { stylishAnalogClock1.ClockTime = DateTime.Now; })); } else { stylishAnalogClock1.ClockTime = DateTime.Now; } } private void Verify() { if (Global.Instance.Worker != null) { if (BCrypt.Verify(txtPasswd.Text.Trim(), Global.Instance.Worker.Passwd)) { this.DialogResult = DialogResult.OK; } else { this.BeginInvoke(new MethodInvoker(() => { this.lblInfo.Text = " 密码错误,请重新输入"; })); this.txtPasswd.Focus(); this.txtPasswd.SelectAll(); this.DialogResult = DialogResult.Cancel; } } else { this.BeginInvoke(new MethodInvoker(() => { this.lblInfo.Text = "咦!操作员去月球了...."; })); this.txtPasswd.Focus(); this.txtPasswd.SelectAll(); this.DialogResult = DialogResult.Cancel; } } private void OnInputEnterClick(object sender, EnterEventArg e) { var valid = ValidateInputValue(); if (valid) { this.Verify(); } } } }