You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.8 KiB
C#

9 months ago
using JwKdsV.Core;
using JwKdsV.Core.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JwKdsV
{
public partial class TenantResetForm : BaseForm
{
private string tenantId = null;
public TenantResetForm()
{
InitializeComponent();
this.Text = string.Format("巨为厨显初始化({0})", Application.ProductVersion);
KeyboardUtils.Instance.RegisterHook(this.AppHookKeyDown);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if(Global.Instance.StoreInfo != null)
{
tenantId = Global.Instance.StoreInfo.TenantId;
this.storeNoLabel.Text = string.Format(this.storeNoLabel.Text, Global.Instance.StoreInfo.StoreNo);
this.storeNameLabel.Text = string.Format(this.storeNameLabel.Text, Global.Instance.StoreInfo.StoreName);
this.posNoLabel.Text = string.Format(this.posNoLabel.Text, Global.Instance.StoreInfo.PosNo);
this.tenantNoLabel.Text = string.Format(this.tenantNoLabel.Text, tenantId);
}
}
protected override void AppHookKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
this.OnInitClick(sender, e);
break;
case Keys.Escape:
this.OnCloseClick(sender, e);
break;
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
KeyboardUtils.Instance.UnRegisterHook(this.AppHookKeyDown);
}
private void OnInitClick(object sender, EventArgs e)
{
//验证密码是否正确
var pwd = this.txtPwd.Text.Trim();
if (GeneratePwd().Equals(pwd))
{
if(MessageBox.Show("确认要初始化吗?", "初始化确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
using (var db = Global.Instance.OpenDataBase)
{
db.Execute("delete from [pos_authc];");
db.Execute("delete from [pos_order];");
db.Execute("delete from [pos_order_item];");
}
this.ShowMessage(this.labelInfo, "重置成功!确定后系统会重启。", true);
MessageBox.Show("重置成功!确定后系统会重启。");
Application.ExitThread();
Application.Exit();
Application.Restart();
Process.GetCurrentProcess().Kill();
}
}
else
{
this.ShowMessage(this.labelInfo, "密码错误!", true);
}
}
/// <summary>
/// 生成动态密码 租户 + 当前年月日
/// </summary>
/// <returns></returns>
private string GeneratePwd()
{
return tenantId + DateTime.Now.ToString("yyyyMMdd");
}
private void OnCloseClick(object sender, EventArgs e)
{
this.Close();
}
private void OnKeyboardButtonClick(object sender, Component.LoginKeyboardEventArgs e)
{
var keyCode = e.Key;
switch (keyCode)
{
case "clear":
this.ActiveControl.Text = "";
break;
default:
InputSimulatorUtils.SendKey(KeyCodes.Map[keyCode]);
break;
}
}
}
}