From a75f121124e90619b2853ad079ae0a733366b022 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 08 十二月 2020 14:48:30 +0800
Subject: [PATCH] 2020-12-08-1

---
 HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs |   60 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
index 81b0ae6..6eeaa59 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
@@ -22,6 +22,47 @@
         {
             MainPage.BasePageView.RemoveViewByTag("Logic");
         }
+
+        /// <summary> Converts an array of bytes into a formatted string of hex digits (ex: E4 CA B2)</summary>
+        /// <param name="data"> The array of bytes to be translated into a string of hex digits. </param>
+        /// <returns> Returns a well formatted string of hex digits with spacing. </returns>
+        static string byteArrayToHexString(byte[] data)
+        {
+            System.Text.StringBuilder sb = new System.Text.StringBuilder();
+            foreach (byte b in data)
+            {
+                sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
+            }
+
+            return sb.ToString().ToUpper();
+        }
+
+        /**
+  * int杞琤yte[]
+  * 璇ユ柟娉曞皢涓�涓猧nt绫诲瀷鐨勬暟鎹浆鎹负byte[]褰㈠紡锛屽洜涓篿nt涓�32bit锛岃�宐yte涓�8bit鎵�浠ュ湪杩涜绫诲瀷杞崲鏃讹紝鐭ヤ細鑾峰彇浣�8浣嶏紝
+  * 涓㈠純楂�24浣嶃�傞�氳繃浣嶇Щ鐨勬柟寮忥紝灏�32bit鐨勬暟鎹浆鎹㈡垚4涓�8bit鐨勬暟鎹�傛敞鎰� &0xff锛屽湪杩欏綋涓紝&0xff绠�鍗曠悊瑙d负涓�鎶婂壀鍒�锛�
+  * 灏嗘兂瑕佽幏鍙栫殑8浣嶆暟鎹埅鍙栧嚭鏉ャ��
+  * @param i 涓�涓猧nt鏁板瓧
+  * @return byte[]
+  */
+        public static byte[] int2ByteArray(int i)
+        {
+            byte[] result = new byte[4];
+            result[0] = (byte)((i >> 24) & 0xFF);
+            result[1] = (byte)((i >> 16) & 0xFF);
+            result[2] = (byte)((i >> 8) & 0xFF);
+            result[3] = (byte)(i & 0xFF);
+            return result;
+        }
+        /// <summary>
+        /// 鑾峰彇鏃堕棿鎴�
+        /// </summary>
+        /// <returns></returns>
+        static int getTimeStamp()
+        {
+            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
+            return (int)ts.TotalSeconds;
+        }
         /// <summary>
         /// 鐢熸垚閫昏緫sid鏂规硶
         /// </summary>
@@ -34,24 +75,9 @@
                 DateTime dt = DateTime.Now;
                 DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
                 long m = (long)((dt - startTime).TotalMilliseconds / 10);
-                string sTimeSpan = "00000000";
+                string sTimeSpan = byteArrayToHexString(int2ByteArray(getTimeStamp()));
 
-                byte[] arry = new byte[4];
-                arry[0] = (byte)(m & 0xFF);
-                arry[1] = (byte)((m & 0xFF00) >> 8);
-                arry[2] = (byte)((m & 0xFF0000) >> 16);
-                arry[3] = (byte)((m >> 24) & 0xFF);
-                sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
-
-
-                if (sTimeSpan.Length > 8)
-                {
-                    sTimeSpan = sTimeSpan.Substring(0, 8);
-                }
-                else
-                {
-                    sTimeSpan = "00000000";
-                }
+               
 
                 logicId = sOidBeginsWith + sTimeSpan;
 

--
Gitblit v1.8.0