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 WeighAndGrading { public partial class GradeSettingFrom : Form { List weight = new List { "IND560", "Xk3124", "Xk3190A9", "Xk3190D10" }; List com = new List { "COM1", "COM2", "COM3", "COM4", "COM5" }; List rate = new List { "4800", "7200", "9600" }; List bit = new List { "5", "6", "7", "8" }; public GradeSettingFrom() { InitializeComponent(); weightSet.DataSource = weight; comSet.DataSource = com; rateSet.DataSource = rate; bitSet.DataSource = bit; if (!string.IsNullOrEmpty(GradeContext.Config.WeightSet)) weightSet.SelectedIndex = weight.IndexOf(GradeContext.Config.WeightSet); else weightSet.SelectedIndex = 0; if (!string.IsNullOrEmpty(GradeContext.Config.ComSet)) comSet.SelectedIndex = com.IndexOf(GradeContext.Config.ComSet); else comSet.SelectedIndex = 0; if (GradeContext.Config.RateSet.HasValue) rateSet.SelectedIndex = rate.IndexOf(GradeContext.Config.RateSet.ToString()); else rateSet.SelectedIndex = 2; if (GradeContext.Config.BitSet.HasValue) bitSet.SelectedIndex = bit.IndexOf(GradeContext.Config.BitSet.ToString()); else bitSet.SelectedIndex = 3; if (string.IsNullOrEmpty(GradeContext.Config.Format)) format.Text = "0.00"; else format.Text = GradeContext.Config.Format; if (GradeContext.Config.Discont == null) discont.Text = "0.00"; else discont.Text = GradeContext.Config.Discont.ToString(); } private void saveBtn_Click(object sender, EventArgs e) { GradeContext.Config.WeightSet = weight[this.weightSet.SelectedIndex]; GradeContext.Config.ComSet = com[this.comSet.SelectedIndex]; GradeContext.Config.RateSet = int.Parse(rate[this.rateSet.SelectedIndex]); GradeContext.Config.BitSet = int.Parse(bit[this.bitSet.SelectedIndex]); GradeContext.Config.Format = format.Text; if (!string.IsNullOrEmpty(discont.Text)) { decimal v; if (decimal.TryParse(discont.Text, out v)) GradeContext.Config.Discont = v; else throw new Exception("扣重格式输入不正确"); } else GradeContext.Config.Discont = 0; GradeContext.Save(); MessageBox.Show("保存成功!"); } private void closeBtn_Click(object sender, EventArgs e) { this.Close(); } } }