屠宰场客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.9 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BWP.WinFormControl.WeightControl_
{
public partial class WeightSetForm : Form
{
List<string> weight = new List<string> { "IND560", "Xk3124", "Xk3190A9", "Xk3190D10", "IND231" };
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" };
List<string> weightRead = new List<string> { "稳定读取", "连续发送" };
private ApplyTo mApplyTo;
public WeightSetForm(ApplyTo applyTo)
{
mApplyTo = applyTo;
InitializeComponent();
weightSet.DataSource = weight;
comSet.DataSource = com;
rateSet.DataSource = rate;
bitSet.DataSource = bit;
weightReadType.DataSource = weightRead;
if (!string.IsNullOrEmpty(WeightContext.GetConfig(applyTo).WeightSet))
weightSet.SelectedIndex = weight.IndexOf(WeightContext.GetConfig(applyTo).WeightSet);
else
weightSet.SelectedIndex = 0;
if (!string.IsNullOrEmpty(WeightContext.GetConfig(applyTo).ComSet))
comSet.SelectedIndex = com.IndexOf(WeightContext.GetConfig(applyTo).ComSet);
else
comSet.SelectedIndex = 0;
if (WeightContext.GetConfig(applyTo).RateSet.HasValue)
rateSet.SelectedIndex = rate.IndexOf(WeightContext.GetConfig(applyTo).RateSet.ToString());
else
rateSet.SelectedIndex = 2;
if (WeightContext.GetConfig(applyTo).BitSet!=0)
bitSet.SelectedIndex = bit.IndexOf(WeightContext.GetConfig(applyTo).BitSet.ToString());
else
bitSet.SelectedIndex = 3;
if (string.IsNullOrEmpty(WeightContext.GetConfig(applyTo).Format))
format.Text = "0.00";
else
format.Text = WeightContext.GetConfig(applyTo).Format;
if (WeightContext.GetConfig(applyTo).Discont == null)
discont.Text = "0.00";
else
discont.Text = WeightContext.GetConfig(applyTo).Discont.ToString();
weightReadType.SelectedIndex = WeightContext.GetConfig(applyTo).WeightType;
minInput.Text = WeightContext.GetConfig(applyTo).MinWeight.ToString();
maxInput.Text = WeightContext.GetConfig(applyTo).MaxWeight.ToString();
}
private void saveBtn_Click(object sender, EventArgs e)
{
WeightContext.GetConfig(mApplyTo).WeightSet = weight[this.weightSet.SelectedIndex];
WeightContext.GetConfig(mApplyTo).ComSet = com[this.comSet.SelectedIndex];
WeightContext.GetConfig(mApplyTo).RateSet = int.Parse(rate[this.rateSet.SelectedIndex]);
WeightContext.GetConfig(mApplyTo).BitSet = int.Parse(bit[this.bitSet.SelectedIndex]);
WeightContext.GetConfig(mApplyTo).Format = format.Text;
WeightContext.GetConfig(mApplyTo).WeightType = weightReadType.SelectedIndex;
if (WeightContext.GetConfig(mApplyTo).WeightType == 1)
{
decimal min = 0;
decimal max = 0;
if (!decimal.TryParse(minInput.Text.Trim(), out min))
throw new Exception("连续发送时 必须输入有效区间");
if (!decimal.TryParse(maxInput.Text.Trim(), out max))
throw new Exception("连续发送时 必须输入有效区间");
WeightContext.GetConfig(mApplyTo).MinWeight = min;
WeightContext.GetConfig(mApplyTo).MaxWeight = max;
}
if (!string.IsNullOrEmpty(discont.Text))
{
decimal v;
if (decimal.TryParse(discont.Text, out v))
WeightContext.GetConfig(mApplyTo).Discont = v;
else
throw new Exception("扣重格式输入不正确");
}
else
{
WeightContext.GetConfig(mApplyTo).Discont = 0;
}
WeightContext.Save(mApplyTo);
MessageBox.Show("保存成功!");
DialogResult = DialogResult.OK;
Close();
}
}
}