|
|
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 DevComponents.Editors;
|
|
|
using System.Threading.Tasks;
|
|
|
using POSV.Entity;
|
|
|
using POSV.Utils;
|
|
|
using POSV.Bean;
|
|
|
using DevComponents.DotNetBar.Controls;
|
|
|
using POSV.Printer;
|
|
|
using POSV.Helper;
|
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
|
|
|
|
namespace POSV.Component
|
|
|
{
|
|
|
[ToolboxItem(true)]
|
|
|
public partial class PrinterParameter : AbstractParameter
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 修改前的数据
|
|
|
/// </summary>
|
|
|
private Dictionary<string, string> _oldValue = new Dictionary<string, string>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改后的数据
|
|
|
/// </summary>
|
|
|
private Dictionary<string, string> _newValue = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否初始化
|
|
|
/// </summary>
|
|
|
private bool _inited = false;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下拉数字选择列表
|
|
|
/// </summary>
|
|
|
private string[] _emptys = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下拉数字选择列表
|
|
|
/// </summary>
|
|
|
private string[] _items = { "0", "1", "2", "3", "4", "5" };
|
|
|
|
|
|
/// <summary>
|
|
|
/// 退纸行数
|
|
|
/// </summary>
|
|
|
private string[] _feedBackRows = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
|
|
|
|
|
|
public PrinterParameter()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
{
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
|
|
this.BackColor = Color.Transparent;
|
|
|
|
|
|
//票头空白行数
|
|
|
this.comboBoxEx1.DataSource = (string[])_emptys.Clone();
|
|
|
this.comboBoxEx1.SelectedIndex = 0;
|
|
|
|
|
|
//票尾空白行数
|
|
|
this.comboBoxEx2.DataSource = (string[])_emptys.Clone();
|
|
|
this.comboBoxEx2.SelectedIndex = 0;
|
|
|
|
|
|
//小票打印份数
|
|
|
this.comboBoxEx3.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx3.SelectedIndex = 1;
|
|
|
|
|
|
//打印发送延迟
|
|
|
this.comboBoxEx4.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx4.SelectedIndex = 1;
|
|
|
|
|
|
//合计小数位数
|
|
|
this.comboBoxEx5.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx5.SelectedIndex = 2;
|
|
|
|
|
|
//数量小数位数
|
|
|
this.comboBoxEx6.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx6.SelectedIndex = 2;
|
|
|
|
|
|
//单价小数位数
|
|
|
this.comboBoxEx7.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx7.SelectedIndex = 2;
|
|
|
|
|
|
//票号长度
|
|
|
this.comboBoxEx8.DataSource = (string[])_emptys.Clone();
|
|
|
this.comboBoxEx8.SelectedIndex = 2;
|
|
|
|
|
|
//序号长度
|
|
|
this.comboBoxEx9.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx9.SelectedIndex = 2;
|
|
|
|
|
|
//退纸行数
|
|
|
this.comboBoxEx10.DataSource = (string[])_feedBackRows.Clone();
|
|
|
this.comboBoxEx10.SelectedIndex = 0;
|
|
|
|
|
|
//充值打印发送延迟
|
|
|
this.comboBoxEx12.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx12.SelectedIndex = 1;
|
|
|
|
|
|
//充值小票打印份数
|
|
|
this.comboBoxEx11.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx11.SelectedIndex = 1;
|
|
|
|
|
|
//开户小票打印份数
|
|
|
this.comboBoxEx13.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx13.SelectedIndex = 1;
|
|
|
|
|
|
//退卡余额小票打印份数
|
|
|
this.comboBoxEx14.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx14.SelectedIndex = 1;
|
|
|
|
|
|
//补换卡小票打印份数
|
|
|
this.comboBoxEx15.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx15.SelectedIndex = 1;
|
|
|
|
|
|
//积分兑换小票打印份数
|
|
|
this.comboBoxEx16.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx16.SelectedIndex = 1;
|
|
|
|
|
|
//卡券核销小票打印份数
|
|
|
this.comboBoxEx17.DataSource = (string[])_items.Clone();
|
|
|
this.comboBoxEx17.SelectedIndex = 1;
|
|
|
|
|
|
this.InitUi();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 初始化界面
|
|
|
/// </summary>
|
|
|
private void InitUi()
|
|
|
{
|
|
|
//界面加载开始
|
|
|
this._inited = false;
|
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
Dictionary<string, string> data = null;
|
|
|
|
|
|
lock (Global.Instance.SyncLock)
|
|
|
{
|
|
|
//获取品类分组下的全部参数
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
data = db.Dictionary<string, string>(string.Format(SqlConstant.ConfigQueryByGroupToDictionary, ConfigConstant.PERIPHERAL_GROUP));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//将新增加或者变更的参数重新更新到数据库
|
|
|
var defaultValue = ConfigConstant.PeripheralGroupDefaultValue();
|
|
|
|
|
|
//数据库有配置参数
|
|
|
if (data != null)
|
|
|
{
|
|
|
var diff = defaultValue.Where(kvp => !data.ContainsKey(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
|
|
|
|
|
if (diff != null && diff.Keys.Count > 0)
|
|
|
{
|
|
|
var list = new List<Config>();
|
|
|
foreach (var v in diff)
|
|
|
{
|
|
|
var config = new Config();
|
|
|
config.Id = IdWorkerUtils.Instance.NextId();
|
|
|
config.Group = ConfigConstant.PERIPHERAL_GROUP;
|
|
|
config.TenantId = Global.Instance.Authc.TenantId;
|
|
|
config.Keys = v.Key;
|
|
|
config.Values = v.Value;
|
|
|
|
|
|
list.Add(config);
|
|
|
}
|
|
|
//如果数据表中没有配置group相关的信息,更新差异
|
|
|
this.SaveChanged(list);
|
|
|
|
|
|
//将差异合并到data,避免再次访问数据库
|
|
|
data = data.Concat(diff).ToDictionary(x => x.Key, x => x.Value);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//加载系统默认参数
|
|
|
data = defaultValue;
|
|
|
|
|
|
var list = new List<Config>();
|
|
|
foreach (var v in defaultValue)
|
|
|
{
|
|
|
var config = new Config();
|
|
|
config.Id = IdWorkerUtils.Instance.NextId();
|
|
|
config.Group = ConfigConstant.PERIPHERAL_GROUP;
|
|
|
config.TenantId = Global.Instance.Authc.TenantId;
|
|
|
config.Keys = v.Key;
|
|
|
config.Values = v.Value;
|
|
|
|
|
|
list.Add(config);
|
|
|
}
|
|
|
|
|
|
//如果数据表中没有配置group相关的信息,保存
|
|
|
this.SaveChanged(list);
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
}).ContinueWith(task =>
|
|
|
{
|
|
|
if (task.IsFaulted)
|
|
|
{
|
|
|
LOGGER.Error(task.Exception.GetBaseException(), "加载外设参数设置异常");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.Invoke(new Action(() =>
|
|
|
{
|
|
|
BindUi(task.Result);
|
|
|
}));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void BindUi(Dictionary<string, string> data)
|
|
|
{
|
|
|
//变更前的数据单独存储
|
|
|
_oldValue.Clear();
|
|
|
_oldValue = ObjectUtils.Copy<Dictionary<string, string>>(data);
|
|
|
//清理历史变更数据
|
|
|
_newValue.Clear();
|
|
|
|
|
|
//串口参数初始值
|
|
|
this.cmbSerialPort.Items.Clear();
|
|
|
this.cmbSerialPort.Items.AddRange(Constant.COM_PORT_NAME_VALUE);
|
|
|
this.cmbSerialPortBaud.Items.Clear();
|
|
|
this.cmbSerialPortBaud.Items.AddRange(Constant.COM_PORT_BAUD_VALUE);
|
|
|
//并口默认参数
|
|
|
this.cmbParallelPort.Items.Clear();
|
|
|
this.cmbParallelPort.Items.AddRange(Constant.LPT_NAME_VALUE);
|
|
|
//打印机驱动默认参数
|
|
|
this.cmbDriverPrinter.Items.Clear();
|
|
|
this.cmbDriverPrinter.Items.AddRange(Global.Instance.AvailablePrinters.ToArray());
|
|
|
|
|
|
var lists = new List<PrinterItem>();
|
|
|
|
|
|
//取系统默认的配置
|
|
|
var defaultPrinterItem = Global.Instance.GetDefaultPrinterItem();
|
|
|
//将默认None打印机压入
|
|
|
lists.Add(defaultPrinterItem);
|
|
|
|
|
|
//将默认参数绑定到Tag,支持更换事件的操作
|
|
|
this.cmbCashierTicketPrinter.Tag = defaultPrinterItem;
|
|
|
|
|
|
//数据表中加载打印机列表
|
|
|
List<Entity.Printer> printers = null;
|
|
|
lock (Global.Instance.SyncLock)
|
|
|
{
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
printers = db.Query<Entity.Printer>().ToList();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (printers != null)
|
|
|
{
|
|
|
foreach (var entity in printers)
|
|
|
{
|
|
|
var printer = new PrinterItem();
|
|
|
|
|
|
printer.Id = entity.Id;
|
|
|
printer.Name = entity.Name;
|
|
|
printer.Port = entity.Port;
|
|
|
|
|
|
//打印机表中没有具体参数对应的值
|
|
|
printer.Data = new Dictionary<string, string>();
|
|
|
|
|
|
printer.DynamicLibrary = entity.DynamicLibrary;
|
|
|
printer.Type = entity.Type;
|
|
|
printer.InitCommand = entity.InitCommand;
|
|
|
printer.NormalCommand = entity.NormalCommand;
|
|
|
printer.DoubleHeightCommand = entity.DoubleHeightCommand;
|
|
|
printer.DoubleWidthCommand = entity.DoubleWidthCommand;
|
|
|
printer.DoubleWidthHeightCommand = entity.DoubleWidthHeightCommand;
|
|
|
printer.CutPageCommand = entity.CutPageCommand;
|
|
|
printer.CashboxCommand = entity.CashboxCommand;
|
|
|
printer.UserDefined = entity.UserDefined;
|
|
|
printer.PageWidth = entity.PageWidth;
|
|
|
|
|
|
lists.Add(printer);
|
|
|
}
|
|
|
}
|
|
|
//打印机列表
|
|
|
this.cmbCashierTicketPrinter.Items.Clear();
|
|
|
this.cmbCashierTicketPrinter.DisplayMember = "Name";
|
|
|
this.cmbCashierTicketPrinter.Items.AddRange(lists.ToArray());
|
|
|
|
|
|
//小票打印机参数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_TICKET))
|
|
|
{
|
|
|
string json = data[ConfigConstant.PERIPHERAL_CASHIER_TICKET];
|
|
|
var item = JsonUtils.Deserialize<PrinterItem>(json);
|
|
|
|
|
|
//将变更前的参数存入Tag,等待端口及配置参数的使用
|
|
|
this.cmbCashierTicketPrinter.Tag = item;
|
|
|
//当前选中的
|
|
|
var _selectedIndex = lists.FindIndex(x => x.Name == item.Name);
|
|
|
|
|
|
this.cmbCashierTicketPrinter.SelectedIndex = _selectedIndex < 0 ? 0 : _selectedIndex;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.cmbCashierTicketPrinter.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//票头空白行数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_HEADER_EMPTY))
|
|
|
{
|
|
|
this.comboBoxEx1.SelectedIndex = this.comboBoxEx1.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_HEADER_EMPTY].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx1.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//票尾空白行数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_FOOTER_EMPTY))
|
|
|
{
|
|
|
this.comboBoxEx2.SelectedIndex = this.comboBoxEx2.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_FOOTER_EMPTY].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx2.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//小票打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_TICKET_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx3.SelectedIndex = this.comboBoxEx3.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_TICKET_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx3.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//打印延迟
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_PRINT_DELAY))
|
|
|
{
|
|
|
this.comboBoxEx4.SelectedIndex = this.comboBoxEx4.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_PRINT_DELAY].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx4.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//单价小数位数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_PRICE_DIGIT))
|
|
|
{
|
|
|
this.comboBoxEx7.SelectedIndex = this.comboBoxEx7.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_PRICE_DIGIT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx7.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//数量小数位数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_QUANTITY_DIGIT))
|
|
|
{
|
|
|
this.comboBoxEx6.SelectedIndex = this.comboBoxEx6.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_QUANTITY_DIGIT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx6.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//合计小数位数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_TOTAL_DIGIT))
|
|
|
{
|
|
|
this.comboBoxEx5.SelectedIndex = this.comboBoxEx5.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_TOTAL_DIGIT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx5.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//小票号长度
|
|
|
if (data.ContainsKey(ConfigConstant.CONFIG_CASHIER_TICKETNO_LENGTH))
|
|
|
{
|
|
|
this.comboBoxEx8.SelectedIndex = this.comboBoxEx8.FindString(data[ConfigConstant.CONFIG_CASHIER_TICKETNO_LENGTH].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx8.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//序号长度
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_LENGTH))
|
|
|
{
|
|
|
this.comboBoxEx9.SelectedIndex = this.comboBoxEx9.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_LENGTH].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx9.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//序号起始位置
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_BEGIN))
|
|
|
{
|
|
|
this.integerInput1.Value = StringUtils.GetInt(data[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_BEGIN]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.integerInput1.Value = 1;
|
|
|
}
|
|
|
|
|
|
//退纸行数
|
|
|
if (data.ContainsKey(ConfigConstant.CONFIG_CASHIER_FEEDBACK_ROW))
|
|
|
{
|
|
|
this.comboBoxEx10.SelectedIndex = this.comboBoxEx10.FindString(data[ConfigConstant.CONFIG_CASHIER_FEEDBACK_ROW].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx10.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//充值打印延迟
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY))
|
|
|
{
|
|
|
this.comboBoxEx12.SelectedIndex = this.comboBoxEx12.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx12.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//充值打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx11.SelectedIndex = this.comboBoxEx11.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx11.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//开户打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_OPENCARD_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx13.SelectedIndex = this.comboBoxEx13.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_OPENCARD_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx13.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//退卡余额打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_BACKCARD_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx14.SelectedIndex = this.comboBoxEx14.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_BACKCARD_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx14.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
//补换卡打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx15.SelectedIndex = this.comboBoxEx15.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx15.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//积分兑换打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx16.SelectedIndex = this.comboBoxEx16.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx16.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//卡券核销打印份数
|
|
|
if (data.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CHECKCOUPON_COUNT))
|
|
|
{
|
|
|
this.comboBoxEx17.SelectedIndex = this.comboBoxEx17.FindString(data[ConfigConstant.PERIPHERAL_CASHIER_CHECKCOUPON_COUNT].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.comboBoxEx17.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
//CheckBoxX处理
|
|
|
foreach (Control control in this.tabPanel.Controls)
|
|
|
{
|
|
|
if (control is CheckBoxX)
|
|
|
{
|
|
|
var item = control as CheckBoxX;
|
|
|
var key = item.Tag.ToString();
|
|
|
if (data.ContainsKey(key))
|
|
|
{
|
|
|
string _value = data[key].ToString();
|
|
|
item.Checked = _value.Equals("1");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
item.Checked = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//CheckBoxX处理
|
|
|
foreach (Control control in this.tabPanel2.Controls)
|
|
|
{
|
|
|
if (control is CheckBoxX)
|
|
|
{
|
|
|
var item = control as CheckBoxX;
|
|
|
var key = item.Tag.ToString();
|
|
|
if (data.ContainsKey(key))
|
|
|
{
|
|
|
string _value = data[key].ToString();
|
|
|
item.Checked = _value.Equals("1");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
item.Checked = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//界面加载完成
|
|
|
this._inited = true;
|
|
|
}
|
|
|
|
|
|
public List<Config> NewChanged()
|
|
|
{
|
|
|
var result = new List<Config>();
|
|
|
//尚未初始化完成
|
|
|
if (!this._inited) return result;
|
|
|
|
|
|
//当前选择的打印机
|
|
|
var printerItem = this.cmbCashierTicketPrinter.SelectedItem as PrinterItem;
|
|
|
|
|
|
var newValue = new PrinterItem();
|
|
|
|
|
|
newValue.Id = printerItem.Id;
|
|
|
newValue.Name = this.cmbCashierTicketPrinter.Text;
|
|
|
newValue.Port = this.cmbCashierTicketPort.Text;
|
|
|
|
|
|
var data = new Dictionary<string, string>();
|
|
|
|
|
|
data.Add(Constant.COM_PORT_NAME, this.cmbSerialPort.Text);
|
|
|
data.Add(Constant.COM_PORT_BAUD, this.cmbSerialPortBaud.Text);
|
|
|
data.Add(Constant.LPT_NAME, this.cmbParallelPort.Text);
|
|
|
data.Add(Constant.USB_PID, "0");
|
|
|
data.Add(Constant.USB_VID, "0");
|
|
|
data.Add(Constant.NET_IP_ADDRESS, this.txtIpAddressInput.Text);
|
|
|
data.Add(Constant.DRIVE_NAME, this.cmbDriverPrinter.Text);
|
|
|
|
|
|
newValue.Data = data;
|
|
|
|
|
|
newValue.DynamicLibrary = printerItem.DynamicLibrary;
|
|
|
newValue.Type = printerItem.Type;
|
|
|
newValue.InitCommand = printerItem.InitCommand;
|
|
|
newValue.NormalCommand = printerItem.NormalCommand;
|
|
|
newValue.DoubleHeightCommand = printerItem.DoubleHeightCommand;
|
|
|
newValue.DoubleWidthCommand = printerItem.DoubleWidthCommand;
|
|
|
newValue.DoubleWidthHeightCommand = printerItem.DoubleWidthHeightCommand;
|
|
|
newValue.CutPageCommand = printerItem.CutPageCommand;
|
|
|
newValue.CashboxCommand = printerItem.CashboxCommand;
|
|
|
newValue.UserDefined = printerItem.UserDefined;
|
|
|
|
|
|
newValue.PageWidth = printerItem.PageWidth;
|
|
|
|
|
|
//变更前的数据
|
|
|
PrinterItem oldValue = this.cmbCashierTicketPrinter.Tag as PrinterItem;
|
|
|
//判断是否更改,如果过更改压入到 NewValue
|
|
|
bool isChanged = !(newValue.Equals(oldValue));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
var config = new Config();
|
|
|
|
|
|
config.Id = IdWorkerUtils.Instance.NextId();
|
|
|
config.Group = ConfigConstant.PERIPHERAL_GROUP;
|
|
|
config.TenantId = Global.Instance.Authc.TenantId;
|
|
|
config.Keys = ConfigConstant.PERIPHERAL_CASHIER_TICKET;
|
|
|
config.Values = JsonUtils.Serialize(newValue);
|
|
|
|
|
|
result.Add(config);
|
|
|
}
|
|
|
|
|
|
|
|
|
var _value = "0";
|
|
|
//票头空白行数
|
|
|
_value = this.comboBoxEx1.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_HEADER_EMPTY) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_HEADER_EMPTY].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_HEADER_EMPTY] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "0";
|
|
|
//票尾空白行数
|
|
|
_value = this.comboBoxEx2.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_FOOTER_EMPTY) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_FOOTER_EMPTY].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_FOOTER_EMPTY] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
//小票打印份数
|
|
|
_value = this.comboBoxEx3.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_TICKET_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_TICKET_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_TICKET_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
//小票打印延迟
|
|
|
_value = this.comboBoxEx4.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_PRINT_DELAY) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_PRINT_DELAY].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_PRINT_DELAY] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "2";
|
|
|
//单价小数位数
|
|
|
_value = this.comboBoxEx7.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_PRICE_DIGIT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_PRICE_DIGIT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_PRICE_DIGIT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "2";
|
|
|
//数量小数位数
|
|
|
_value = this.comboBoxEx6.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_QUANTITY_DIGIT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_QUANTITY_DIGIT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_QUANTITY_DIGIT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "2";
|
|
|
//合计小数位数
|
|
|
_value = this.comboBoxEx5.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_TOTAL_DIGIT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_TOTAL_DIGIT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_TOTAL_DIGIT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "0";
|
|
|
//打印小票长度
|
|
|
_value = this.comboBoxEx8.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.CONFIG_CASHIER_TICKETNO_LENGTH) && this._oldValue[ConfigConstant.CONFIG_CASHIER_TICKETNO_LENGTH].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.CONFIG_CASHIER_TICKETNO_LENGTH] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "0";
|
|
|
//打印序号长度
|
|
|
_value = this.comboBoxEx9.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_LENGTH) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_LENGTH].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_LENGTH] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
//每天序号起始数值
|
|
|
_value = this.integerInput1.Value.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_BEGIN) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_BEGIN].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_ORDERNO_BEGIN] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "0";
|
|
|
//退纸行数
|
|
|
_value = this.comboBoxEx10.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.CONFIG_CASHIER_FEEDBACK_ROW) && this._oldValue[ConfigConstant.CONFIG_CASHIER_FEEDBACK_ROW].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.CONFIG_CASHIER_FEEDBACK_ROW] = _value;
|
|
|
}
|
|
|
|
|
|
//卡务打印延迟
|
|
|
_value = this.comboBoxEx12.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "2";
|
|
|
|
|
|
//充值打印份数
|
|
|
_value = this.comboBoxEx11.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//开户打印份数
|
|
|
_value = this.comboBoxEx13.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_OPENCARD_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_OPENCARD_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_OPENCARD_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//退卡余额打印份数
|
|
|
_value = this.comboBoxEx14.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_BACKCARD_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_BACKCARD_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_BACKCARD_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//补换卡打印份数
|
|
|
_value = this.comboBoxEx15.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_CHANGECARD_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//积分兑换打印份数
|
|
|
_value = this.comboBoxEx16.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_EXRECHARGE_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//卡券核销打印份数
|
|
|
_value = this.comboBoxEx17.SelectedItem.ToString();
|
|
|
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_CASHIER_CHECKCOUPON_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_CASHIER_CHECKCOUPON_COUNT].Equals(_value));
|
|
|
if (isChanged)
|
|
|
{
|
|
|
this._newValue[ConfigConstant.PERIPHERAL_CASHIER_CHECKCOUPON_COUNT] = _value;
|
|
|
}
|
|
|
|
|
|
_value = "1";
|
|
|
|
|
|
//CheckBoxX处理
|
|
|
foreach (Control control in tabPanel.Controls)
|
|
|
{
|
|
|
if (control is CheckBoxX)
|
|
|
{
|
|
|
var item = control as CheckBoxX;
|
|
|
var key = item.Tag.ToString();
|
|
|
//忽略为空的
|
|
|
if (string.IsNullOrEmpty(key)) continue;
|
|
|
|
|
|
var value = item.Checked ? "1" : "0";
|
|
|
|
|
|
//判断是否更改,如果过更改压入到 NewValue
|
|
|
bool changed = !(this._oldValue.ContainsKey(key) && this._oldValue[key].Equals(value));
|
|
|
if (changed)
|
|
|
{
|
|
|
this._newValue[key] = value;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//CheckBoxX处理
|
|
|
foreach (Control control in tabPanel2.Controls)
|
|
|
{
|
|
|
if (control is CheckBoxX)
|
|
|
{
|
|
|
var item = control as CheckBoxX;
|
|
|
var key = item.Tag.ToString();
|
|
|
//忽略为空的
|
|
|
if (string.IsNullOrEmpty(key)) continue;
|
|
|
|
|
|
var value = item.Checked ? "1" : "0";
|
|
|
|
|
|
//判断是否更改,如果过更改压入到 NewValue
|
|
|
bool changed = !(this._oldValue.ContainsKey(key) && this._oldValue[key].Equals(value));
|
|
|
if (changed)
|
|
|
{
|
|
|
this._newValue[key] = value;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//转换为Config对象,便于存储
|
|
|
foreach (var v in this._newValue)
|
|
|
{
|
|
|
var config = new Config();
|
|
|
|
|
|
config.Id = IdWorkerUtils.Instance.NextId();
|
|
|
config.Group = ConfigConstant.PERIPHERAL_GROUP;
|
|
|
config.TenantId = Global.Instance.Authc.TenantId;
|
|
|
config.Keys = v.Key;
|
|
|
config.Values = v.Value;
|
|
|
|
|
|
result.Add(config);
|
|
|
}
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public Tuple<bool, string> SaveChanged(List<Config> data)
|
|
|
{
|
|
|
bool isSuccess = true;
|
|
|
string message = "参数更新成功";
|
|
|
try
|
|
|
{
|
|
|
lock (Global.Instance.SyncLock)
|
|
|
{
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
using (var trans = db.GetTransaction())
|
|
|
{
|
|
|
foreach (var config in data)
|
|
|
{
|
|
|
db.Save(config);
|
|
|
}
|
|
|
trans.Complete();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
isSuccess = false;
|
|
|
message = "参数更新异常";
|
|
|
|
|
|
LOGGER.Error(ex, message);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
if (isSuccess)
|
|
|
{
|
|
|
//新修改后的参数应用后,重置OldValue,避免用户在没有切换Tab情况下,直接修改当前Tab内容
|
|
|
foreach (var config in data)
|
|
|
{
|
|
|
string key = config.Keys;
|
|
|
string value = config.Values;
|
|
|
|
|
|
this._oldValue[key] = value;
|
|
|
|
|
|
if (ConfigConstant.PERIPHERAL_CASHIER_TICKET.Equals(key))
|
|
|
{
|
|
|
this.cmbCashierTicketPrinter.Tag = JsonUtils.Deserialize<PrinterItem>(value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this._newValue.Clear();
|
|
|
|
|
|
//更新控件UI
|
|
|
UpdatePrinterUi();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return new Tuple<bool, string>(isSuccess, message);
|
|
|
}
|
|
|
|
|
|
private void UpdatePrinterUi()
|
|
|
{
|
|
|
Global.Instance.ReloadConfig(ConfigConstant.PERIPHERAL_GROUP);
|
|
|
}
|
|
|
|
|
|
private void OnIpAddressCustomClick(object sender, EventArgs e)
|
|
|
{
|
|
|
var item = sender as IpAddressInput;
|
|
|
|
|
|
NumericKeyboard.ShowKeyboard(this, item);
|
|
|
}
|
|
|
|
|
|
private void OnCashierTicketPrinterChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
ComboBoxEx item = (ComboBoxEx)sender;
|
|
|
|
|
|
//变更前的数据
|
|
|
PrinterItem oldValue = item.Tag as PrinterItem;
|
|
|
//当前选择的打印机数据
|
|
|
PrinterItem newValue = item.SelectedItem as PrinterItem;
|
|
|
|
|
|
if (newValue.UserDefined == 1)
|
|
|
{
|
|
|
this.ButtonAddPrinter.Enabled = true;
|
|
|
|
|
|
this.ButtonDeletePrinter.Enabled = true;
|
|
|
|
|
|
this.ButtonEditPrinter.Enabled = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.ButtonAddPrinter.Enabled = true;
|
|
|
|
|
|
this.ButtonDeletePrinter.Enabled = false;
|
|
|
|
|
|
this.ButtonEditPrinter.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//绑定端口
|
|
|
this.cmbCashierTicketPort.Items.Clear();
|
|
|
var items = newValue.Port.Split(',');
|
|
|
this.cmbCashierTicketPort.Items.AddRange(items);
|
|
|
|
|
|
if (items.Contains(oldValue.Port))
|
|
|
{
|
|
|
this.cmbCashierTicketPort.SelectedIndex = Array.IndexOf(items, oldValue.Port);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.cmbCashierTicketPort.SelectedIndex = 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
//参数显示
|
|
|
if (newValue.Name.Contains("针式驱动打印"))
|
|
|
{
|
|
|
this.chaPrintBeyondNewLine.Visible = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.chaPrintBeyondNewLine.Visible = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnCashierTicketPortChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
ComboBoxEx item = (ComboBoxEx)sender;
|
|
|
|
|
|
//变更前的数据
|
|
|
PrinterItem oldValue = this.cmbCashierTicketPrinter.Tag as PrinterItem;
|
|
|
|
|
|
//默认值
|
|
|
int inx = Array.IndexOf(Global.Instance.AvailablePrinters.ToArray(), oldValue.Data[Constant.DRIVE_NAME]);
|
|
|
this.cmbDriverPrinter.SelectedIndex = inx < 0 ? 0 : inx;
|
|
|
inx = Array.IndexOf(Constant.COM_PORT_NAME_VALUE, oldValue.Data[Constant.COM_PORT_NAME]);
|
|
|
this.cmbSerialPort.SelectedIndex = inx < 0 ? 0 : inx;
|
|
|
inx = Array.IndexOf(Constant.COM_PORT_BAUD_VALUE, oldValue.Data[Constant.COM_PORT_BAUD]);
|
|
|
this.cmbSerialPortBaud.SelectedIndex = inx < 0 ? 0 : inx;
|
|
|
inx = Array.IndexOf(Constant.LPT_NAME_VALUE, oldValue.Data[Constant.LPT_NAME]);
|
|
|
this.cmbParallelPort.SelectedIndex = inx < 0 ? 0 : inx;
|
|
|
|
|
|
this.txtIpAddressInput.Value = oldValue.Data[Constant.NET_IP_ADDRESS];
|
|
|
|
|
|
switch (item.Text)
|
|
|
{
|
|
|
case "串口":
|
|
|
|
|
|
this.cmbSerialPort.Enabled = true;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = true;//波特率
|
|
|
this.cmbParallelPort.Enabled = false;//并口
|
|
|
this.cmbDriverPrinter.Enabled = false;//驱动
|
|
|
this.txtIpAddressInput.Enabled = false;//网口
|
|
|
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = true;//打印测试页
|
|
|
|
|
|
break;
|
|
|
case "并口":
|
|
|
this.cmbSerialPort.Enabled = false;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = false;//波特率
|
|
|
this.cmbParallelPort.Enabled = true;//并口
|
|
|
this.cmbDriverPrinter.Enabled = false;//驱动
|
|
|
this.txtIpAddressInput.Enabled = false;//网口
|
|
|
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = true;
|
|
|
|
|
|
break;
|
|
|
case "网口":
|
|
|
this.cmbSerialPort.Enabled = false;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = false;//波特率
|
|
|
this.cmbParallelPort.Enabled = false;//并口
|
|
|
this.cmbDriverPrinter.Enabled = false;//驱动
|
|
|
this.txtIpAddressInput.Enabled = true;//网口
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = true;
|
|
|
|
|
|
|
|
|
break;
|
|
|
case "USB":
|
|
|
this.cmbSerialPort.Enabled = false;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = false;//波特率
|
|
|
this.cmbParallelPort.Enabled = false;//并口
|
|
|
this.cmbDriverPrinter.Enabled = false;//驱动
|
|
|
this.txtIpAddressInput.Enabled = false;//网口
|
|
|
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = true;
|
|
|
|
|
|
break;
|
|
|
case "驱动":
|
|
|
this.cmbSerialPort.Enabled = false;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = false;//波特率
|
|
|
this.cmbParallelPort.Enabled = false;//并口
|
|
|
this.cmbDriverPrinter.Enabled = true;//驱动
|
|
|
this.txtIpAddressInput.Enabled = false;//网口
|
|
|
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = true;
|
|
|
|
|
|
break;
|
|
|
default:
|
|
|
|
|
|
this.cmbSerialPort.Enabled = false;//串口
|
|
|
this.cmbSerialPortBaud.Enabled = false;//波特率
|
|
|
this.cmbParallelPort.Enabled = false;//并口
|
|
|
this.cmbDriverPrinter.Enabled = false;//驱动
|
|
|
this.txtIpAddressInput.Enabled = false;//网口
|
|
|
|
|
|
//打印测试页
|
|
|
this.ButtonPrintTestPager.Enabled = false;
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnButtonPrintTestPager(object sender, EventArgs e)
|
|
|
{
|
|
|
this.ButtonPrintTestPager.Enabled = false;
|
|
|
this.ButtonPrintTestPager.Text = "请稍候..";
|
|
|
|
|
|
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
this.Invoke((EventHandler)delegate
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
bool cutPager = checkBoxX34.Checked;
|
|
|
|
|
|
//是否允许打开钱箱
|
|
|
bool openCashbox = checkBoxX27.Checked;
|
|
|
|
|
|
var pobject = PrintHelper.GetTicketPrinterObject(cutPager, openCashbox);
|
|
|
|
|
|
var status = PrinterUtils.CheckPrinterStatus(pobject);
|
|
|
|
|
|
if (status.Item1)
|
|
|
{
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
using (var reader = new StreamReader(assembly.GetManifestResourceStream("POSV.Test.TicketTest.json")))
|
|
|
{
|
|
|
var json = reader.ReadToEnd();
|
|
|
|
|
|
var vars = JsonUtils.Deserialize<List<VariableValue>>(json);
|
|
|
|
|
|
//票头空白行
|
|
|
int headerLine = Convert.ToInt32(this.comboBoxEx1.SelectedItem.ToString());
|
|
|
|
|
|
//票尾空白行
|
|
|
int footerLine = Convert.ToInt32(this.comboBoxEx2.SelectedItem.ToString());
|
|
|
|
|
|
//执行收银小票打印
|
|
|
PrintHelper.PrinterTicket("收银小票", vars, cutPager, openCashbox, headerLine, footerLine);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LOGGER.Error(ex, "打印机测试发生异常");
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
this.ButtonPrintTestPager.Enabled = true;
|
|
|
this.ButtonPrintTestPager.Text = "打印测试";
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void OnButtonAddPrinterClick(object sender, EventArgs e)
|
|
|
{
|
|
|
var form = new EditPrinterForm(null);
|
|
|
form.AcceptButtonClick += (o, args) =>
|
|
|
{
|
|
|
this.InitUi();
|
|
|
};
|
|
|
|
|
|
form.CancelButtonClick += (o, args) => { };
|
|
|
|
|
|
|
|
|
TransparentForm trans = new TransparentForm(this.FindForm(), form);
|
|
|
trans.Show(this);
|
|
|
}
|
|
|
|
|
|
private void OnButtonEditPrinterClick(object sender, EventArgs e)
|
|
|
{
|
|
|
//当前选择的打印机数据
|
|
|
var printerItem = this.cmbCashierTicketPrinter.SelectedItem as PrinterItem;
|
|
|
|
|
|
var form = new EditPrinterForm(printerItem);
|
|
|
form.AcceptButtonClick += (o, args) =>
|
|
|
{
|
|
|
this.InitUi();
|
|
|
};
|
|
|
|
|
|
form.CancelButtonClick += (o, args) => { };
|
|
|
|
|
|
TransparentForm trans = new TransparentForm(this.FindForm(), form);
|
|
|
trans.Show(this);
|
|
|
}
|
|
|
|
|
|
private void OnButtonDeletePrinterClick(object sender, EventArgs e)
|
|
|
{
|
|
|
//当前选择的打印机数据
|
|
|
var printerItem = this.cmbCashierTicketPrinter.SelectedItem as PrinterItem;
|
|
|
|
|
|
bool isException = true;
|
|
|
try
|
|
|
{
|
|
|
lock (Global.Instance.SyncLock)
|
|
|
{
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
using (var trans = db.GetTransaction())
|
|
|
{
|
|
|
db.Delete<Entity.Printer>("where id = @0 and userDefined = 1;", printerItem.Id);
|
|
|
|
|
|
trans.Complete();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
isException = false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
isException = true;
|
|
|
|
|
|
LOGGER.Error(ex, "删除打印机发生异常");
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
if (!isException)
|
|
|
{
|
|
|
this.InitUi();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|