Browse Source

添加设备运行状态记录

章政 7 years ago
parent
commit
7283bc8aff
3 changed files with 46 additions and 20 deletions
  1. 15 0
      PLCDataReader/Entity/Polling.cs
  2. 19 8
      PLCDataReader/Main.Designer.cs
  3. 12 12
      PLCDataReader/Main.cs

+ 15 - 0
PLCDataReader/Entity/Polling.cs

@@ -12,6 +12,8 @@ namespace UAS_PLCDataReader.Entity
 
         private string deviceCode;
 
+        private string deviceName;
+
         private string iP;
 
         private string port;
@@ -142,5 +144,18 @@ namespace UAS_PLCDataReader.Entity
                 commandCode = value;
             }
         }
+
+        public string DeviceName
+        {
+            get
+            {
+                return deviceName;
+            }
+
+            set
+            {
+                deviceName = value;
+            }
+        }
     }
 }

+ 19 - 8
PLCDataReader/Main.Designer.cs

@@ -168,6 +168,7 @@ namespace UAS_PLCDataReader
             this.GridViewWorkCenterStatus = new UAS_PLCDataReader.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
             this.TimerDeviceStatus = new System.Windows.Forms.Timer(this.components);
             this.CommonTipController = new DevExpress.Utils.ToolTipController(this.components);
+            this.dpc_dename = new DevExpress.XtraGrid.Columns.GridColumn();
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -1169,6 +1170,7 @@ namespace UAS_PLCDataReader
             this.PollSettingCheckedColumn,
             this.dpc_id,
             this.dpc_decode,
+            this.dpc_dename,
             this.dpc_interval,
             this.dpc_dccode,
             this.dpc_function,
@@ -1219,7 +1221,7 @@ namespace UAS_PLCDataReader
             this.dpc_interval.FieldName = "DPC_INTERVAL";
             this.dpc_interval.Name = "dpc_interval";
             this.dpc_interval.Visible = true;
-            this.dpc_interval.VisibleIndex = 2;
+            this.dpc_interval.VisibleIndex = 3;
             this.dpc_interval.Width = 90;
             // 
             // dpc_dccode
@@ -1229,7 +1231,7 @@ namespace UAS_PLCDataReader
             this.dpc_dccode.FieldName = "DPC_DCCODE";
             this.dpc_dccode.Name = "dpc_dccode";
             this.dpc_dccode.Visible = true;
-            this.dpc_dccode.VisibleIndex = 3;
+            this.dpc_dccode.VisibleIndex = 4;
             this.dpc_dccode.Width = 90;
             // 
             // PollSettingItemSearchLookUpEdit
@@ -1282,7 +1284,7 @@ namespace UAS_PLCDataReader
             this.dpc_function.FieldName = "DPC_FUNCTION";
             this.dpc_function.Name = "dpc_function";
             this.dpc_function.Visible = true;
-            this.dpc_function.VisibleIndex = 4;
+            this.dpc_function.VisibleIndex = 5;
             this.dpc_function.Width = 90;
             // 
             // dpc_enable
@@ -1292,7 +1294,7 @@ namespace UAS_PLCDataReader
             this.dpc_enable.FieldName = "DPC_ENABLE";
             this.dpc_enable.Name = "dpc_enable";
             this.dpc_enable.Visible = true;
-            this.dpc_enable.VisibleIndex = 5;
+            this.dpc_enable.VisibleIndex = 6;
             this.dpc_enable.Width = 90;
             // 
             // em_name1
@@ -1302,7 +1304,7 @@ namespace UAS_PLCDataReader
             this.em_name1.Name = "em_name1";
             this.em_name1.OptionsColumn.AllowEdit = false;
             this.em_name1.Visible = true;
-            this.em_name1.VisibleIndex = 9;
+            this.em_name1.VisibleIndex = 10;
             // 
             // dpc_status
             // 
@@ -1311,7 +1313,7 @@ namespace UAS_PLCDataReader
             this.dpc_status.Name = "dpc_status";
             this.dpc_status.OptionsColumn.AllowEdit = false;
             this.dpc_status.Visible = true;
-            this.dpc_status.VisibleIndex = 6;
+            this.dpc_status.VisibleIndex = 7;
             this.dpc_status.Width = 90;
             // 
             // dpc_man
@@ -1327,7 +1329,7 @@ namespace UAS_PLCDataReader
             this.dpc_remark.FieldName = "DPC_REMARK";
             this.dpc_remark.Name = "dpc_remark";
             this.dpc_remark.Visible = true;
-            this.dpc_remark.VisibleIndex = 7;
+            this.dpc_remark.VisibleIndex = 8;
             this.dpc_remark.Width = 87;
             // 
             // POLLSETTINGSTATUSCOLUMN
@@ -1337,7 +1339,7 @@ namespace UAS_PLCDataReader
             this.POLLSETTINGSTATUSCOLUMN.Name = "POLLSETTINGSTATUSCOLUMN";
             this.POLLSETTINGSTATUSCOLUMN.OptionsColumn.ReadOnly = true;
             this.POLLSETTINGSTATUSCOLUMN.Visible = true;
-            this.POLLSETTINGSTATUSCOLUMN.VisibleIndex = 8;
+            this.POLLSETTINGSTATUSCOLUMN.VisibleIndex = 9;
             this.POLLSETTINGSTATUSCOLUMN.Width = 98;
             // 
             // PollingSetItemLookUpEdit
@@ -1613,6 +1615,14 @@ namespace UAS_PLCDataReader
             // 
             this.CommonTipController.AutoPopDelay = 10000;
             // 
+            // dpc_dename
+            // 
+            this.dpc_dename.Caption = "设备名称";
+            this.dpc_dename.FieldName = "DPC_DENAME";
+            this.dpc_dename.Name = "dpc_dename";
+            this.dpc_dename.Visible = true;
+            this.dpc_dename.VisibleIndex = 2;
+            // 
             // Main
             // 
             this.AllowFormGlass = DevExpress.Utils.DefaultBoolean.False;
@@ -1811,5 +1821,6 @@ namespace UAS_PLCDataReader
         private DevExpress.XtraGrid.Columns.GridColumn DeviceListCheckedColumn;
         private DevExpress.XtraGrid.Columns.GridColumn de_sourcecode;
         private DevExpress.XtraEditors.Repository.RepositoryItemDateEdit repositoryItemDateEdit1;
+        private DevExpress.XtraGrid.Columns.GridColumn dpc_dename;
     }
 }

+ 12 - 12
PLCDataReader/Main.cs

@@ -30,7 +30,7 @@ namespace UAS_PLCDataReader
         ModeBusTCPServer mbt = new ModeBusTCPServer();
         List<string> SQL = new List<string>();
         //存放所有的设备返回的数据,用于比较
-        Dictionary<string, Dictionary<string, string>> ReturnData = new Dictionary<string, Dictionary<string, string>>();
+        public static Dictionary<string, Dictionary<string, string>> ReturnData = new Dictionary<string, Dictionary<string, string>>();
 
         #region 初始化代码
         public Main()
@@ -84,7 +84,7 @@ namespace UAS_PLCDataReader
             GridDeviceList.GetDataSQL = "SELECT 0 CHECKEDCOLUMN,DE_ID,DE_CODE,DE_NAME,DE_SPEC,DE_INDATE,DE_RUNSTATUS,DE_ADDRESS,DE_INMAN,DE_LINECODE,DE_WCCODE,DE_VENDCODE,DE_VENDNAME,DE_STEPCODE,DE_STEPNAME,DE_SOURCECODE FROM DEVICE ORDER BY DE_CODE".ToUpper();
             GridDeviceList.TableName = "device";
             GridDeviceList.ID = "de_id";
-            GridDeviceList.InsertSQL = "INSERT INTO DEVICE(DE_ID,DE_CODE,DE_NAME,DE_SPEC,DE_INDATE,DE_RUNSTATUS,DE_ADDRESS,DE_INMAN,DE_LINECODE,DE_WCCODE,DE_VENDCODE,DE_VENDNAME,DE_STEPCODE,DE_STEPNAME,DE_SOURCECODE) VALUES(DEVICE_SEQ.NEXTVAL,:DE_CODE,:DE_NAME,:DE_SPEC,:DE_INDATE,:DE_RUNSTATUS,:DE_ADDRESS,:DE_INMAN,:DE_LINECODE,:DE_WCCODE,:DE_VENDCODE,:DE_VENDNAME,:DE_STEPCODE,:DE_STEPNAME,:DE_SOURCECODE)";
+            GridDeviceList.InsertSQL = "INSERT INTO DEVICE(DE_ID,DE_CODE,DE_NAME,DE_SPEC,DE_INDATE,DE_RUNSTATUS,DE_ADDRESS,DE_INMAN,DE_LINECODE,DE_WCCODE,DE_VENDCODE,DE_VENDNAME,DE_STEPCODE,DE_STEPNAME,DE_SOURCECODE) VALUES(DEVICE_SEQ.NEXTVAL,:DE_CODE,:DE_NAME,:DE_SPEC,sysdate,:DE_RUNSTATUS,:DE_ADDRESS,:DE_INMAN,:DE_LINECODE,:DE_WCCODE,:DE_VENDCODE,:DE_VENDNAME,:DE_STEPCODE,:DE_STEPNAME,:DE_SOURCECODE)";
             ButtonAddDevice.Grid = GridDeviceList;
             ButtonSaveDevice.Grid = GridDeviceList;
             ButtonDeleteDevice.Grid = GridDeviceList;
@@ -98,10 +98,10 @@ namespace UAS_PLCDataReader
             //ButtonSavePolling.Grid = GridPolling;
             //ButtonAddPolling.Grid = GridPolling;
             //轮询配置界面
-            GridPollingSetting.GetDataSQL = "SELECT '' POLLSETTINGSTATUSCOLUMN,0 CHECKEDCOLUMN,DPC_MAN,DPC_ID,DPC_DECODE ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , nvl(DPC_ENABLE,0)DPC_ENABLE,DPC_STATUS,DPC_REMARK,EM_NAME FROM DEVICEPOLLINGCONFIG left join EMPLOYEE on em_code=dpc_man WHERE DPC_MAN='" + User.UserCode + "' ORDER BY DPC_ID";
+            GridPollingSetting.GetDataSQL = "SELECT '' POLLSETTINGSTATUSCOLUMN,0 CHECKEDCOLUMN,DPC_MAN,DPC_ID,DPC_DECODE,DPC_DENAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , nvl(DPC_ENABLE,0)DPC_ENABLE,DPC_STATUS,DPC_REMARK,EM_NAME FROM DEVICEPOLLINGCONFIG left join EMPLOYEE on em_code=dpc_man WHERE DPC_MAN='" + User.UserCode + "' ORDER BY DPC_ID";
             GridPollingSetting.ID = "DPC_ID";
             GridPollingSetting.TableName = "DEVICEPOLLINGCONFIG";
-            GridPollingSetting.InsertSQL = "insert into DEVICEPOLLINGCONFIG(DPC_ID,DPC_DECODE ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK,DPC_MAN) values(DEVICEPOLLINGCONFIG_seq.nextval,:DPC_DECODE  ,:DPC_INTERVAL ,:DPC_DCCODE ,:DPC_FUNCTION , :DPC_ENABLE,:DPC_STATUS ,:DPC_REMARK,'" + User.UserCode + "')";
+            GridPollingSetting.InsertSQL = "insert into DEVICEPOLLINGCONFIG(DPC_ID,DPC_DECODE,DPC_DENAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK,DPC_MAN) values(DEVICEPOLLINGCONFIG_seq.nextval,:DPC_DECODE  ,:DPC_INTERVAL ,:DPC_DCCODE ,:DPC_FUNCTION , :DPC_ENABLE,:DPC_STATUS ,:DPC_REMARK,'" + User.UserCode + "')";
             ButtonSaveCommandSet.Grid = GridPollingSetting;
             ButtonNewCommandSet.Grid = GridPollingSetting;
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
@@ -337,6 +337,7 @@ namespace UAS_PLCDataReader
                 Polling pl = new Polling();
                 pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_ID").ToString());
                 pl.DeviceCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DECODE").ToString();
+                pl.DeviceName = GridViewPollSetting.GetRowCellValue(i, "DPC_DENAME").ToString();
                 pl.CommandCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DCCODE").ToString();
                 pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString());
                 pl.Enable = GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0";
@@ -348,6 +349,12 @@ namespace UAS_PLCDataReader
                     sql.Append("insert into DEVICEPOLLINGLOG(dpg_id,dpg_decode,dpg_starttime,dpg_interval)values");
                     sql.Append("(DEVICEPOLLINGLOG_seq.nextval,'" + pl.DeviceCode + "',sysdate,'" + pl.Interval + "')");
                     dh.ExecuteSql(sql.ToString(), "insert");
+                    sql.Clear();
+                    sql.Append("MERGE INTO DeviceRunstatus alias1 USING (select '" + pl.DeviceCode + "' dr_decode from  dual) alias2 ");
+                    sql.Append("ON (alias1.dr_decode=alias2.dr_decode) WHEN MATCHED THEN  UPDATE  SET dr_startdate =sysdate ");
+                    sql.Append("WHEN NOT MATCHED THEN INSERT (Dr_id,dr_decode,dr_dename,Dr_runstatus,dr_startdate) VALUES (DeviceRunstatus_seq.nextval,");
+                    sql.Append("'" + pl.DeviceCode + "','" + pl.DeviceName + "','running',sysdate)");
+                    dh.ExecuteSql(sql.ToString(), "update");
                     pt.AddTask(RunTask, pl);
                     //添加到状态为运行的行
                     PollSettingPaintRowIndex.Add(i);
@@ -420,8 +427,6 @@ namespace UAS_PLCDataReader
                     SendCommandByteSize = Encoding.Default.GetBytes(Command.ToCharArray()).Length;
                 }
                 mbt.Send(IP, SendCoding, ReceiveCoding, Command);
-                //处理2秒之内返回的指令
-                //Thread.Sleep(1000);
                 if (mbt.Returnvalue.ContainsKey(IP))
                 {
                     int ReceiveCommandByteSize = Encoding.Default.GetBytes(mbt.Returnvalue[IP].ToCharArray()).Length;
@@ -450,15 +455,12 @@ namespace UAS_PLCDataReader
                     sql.Clear();
                     sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Running' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
                     dh.ExecuteSql(sql.ToString(), "update");
-                    //SQL.Add(sql.ToString());
                     //更新轮询日志状态
                     sql.Clear();
                     sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + SendCommandByteSize);
                     sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + ReceiveCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
                     sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
-                    //SQL.Add(sql.ToString());
                     dh.ExecuteSql(sql.ToString(), "update");
-                    //dh.ExecuteSQLTran(SQL.ToArray());
                 }
                 else
                 {
@@ -466,16 +468,13 @@ namespace UAS_PLCDataReader
                     //更新轮询状态
                     sql.Clear();
                     sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Stop' where dpc_decode='" + Decode + "' and dpc_dccode='" + Dccode + "'");
-                    //SQL.Add(sql.ToString());
                     dh.ExecuteSql(sql.ToString(), "update");
                     //更新轮询日志状态
                     sql.Clear();
                     sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+");
                     sql.Append(SendCommandByteSize + ",dpg_count=nvl(dpg_count,0)+1 ");
                     sql.Append("where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + Decode + "')");
-                    //SQL.Add(sql.ToString());
                     dh.ExecuteSql(sql.ToString(), "update");
-                    //dh.ExecuteSQLTran(SQL.ToArray());
                 }
             }
         }
@@ -525,6 +524,7 @@ namespace UAS_PLCDataReader
                     Polling pl = new Polling();
                     pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ID").ToString());
                     pl.DeviceCode = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_DECODE").ToString();
+                    pl.DeviceName = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_DENAME").ToString();
                     pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_INTERVAL").ToString());
                     pl.CommandCode = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_DCCODE").ToString();
                     pl.Enable = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString() != "0";