using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Traffic.Data.ViewModels;
namespace LiangLiSystem.Services.Helpers
{
public static class Util
{
public static string GetEnumDesc(Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[];
if (attributes != null && attributes.Any())
{
return attributes.First().Description;
}
return value.ToString();
}
public static DateTime GetDateTimeNow()
{
return Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
}
public static string GetDateTimeNow(string date)
{
return Convert.ToDateTime(date).ToString("yyyy-MM-dd HH:mm:ss");
}
public static SearchModel GetSearchModel(SearchModelViewModel searchModel)
{
return new SearchModel
{
Term = searchModel.Term,
Page = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.Page) ? "1" : searchModel.Page),
PageSize = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.PageSize) ? "1" : searchModel.PageSize),
IsAsc = (searchModel.IsAsc == "true" || searchModel.IsAsc == "") ? true : false,
Order = string.IsNullOrWhiteSpace(searchModel.Order) ? "id" : searchModel.Order,
};
}
///
/// #必須包含數字, #必須包含小寫字母, #必須包含大寫字母, #必須包含特殊符號, #至少8個字符,最多30個字符
///
///
///
public static bool IsValidPassword(string password)
{
var regex = new Regex(@"
(?=.*[0-9]) #必須包含數字
(?=.*[a-z]) #必須包含小寫字母
(?=.*[A-Z]) #必須包含大寫字母
(?=([\x21-\x7e]+)[^a-zA-Z0-9]) #必須包含特殊符號
.{12,30} #至少12個字符,最多30個字符
", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
return regex.Match(password).Success;
}
}
}