diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs new file mode 100644 index 0000000..706f323 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjHelp.cs @@ -0,0 +1,8 @@ +namespace Mesnac.Action.ChemicalWeighing +{ + public static class LjHelp + { + //开门狗 + public static int WatchDog=>BasePlcHelper.Instance.WatchDog.LastValue.ToInt(); + } +} \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.Designer.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.Designer.cs index b065df0..b493033 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.Designer.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.Designer.cs @@ -138,10 +138,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure this.Controls.Add(this.label1); this.ForeColor = System.Drawing.SystemColors.ControlText; this.Name = "FrmPressureUpdate"; - this.Text = "需改压力参数"; + this.Text = "修改压力参数"; this.ResumeLayout(false); this.PerformLayout(); - } private System.Windows.Forms.ComboBox Alarm; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs index b6d9fc8..6c600a1 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/FrmPressureUpdate.cs @@ -18,6 +18,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure private int _id; public FrmPressureUpdate(int id) : this() { + + LoadingHelper.ShowLoadingScreen(); + _id = id; IList ls = new List(); @@ -34,7 +37,15 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure 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) { @@ -55,6 +66,8 @@ 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/PressurePLC.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs index 6d4d75e..f9694bc 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/PressurePLC.cs @@ -45,8 +45,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure var basePlcHelper = GetPlcHelper; basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.topPressure_V1_LowLimit, view.LowLimit); basePlcHelper.PlcWriteFloatByDataKey(basePlcHelper.topPressure_V1_HighLimit, view.HighLimit); - // basePlcHelper.PlcWriteByDataKey(basePlcHelper.topPressure_V1_Alarm, - // new object[] { Convert.ToBoolean(view.Alarm) }); + } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs index 07b500d..a854bb9 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPressure/UpAction.cs @@ -30,6 +30,15 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure private void DoWord() { + LoadingHelper.ShowLoadingScreen(); + var i = BasePlcHelper.Instance.WatchDog.LastValue.ToInt(); + if (i == 0) + { + LoadingHelper.CloseForm(); + MessageBox.Show("PLC通讯失败"); + return; + } + var pressureSettingViews = PressurePLC.UpdateFromPlc(); foreach (var v in pressureSettingViews) { @@ -38,6 +47,8 @@ namespace Mesnac.Action.ChemicalWeighing.LjPressure DBHelp.ExecuteNonQuery(sql); } + LoadingHelper.CloseForm(); + if (OnHandler != null) { diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.Designer.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.Designer.cs new file mode 100644 index 0000000..bb41fec --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.Designer.cs @@ -0,0 +1,66 @@ +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace Mesnac.Action.ChemicalWeighing +{ + partial class Loading + { + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(122, 40); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 0; + this.label2.Text = "数据加载中"; + // + // Loading + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(299, 72); + this.Controls.Add(this.label2); + this.Name = "Loading"; + this.Text = "Loading"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.cs new file mode 100644 index 0000000..cbb43a9 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.cs @@ -0,0 +1,68 @@ +using System; +using System.Windows.Forms; + +namespace Mesnac.Action.ChemicalWeighing +{ + public partial class Loading : Form + { + public Loading() + { + InitializeComponent(); + } + + private void loading_Load(object sender, EventArgs e) + { + //this.BackColor = Color.Transparent; + this.Opacity = 1; + + } + + /// + /// 关闭命令 + /// + public void CloseOrder() + { + if (this.InvokeRequired) + { + //这里利用委托进行窗体的操作,避免跨线程调用时抛异常,后面给出具体定义 + CONSTANTDEFINE.SetUISomeInfo UIinfo = new CONSTANTDEFINE.SetUISomeInfo(new System.Action(() => + { + while (!this.IsHandleCreated) + { + ; + } + + if (!this.IsDisposed) + { + this.Dispose(); + } + + })); + this.Invoke(UIinfo); + } + else + { + if (this.IsDisposed) + return; + if (!this.IsDisposed) + { + this.Dispose(); + } + } + } + + private void loading_FormClosing(object sender, FormClosingEventArgs e) + { + if (!this.IsDisposed) + { + this.Dispose(true); + } + + } + } + + class CONSTANTDEFINE + { + public delegate void SetUISomeInfo(); + } +} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.resx b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Loading.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs new file mode 100644 index 0000000..f5a871a --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LoadingHelper.cs @@ -0,0 +1,81 @@ +using System; +using System.Threading; + +namespace Mesnac.Action.ChemicalWeighing +{ + public class LoadingHelper + { + #region 相关变量定义 + /// + /// 定义委托进行窗口关闭 + /// + private delegate void CloseDelegate(); + private static Loading loadingForm; + private static readonly Object syncLock = new Object(); //加锁使用 + + #endregion + + //private LoadingHelper() + //{ + + //} + + /// + /// 显示loading框 + /// + public static void ShowLoadingScreen() + { + // Make sure it is only launched once. + if (loadingForm != null) + return; + Thread thread = new Thread(new ThreadStart(LoadingHelper.ShowForm)); + thread.IsBackground = true; + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + + } + /// + /// 显示窗口 + /// + private static void ShowForm() + { + if (loadingForm != null) + { + loadingForm.CloseOrder(); + loadingForm = null; + } + loadingForm = new Loading(); + loadingForm.TopMost = true; + loadingForm.ShowDialog(); + } + /// + /// 关闭窗口 + /// + public static void CloseForm() + { + Thread.Sleep(50); //可能到这里线程还未起来,所以进行延时,可以确保线程起来,彻底关闭窗口 + if (loadingForm != null) + { + lock (syncLock) + { + Thread.Sleep(50); + if (loadingForm != null) + { + Thread.Sleep(50); //通过三次延时,确保可以彻底关闭窗口 + loadingForm.Invoke(new CloseDelegate(LoadingHelper.CloseFormInternal)); + } + } + } + } + /// + /// 关闭窗口,委托中使用 + /// + private static void CloseFormInternal() + { + loadingForm.CloseOrder(); + loadingForm = null; + } + } + + +} \ No newline at end of file diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index b8f7ae4..a36cb46 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -335,6 +335,7 @@ + @@ -502,6 +503,13 @@ + + Form + + + Loading.cs + + Component @@ -832,6 +840,9 @@ FrmWeight.cs + + Loading.cs + BarcodeReport.cs