using System; using System.Data; using System.Linq; using Mesnac.Action.Base; using Mesnac.Action.ChemicalWeighing.LjElectrical; using Mesnac.Action.ChemicalWeighing.LjMaterial; using Mesnac.Action.ChemicalWeighing.LjMetage; using Mesnac.Action.ChemicalWeighing.LjPressure; using Mesnac.Action.ChemicalWeighing.LjProportional; using Mesnac.Action.ChemicalWeighing.LjWeight; namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting { public class InItDbAction: ChemicalWeighingAction, IAction { LjElectrical.UpAction UpActionElectrical = new LjElectrical.UpAction(); LjMetage.UpAction UpActionMetage = new LjMetage.UpAction(); LjPressure.UpAction UpActionPressure = new LjPressure.UpAction(); LjProportional.UpAction UpActionProportional = new LjProportional.UpAction(); LjWeight.UpAction UpActionWeight = new LjWeight.UpAction(); public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 //FillPressureSetting(); //FillProportionalSetting(); //FillWeightSetting(); //FillElectricalSetting(); //FillMetageSetting(); InitEvent(); UpActionElectrical.Run(runtime); UpActionMetage.Run(runtime); UpActionPressure.Run(runtime); UpActionProportional.Run(runtime); UpActionWeight.Run(runtime); } private void InitEvent() { LjPressure.UpdateAction.OnUpdate -= null; LjPressure.DownAction.OnHandler -= null; LjPressure.UpAction.OnHandler -= null; LjPressure.UpdateAction.OnUpdate += delegate { FillPressureSetting(); }; LjPressure.DownAction.OnHandler += delegate { FillPressureSetting(); }; LjPressure.UpAction.OnHandler += delegate { FillPressureSetting(); }; LjProportional.UpdateAction.OnUpdate -= null; LjProportional.DownAction.OnHandler -= null; LjProportional.UpAction.OnHandler -= null; LjProportional.UpdateAction.OnUpdate+= delegate { FillProportionalSetting(); }; LjProportional.DownAction.OnHandler+= delegate { FillProportionalSetting(); }; LjProportional.UpAction.OnHandler+= delegate { FillProportionalSetting(); }; LjWeight.UpdateAction.OnUpdate -= null; LjWeight.DownAction.OnHandler -= null; LjWeight.UpAction.OnHandler -= null; LjWeight.UpdateAction.OnUpdate += delegate { FillWeightSetting(); }; LjWeight.DownAction.OnHandler += delegate { FillWeightSetting(); }; LjWeight.UpAction.OnHandler += delegate { FillWeightSetting(); }; LjElectrical.DownAction.OnHandler -= null; LjElectrical.UpAction.OnHandler -= null; LjElectrical.UpdateAction.OnUpdate -= null; LjElectrical.DownAction.OnHandler += delegate { FillElectricalSetting(); }; LjElectrical.UpAction.OnHandler += delegate { FillElectricalSetting(); }; LjElectrical.UpdateAction.OnUpdate += delegate { FillElectricalSetting(); }; LjMetage.DownAction.OnHandler -= null; LjMetage.UpAction.OnHandler -= null; LjMetage.UpdateAction.OnUpdate -= null; LjMetage.DownAction.OnHandler += delegate { FillMetageSetting(); }; LjMetage.UpAction.OnHandler += delegate { FillMetageSetting(); }; LjMetage.UpdateAction.OnUpdate += delegate { FillMetageSetting(); }; } private void FillPressureSetting() { DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "pressureSetting") .FirstOrDefault(); //获取物料数据控件 //table.Rows.Clear(); var pressureSettingViews = PressurePLC.UpdateFromPlc(); foreach (var v in pressureSettingViews) { if(v.LowLimit>0 || v.HighLimit > 0) { string sql = $"update PressureSetting set LowLimit={v.LowLimit},HighLimit={v.HighLimit} where Id={v.Id}"; DBHelp.ExecuteNonQuery(sql); } } DataTable table = DBHelp.GetTable(@"select Id,Name,ActualValue,LowLimit,HighLimit,Alarm, case Alarm when 1 then '超压' else '正常' end as AlarmValue from pressureSetting;"); if (materialGridControl != null && materialGridControl.BaseControl != null) { materialGridControl.BaseControl.BindDataSource = null; materialGridControl.BaseControl.BindDataSource = table; //DBLog("成功!"); } } private void FillProportionalSetting() { DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ProportionalSetting") .FirstOrDefault(); //获取物料数据控件 var views = ProportionalPlc.UpFromPlc(); foreach (var v in views) { if(v.SV>0 || v.PV > 0) { string sql = $"update ProportionalSetting set SV={v.SV},PV={v.PV} where Id={v.Id}"; DBHelp.ExecuteNonQuery(sql); } } DataTable table = DBHelp.GetTable(@"select Id, Name, PV, SV from ProportionalSetting"); if (materialGridControl != null && materialGridControl.BaseControl != null) { materialGridControl.BaseControl.BindDataSource = null; materialGridControl.BaseControl.BindDataSource = table; //DBLog("成功!"); } } // private void FillWeightSetting() { DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "WeightSetting") .FirstOrDefault(); //获取物料数据控件 var views = WeightSettingPlc.UpFromPlc(); foreach (var v in views) { if(v.LowWeight>0 || v.HighWeight > 0) { string sql = $"update WeightSetting set LowWeight={v.LowWeight},HighWeight={v.HighWeight} where Id={v.Id}"; DBHelp.ExecuteNonQuery(sql); } } DataTable table = DBHelp.GetTable(@"select Id,Name,ActWeight,HighLevel,HighWeight,LowLevel,LowWeight from WeightSetting"); if (materialGridControl != null && materialGridControl.BaseControl != null) { materialGridControl.BaseControl.BindDataSource = null; materialGridControl.BaseControl.BindDataSource = table; //DBLog("成功!"); } } private void FillElectricalSetting() { DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ElectricalSetting") .FirstOrDefault(); //获取物料数据控件 var view = ElectricalPlc.UpFromPlc(); foreach (var v in view) { if (v.Speed > 0) { string sql = $"update ElectricalSetting set Speed={v.Speed} where Id={v.Id}"; DBHelp.ExecuteNonQuery(sql); } } DataTable table = DBHelp.GetTable(@"select Id, Name, Speed from ElectricalSetting"); if (materialGridControl != null && materialGridControl.BaseControl != null) { materialGridControl.BaseControl.BindDataSource = null; materialGridControl.BaseControl.BindDataSource = table; //DBLog("成功!"); } } private void FillMetageSetting() { DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "MetageSetting") .FirstOrDefault(); //获取物料数据控件 var view = MetagePlc.UpFromPlc(); foreach (var v in view) { if(v.HighSpeed > 0 || v.LowSpeed>0 || v.WeightSlow>0 || v.Precut>0 || v.JogTime > 0) { string sql = $"update MetageSetting set HighSpeed={v.HighSpeed},LowSpeed={v.LowSpeed}," + $"WeightSlow={v.WeightSlow},Precut={v.Precut},JogTime={v.JogTime} where Id={v.Id}"; DBHelp.ExecuteNonQuery(sql); } } DataTable table = DBHelp.GetTable(@"select Id, Name, HighSpeed, LowSpeed, WeightSlow, Precut, JogTime from MetageSetting"); if (materialGridControl != null && materialGridControl.BaseControl != null) { materialGridControl.BaseControl.BindDataSource = null; materialGridControl.BaseControl.BindDataSource = table; //DBLog("成功!"); } } } }