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.

155 lines
4.5 KiB
C#

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;
namespace POSV.Component
{
public partial class WeightSettings : AbstractSettings
{
public WeightSettings()
{
InitializeComponent();
this.superTabControl.SelectedTabChanging += OnSelectedTabChanging;
this.superTabControl.SelectedTabChanged += OnSelectedTabChanged;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.BackColor = Color.Transparent;
}
private void OnSelectedTabChanged(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
{
}
private void OnSelectedTabChanging(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangingEventArgs e)
{
if (e.OldValue == null)
{
return;
}
//电子秤配置
if (this.weightParameter1 is AbstractParameter)
{
var newValue = this.weightParameter1.NewChanged();
if (newValue.Count > 0)
{
this.weightParameter1.SaveChanged(newValue);
}
}
}
public override 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(poco: config);
}
trans.Complete();
}
}
}
}
catch (Exception ex)
{
isSuccess = false;
message = "参数更新异常";
LOGGER.Error(ex, message);
}
finally
{
if (isSuccess)
{
//更新控件UI
UpdatePeripheralUi();
}
}
return new Tuple<bool, string>(isSuccess, message);
}
public override List<Config> NewChanged()
{
var result = new List<Config>();
//收银小票参数
var printerValue = this.weightParameter1.NewChanged();
result.AddRange(printerValue);
return result;
}
private void UpdatePeripheralUi()
{
Global.Instance.ReloadConfig(ConfigConstant.PERIPHERAL_GROUP);
}
private void OnButtonOKClick(object sender, EventArgs e)
{
var selected = this.superTabControl.SelectedTabIndex;
var result = new Tuple<bool, string>(true, "没有任何更新");
switch (selected)
{
case 0:
{
var newValue = this.weightParameter1.NewChanged();
if (newValue.Count > 0)
{
result = this.weightParameter1.SaveChanged(newValue);
}
}
break;
}
if (result.Item1)
{
string message = "[" + this.Tag.ToString() + "]的参数修改成功";
DialogForm dialog = new DialogForm("参数更新成功", message, MessageBoxIcon.Information, MessageBoxButtons.OK);
dialog.ShowDialog();
}
else
{
string message = "[" + this.Tag.ToString() + "]的参数修改失败";
DialogForm dialog = new DialogForm("参数更新失败", message, MessageBoxIcon.Error, MessageBoxButtons.OK);
dialog.ShowDialog();
}
}
private void OnButtonCloseClick(object sender, EventArgs e)
{
var parent = this.FindForm();
if (parent != null && parent is SettingsForm)
{
var settings = parent as SettingsForm;
settings.FormClose();
}
}
}
}