From c052583025ff87735d2120dc63aeee7ea5e5524e Mon Sep 17 00:00:00 2001
From: wzp <2040239371@qq.com>
Date: 星期三, 23 十一月 2022 09:25:11 +0800
Subject: [PATCH] 多项优化

---
 web/Common/DataConverter.cs |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/web/Common/DataConverter.cs b/web/Common/DataConverter.cs
index 421765e..39c3785 100644
--- a/web/Common/DataConverter.cs
+++ b/web/Common/DataConverter.cs
@@ -1,8 +1,10 @@
 锘縩amespace Common
 {
     using System;
+    using System.Collections.Generic;
     using System.Runtime.InteropServices;
     using System.Text.RegularExpressions;
+    using System.Linq;
 
     public class DataConverter
     {
@@ -179,6 +181,102 @@
             [FieldOffset(0)]
             public DataConverter.IPAdress _IP;
         }
+
+        //鑾峰彇闅忔満鐮�
+        public static string getRandom(int strLength)
+        {
+            string random = "";
+            if (strLength <= 0)
+            {
+                strLength = 6;  //榛樿6浣嶉暱搴�
+            }
+            //random = Guid.NewGuid().ToString().Replace("-", "").Substring(0, strLength);
+            random = Guid.NewGuid().ToString();
+            random = random.Replace("-", "");
+            random = random.Substring(0, strLength);
+
+            return random;
+        }
+
+        //瀛楃涓茶浆鏁扮粍
+        public static object[] stringToArray(string str)
+        {
+            object[] array = str.Split(',');
+            return array;
+        }
+
+        //鏁扮粍杞瓧绗︿覆
+        public static string arrayToString(object[] array)
+        {
+            if (array == null)
+                return "";
+            string str = string.Join(",", array);
+            return str;
+        }
+
+        //鏁扮粍杞崲List锛歴tring[] str ={ "str","string","abc"}杞� List<string>
+        public static List<object> arrayToList(object[] array)
+        {
+            List<object> list = new List<object>(array);
+
+            return list;
+        }
+
+        //List杞崲鏁扮粍锛歀ist<string>杞埌string[]
+        public static object[] listToArray(List<object> list)
+        {
+            object[] array = list.ToArray();
+
+            return array;
+        }
+
+        //瀛楃涓茶浆List
+        public static List<object> stringToList(string str)
+        {
+            if (string.IsNullOrEmpty(str))
+                return null;
+
+            List<object> list = new List<object>();
+            //瀛楃涓茶浆鏁扮粍锛屽啀鏁扮粍鍚堝苟
+            list.AddRange(str.Split(','));
+
+            return list;
+        }
+
+        //鏁扮粍鍘婚噸锛岀Щ闄ゆ暟缁勪腑閲嶅鏁版嵁
+        public static string[] DelRepeatData(string[] array)
+        {
+            return array.GroupBy(p => p).Select(p => p.Key).ToArray();
+        }
+
+        //妫�鏌ユ暟缁勬牸寮忓瓧绗︿覆涓槸鍚﹀寘鍚煇鍏冪礌
+        public static bool checkStrForArrayStr(object str, string arrayStr )
+        {
+            return stringToArray(arrayStr).Contains(str.ToString() );
+        }
+
+        //妫�鏌ユ暟缁勪腑鏄惁鍖呭惈鏌愬厓绱�
+        public static bool checkStrForArray(object str, object[] array)
+        {
+            return array.Contains(str);
+        }
+
+        //鏍规嵁鏁扮粍瀛楃涓茶浆鎹㈠瓧鍏�
+        public Dictionary<string, object> arrayStrToDict(object userId, string arrayStr)
+        {
+            Dictionary<string, object> dictionary = new Dictionary<string, object>();
+            if (string.IsNullOrEmpty(arrayStr))
+                return dictionary;
+
+            List<object> list = DataConverter.stringToList(arrayStr);
+            for (int i = 0; i < list.Count; i++)
+            {
+                dictionary[userId.ToString()] = list[i];
+            }
+            return dictionary;
+        }
+
     }
+
 }
 

--
Gitblit v1.9.1