mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-18 09:44:28 +08:00
flow ui
This commit is contained in:
122
Infrastructure/CommonHelper.cs
Normal file
122
Infrastructure/CommonHelper.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// 常用公共类
|
||||
/// </summary>
|
||||
public class CommonHelper
|
||||
{
|
||||
#region Stopwatch计时器
|
||||
/// <summary>
|
||||
/// 计时器开始
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Stopwatch TimerStart()
|
||||
{
|
||||
Stopwatch watch = new Stopwatch();
|
||||
watch.Reset();
|
||||
watch.Start();
|
||||
return watch;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计时器结束
|
||||
/// </summary>
|
||||
/// <param name="watch"></param>
|
||||
/// <returns></returns>
|
||||
public static string TimerEnd(Stopwatch watch)
|
||||
{
|
||||
watch.Stop();
|
||||
double costtime = watch.ElapsedMilliseconds;
|
||||
return costtime.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除数组中的重复项
|
||||
/// <summary>
|
||||
/// 删除数组中的重复项
|
||||
/// </summary>
|
||||
/// <param name="values"></param>
|
||||
/// <returns></returns>
|
||||
public static string[] RemoveDup(string[] values)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
for (int i = 0; i < values.Length; i++)//遍历数组成员
|
||||
{
|
||||
if (!list.Contains(values[i]))
|
||||
{
|
||||
list.Add(values[i]);
|
||||
};
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 自动生成日期编号
|
||||
/// <summary>
|
||||
/// 自动生成编号 201008251145409865
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string CreateNo()
|
||||
{
|
||||
Random random = new Random();
|
||||
string strRandom = random.Next(1000, 10000).ToString(); //生成编号
|
||||
string code = DateTime.Now.ToString("yyyyMMddHHmmss") + strRandom;//形如
|
||||
return code;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生成0-9随机数
|
||||
/// <summary>
|
||||
/// 生成0-9随机数
|
||||
/// </summary>
|
||||
/// <param name="codeNum">生成长度</param>
|
||||
/// <returns></returns>
|
||||
public static string RndNum(int codeNum)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(codeNum);
|
||||
Random rand = new Random();
|
||||
for (int i = 1; i < codeNum + 1; i++)
|
||||
{
|
||||
int t = rand.Next(9);
|
||||
sb.AppendFormat("{0}", t);
|
||||
}
|
||||
return sb.ToString();
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除最后一个字符之后的字符
|
||||
/// <summary>
|
||||
/// 删除最后结尾的一个逗号
|
||||
/// </summary>
|
||||
public static string DelLastComma(string str)
|
||||
{
|
||||
return str.Substring(0, str.LastIndexOf(","));
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除最后结尾的指定字符后的字符
|
||||
/// </summary>
|
||||
public static string DelLastChar(string str, string strchar)
|
||||
{
|
||||
return str.Substring(0, str.LastIndexOf(strchar));
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除最后结尾的长度
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="Length"></param>
|
||||
/// <returns></returns>
|
||||
public static string DelLastLength(string str, int Length)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return "";
|
||||
str = str.Substring(0, str.Length - Length);
|
||||
return str;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
45
Infrastructure/Json.cs
Normal file
45
Infrastructure/Json.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// Json操作
|
||||
/// </summary>
|
||||
public static class Json
|
||||
{
|
||||
public static object ToJson(this string Json)
|
||||
{
|
||||
return Json == null ? null : JsonConvert.DeserializeObject(Json);
|
||||
}
|
||||
public static string ToJson(this object obj)
|
||||
{
|
||||
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
|
||||
return JsonConvert.SerializeObject(obj, timeConverter);
|
||||
}
|
||||
public static string ToJson(this object obj, string datetimeformats)
|
||||
{
|
||||
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = datetimeformats };
|
||||
return JsonConvert.SerializeObject(obj, timeConverter);
|
||||
}
|
||||
public static T ToObject<T>(this string Json)
|
||||
{
|
||||
return Json == null ? default(T) : JsonConvert.DeserializeObject<T>(Json);
|
||||
}
|
||||
public static List<T> ToList<T>(this string Json)
|
||||
{
|
||||
return Json == null ? null : JsonConvert.DeserializeObject<List<T>>(Json);
|
||||
}
|
||||
public static DataTable ToTable(this string Json)
|
||||
{
|
||||
return Json == null ? null : JsonConvert.DeserializeObject<DataTable>(Json);
|
||||
}
|
||||
public static JObject ToJObject(this string Json)
|
||||
{
|
||||
return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", ""));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user