Edit D:\xinhaisoft\crisis_new\App_Code\Common.cs
??sing System; using System.Collections.Generic; using System.Web; using System.Text.RegularExpressions; using System.Web.Security; using System.Web.Caching; using System.Data; using System.Text; using System.Web.UI; /// <summary> /// ????????????? /// </summary> public abstract class Common { private static HttpResponse Response = HttpContext.Current.Response; private static HttpRequest Request = HttpContext.Current.Request; private static Cache Cache = HttpContext.Current.Cache; //???????????????????? public static readonly string[] MemberQuestionType = { "??????", "??????", "??????", "??????", "??????" }; public Common() { // //TODO: ????????????????? // } public static void Alert(string msg) { HttpContext.Current.Response.Write("<script>alert(\"" + msg + "\");history.back();</script>"); HttpContext.Current.Response.End(); } /// <summary> /// ??????????? /// </summary> public static bool IsInteger(string number) { if (string.IsNullOrEmpty(number)) { return false; } else { Regex r = new Regex(@"^\d+$"); return r.IsMatch(number); } } /// <summary> /// ?????????18????????? /// </summary> public static bool IsIDCard(string CardId) { if (string.IsNullOrEmpty(CardId)) { return false; } else if (CardId.Length < 18) { return false; } else { long n = 0; //?????? if (long.TryParse(CardId.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(CardId.Replace('x', '0').Replace('X', '0'), out n) == false) { return false; } //?????? string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(CardId.Remove(2)) == -1) { return false; } //?????? string Mybirth = CardId.Substring(6, 8).Insert(6, "-").Insert(4, "-"); DateTime Mytime = new DateTime(); if (DateTime.TryParse(Mybirth, out Mytime) == false) { return false; } //???????? string[] MyVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(','); string[] wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(','); char[] ai = CardId.Remove(17).ToCharArray(); int sum = 0; for (int i = 0; i < 17; i++) { sum += int.Parse(wi[i]) * int.Parse(ai[i].ToString()); } int y = -1; Math.DivRem(sum, 11, out y); if (MyVarifyCode[y] != CardId.Substring(17, 1).ToLower()) { return false; } return true; } } /// <summary> /// ?????????????????? /// </summary> public static bool IsMobile(string s) { if (string.IsNullOrEmpty(s)) { return false; } else { Regex r = new Regex(@"^\+?(86)?1(3[0-9]|47|5[0-9]|7[0-9]|8[0-9])\d{8}$"); return r.IsMatch(s); } } /// <summary> /// ????????????MD5?????? /// </summary> public static bool IsMD5(string s) { if (string.IsNullOrEmpty(s)) { return false; } else { Regex r = new Regex(@"^[a-fA-F0-9]{32}$"); return r.IsMatch(s); } } /// <summary> /// ?????????????????? /// </summary> public static bool IsMoney(string s) { if (string.IsNullOrEmpty(s)) { return false; } else { Regex r = new Regex(@"^(0(?:[.](?:[1-9]\d?|0[1-9]))|[1-9]\d*(?:[.]\d{1,2}|$))$"); return r.IsMatch(s); } } /// <summary> /// ?????????????????? /// </summary> public static DateTime CDate(string date) { DateTime d; DateTime.TryParse(date, out d); if (d == DateTime.MinValue) { d = DateTime.Today; } return d; } /// <summary> /// ????????????????????????????????????????? /// </summary> public static bool IsDate(object dt) { if (dt == null) { return false; } else if (dt is DateTime) { return true; } else if (dt is string) { DateTime d; return DateTime.TryParse((string)dt, out d); } else { return false; } } //?????????????? public static string CutString(string str, int len) { if (str == null || str.Length == 0 || len <= 0) { return string.Empty; } int l = str.Length; int clen = 0; while (clen < len && clen < l) { //?????????????????????????? if ((int)str[clen] > 128) { len--; } clen++; } if (clen < l) { return str.Substring(0, clen) + "..."; } else { return str; } } //?????? public static void Redirect(string url) { HttpContext.Current.Response.Redirect(url, true); } //?????? public static void InsertCache(string key, object value) { Cache.Insert(key, value); } //?????? public static object GetCache(string key) { return Cache[key]; } //?????? public static void RemoveCache(string key) { Cache.Remove(key); } //????????? public static void Debug(string msg) { HttpContext.Current.Response.Write(msg); HttpContext.Current.Response.End(); } //????????????????????????????????????????? public static float[] GetMaxandMinandMandSD(float[] Number) { float[] Result = { 0, 0, 0, 0 }; Result[0] = Number[0]; Result[1] = Number[0]; float Sum = 0; int Count = Number.Length; float SumSqdDevs = 0; //???????????????? for (int i = 0; i < Count; i++) { if (Number[i] > Result[0]) { Result[0] = Number[i]; } if (Number[i] < Result[0]) { Result[1] = Number[i]; } Sum += Number[i]; } //????? Result[2] = Sum / Count; //??? for (int i = 0; i < Count; i++) { SumSqdDevs += (float)Math.Pow((Number[i] - Result[2]), 2); } //????? Result[3] = (float)Math.Sqrt(SumSqdDevs / Count); return Result; } /// <summary> /// ???????????????Null???????? /// </summary> public static bool IsNotNullAndEmpty(string s) { return !(s == null || s == string.Empty); } /// <summary> /// MD5?????32???????? /// </summary> public static string MD5(string s) { return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5").ToLower(); } /// <summary> /// SHA1??? /// </summary> public static string SHA1(string s) { return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "SHA1").ToLower(); } //??????? public static void CheckRole(string role) { if (!HttpContext.Current.User.IsInRole(role)) { HttpContext.Current.Response.Redirect("Message.aspx?Msg=0???????????????????????"); } } /// <summary> /// ???????????son??????????????? /// </summary> public static string JsonEncode(object json) { return json.ToString().Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"); } /// <summary> /// ????????????????? /// </summary> public static string RndNumber(int l) { StringBuilder sb = new StringBuilder(l); Random rd = new Random(); for (int i = 0; i < l; i++) { sb.Append(rd.Next(10)); } return sb.ToString(); } /// <summary> /// ???????????? /// </summary> public static string Right(string str, int n) { return str.Substring(n > str.Length ? 0 : str.Length - n); } }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de