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.

883 lines
33 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 WmPrinterParameter : 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 WmPrinterParameter()
{
InitializeComponent();
OnAloneCheckedChanged(this, null);
}
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.comboBoxEx5.DataSource = (string[])_items.Clone();
this.comboBoxEx5.SelectedIndex = 1;
//打印发送延迟
this.comboBoxEx4.DataSource = (string[])_items.Clone();
this.comboBoxEx4.SelectedIndex = 1;
//退纸行数
this.comboBoxEx10.DataSource = (string[])_feedBackRows.Clone();
this.comboBoxEx10.SelectedIndex = 0;
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_WM_TICKET_PRINTER))
{
string json = data[ConfigConstant.PERIPHERAL_WM_TICKET_PRINTER];
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_WM_CASHIER_HEADER_EMPTY))
{
this.comboBoxEx1.SelectedIndex = this.comboBoxEx1.FindString(data[ConfigConstant.PERIPHERAL_WM_CASHIER_HEADER_EMPTY].ToString());
}
else
{
this.comboBoxEx1.SelectedIndex = 0;
}
//票尾空白行数
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_FOOTER_EMPTY))
{
this.comboBoxEx2.SelectedIndex = this.comboBoxEx2.FindString(data[ConfigConstant.PERIPHERAL_WM_CASHIER_FOOTER_EMPTY].ToString());
}
else
{
this.comboBoxEx2.SelectedIndex = 0;
}
//小票打印份数
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_TICKET_COUNT))
{
this.comboBoxEx3.SelectedIndex = this.comboBoxEx3.FindString(data[ConfigConstant.PERIPHERAL_WM_CASHIER_TICKET_COUNT].ToString());
}
else
{
this.comboBoxEx3.SelectedIndex = 0;
}
//收银台外卖小票打印份数
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_DESK_TICKET_COUNT))
{
this.comboBoxEx5.SelectedIndex = this.comboBoxEx5.FindString(data[ConfigConstant.PERIPHERAL_WM_CASHIER_DESK_TICKET_COUNT].ToString());
}
else
{
this.comboBoxEx5.SelectedIndex = 0;
}
//打印延迟
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_PRINT_DELAY))
{
this.comboBoxEx4.SelectedIndex = this.comboBoxEx4.FindString(data[ConfigConstant.PERIPHERAL_WM_CASHIER_PRINT_DELAY].ToString());
}
else
{
this.comboBoxEx4.SelectedIndex = 0;
}
//退纸行数
if (data.ContainsKey(ConfigConstant.CONFIG_WM_PRINTER_FEEDBACK_ROW))
{
this.comboBoxEx10.SelectedIndex = this.comboBoxEx10.FindString(data[ConfigConstant.CONFIG_WM_PRINTER_FEEDBACK_ROW].ToString());
}
else
{
this.comboBoxEx10.SelectedIndex = 0;
}
//外卖是否单独配置打印机
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_WMPRINTERALONE))
{
this.checkBoxX1.Checked = data[ConfigConstant.PERIPHERAL_WM_WMPRINTERALONE].Equals("1");
}
//厨打机同时打印外卖厨打票(适用于菜品未映射的厨打模式)
if (data.ContainsKey(ConfigConstant.PERIPHERAL_WM_WMPRINTERKIT))
{
this.checkBoxX4.Checked = data[ConfigConstant.PERIPHERAL_WM_WMPRINTERKIT].Equals("1");
}
//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;
}
}
}
//界面加载完成
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_WM_TICKET_PRINTER;
config.Values = JsonUtils.Serialize(newValue);
result.Add(config);
}
var _value = "0";
//票头空白行数
_value = this.comboBoxEx1.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_HEADER_EMPTY) && this._oldValue[ConfigConstant.PERIPHERAL_WM_CASHIER_HEADER_EMPTY].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_CASHIER_HEADER_EMPTY] = _value;
}
_value = "0";
//票尾空白行数
_value = this.comboBoxEx2.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_FOOTER_EMPTY) && this._oldValue[ConfigConstant.PERIPHERAL_WM_CASHIER_FOOTER_EMPTY].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_CASHIER_FOOTER_EMPTY] = _value;
}
_value = "1";
//小票打印份数
_value = this.comboBoxEx3.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_TICKET_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_WM_CASHIER_TICKET_COUNT].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_CASHIER_TICKET_COUNT] = _value;
}
_value = "1";
//收银台小票打印份数
_value = this.comboBoxEx5.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_DESK_TICKET_COUNT) && this._oldValue[ConfigConstant.PERIPHERAL_WM_CASHIER_DESK_TICKET_COUNT].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_CASHIER_DESK_TICKET_COUNT] = _value;
}
_value = "1";
//小票打印延迟
_value = this.comboBoxEx4.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_CASHIER_PRINT_DELAY) && this._oldValue[ConfigConstant.PERIPHERAL_WM_CASHIER_PRINT_DELAY].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_CASHIER_PRINT_DELAY] = _value;
}
_value = "0";
//退纸行数
_value = this.comboBoxEx10.SelectedItem.ToString();
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.CONFIG_WM_PRINTER_FEEDBACK_ROW) && this._oldValue[ConfigConstant.CONFIG_WM_PRINTER_FEEDBACK_ROW].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.CONFIG_WM_PRINTER_FEEDBACK_ROW] = _value;
}
//外卖是否单独配置打印机
_value = "0";
_value = this.checkBoxX1.Checked ? "1" : "0";
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_WMPRINTERALONE) && this._oldValue[ConfigConstant.PERIPHERAL_WM_WMPRINTERALONE].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_WMPRINTERALONE] = _value;
}
//厨打机同时打印外卖厨打票(适用于菜品未映射的厨打模式)
_value = "0";
_value = this.checkBoxX4.Checked ? "1" : "0";
isChanged = !(this._oldValue.ContainsKey(ConfigConstant.PERIPHERAL_WM_WMPRINTERKIT) && this._oldValue[ConfigConstant.PERIPHERAL_WM_WMPRINTERKIT].Equals(_value));
if (isChanged)
{
this._newValue[ConfigConstant.PERIPHERAL_WM_WMPRINTERKIT] = _value;
}
//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;
}
}
}
//转换为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;
}
}
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 = "请稍候..";
try
{
bool cutPager = checkBoxX34.Checked;
//是否允许打开钱箱 外卖默认不开钱箱
bool openCashbox = false;
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();
}
}
}
/// <summary>
/// 单独设置外卖打印机
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAloneCheckedChanged(object sender, EventArgs e)
{
this.groupPanel4.Visible = checkBoxX1.Checked;
this.doubleBufferPanelX1.Visible = checkBoxX1.Checked;
this.superTabControl.Visible = checkBoxX1.Checked;
}
}
}