using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace B3DealerClient.Control
|
|
{
|
|
/// <summary>
|
|
/// WeightSettingWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class WeightSettingWindow : Window
|
|
{
|
|
List<string> weight = new List<string> { "IND560", "Xk3124", "Xk3190A9" };
|
|
List<string> com = new List<string> { "COM1", "COM2", "COM3", "COM4", "COM5" };
|
|
List<string> rate = new List<string> { "1200", "2400", "4800", "7200", "9600" };
|
|
List<string> bit = new List<string> { "5", "6", "7", "8" };
|
|
string _flag;
|
|
WeightConfig config;
|
|
|
|
public WeightSettingWindow(string flag)
|
|
{
|
|
this._flag = flag;
|
|
InitializeComponent();
|
|
weightSet.ItemsSource = weight;
|
|
comSet.ItemsSource = com;
|
|
rateSet.ItemsSource = rate;
|
|
bitSet.ItemsSource = bit;
|
|
config = WeightConfig.Init(flag);
|
|
if (!string.IsNullOrEmpty(config.WeightSet))
|
|
weightSet.SelectedIndex = weight.IndexOf(config.WeightSet);
|
|
else
|
|
weightSet.SelectedIndex = 0;
|
|
if (!string.IsNullOrEmpty(config.ComSet))
|
|
comSet.SelectedIndex = com.IndexOf(config.ComSet);
|
|
else
|
|
comSet.SelectedIndex = 0;
|
|
if (config.RateSet.HasValue)
|
|
rateSet.SelectedIndex = rate.IndexOf(config.RateSet.ToString());
|
|
else
|
|
rateSet.SelectedIndex = 2;
|
|
if (config.BitSet.HasValue)
|
|
bitSet.SelectedIndex = bit.IndexOf(config.BitSet.ToString());
|
|
else
|
|
bitSet.SelectedIndex = 3;
|
|
if (string.IsNullOrEmpty(config.Format))
|
|
format.Text = "0.00";
|
|
else
|
|
format.Text = config.Format;
|
|
if (config.Discont == null)
|
|
discont.Text = "0.00";
|
|
else
|
|
discont.Text = config.Discont.ToString();
|
|
}
|
|
|
|
bool changed;
|
|
private void saveBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
config.WeightSet = weight[this.weightSet.SelectedIndex];
|
|
config.ComSet = com[this.comSet.SelectedIndex];
|
|
config.RateSet = int.Parse(rate[this.rateSet.SelectedIndex]);
|
|
config.BitSet = int.Parse(bit[this.bitSet.SelectedIndex]);
|
|
config.Format = format.Text;
|
|
if (!string.IsNullOrEmpty(discont.Text))
|
|
{
|
|
decimal v;
|
|
if (decimal.TryParse(discont.Text, out v))
|
|
config.Discont = v;
|
|
else
|
|
throw new Exception("扣重格式输入不正确");
|
|
}
|
|
else
|
|
config.Discont = 0;
|
|
config.Save(_flag);
|
|
changed = true;
|
|
MessageBox.Show("保存成功!");
|
|
}
|
|
|
|
private void closeBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (changed)
|
|
DialogResult = true;
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|