using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Windows.Forms; using Mesnac.Action.ChemicalWeighing.LjMaterial; namespace Mesnac.Action.ChemicalWeighing.LjPressure { public partial class FrmPressureUpdate : Form { public FrmPressureUpdate() { InitializeComponent(); } private int _id; public FrmPressureUpdate(int id) : this() { _id = id; IList ls = new List(); ls.Add(new MyNameValue() { Id = 1,Name = "超压", }); ls.Add(new MyNameValue() { Id = 0,Name = "正常", }); this.Alarm.DataSource = ls; Alarm.ValueMember = "Id"; Alarm.DisplayMember = "Name"; var pressureSettingViews = PressurePLC.UpdateFromPlc(id); if (pressureSettingViews.Count == 1) { var v = pressureSettingViews.First(); this.LowLimit.Text = v.LowLimit.ToString(); this.HighLimit.Text = v.HighLimit.ToString(); foreach (MyNameValue combo in Alarm.Items) { if (combo.Id == v.Alarm) { Alarm.SelectedItem = combo; break; } } } else { MessageBox.Show("获取PLC 异常请联系管理员"); } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void Alarm_SelectedIndexChanged(object sender, EventArgs e) { } private void btnOK_Click(object sender, EventArgs e) { if (!float.TryParse(LowLimit.Text.Trim(), out float a)) { LowLimit.Focus(); MessageBox.Show("请输入正确的数值"); return; } if (!float.TryParse(HighLimit.Text.Trim(), out float b)) { HighLimit.Focus(); MessageBox.Show("请输入正确的数值"); return; } PressureSettingView view = new PressureSettingView() { HighLimit = b, LowLimit = a, Alarm = Convert.ToInt16(Alarm.SelectedValue) }; PressurePLC.DownToPlc(new List() { view }); this.DialogResult = System.Windows.Forms.DialogResult.OK; } } }