using System; using System.Collections.Generic; using System.Globalization; 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() { LoadingHelper.ShowLoadingScreen(); _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 i = BasePlcHelper.Instance.WatchDog.LastValue.ToInt(); if (i == 0) { LoadingHelper.CloseForm(); MessageBox.Show("PLC通讯失败"); return; } var v = PressurePLC.UpdateFromPlc(id); if (null!=v) { this.LowLimit.Text = v.LowLimit.ToString(CultureInfo.InvariantCulture); this.HighLimit.Text = v.HighLimit.ToString(CultureInfo.InvariantCulture); // foreach (MyNameValue combo in Alarm.Items) // { // if (combo.Id == v.Alarm) // { // Alarm.SelectedItem = combo; // Alarm.Enabled = false; // break; // } // } } else { MessageBox.Show("获取PLC 异常请联系管理员"); } LoadingHelper.CloseForm(); } 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() { Id = _id, HighLimit = b, LowLimit = a, }; PressurePLC.DownToPlc(new List() { view }); string sql = $"update PressureSetting set LowLimit={view.LowLimit},HighLimit={view.HighLimit} where Id={view.Id}"; DBHelp.ExecuteNonQuery(sql); this.DialogResult = System.Windows.Forms.DialogResult.OK; } } }