using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.LjPressure; namespace Mesnac.Action.ChemicalWeighing.LjWeight { public class DownAction : ChemicalWeighingAction, IAction { public static event EventHandler OnHandler; private DbMCControl _materialGridControl = null; //物料列表控件 private RuntimeParameter _runtime; public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 this._runtime = runtime; DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "WeightSetting") .FirstOrDefault(); //获取物料数据控件 this._materialGridControl = materialGridControl; if (MessageBox.Show("确定下发重量参数到PLC?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { DoWord(); } } private void DoWord() { DataGridView gridView = _materialGridControl.BaseControl as DataGridView; var gridViewDataSource = gridView.DataSource as DataTable; List lsView = new List(); var dataRowCollection = gridViewDataSource.Rows; foreach (DataRow o in dataRowCollection) { WeightSettingView view = new WeightSettingView(); view.Id = (int)o["Id"]; view.Name = o["Name"].ToString(); view.HighWeight = Convert.ToSingle(o["HighWeight"]); view.LowWeight = Convert.ToSingle(o["LowWeight"]); lsView.Add(view); } new WeightSettingPlc().DownToPlc(lsView); } } }