From 9a6b601201d086831bda87c51ad74f211e796a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=91=E5=8F=AB=E9=94=84=E5=A4=B4?= Date: Mon, 15 Jan 2024 14:52:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BC=98=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LjElectrical/FrmElectrical.cs | 6 +- .../LjElectrical/InitDbAction.cs | 4 ++ .../LjMetage/DownAction.cs | 6 +- .../LjPlanning/DownloadAction.cs | 6 +- .../LjPressure/FrmPressureUpdate.cs | 6 +- .../LjPressure/UpAction.cs | 7 +- .../LjProportional/DownAction.cs | 6 +- .../LjProportional/FrmProportional.cs | 8 +-- .../LoadingHelper.cs | 52 +++++++------- .../OliveEQSetting/InItDbAction.cs | 72 ++++++++++++++++--- 10 files changed, 116 insertions(+), 57 deletions(-) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/FrmElectrical.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/FrmElectrical.cs index d043e27..d2412c3 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/FrmElectrical.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/FrmElectrical.cs @@ -41,11 +41,11 @@ namespace Mesnac.Action.ChemicalWeighing.LjElectrical return; } - LoadingHelper.ShowLoadingScreen(); + var watchDog = LjHelp.WatchDog; if (watchDog == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } @@ -61,7 +61,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjElectrical //select Id, Name, Speed from ElectricalSetting string sql = $"update ElectricalSetting set Speed={view.Speed} where id={view.Id}"; DBHelp.ExecuteNonQuery(sql); - LoadingHelper.CloseForm(); + this.DialogResult = DialogResult.OK; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/InitDbAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/InitDbAction.cs index 7d376cd..cb074d6 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/InitDbAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjElectrical/InitDbAction.cs @@ -37,6 +37,10 @@ namespace Mesnac.Action.ChemicalWeighing.LjElectrical DataTable table = DBHelp.GetTable(@"select Id, Name, Speed from ElectricalSetting"); + + var view = ElectricalPlc.UpFromPlc(); + + if (this._materialGridControl != null && this._materialGridControl.BaseControl != null) { this._materialGridControl.BaseControl.BindDataSource = null; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjMetage/DownAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjMetage/DownAction.cs index 1bd83e2..e9310e9 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjMetage/DownAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjMetage/DownAction.cs @@ -30,17 +30,17 @@ namespace Mesnac.Action.ChemicalWeighing.LjMetage if (MessageBox.Show("确定下发称量频参数到PLC?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information) == DialogResult.OK) { - LoadingHelper.ShowLoadingScreen(); + var watchDog = LjHelp.WatchDog; if (watchDog == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } DoWord(); - LoadingHelper.CloseForm(); + }; } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/DownloadAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/DownloadAction.cs index e16c41e..6bc9582 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/DownloadAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/DownloadAction.cs @@ -55,7 +55,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPlanning } - LoadingHelper.ShowLoadingScreen(); + @@ -97,7 +97,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPlanning var watchDog = LjHelp.WatchDog; if (watchDog == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } @@ -489,7 +489,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPlanning - LoadingHelper.CloseForm(); + MessageBox.Show("数据下发成功"); if (OnDown != null) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs index 0afbf02..6412bf8 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs @@ -19,7 +19,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure public FrmPressureUpdate(int id) : this() { - LoadingHelper.ShowLoadingScreen(); + _id = id; @@ -41,7 +41,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure var i = LjHelp.WatchDog; if (i == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } @@ -67,7 +67,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure MessageBox.Show("获取PLC 异常请联系管理员"); } - LoadingHelper.CloseForm(); + } private void btnCancel_Click(object sender, EventArgs e) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs index 01efb18..7be6b7c 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs @@ -28,11 +28,11 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure private void DoWord() { - LoadingHelper.ShowLoadingScreen(); + var i = LjHelp.WatchDog; if (i == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); ICSharpCode.Core.LoggingService.Warn("PLC通讯失败"); return; @@ -46,8 +46,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure DBHelp.ExecuteNonQuery(sql); } - LoadingHelper.CloseForm(); - + if (OnHandler != null) { OnHandler(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty); diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/DownAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/DownAction.cs index e836607..23c9e04 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/DownAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/DownAction.cs @@ -28,17 +28,17 @@ namespace Mesnac.Action.ChemicalWeighing.LjProportional if (MessageBox.Show("确定下发比例阀参数到PLC?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { - LoadingHelper.ShowLoadingScreen(); + var watchDog = LjHelp.WatchDog; if (watchDog == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } DoWord(); - LoadingHelper.CloseForm(); + if (OnHandler != null) { diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/FrmProportional.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/FrmProportional.cs index 7930be4..2b456ac 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/FrmProportional.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjProportional/FrmProportional.cs @@ -46,7 +46,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjProportional var watchDoy = LjHelp.WatchDog; if (watchDoy == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } @@ -59,14 +59,14 @@ namespace Mesnac.Action.ChemicalWeighing.LjProportional var i = LjHelp.WatchDog; if (i == 0) { - LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); return; } - LoadingHelper.ShowLoadingScreen(); + ProportionalPlc.DownToPlc(new []{view}); ProportionalDB.Update(view); - LoadingHelper.CloseForm(); + this.DialogResult = DialogResult.OK; } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs index a566d06..b8cfbca 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs @@ -24,17 +24,17 @@ namespace Mesnac.Action.ChemicalWeighing /// /// 显示loading框 /// - public static void ShowLoadingScreen() - { - // Make sure it is only launched once. - if (loading != null) - return; - Thread thread = new Thread(new ThreadStart(LoadingHelper.ShowForm)); - thread.IsBackground = true; - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); + //public static void ShowLoadingScreen() + //{ + // // Make sure it is only launched once. + // if (loading != null) + // return; + // Thread thread = new Thread(new ThreadStart(LoadingHelper.ShowForm)); + // thread.IsBackground = true; + // thread.SetApartmentState(ApartmentState.STA); + // thread.Start(); - } + //} /// /// 显示窗口 @@ -54,22 +54,22 @@ namespace Mesnac.Action.ChemicalWeighing /// /// 关闭窗口 /// - public static void CloseForm() - { - Thread.Sleep(50); //可能到这里线程还未起来,所以进行延时,可以确保线程起来,彻底关闭窗口 - if (loading != null) - { - lock (syncLock) - { - Thread.Sleep(50); - if (loading != null) - { - Thread.Sleep(50); //通过三次延时,确保可以彻底关闭窗口 - loading.Invoke(new CloseDelegate(LoadingHelper.CloseFormInternal)); - } - } - } - } + //public static void CloseForm() + //{ + // Thread.Sleep(50); //可能到这里线程还未起来,所以进行延时,可以确保线程起来,彻底关闭窗口 + // if (loading != null) + // { + // lock (syncLock) + // { + // Thread.Sleep(50); + // if (loading != null) + // { + // Thread.Sleep(50); //通过三次延时,确保可以彻底关闭窗口 + // loading.Invoke(new CloseDelegate(LoadingHelper.CloseFormInternal)); + // } + // } + // } + //} /// /// 关闭窗口,委托中使用 diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/OliveEQSetting/InItDbAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/OliveEQSetting/InItDbAction.cs index 770f0ec..2422943 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/OliveEQSetting/InItDbAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/OliveEQSetting/InItDbAction.cs @@ -2,7 +2,12 @@ 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 { @@ -31,7 +36,7 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting UpActionProportional.Run(runtime); UpActionWeight.Run(runtime); - LoadingHelper.CloseForm(); + } private void InitEvent() @@ -140,11 +145,24 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "pressureSetting") .FirstOrDefault(); //获取物料数据控件 + + + //table.Rows.Clear(); + + var pressureSettingViews = PressurePLC.UpdateFromPlc(); + + foreach (var v in pressureSettingViews) + { + 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, + 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) { @@ -159,7 +177,17 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ProportionalSetting") .FirstOrDefault(); //获取物料数据控件 - + + + var views = ProportionalPlc.UpFromPlc(); + foreach (var v in views) + { + 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"); @@ -178,7 +206,16 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "WeightSetting") .FirstOrDefault(); //获取物料数据控件 - + + + var views = WeightSettingPlc.UpFromPlc(); + foreach (var v in views) + { + 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"); @@ -195,7 +232,17 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "ElectricalSetting") .FirstOrDefault(); //获取物料数据控件 - + + + + var view = ElectricalPlc.UpFromPlc(); + foreach (var v in view) + { + 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"); @@ -212,7 +259,16 @@ namespace Mesnac.Action.ChemicalWeighing.OliveEQSetting DbMCControl materialGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "MetageSetting") .FirstOrDefault(); //获取物料数据控件 - + + + var view = MetagePlc.UpFromPlc(); + foreach (var v in view) + { + 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");