using Mesnac.Action.Base; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mesnac.Action.ChemicalWeighing.Package { class InitFormAction : ChemicalWeighingAction, IAction { #region 事件定义 /// /// 刷新物料信息事件 /// public static event EventHandler OnRefresh; #endregion private RuntimeParameter _runtime; private DbMCControl _gridControl = null; //物料列表控件 public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 this._runtime = runtime; #region 事件订阅 if (true) { //新增物料后,要刷新物料页面 InsertAction.OnInsert -= Process_Event; InsertAction.OnInsert += Process_Event; //修改物料信息后,触发刷新页面事件 ModifyAction.OnModify -= Process_Event; ModifyAction.OnModify += Process_Event; //删除物料后,触发刷新页面事件 DeleteAction.OnDelete -= Process_Event; DeleteAction.OnDelete += Process_Event; } #endregion DbMCControl gridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_Package").FirstOrDefault(); //获取物料数据控件 this._gridControl = gridControl; //刷新信息 this.requestInfo(); } /// /// 刷新信息 /// protected void requestInfo() { //获取信息表 DataTable dataTable = PackageHelper.QueryPackage(); lock (String.Empty) { if (this._gridControl != null && this._gridControl.BaseControl != null) { this._gridControl.BaseControl.BindDataSource = null; this._gridControl.BaseControl.BindDataSource = dataTable; DBLog("成功!"); } else { ICSharpCode.Core.LoggingService.Warn("刷新信息失败:数据控件为Null..."); } } #region 触发事件, 刷新信息 if (OnRefresh != null) { OnRefresh(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty); } #endregion } #region 事件处理方法 private void Process_Event(object sender, EventArgs e) { if (sender is RuntimeParameter) { this.Run(sender as RuntimeParameter); } else { this.Run(this._runtime); } } #endregion } }