屠宰场客户端
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.

95 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 SegmentationWeight
{
public partial class WeightSettingFrom : 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> { "稳定读取", "连续发送" };
public WeightSettingFrom()
{
InitializeComponent();
weightSet.DataSource = weight;
comSet.DataSource = com;
rateSet.DataSource = rate;
bitSet.DataSource = bit;
weightReadType.DataSource = weightRead;
if (!string.IsNullOrEmpty(SegmentationWeightContext.Config.WeightSet))
weightSet.SelectedIndex = weight.IndexOf(SegmentationWeightContext.Config.WeightSet);
else
weightSet.SelectedIndex = 0;
if (!string.IsNullOrEmpty(SegmentationWeightContext.Config.ComSet))
comSet.SelectedIndex = com.IndexOf(SegmentationWeightContext.Config.ComSet);
else
comSet.SelectedIndex = 0;
if (SegmentationWeightContext.Config.RateSet.HasValue)
rateSet.SelectedIndex = rate.IndexOf(SegmentationWeightContext.Config.RateSet.ToString());
else
rateSet.SelectedIndex = 2;
if (SegmentationWeightContext.Config.BitSet.HasValue)
bitSet.SelectedIndex = bit.IndexOf(SegmentationWeightContext.Config.BitSet.ToString());
else
bitSet.SelectedIndex = 3;
if (string.IsNullOrEmpty(SegmentationWeightContext.Config.Format))
format.Text = "0.00";
else
format.Text = SegmentationWeightContext.Config.Format;
if (SegmentationWeightContext.Config.Discont == null)
discont.Text = "0.00";
else
discont.Text = SegmentationWeightContext.Config.Discont.ToString();
weightReadType.SelectedIndex = SegmentationWeightContext.Config.WeightType;
minInput.Text = SegmentationWeightContext.Config.MinWeight.ToString();
maxInput.Text = SegmentationWeightContext.Config.MaxWeight.ToString();
}
private void saveBtn_Click(object sender, EventArgs e)
{
SegmentationWeightContext.Config.WeightSet = weight[this.weightSet.SelectedIndex];
SegmentationWeightContext.Config.ComSet = com[this.comSet.SelectedIndex];
SegmentationWeightContext.Config.RateSet = int.Parse(rate[this.rateSet.SelectedIndex]);
SegmentationWeightContext.Config.BitSet = int.Parse(bit[this.bitSet.SelectedIndex]);
SegmentationWeightContext.Config.Format = format.Text;
SegmentationWeightContext.Config.WeightType = weightReadType.SelectedIndex;
if (SegmentationWeightContext.Config.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("连续发送时 必须输入有效区间");
SegmentationWeightContext.Config.MinWeight = min;
SegmentationWeightContext.Config.MaxWeight = max;
}
if (!string.IsNullOrEmpty(discont.Text))
{
decimal v;
if (decimal.TryParse(discont.Text, out v))
SegmentationWeightContext.Config.Discont = v;
else
throw new Exception("扣重格式输入不正确");
}
else
SegmentationWeightContext.Config.Discont = 0;
SegmentationWeightContext.Save();
MessageBox.Show("保存成功!");
}
private void closeBtn_Click(object sender, EventArgs e)
{
Close();
}
}
}