章政 7 years ago
parent
commit
1733498fa1

+ 42 - 2
UAS_DeviceMonitor/Main.Designer.cs

@@ -98,6 +98,8 @@ namespace UAS_DeviceMonitor
             this.dpc_enable = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_status = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_remark = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.PollSettingStatusColumn = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.PollSettingItemColorEdit = new DevExpress.XtraEditors.Repository.RepositoryItemColorEdit();
             this.PagePolling = new DevExpress.XtraTab.XtraTabPage();
             this.ButtonAddPolling = new UAS_DeviceMonitor.CustomerControl.Button.ButtonAddRow();
             this.ButtonDeletePolling = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
@@ -111,6 +113,7 @@ namespace UAS_DeviceMonitor
             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);
+            this.repositoryItemColorPickEdit1 = new DevExpress.XtraEditors.Repository.RepositoryItemColorPickEdit();
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -127,9 +130,11 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.dpc_enableCheckEdit)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.PollSettingItemColorEdit)).BeginInit();
             this.PagePolling.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.repositoryItemColorPickEdit1)).BeginInit();
             this.SuspendLayout();
             // 
             // RibbonNav
@@ -638,7 +643,9 @@ namespace UAS_DeviceMonitor
             this.GridPollingSetting.Name = "GridPollingSetting";
             this.GridPollingSetting.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
             this.dpc_enableCheckEdit,
-            this.PollingSetItemLookUpEdit});
+            this.PollingSetItemLookUpEdit,
+            this.PollSettingItemColorEdit,
+            this.repositoryItemColorPickEdit1});
             this.GridPollingSetting.RowCount = 0;
             this.GridPollingSetting.Size = new System.Drawing.Size(1027, 544);
             this.GridPollingSetting.TabIndex = 0;
@@ -659,7 +666,8 @@ namespace UAS_DeviceMonitor
             this.dpc_function,
             this.dpc_enable,
             this.dpc_status,
-            this.dpc_remark});
+            this.dpc_remark,
+            this.PollSettingStatusColumn});
             this.GridViewPollSetting.GridControl = this.GridPollingSetting;
             this.GridViewPollSetting.IndicatorWidth = 30;
             this.GridViewPollSetting.Name = "GridViewPollSetting";
@@ -775,6 +783,26 @@ namespace UAS_DeviceMonitor
             this.dpc_remark.Visible = true;
             this.dpc_remark.VisibleIndex = 9;
             // 
+            // PollSettingStatusColumn
+            // 
+            this.PollSettingStatusColumn.Caption = "运行状态";
+            this.PollSettingStatusColumn.ColumnEdit = this.PollSettingItemColorEdit;
+            this.PollSettingStatusColumn.FieldName = "PollSettingItemColorEdit";
+            this.PollSettingStatusColumn.Name = "PollSettingStatusColumn";
+            this.PollSettingStatusColumn.Visible = true;
+            this.PollSettingStatusColumn.VisibleIndex = 10;
+            // 
+            // PollSettingItemColorEdit
+            // 
+            this.PollSettingItemColorEdit.Appearance.BackColor = System.Drawing.Color.White;
+            this.PollSettingItemColorEdit.Appearance.ForeColor = System.Drawing.Color.White;
+            this.PollSettingItemColorEdit.Appearance.Options.UseBackColor = true;
+            this.PollSettingItemColorEdit.Appearance.Options.UseForeColor = true;
+            this.PollSettingItemColorEdit.AutoHeight = false;
+            this.PollSettingItemColorEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
+            this.PollSettingItemColorEdit.Name = "PollSettingItemColorEdit";
+            // 
             // PagePolling
             // 
             this.PagePolling.Controls.Add(this.ButtonAddPolling);
@@ -896,6 +924,13 @@ namespace UAS_DeviceMonitor
             this.pl_remark.Visible = true;
             this.pl_remark.VisibleIndex = 4;
             // 
+            // repositoryItemColorPickEdit1
+            // 
+            this.repositoryItemColorPickEdit1.AutoHeight = false;
+            this.repositoryItemColorPickEdit1.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
+            this.repositoryItemColorPickEdit1.Name = "repositoryItemColorPickEdit1";
+            // 
             // Main
             // 
             this.AllowFormGlass = DevExpress.Utils.DefaultBoolean.False;
@@ -928,9 +963,11 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.dpc_enableCheckEdit)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.PollSettingItemColorEdit)).EndInit();
             this.PagePolling.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.repositoryItemColorPickEdit1)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -1014,5 +1051,8 @@ namespace UAS_DeviceMonitor
         private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit PollingSetItemLookUpEdit;
         private System.Windows.Forms.Timer PollingTimer;
         private DevExpress.XtraGrid.Columns.GridColumn GRIDVIEWPOLLSETTINGCHOOSE;
+        private DevExpress.XtraGrid.Columns.GridColumn PollSettingStatusColumn;
+        private DevExpress.XtraEditors.Repository.RepositoryItemColorEdit PollSettingItemColorEdit;
+        private DevExpress.XtraEditors.Repository.RepositoryItemColorPickEdit repositoryItemColorPickEdit1;
     }
 }

+ 31 - 10
UAS_DeviceMonitor/Main.cs

@@ -6,13 +6,9 @@ using System.Text;
 using UAS_DeviceMonitor.Entity;
 using UAS_DeviceMonitor.Device.Command;
 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;
 using System.Collections.Generic;
+using DevExpress.XtraEditors;
 
 namespace UAS_DeviceMonitor
 {
@@ -58,6 +54,8 @@ namespace UAS_DeviceMonitor
             GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_command) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_command)";
             ButtonSaveCommand.Grid = GridCommandSetting;
             ButtonDeleteCommand.Grid = GridCommandSetting;
+
+            Ptime = new Dictionary<int, PollingTimer>();
         }
 
         #region 界面通用事件
@@ -187,19 +185,33 @@ namespace UAS_DeviceMonitor
             }
         }
 
-        Dictionary<int, PollingTimer> Ptime = new Dictionary<int, PollingTimer>();
+        Dictionary<int, PollingTimer> Ptime;
 
         private void RunTask(object i)
         {
             PollingTimer timer = new PollingTimer();
             Polling pl = (Polling)i;
             timer.Polling = i;
-            timer.Interval = pl.Interval * 1000;
+            timer.Interval = pl.Interval * 5000;
             timer.Elapsed += Timer_Tick;
-            Ptime.Add(pl.Id, timer);
             timer.Start();
+            try
+            {
+                if (!Ptime.ContainsKey(pl.Id))
+                    Ptime.Add(pl.Id, timer);
+            }
+            catch (Exception)
+            {
+                if (!Ptime.ContainsKey(pl.Id))
+                    Ptime.Add(pl.Id, timer);
+            }
         }
 
+        /// <summary>
+        /// 轮询执行的业务
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void Timer_Tick(object sender, EventArgs e)
         {
             PollingTimer timer = (PollingTimer)sender;
@@ -208,20 +220,26 @@ namespace UAS_DeviceMonitor
             Console.WriteLine(Decode);
         }
 
+        /// <summary>
+        /// 停止全部轮询
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ButtonPausePolling_Click(object sender, EventArgs e)
         {
             foreach (var item in Ptime)
             {
                 item.Value.Stop();
             }
+            Ptime.Clear();
         }
 
         private void GridViewPollSetting_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
         {
+            GridViewPollSetting.SetRowCellValue(e.RowHandle, e.Column, e.Value);
             if (e.Column.Name.ToUpper() == "DPC_ENABLE")
             {
-                GridViewPollSetting.SetRowCellValue(e.RowHandle, e.Column, e.Value);
-                Console.WriteLine(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString());
+
                 if (GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString() == "0")
                 {
                     int id = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ID").ToString());
@@ -241,8 +259,11 @@ namespace UAS_DeviceMonitor
                     pl.Code = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_PLCODE").ToString();
                     if (pl.Enable)
                         pt.AddTask(RunTask, pl);
+
+                    //GridViewPollSetting.SetRowCellValue(e.RowHandle, "PollSettingStatusColumn", Color.Green);
                 }
             }
+            Console.WriteLine(GridViewPollSetting.GetRowCellValue(e.RowHandle, e.Column));
         }
 
         /// <summary>

+ 0 - 3
UAS_DeviceMonitor/Program.cs

@@ -54,9 +54,6 @@ namespace UAS_DeviceMonitor
                     doc.AppendChild(xeRoot);
                     doc.Save(SystemInf.CacheFilePath);
                 }
-                //创建记录打印进程的文件
-                FileStream fas = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
-                fas.Close();
                 DevExpress.Skins.SkinManager.EnableFormSkins();
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                     Application.Run(new Main());

+ 6 - 5
UAS_DeviceMonitor/PublicMethod/PollingTask.cs

@@ -40,11 +40,12 @@ namespace UAS_DeviceMonitor.PublicMethod
         /// <returns></returns>
         public void AddTask(Action<object> action, object obj)
         {
-            Polling pl = (Polling)obj;
-            if (!InTask.ContainsKey(pl.Code))
-            {
-                InTask.Add(pl.Code, Task.Factory.StartNew(action, obj));
-            }
+            Task.Factory.StartNew(action, obj);
+            //Polling pl = (Polling)obj;
+            //if (!InTask.ContainsKey(pl.Code))
+            //{
+            //    InTask.Add(pl.Code, Task.Factory.StartNew(action, obj));
+            //}
         }
 
         /// 添加一系列任务