Browse Source

添加轮询方法

章政 7 years ago
parent
commit
6f1f0ddb11
3 changed files with 23 additions and 5 deletions
  1. 3 0
      UAS_DeviceMonitor/Main.Designer.cs
  2. 17 5
      UAS_DeviceMonitor/Main.cs
  3. 3 0
      UAS_DeviceMonitor/Main.resx

+ 3 - 0
UAS_DeviceMonitor/Main.Designer.cs

@@ -33,6 +33,7 @@ namespace UAS_DeviceMonitor
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
             this.RibbonNav = new DevExpress.XtraBars.Ribbon.RibbonControl();
             this.ButtonDeviceList = new DevExpress.XtraBars.BarButtonItem();
@@ -108,6 +109,7 @@ namespace UAS_DeviceMonitor
             this.pl_type = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_dccode = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_remark = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.PollingTimer = new System.Windows.Forms.Timer(this.components);
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -998,5 +1000,6 @@ namespace UAS_DeviceMonitor
         private CustomerControl.Button.ButtonAddRow ButtonNewCommandSet;
         private CustomerControl.Button.ButtonSaveGrid ButtonSaveCommandSet;
         private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit PollingSetItemLookUpEdit;
+        private System.Windows.Forms.Timer PollingTimer;
     }
 }

+ 17 - 5
UAS_DeviceMonitor/Main.cs

@@ -9,6 +9,7 @@ using UAS_DeviceMonitor.PublicMethod;
 using DevExpress.XtraEditors;
 using DevExpress.XtraGrid;
 using DevExpress.XtraGrid.Views.Grid;
+using System.Timers;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -167,6 +168,9 @@ namespace UAS_DeviceMonitor
         #endregion
 
         #region PagePollingSetting业务代码
+
+        bool PollingSign = false;
+
         private void ButtonStartPolling_Click(object sender, EventArgs e)
         {
             PollingTask pt = new PollingTask();
@@ -176,21 +180,29 @@ namespace UAS_DeviceMonitor
                 Polling pl = new Polling();
                 pl.DeviceCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DECODE").ToString();
                 pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString());
-                pl.Enable = (bool)GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE");
-                pt.AddTask(RunTask, pl);
+                pl.Enable = GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0";
+                if (pl.Enable)
+                    pt.AddTask(RunTask, pl);
             }
+            PollingSign = true;
             pt.StartAllTask();
         }
 
         private void RunTask(object i)
         {
-            Polling pl = (Polling)i;
-            //Interval
+            while (PollingSign)
+            {
+                Polling pl = (Polling)i;
+                int Interval = pl.Interval;
+                string Decode = pl.DeviceCode;
+                Thread.Sleep(Interval * 1000);
+                SystemInf.dh.ExecuteSql("insert into DEVICEPOLLINGCONFIG(DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK) values(DEVICEPOLLINGCONFIG_seq.nextval,'" + Decode + "','','' ,'' ,'' ,'' , '','' ,'')", "insert");
+            }
         }
 
         private void ButtonPausePolling_Click(object sender, EventArgs e)
         {
-
+            PollingSign = false;
         }
 
         /// <summary>

+ 3 - 0
UAS_DeviceMonitor/Main.resx

@@ -453,6 +453,9 @@
         geLKUTtl+f8gY//Axjn6F8f+AXtHGV3GT+qTmOL/wFqMAAAAAElFTkSuQmCC
 </value>
   </data>
+  <metadata name="PollingTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEAAABMLAAATCwAAAAAAAAAA