| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Windows.Forms;
- namespace UppPay.Forms
- {
- public partial class SMForm : Form
- {
- public JObject OutjObject { get; set; }
- public string authcode { get; set; }
- private bool isButtonClose = false;
- public SMForm()
- {
- InitializeComponent();
- OutjObject = new JObject();
- authcode = "";
- // 设置窗体在屏幕上居中显示
- this.StartPosition = FormStartPosition.CenterScreen;
- // 设置窗体始终显示在其他窗口的最前面
- this.TopMost = true;
- authcodeBox.Focus();
- // 为 TextBox 的 KeyDown 事件添加处理程序
- authcodeBox.KeyDown += authcodeBox_KeyDown;
- // 处理窗体关闭事件,阻止关闭操作
- this.FormClosing += MainForm_FormClosing;
- authcodeBox.Focus();
- }
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (!isButtonClose)
- {
- OutjObject = new JObject();
- OutjObject["errorCode"] = "-1";
- OutjObject["errorMessage"] = "收费员已取消操作";
- //this.DialogResult = DialogResult.OK;
- //this.Close();
- }
- }
- private void authcodeBox_KeyDown(object sender, KeyEventArgs e)
- {
- // 检查是否按下回车键
- if (e.KeyCode == Keys.Enter)
- {
- // 处理回车键按下事件
- SMPayLoading(authcodeBox.Text);
- // 阻止回车键的默认行为,避免在多行文本框中换行
- e.SuppressKeyPress = true;
- }
- }
- private async void SMPayLoading(string authcode)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(authcode))
- {
- Tlabel.Text = "请输入支付码内容....";
- authcodeBox.Focus();
- }
- else
- {
- OutjObject = new JObject();
- OutjObject["errorCode"] = "0";
- OutjObject["errorMessage"] = "扫码成功";
- OutjObject["authcode"] = authcode;
- isButtonClose = true;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
-
- }
- catch (Exception ex)
- {
- // 处理异常
- Tlabel.Text = $"发生错误: {ex.Message}";
- }
- }
- }
- }
|