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.

247 lines
7.8 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using POSV.Entity;
using POSV.Common.Util;
using POSV.Utils;
using DevComponents.DotNetBar.SuperGrid;
using System.Reflection;
namespace POSV.Component
{
public partial class SlotCardAuthorization : AbstractParameter
{
public SlotCardAuthorization()
{
InitializeComponent();
DefaultGridStyle.setSmallGridStyle(this.salesListTable);
}
public DevComponents.DotNetBar.LabelX lblInfo = null;
private void btnAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.lblCardNo.Text) || this.lblCardNo.Text.Equals("授权卡号..."))
{
this.ShowMessage(this.lblInfo, "请使用读卡器读取卡信息!");
return;
}
if (string.IsNullOrEmpty(this.txtAccount.Text))
{
this.ShowMessage(this.lblInfo, "请输入账号!");
this.txtAccount.Focus();
return;
}
if (string.IsNullOrEmpty(this.txtPassword.Text))
{
this.ShowMessage(this.lblInfo, "请输入密码!");
this.txtPassword.Focus();
return;
}
var _data = JSON.Deserialize<List<SlotCardAuthorizationData>>(Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SWIPING_CARD_DATA, "[]"));
if (_data.Where(f => f.CardNo == this.lblCardNo.Text).Count() > 0)
{
this.ShowMessage(this.lblInfo, "此卡已绑定了其他账号,请确认!");
return;
}
SlotCardAuthorizationData cardAuthorizationData = new SlotCardAuthorizationData()
{
CardNo = this.lblCardNo.Text,
Account = this.txtAccount.Text,
Password = this.txtPassword.Text
};
_data.Add(cardAuthorizationData);
SetAuthorizationData(_data);
}
private void btnDele_Click(object sender, EventArgs e)
{
var panel = salesListTable.PrimaryGrid;
if (panel.ActiveRow == null)
{
this.ShowMessage(this.lblInfo, "请选择一条数据操作");
return;
}
//提示
var row = panel.ActiveRow as GridRow;
var _card = row.Cells[0].Value.ToString();
var _data = JSON.Deserialize<List<SlotCardAuthorizationData>>(Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SWIPING_CARD_DATA, "[]"));
this.SetAuthorizationData(_data.Where(f => f.CardNo != _card).ToList());
}
private void txtInput_ButtonCustomClick(object sender, EventArgs e)
{
}
private void buttonX1_Click(object sender, EventArgs e)
{
var result = Utils.CardOperateUtils.Instance.ReadCardNo();
if (result.Item1)
{
this.lblCardNo.Text = result.Item2;
}
else
{
result = Utils.CardOperateUtilsOther.Instance.ReadCardNo();
if (result.Item1)
{
this.lblCardNo.Text = result.Item2;
}
else
{
this.ShowMessage(lblInfo, result.Item2);
}
}
}
public Tuple<bool, string> SaveConfig()
{
Tuple<bool, string> tuple = new Tuple<bool, string>(false, "");
var config = new Config();
config.Id = IdWorkerUtils.Instance.NextId();
config.Group = ConfigConstant.DEVICE_GROUP;
config.TenantId = Global.Instance.Authc.TenantId;
config.Keys = ConfigConstant.DEVICE_SWIPING_CARD_ENABLED;
config.Values = string.Format("{0}", enableServiceCenter.Value);
try
{
using (var db = Global.Instance.OpenDataBase)
{
db.Save(config);
}
Global.Instance.ReloadConfig(ConfigConstant.DEVICE_GROUP);
return new Tuple<bool, string>(true, "保存成功");
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
return tuple;
}
private void SetAuthorizationData(List<SlotCardAuthorizationData> slotCardAuthorizations)
{
salesListTable.PrimaryGrid.DataSource = slotCardAuthorizations;
var config = new Config();
config.Id = IdWorkerUtils.Instance.NextId();
config.Group = ConfigConstant.DEVICE_GROUP;
config.TenantId = Global.Instance.Authc.TenantId;
config.Keys = ConfigConstant.DEVICE_SWIPING_CARD_DATA;
config.Values = string.Format("{0}", JsonUtils.Serialize(slotCardAuthorizations));
try
{
using (var db = Global.Instance.OpenDataBase)
{
db.Save(config);
}
Global.Instance.ReloadConfig(ConfigConstant.DEVICE_GROUP);
}
catch (Exception ex)
{
LOGGER.Error(ex);
}
}
public void GetAuthorizationData()
{
var _data = JSON.Deserialize<List<SlotCardAuthorizationData>>(Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SWIPING_CARD_DATA, "[]"));
var _enabled = Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SWIPING_CARD_ENABLED, "false");
if (_enabled.ToLower().Equals("true"))
{
this.enableServiceCenter.Value = true;
}
salesListTable.PrimaryGrid.DataSource = _data;
}
private void SlotCardAuthorization_Load(object sender, EventArgs e)
{
}
private void txtAccount_ButtonCustomClick(object sender, EventArgs e)
{
try
{
KeyboardType keyboardType = KeyboardType.;
Type type = this.ActiveControl.GetType();
PropertyInfo pinfo = type.GetProperty("Keyboard");
if (pinfo != null)
{
keyboardType = (KeyboardType)pinfo.GetValue(this.ActiveControl, null);
}
var keyboard = Application.OpenForms["VirtualKeyboard"];
if (keyboard == null)
{
keyboard = new VirtualKeyboard(keyboardType);
}
((VirtualKeyboard)keyboard).ShowVirtualKeyboard(this, keyboardType);
}
catch (Exception ex)
{
LOGGER.Error(ex, "打开屏幕键盘异常");
}
}
private void txtPassword_ButtonCustomClick(object sender, EventArgs e)
{
try
{
KeyboardType keyboardType = KeyboardType.;
Type type = this.ActiveControl.GetType();
PropertyInfo pinfo = type.GetProperty("Keyboard");
if (pinfo != null)
{
keyboardType = (KeyboardType)pinfo.GetValue(this.ActiveControl, null);
}
var keyboard = Application.OpenForms["VirtualKeyboard"];
if (keyboard == null)
{
keyboard = new VirtualKeyboard(keyboardType);
}
((VirtualKeyboard)keyboard).ShowVirtualKeyboard(this, keyboardType);
}
catch (Exception ex)
{
LOGGER.Error(ex, "打开屏幕键盘异常");
}
}
}
}