|
Server : Microsoft-IIS/10.0 System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586 User : jxgj ( 0) PHP Version : 7.0.33 Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server Directory : D:/tmp_aspnet/root/794bf435/a236a820/ |
?#pragma checksum "d:\wwwroot\sznzpj\wwwroot\App_Code\StringHelper.cs" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "6F05669CC05147B602AE1A7C73F2FC38"
#line 1 "d:\wwwroot\sznzpj\wwwroot\App_Code\StringHelper.cs"
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Web.UI.MobileControls;
using Model;
using System.Collections.Generic;
/// <summary>
///StringHelper 的提要注明
/// </summary>
public class StringHelper
{
//扩大名
public static readonly string ExtensionString = ConfigurationManager.ConnectionStrings["ExtensionString"].ConnectionString;
//首页
public static readonly string sy = ConfigurationManager.ConnectionStrings["sy"].ConnectionString;
//网站标题
public static readonly string webTitle = ConfigurationManager.ConnectionStrings["webTitle"].ConnectionString;
public static Dictionary<string, List<Images>> GetImgList()
{
Dictionary<string, List<Images>> d = new Dictionary<string, List<Images>>();
List<Images> list;
//默认
list = new List<Images>();
list.Add(new Images(2, "z_", 500, 493));
list.Add(new Images(1, "x_", 200, 150));
d.Add("Default", list);
//轮播图片
list = new List<Images>();
list.Add(new Images(1, "x_", 150, 61));
d.Add("lb", list);
//产品展示
list = new List<Images>();
list.Add(new Images(1, "sy_", 85, 73));
list.Add(new Images(3, "x_", 200, 150));
d.Add("Products", list);
//新闻动态
list = new List<Images>();
list.Add(new Images(3, "sy_", 174, 120));
d.Add("News", list);
//图片
list = new List<Images>();
list.Add(new Images(3, "x_", 200, 100));
d.Add("tu", list);
return d;
}
//返回封面图片
public static string GetImgUrl(string tableName, string x_,string FHimgUrl, int TID,int Order)
{
Images img = AccessManager.GetImages(tableName, TID, Order);
if (img != null)
return "Images/" + tableName + "/" + x_ + img.ImgUrl;
else
return FHimgUrl;
}
/// <summary>
/// 删除图片文件
/// </summary>
/// <param name="ImgUrl">图片蹊径</param>
/// <param name="ImgName">图片名称</param>
/// <param name="tableName">图片类型</param>
public static void DelImgFile(string ImgUrl,string ImgName, string tableName)
{
List<Images> list;
if (StringHelper.GetImgList().ContainsKey(tableName))
list = StringHelper.GetImgList()[tableName];
else
list = StringHelper.GetImgList()["Default"];
//缩列图
foreach (Images item in list)
if (File.Exists(ImgUrl + item.tableName + ImgName))
File.Delete(ImgUrl + item.tableName + ImgName);
//原图片
if (File.Exists(ImgUrl + ImgName))
File.Delete(ImgUrl + ImgName);
}
#region 字符串剪切
/// <summary>
/// 字符串剪切
/// </summary>
/// <param name="textStr">字符串</param>
/// <param name="length">返回长度</param>
/// <returns>返回剪切字符串</returns>
public static string CutString(string textStr, int length)
{
if (textStr.Length <= length)
return textStr;
else
return textStr.Substring(0, length - 1) + "…";
}
/// <summary>
/// 字符串剪切
/// </summary>
/// <param name="textStr">字符串</param>
/// <param name="length">返回长度</param>
/// <param name="fh">符号</param>
/// <returns>返回剪切字符串</returns>
public static string CutString(string textStr, int length, string fh)
{
if (textStr.Length <= length)
return textStr;
else
return textStr.Substring(0, length - 1) + fh;
}
#endregion
/// <summary>
/// Make分隔符
/// </summary>
/// <param name="count"></param>
/// <returns></returns>
public static string MakeFelgefu(int count)
{
string Returnwords = string.Empty;
if (count == 0)
{
Returnwords = "";
}
else
{
Returnwords = ("┗").PadLeft(count, ' ');
}
return Returnwords;
}
public static string GetContent(string content)
{
content = content.Replace(" ", " ");
content = content.Replace(Environment.NewLine, "<br /> ");
return content;
}
public static string GetContent2(string content)
{
content = content.Replace("/r", "/");
return content;
}
public static string GetContent3(string content)
{
content = content.Replace("/r", "<br />");
return content;
}
//url里有key的值,就代替为value,没有的话就追加.
public static string BuildUrl(string url, string ParamText, string ParamValue)
{
Regex reg = new Regex(string.Format("{0}=[^&]*", ParamText), RegexOptions.IgnoreCase);
Regex reg1 = new Regex("[&]{2,}", RegexOptions.IgnoreCase);
string _url = reg.Replace(url, "");
//_url = reg1.Replace(_url, "");
if (_url.IndexOf("?") == -1)
_url += string.Format("?{0}={1}", ParamText, ParamValue);//?
else
_url += string.Format("&{0}={1}", ParamText, ParamValue);//&
_url = reg1.Replace(_url, "&");
_url = _url.Replace("?&", "?");
return _url;
}
/// <summary>
/// 转换数字体式123,456
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string GetString(string str) //出租
{
//步骤一
if (!string.IsNullOrEmpty(str))
{
decimal p = 0;
decimal.TryParse(str, out p);
//return p.ToString("#,##0");
p = decimal.Round(p, 2);
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NumberDecimalDigits = 0;
return p.ToString("n", nfi);
}
else
{
return "";
}
}
#region Cookie
/// <summary>
/// 保留信息到Cookie
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void SetCookie(string key, string value, DateTime time)
{
HttpCookie cookie = new HttpCookie(key, value);
cookie.Expires = time;
HttpContext.Current.Response.Cookies.Add(cookie);
}
public static string MD5(string str)
{
byte[] bytes = Encoding.Default.GetBytes(str);
bytes = new MD5CryptoServiceProvider().ComputeHash(bytes);
string str2 = "";
for (int i = 0; i < bytes.Length; i++)
{
str2 = str2 + bytes[i].ToString("x").PadLeft(2, '0');
}
return str2;
}
/// <summary>
/// 获取Cookie信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetCookieValue(string key)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[key];
if (cookie == null)
{
return "";
}
return cookie.Value;
}
#endregion
#region 判断远程文件是否存在
///1.判断远程文件是否存在
///fileUrl:远程文件蹊径,蕴含IP地址以及具体的蹊径
public static bool RemoteFileExists(string fileUrl)
{
bool result = false;//下载了局
WebResponse response = null;
try
{
WebRequest req = WebRequest.Create(fileUrl);
response = req.GetResponse();
result = response == null ? false : true;
}
catch (Exception ex)
{
result = false;
}
finally
{
if (response != null)
{
response.Close();
}
}
return result;
}
#endregion
#region 关键字
/// <summary>
/// 查问第一个关键字扭转色彩
/// </summary>
/// <param name="text">显示内容</param>
/// <param name="key">关键字</param>
/// <param name="Color">字体色彩</param>
/// <returns></returns>
public static string SetKeyOne(string text, string key, string Color)
{
if (Color != "" && Color != null)
Color = string.Format(" style='color:{0};'", Color);
if (key == "")
{
return text;
}
else
{
string text2 = text.ToLower(); //全数转换为幼写,由于查找字符串时分辨大幼写
int weizhi = 0; //查找到子字符串的地位
int qidian = 0; //查找字符串的起点地位
weizhi = text2.IndexOf(key, qidian);
if (weizhi >= 0) //查找不到子字符串时返回-1,查到则执行
{
text = text.Insert(weizhi + key.Length, "</span>"); //在查到的子字符串后面加标签
text = text.Insert(weizhi, "<span " + Color + " class='sp'>"); //在查到的子字符串前面加标签
}
return text;
}
}
/// <summary>
/// 查问第一个关键字变超链接
/// </summary>
/// <param name="text">显示内容</param>
/// <param name="key">关键字</param>
/// <param name="URL">超链接</param>
/// <param name="Color">字体色彩</param>
/// <returns></returns>
public static string SetKeyOne(string text, string key, string URL, string Color)
{
if (Color != "" && Color != null)
Color = string.Format(" style='color:{0};'", Color);
if (key == "")
{
return text;
}
else
{
string text2 = text.ToLower(); //全数转换为幼写,由于查找字符串时分辨大幼写
int weizhi = 0; //查找到子字符串的地位
int qidian = 0; //查找字符串的起点地位
weizhi = text2.IndexOf(key, qidian);
if (weizhi >= 0) //查找不到子字符串时返回-1,查到则执行
{
text = text.Insert(weizhi + key.Length, "</a>"); //在查到的子字符串后面加标签
text = text.Insert(weizhi, string.Format("<a class='sp' {0} href='{1}' target='_blank' title='{2}'>", Color, URL, key)); //在查到的子字符串前面加标签
}
return text;
}
}
/// <summary>
/// 查问关键字扭转色彩
/// </summary>
/// <param name="text">显示内容</param>
/// <param name="key">关键字</param>
/// <param name="Color">字体色彩</param>
/// <returns></returns>
public static string SetKey(string text, string key, string Color)
{
if (Color != "" && Color != null)
Color = string.Format(" style='color:{0};'", Color);
if (key == "")
{
return text;
}
else
{
return Regex.Replace(text, key, "<span " + Color + " class='sp'>" + key + "</span>", RegexOptions.IgnoreCase);
}
}
/// <summary>
/// 查问关键字变超链接
/// </summary>
/// <param name="text">显示内容</param>
/// <param name="key">关键字</param>
/// <param name="URL">超链接</param>
/// <param name="Color">字体色彩</param>
/// <returns></returns>
public static string SetKey(string text, string key, string URL, string Color)
{
if (Color != "" && Color != null)
Color = string.Format(" style='color:{0};'", Color);
if (key == "")
{
return text;
}
else
{
return Regex.Replace(text, key, string.Format("<a class='sp' {0} href='{1}' target='_blank' title='{2}'>{2}</a>", Color, URL, key), RegexOptions.IgnoreCase);
}
}
#endregion
#region 断根html代码
/// <summary>
/// 断根html代码
/// </summary>
/// <param name="strHtml">HTML内容</param>
/// <param name="clearSpace">是否要断根空格</param>
/// <returns>Text文字</returns>
public static string ClearHtml(string strHtml, bool clearSpace)
{
if (strHtml != "")
{
Regex r = null;
Match m = null;
r = new Regex(@"<\/?[^>]*>", RegexOptions.IgnoreCase);
for (m = r.Match(strHtml); m.Success; m = m.NextMatch())
{
strHtml = strHtml.Replace(m.Groups[0].ToString().Trim(), "");
}//exit for
}//end if
if (clearSpace)
{
strHtml = Regex.Replace(strHtml, "\\s", "");
strHtml = strHtml.Replace(" ", "");
}
return strHtml;
}
/// <summary>
/// 断根html代码
/// </summary>
/// <param name="strHtml">HTML内容</param>
/// <param name="clearSpace">是否要断根空格</param>
/// <param name="length">返回文字长度</param>
/// <returns>Text文字</returns>
public static string ClearHtml(string strHtml, bool clearSpace, int length)
{
if (strHtml != "")
{
Regex r = null;
Match m = null;
r = new Regex(@"<\/?[^>]*>", RegexOptions.IgnoreCase);
for (m = r.Match(strHtml); m.Success; m = m.NextMatch())
{
strHtml = strHtml.Replace(m.Groups[0].ToString().Trim(), "");
}//exit for
}//end if
if (clearSpace)
{
strHtml = Regex.Replace(strHtml, "\\s", "");
strHtml = strHtml.Replace(" ", "");
}
return CutString(strHtml, length);
}
#endregion
#region MD5加密、解密
/// <summary>
/// MD5加密
/// </summary>
/// <param name="strSource">必要加密的字符串</param>
/// <returns>MD5加密后的字符串</returns>
public static string Md5Encrypt(string strSource)
{
//把字符串放到byte数组中
byte[] bytIn = System.Text.Encoding.Default.GetBytes(strSource); //成立加密对象的密钥和偏移量
byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//界说偏移量
byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//界说密钥
//事俘DES加密类
DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
mobjCryptoService.Key = iv;
mobjCryptoService.IV = key;
ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
//事俘MemoryStream流加密密文件
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
return System.Convert.ToBase64String(ms.ToArray());
}
/// <summary>
/// MD5解密
/// </summary>
/// <param name="Source">必要解密的字符串</param>
/// <returns>MD5解密后的字符串</returns>
public static string Md5Decrypt(string Source)
{
//将解密字符串转换成字节数组
byte[] bytIn = System.Convert.FromBase64String(Source);
//给出解密的密钥和偏移量,密钥和偏移量必须与加密时的密钥和偏移量一样
byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//界说偏移量
byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//界说密钥
DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
mobjCryptoService.Key = iv;
mobjCryptoService.IV = key;
//事俘流进行解密
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length);
ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
StreamReader strd = new StreamReader(cs, Encoding.Default);
return strd.ReadToEnd();
}
#endregion
}
#line default
#line hidden