Browse Source

修改设备详细展示信息查询

章政 6 years ago
parent
commit
3f34d614ee

+ 3 - 3
PLCDataReader/CustomerControl/Button/ButtonSaveGrid.cs

@@ -68,18 +68,18 @@ namespace UAS_PLCDataReader.CustomerControl.Button
         /// <summary>
         /// 外部调用,不重新刷新数据
         /// </summary>
-        public void DoSaveAfterHandler(bool MessageBoxAlert)
+        public void DoSaveAfterHandler(bool iMessageBoxAlert)
         {
             DataTable dt = ((DataTable)grid.DataSource).GetChanges();
             if (dt != null && dt.Rows.Count > 0)
             {
                 SystemInf.dh.SaveDataTable(dt, grid.TableName, grid.ID, out LastSaveID, grid.InsertSQL);
-                if (MessageBoxAlert)
+                if (iMessageBoxAlert)
                     XtraMessageBox.Show("保存成功", "提示");
             }
             else
             {
-                if (MessageBoxAlert)
+                if (iMessageBoxAlert)
                     XtraMessageBox.Show("没有修改过的数据", "提示");
             }
         }

+ 54 - 32
PLCDataReader/Device/Information/DeviceStatusInfo.Designer.cs

@@ -55,10 +55,12 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.labelControl9 = new DevExpress.XtraEditors.LabelControl();
             this.labelControl14 = new DevExpress.XtraEditors.LabelControl();
             this.groupControl3 = new DevExpress.XtraEditors.GroupControl();
-            this.dpg_runtime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.dpg_count = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.dpg_receivedatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
-            this.dpg_starttime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.dnc_port = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.dpg_runtime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.dpg_interval = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.dpg_senddatasize = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
+            this.dpg_onlinetime = new UAS_PLCDataReader.CustomerControl.ValueLabel.ValueLabel();
             this.GridDeivceStatusInfo = new DevExpress.XtraGrid.GridControl();
             this.GridViewDeviceStatusInfo = new DevExpress.XtraGrid.Views.Grid.GridView();
             this.dc_name = new DevExpress.XtraGrid.Columns.GridColumn();
@@ -274,7 +276,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             // labelControl11
             // 
             this.labelControl11.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl11.Location = new System.Drawing.Point(21, 41);
+            this.labelControl11.Location = new System.Drawing.Point(16, 35);
             this.labelControl11.Name = "labelControl11";
             this.labelControl11.Size = new System.Drawing.Size(64, 16);
             this.labelControl11.TabIndex = 11;
@@ -283,7 +285,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             // labelControl12
             // 
             this.labelControl12.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl12.Location = new System.Drawing.Point(21, 72);
+            this.labelControl12.Location = new System.Drawing.Point(16, 68);
             this.labelControl12.Name = "labelControl12";
             this.labelControl12.Size = new System.Drawing.Size(64, 16);
             this.labelControl12.TabIndex = 12;
@@ -292,7 +294,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             // labelControl9
             // 
             this.labelControl9.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl9.Location = new System.Drawing.Point(21, 132);
+            this.labelControl9.Location = new System.Drawing.Point(16, 159);
             this.labelControl9.Name = "labelControl9";
             this.labelControl9.Size = new System.Drawing.Size(64, 16);
             this.labelControl9.TabIndex = 14;
@@ -301,7 +303,7 @@ namespace UAS_PLCDataReader.Device.Infomation
             // labelControl14
             // 
             this.labelControl14.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.labelControl14.Location = new System.Drawing.Point(21, 102);
+            this.labelControl14.Location = new System.Drawing.Point(16, 100);
             this.labelControl14.Name = "labelControl14";
             this.labelControl14.Size = new System.Drawing.Size(64, 16);
             this.labelControl14.TabIndex = 15;
@@ -309,11 +311,13 @@ namespace UAS_PLCDataReader.Device.Infomation
             // 
             // groupControl3
             // 
-            this.groupControl3.Controls.Add(this.dpg_runtime);
-            this.groupControl3.Controls.Add(this.dpg_count);
             this.groupControl3.Controls.Add(this.dpg_receivedatasize);
+            this.groupControl3.Controls.Add(this.dnc_port);
+            this.groupControl3.Controls.Add(this.dpg_runtime);
+            this.groupControl3.Controls.Add(this.dpg_interval);
+            this.groupControl3.Controls.Add(this.dpg_senddatasize);
             this.groupControl3.Controls.Add(this.labelControl14);
-            this.groupControl3.Controls.Add(this.dpg_starttime);
+            this.groupControl3.Controls.Add(this.dpg_onlinetime);
             this.groupControl3.Controls.Add(this.labelControl9);
             this.groupControl3.Controls.Add(this.labelControl12);
             this.groupControl3.Controls.Add(this.labelControl11);
@@ -323,37 +327,53 @@ namespace UAS_PLCDataReader.Device.Infomation
             this.groupControl3.TabIndex = 2;
             this.groupControl3.Text = "运行信息";
             // 
+            // dpg_receivedatasize
+            // 
+            this.dpg_receivedatasize.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dpg_receivedatasize.Location = new System.Drawing.Point(97, 190);
+            this.dpg_receivedatasize.Name = "dpg_receivedatasize";
+            this.dpg_receivedatasize.Size = new System.Drawing.Size(0, 16);
+            this.dpg_receivedatasize.TabIndex = 18;
+            // 
+            // dnc_port
+            // 
+            this.dnc_port.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dnc_port.Location = new System.Drawing.Point(96, 130);
+            this.dnc_port.Name = "dnc_port";
+            this.dnc_port.Size = new System.Drawing.Size(0, 16);
+            this.dnc_port.TabIndex = 17;
+            // 
             // dpg_runtime
             // 
             this.dpg_runtime.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.dpg_runtime.Location = new System.Drawing.Point(101, 72);
+            this.dpg_runtime.Location = new System.Drawing.Point(96, 68);
             this.dpg_runtime.Name = "dpg_runtime";
             this.dpg_runtime.Size = new System.Drawing.Size(0, 16);
             this.dpg_runtime.TabIndex = 16;
             // 
-            // dpg_count
+            // dpg_interval
             // 
-            this.dpg_count.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.dpg_count.Location = new System.Drawing.Point(101, 102);
-            this.dpg_count.Name = "dpg_count";
-            this.dpg_count.Size = new System.Drawing.Size(0, 16);
-            this.dpg_count.TabIndex = 3;
+            this.dpg_interval.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dpg_interval.Location = new System.Drawing.Point(96, 100);
+            this.dpg_interval.Name = "dpg_interval";
+            this.dpg_interval.Size = new System.Drawing.Size(0, 16);
+            this.dpg_interval.TabIndex = 3;
             // 
-            // dpg_receivedatasize
+            // dpg_senddatasize
             // 
-            this.dpg_receivedatasize.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.dpg_receivedatasize.Location = new System.Drawing.Point(101, 132);
-            this.dpg_receivedatasize.Name = "dpg_receivedatasize";
-            this.dpg_receivedatasize.Size = new System.Drawing.Size(0, 16);
-            this.dpg_receivedatasize.TabIndex = 2;
+            this.dpg_senddatasize.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dpg_senddatasize.Location = new System.Drawing.Point(96, 159);
+            this.dpg_senddatasize.Name = "dpg_senddatasize";
+            this.dpg_senddatasize.Size = new System.Drawing.Size(0, 16);
+            this.dpg_senddatasize.TabIndex = 2;
             // 
-            // dpg_starttime
+            // dpg_onlinetime
             // 
-            this.dpg_starttime.Appearance.Font = new System.Drawing.Font("黑体", 12F);
-            this.dpg_starttime.Location = new System.Drawing.Point(101, 41);
-            this.dpg_starttime.Name = "dpg_starttime";
-            this.dpg_starttime.Size = new System.Drawing.Size(0, 16);
-            this.dpg_starttime.TabIndex = 0;
+            this.dpg_onlinetime.Appearance.Font = new System.Drawing.Font("黑体", 12F);
+            this.dpg_onlinetime.Location = new System.Drawing.Point(96, 35);
+            this.dpg_onlinetime.Name = "dpg_onlinetime";
+            this.dpg_onlinetime.Size = new System.Drawing.Size(0, 16);
+            this.dpg_onlinetime.TabIndex = 0;
             // 
             // GridDeivceStatusInfo
             // 
@@ -475,10 +495,10 @@ namespace UAS_PLCDataReader.Device.Infomation
         private DevExpress.XtraEditors.LabelControl labelControl11;
         private DevExpress.XtraEditors.LabelControl labelControl12;
         private DevExpress.XtraEditors.LabelControl labelControl9;
-        private ValueLabel dpg_starttime;
+        private ValueLabel dpg_onlinetime;
         private DevExpress.XtraEditors.LabelControl labelControl14;
-        private ValueLabel dpg_receivedatasize;
-        private ValueLabel dpg_count;
+        private ValueLabel dpg_senddatasize;
+        private ValueLabel dpg_interval;
         private DevExpress.XtraEditors.GroupControl groupControl3;
         private ValueLabel de_linecode;
         private ValueLabel de_address;
@@ -499,5 +519,7 @@ namespace UAS_PLCDataReader.Device.Infomation
         private DevExpress.XtraGrid.Views.Grid.GridView GridViewDeviceRunLog;
         private DevExpress.XtraGrid.Columns.GridColumn drr_command;
         private DevExpress.XtraGrid.Columns.GridColumn drr_commandfrom;
+        private ValueLabel dnc_port;
+        private ValueLabel dpg_receivedatasize;
     }
 }

+ 16 - 4
PLCDataReader/Device/Information/DeviceStatusInfo.cs

@@ -32,6 +32,7 @@ namespace UAS_PLCDataReader.Device.Infomation
 
         private void DeviceStatusInfo_Load(object sender, EventArgs e)
         {
+            //查询设备基础信息
             sql.Clear();
             sql.Append("select de_linecode,de_wccode,de_name,de_address,de_sourcecode,sc_name from device ");
             sql.Append("left join source on sc_code=de_sourcecode where de_code='" + de_code + "'");
@@ -40,21 +41,32 @@ namespace UAS_PLCDataReader.Device.Infomation
             {
                 BaseUtil.SetFormValue(Controls, dt);
             }
+            //查询设备参数信息
             sql.Clear();
             sql.Append("select dc_name,case when dc_type='INQTY' then dr_qty when dc_type='OUTQTY' then dr_okqty end data ");
             sql.Append("from DEVICEPOLLINGCONFIG left join devicecommand on dpc_dccode = dc_code left join DEVICERUNSTATUS ");
             sql.Append("on dpc_decode = dr_decode where dpc_decode = '" + de_code + "'");
             GridDeivceStatusInfo.DataSource = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
             sql.Clear();
+            //查询设备运行日志
             sql.Append("select * from DEVICERUNRECORD");
             GridDeviceRunLog.DataSource = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+            sql.Clear();
+            sql.Append("select '接收'||nvl(dpg_senddatasize,0)||'字节' dpg_receivedatasize,'发送'||nvl(dpg_receivedatasize,0)||'字节' dpg_senddatasize");
+            sql.Append(",dpg_onlinetime,dpg_offlinetime,'IP:'||dnc_ip dpg_interval,'端口:'|| dnc_port||',间隔'||dpg_interval||'S' dnc_port ");
+            sql.Append("from devicepollinglog left join DEVICENETCONFIG on dnc_decode=dpg_decode ");
+            sql.Append("where dpg_id=(select max(dpg_id) from devicepollinglog where dpg_decode='"+de_code+"')");
+            dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+            if (dt.Rows.Count > 0)
+            {
+                BaseUtil.SetFormValue(this.Controls, dt);
+            }
             if (Main.ReturnData.ContainsKey(de_code))
             {
-                dpg_count.Text = Main.ReturnData[de_code].SendCount.ToString();
-                string totalMinutes = (DateTime.Now - Main.ReturnData[de_code].StartTime).TotalMinutes.ToString();
+                dpg_interval.Text = Main.ReturnData[de_code].SendCount.ToString();
                 dpg_runtime.Text = (DateTime.Now - Main.ReturnData[de_code].StartTime).TotalMinutes.ToString("f1") + "分钟";
-                dpg_starttime.Text = Main.ReturnData[de_code].StartTime.ToString("yyyy-MM-dd HH:mm:ss");
-                dpg_receivedatasize.Text = Main.ReturnData[de_code].ReceiveDataSize.ToString();
+                dpg_onlinetime.Text = Main.ReturnData[de_code].StartTime.ToString("yyyy-MM-dd HH:mm:ss");
+                dpg_senddatasize.Text = Main.ReturnData[de_code].ReceiveDataSize.ToString();
                 Dictionary<string, string> ItemData = Main.ReturnData[de_code].ItemData;
                 if (ItemData != null && ItemData.Count > 0)
                 {

+ 4 - 12
PLCDataReader/Main.cs

@@ -328,16 +328,8 @@ namespace UAS_PLCDataReader
             {
                 Entity.Device item = QueueUpdateDevice.Dequeue();
                 SQL.Clear();
-                //更新轮询状态
-                sql.Clear();
-                sql.Append("update DEVICEPOLLINGCONFIG set dpc_status='Running' where dpc_decode='" + item.Decode + "' and dpc_dccode='" + item.Dccode + "'");
-                dh.ExecuteSql(sql.ToString(), "update");
                 //更新轮询日志状态
-                sql.Clear();
-                sql.Append("update DEVICEPOLLINGLOG set dpg_status='Running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + item.SendDataSize);
-                sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + item.ReceiveDataSize + ",dpg_count=nvl(dpg_count,0)+1 ");
-                sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + item.Decode + "')");
-                dh.ExecuteSql(sql.ToString(), "update");
+                LogicHandler.DoDevicePollingLog(item.Decode, item.SendDataSize.ToString(), item.ReceiveDataSize.ToString());
             }
         }
         #endregion
@@ -413,7 +405,7 @@ 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");
-                    LogicHandler.UpdateDeviceStatus(pl.Dh, pl.DeviceCode, pl.DeviceName, "running");
+                    LogicHandler.UpdateDeviceStatus(pl.Dh, pl.DeviceCode, pl.DeviceName, "noanswer");
                     pt.AddTask(RunTask, pl);
                     //添加到状态为运行的行
                     PollSettingPaintRowIndex.Add(i);
@@ -507,7 +499,7 @@ namespace UAS_PLCDataReader
                     device.Decode = pl.DeviceCode;
                     device.Dename = pl.DeviceName;
                     device.StartTime = DateTime.Now;
-                    device.RunStatus = "Running";
+                    device.RunStatus = "running";
                     device.SendDataSize += SendCommandByteSize;
                     device.SendCount += 1;
                     device.Dccode = pl.CommandCode;
@@ -549,7 +541,7 @@ namespace UAS_PLCDataReader
                         device.Decode = pl.DeviceCode;
                         device.Dename = pl.DeviceName;
                         device.StartTime = DateTime.Now;
-                        device.RunStatus = "Running";
+                        device.RunStatus = "running";
                         device.ReceiveDataSize += ReceiveCommandByteSize;
                         device.Dccode = pl.CommandCode;
                         device.ItemData = ItemData;

+ 39 - 0
PLCDataReader/PublicMethod/LogicHandler.cs

@@ -49,6 +49,45 @@ namespace UAS_PLCDataReader.PublicMethod
             dh.ExecuteSql(sql.ToString(), "insert");
         }
 
+        /// <summary>
+        /// 记录轮询日志,记录时间
+        /// </summary>
+        /// <param name="iDeCode">设备编号</param>
+        /// <param name="iSendDataSize">发送数据大小</param>
+        /// <param name="iReceiveDataSize">接收数据大小</param>
+        /// <param name="iOnLine">上线或者离线</param>
+        public static void DoDevicePollingLog(string iDeCode, string iSendDataSize, string iReceiveDataSize, bool iOnLine)
+        {
+            sql.Clear();
+            sql.Append("update DEVICEPOLLINGLOG set dpg_status='running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + iSendDataSize);
+            sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + iReceiveDataSize + ",dpg_count=nvl(dpg_count,0)+1 ");
+            if (iOnLine)
+            {
+                sql.Append(",dpg_onlinetime = sysdate");
+            }
+            else
+            {
+                sql.Append(",dpg_offlinetime = sysdate");
+            }
+            sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + iDeCode + "')");
+            dh.ExecuteSql(sql.ToString(), "insert");
+        }
+
+        /// <summary>
+        /// 记录轮询日志,不记录时间
+        /// </summary>
+        /// <param name="iDeCode">设备编号</param>
+        /// <param name="iSendDataSize">发送数据大小</param>
+        /// <param name="iReceiveDataSize">接收数据大小</param>
+        public static void DoDevicePollingLog(string iDeCode, string iSendDataSize, string iReceiveDataSize)
+        {
+            sql.Clear();
+            sql.Append("update DEVICEPOLLINGLOG set dpg_status='running',dpg_senddatasize=nvl(dpg_senddatasize,0)+" + iSendDataSize);
+            sql.Append(",dpg_receivedatasize=nvl(dpg_receivedatasize,0)+" + iReceiveDataSize + ",dpg_count=nvl(dpg_count,0)+1 ");
+            sql.Append(" where dpg_id=(select max(dpg_id) from DEVICEPOLLINGLOG where dpg_decode='" + iDeCode + "')");
+            dh.ExecuteSql(sql.ToString(), "insert");
+        }
+
         /// <summary>
         /// 更新设备数据投入,产出等数据
         /// </summary>

+ 0 - 1
PLCDataReader/PublicMethod/ModBusTCPClient.cs

@@ -117,7 +117,6 @@ namespace UAS_PLCDataReader.PublicMethod
             }
             catch (Exception e)
             {
-                Console.WriteLine(e.Message);
                 LogicHandler.UpdateDeviceStatus(Dh,decode, dename, "disconnect");
             }
         }