GUI
来源:互联网 发布:win8 mac地址 编辑:程序博客网 时间:2024/05/16 01:47
只要添加引用System.Web.Extensions
在项目引用里添加 system.drawing.dll
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.Security.Cryptography;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Globalization;
using System.Text.RegularExpressions;
namespace PanSoft.Web
{
public class GUI
{
public GUI()
{
}
#region 参数
// public static string Constr = PubConstant.ConnectionString;//数据库连接字符串
public static string NoImagePath = "";
public static string IcoImagePath = "../Images/Ico";
public static string ProductImagePath = "/images/product";
public static int rep = 0;
//public static string OrderType = "ZD";
//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;
}
//url里有key的值,就替换为value,没有的话就追加.(去除关键字)
public static string BuildUrlNoKey(string url, string ParamText, string ParamValue)
{
string url1 = BuildUrl(url, "k", "");
url1 = BuildUrl(url1, ParamText, ParamValue);
return url1;
}
/// <summary>
/// 跳转错误页面
/// </summary>
/// <param name="page"></param>
public static void RedirectErorPage(Page page)
{
page.Response.Redirect("/error.htm");
}
/// <summary>
/// 没有权限访问页面
/// </summary>
/// <param name="page"></param>
public static void RedirectNoPower(Page page)
{
page.Response.Redirect("/nopwoer.htm");
}
/// <summary>
/// 获取客户端ip
/// </summary>
/// <returns></returns>
public static string getClientIP()
{
string userIP = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] == null)
{
userIP = HttpContext.Current.Request.UserHostAddress;
}
else
{
userIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
}
return userIP;
// return HttpContext.Current.Request.UserHostAddress.ToString().Trim();
}
/// <summary>
/// 写入文件
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <param name="contents"></param>
public static void WriteFile(string path, string filename, string contents, Page page)
{
//写入文件
//创建文件夹
AutoCreatDir(page.Server.MapPath(path));
path = path + "/" + filename;
//打开或者创建文件
FileStream fs = new FileStream(page.Server.MapPath(path), FileMode.OpenOrCreate);
//如果原来存在文件则 清空原来文件的内容
fs.SetLength(0);
//创建文本写入流
StreamWriter st = new StreamWriter(fs, Encoding.UTF8);
//将字符串写入文件
st.WriteLine(contents);
//关闭流
st.Close();
fs.Close();
}
/// <summary>
/// 删除指定的html标签
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
public static string RemoveSpecifyHtml(string ctx)
{
string[] holdTags = { "a", "img", "br", "strong", "b", "span", "li" };//保留的 tag
// <(?!((/?\s?li\b)|(/?\s?ul\b)|(/?\s?a\b)|(/?\s?img\b)|(/?\s?br\b)|(/?\s?span\b)|(/?\s?b\b)))[^>]+>
string regStr = string.Format(@"<(?!((/?\s?{0})))[^>]+>", string.Join(@"\b)|(/?\s?", holdTags));
Regex reg = new Regex(regStr, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
return reg.Replace(ctx, "");
}
//判断是否整数
/// <summary>
/// 判断是否整数
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsInteger(object sNum)
{
int num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (int.TryParse(sNum.ToString(), out num))
{
//成功返回True
return true;
}
else
{
//失败返回False
return false;
}
}
//
/// <summary>
/// 判断是否正数包含正小数
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsPositiveNumber(object sNum)
{
decimal num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (decimal.TryParse(sNum.ToString(), out num))
{
if (num > 0)
{
//成功返回True
return true;
}
else
{
return false;
}
}
else
{
//失败返回False
return false;
}
}
//判断是否正数
public static bool IsPositiveNumberOrLing(object sNum)
{
decimal num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (decimal.TryParse(sNum.ToString(), out num))
{
if (num >= 0)
{
//成功返回True
return true;
}
else
{
return false;
}
}
else
{
//失败返回False
return false;
}
}
/// <summary>
/// 判断是否为时间格式
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsDateTime(object sNum)
{
DateTime num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (DateTime.TryParse(sNum.ToString(), out num))
{
//成功返回True
return true;
}
else
{
//失败返回False
return false;
}
}
/// <summary>
/// 验证是否为手机号
/// </summary>
/// <param name="str_handset"></param>
/// <returns></returns>
public static bool IsHandset(string str_handset)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^[1]+[3,5,8]+\d{9}");
}
/// <summary>
/// 验证邮政编码
/// </summary>
/// <param name="str_postalcode"></param>
/// <returns></returns>
public bool IsPostalcode(string str_postalcode)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$");
}
/// <summary>
/// 判断是否为正整数
/// </summary>
/// <param name="strValue"></param>
/// <returns>是正整数返回true,不是返回false</returns>
public static bool isNumber(string strValue)
{
Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
return regex.IsMatch(strValue.Trim());
}
/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name="Htmlstring">包括HTML标签的源码</param>
/// <returns>已经去除后的文字</returns>
public static string NoHTML(string Htmlstring)
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
/// <summary>
/// 脏字过滤
/// </summary>
/// <param name="content"></param>
/// <param name="dirty"></param>
/// <returns></returns>
public static string Dirty_Filter(string content, string dirty)
{
return Regex.Replace(content, dirty, "***", RegexOptions.IgnoreCase);
}
/// <summary>
/// 换行替换
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string Line_Replace(string content)
{
return content.Replace("<br>", "\n").Replace("<br />", "\n").Replace("<br/>", "\n");
}
/// <summary>
/// 换行反替换
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string Line_UnReplace(string content)
{
return content.Replace("\n", "<br />");
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(object obj, object count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(object obj, string count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(string obj, string count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 获取CheckBoxList选中的值
/// </summary>
/// <param name="cbk"></param>
/// <returns></returns>
public static string get_CheckBoxList_Select(CheckBoxList cbk)
{
string ss = ",";
foreach (ListItem item in cbk.Items)
{
if (item.Selected == true)
{
ss = ss + item.Value + ",";
}
}
if (ss.Length == 1)
{
return "";
}
else
{
return ss.Substring(1, ss.Length - 2);
}
}
/// <summary>
/// 换行替换
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strHHReplace(string str)
{
return str.Replace("\n", "<br />");
}
/// <summary>
/// 换行反替换
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strHHUnRelpace(string str)
{
return str.Replace("<br />", "\n");
}
/// <summary>
/// 发送邮件
/// </summary>
/// <returns></returns>
public static string PostMail(string Smtp, int Port, string Usr, string Pwd, string From, string FromName, string To, string ToName, string Subject, string Body)
{
MailMessage email = new MailMessage(new MailAddress(From, FromName), new MailAddress(To, ToName));
email.BodyEncoding = Encoding.UTF8;
email.IsBodyHtml = true;
email.Subject = Subject;
email.Body = Body;
SmtpClient Client = new SmtpClient(Smtp, Port);
Client.UseDefaultCredentials = false;
Client.Credentials = new NetworkCredential(Usr, Pwd);
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
Client.Send(email);
return "true";
}
catch
{
return "发送失败!";
}
}
/// <summary>
/// ajax弹出提示框
/// </summary>
public static void Alert(string key, string info, UpdatePanel up)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');</script>", false);
}
/// <summary>
/// ajax弹出Dialog_Prompt提示框
/// </summary>
public static void AlertDialog_Prompt(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'提示',content: '" + message + "',max: false,min: false,lock:true});</script>");
}
/// <summary>
/// ajax弹出Dialog_Prompt 2s自动关闭提示框
/// </summary>
public static void AlertDialog_Prompt_2s(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'2秒自动关闭',content: '" + message + "',max: false,min: false,lock:true,time:2});</script>");
}
public static void AlertDialog_Prompt_Refresh(string message, Page page,string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '" + message + "',max: false,min: false,lock:true,ok:function(){window.location.href='"+url+"'}});</script>");
}
/// <summary>
/// ajax框架页面跳转
/// </summary>
public static void AlertAndRedirect(string key, string info, UpdatePanel up, string url)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');parent.location.href='" + url + "'</script>", false);
}
/// <summary>
/// 弹出提示框并跳转页面
/// </summary>
public static void AlertAndRedirect(string key, string info, UpdatePanel up, string url, bool bn)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');window.location.href='" + url + "'</script>", bn);
}
/// <summary>
/// ajax执行js方法
/// </summary>
public static void RunJs(string key, UpdatePanel up, string method)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>" + method + "</script>", false);
}
/// <summary>
/// 弹出提示框
/// </summary>
public static void Alert(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + message.Trim() + "\");</script>");
//page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'警告',content: '" + message.Trim() + "',max: false,min: false,lock:true,heigt:300,width:400});;</script>");
}
/// <summary>
/// 执行js
/// </summary>
/// <param name="js"></param>
/// <param name="page"></param>
public static void RunJs(string js, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>" + js + "</script>");
}
/// <summary>
/// 弹出提示框,并跳转页面
/// </summary>
public static void AlertAndRedirect(string message, string url, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + message.Trim() + "\");window.location.href='" + url + "'</script>");
}
public static void CloseAndRefreshParent(Page page, string msg)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href=window.parent.location.href</script>");
}
public static void CloseAndRefreshParent(UpdatePanel up, string msg)
{
//保存完成后弹出提示并刷新父窗口
GUI.RunJs("a0", up, "alert('" + msg + "');window.parent.location.href=window.parent.location.href");
}
public static void Dialog_Session_Index(Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>window.parent.location.href='login.aspx'</script>");
// page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '长时间未进行操作,为安全期间请重新登录',max: false,min: false,lock:true,ok: function(){window.parent.location.href='login.aspx'}});</script>");
}
public static void CloseAndRefreshParent(Page page, string msg, string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href='" + url + "'</script>");
}
public static void Dialog_CloseAndRefreshParent(Page page, string msg, string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href='" + url + "'</script>");
// page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '" + msg.Trim() + "',max: false,min: false,lock:true,ok: function(){window.parent.location.href='" + url + "'}});</script>");
}
public static void CloseAndRefreshParent(UpdatePanel up, string msg, string url)
{
//保存完成后弹出提示并刷新父窗口
GUI.RunJs("a0", up, "alert('" + msg + "');window.parent.location.href='" + url + "'"); ;
}
/// <summary>
/// md5加密
/// </summary>
public static string MD5(string Scode)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Scode.Trim(), "MD5").ToLower();
}
/// <summary>
/// 自动创建文件夹
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public static bool AutoCreatDir(string Path)
{
if (Directory.Exists(Path) == false) //检查主目录File是否存在
{
try
{
DirectoryInfo info = new DirectoryInfo(Path);
info.Create();
return true;
}
catch
{
return false;
}
}
else
{
return true;
}
}
/// <summary>
/// 获取文件夹大小
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public static long GetDirectoryLength(string dirPath)
{
if (!Directory.Exists(dirPath))
{
return 0;
}
long len = 0;
DirectoryInfo di = new DirectoryInfo(dirPath);
foreach (FileInfo fi in di.GetFiles())
{
len += fi.Length;
}
DirectoryInfo[] dis = di.GetDirectories();
if (dis.Length > 0)
{
for (int i = 0; i < dis.Length; i++)
{
len += GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
/// <summary>
/// 根据文本选中dropdownlist
/// </summary>
/// <param name="DDL"></param>
/// <param name="Title"></param>
public static void DropDownListSelByTitle(DropDownList DDL, string Title)
{
for (int i = 0; i < DDL.Items.Count; i++)
{
DDL.Items[i].Selected = false;
}
for (int i = 0; i < DDL.Items.Count; i++)
{
if (DDL.Items[i].Text == Title)
{
DDL.Items[i].Selected = true;
break;
}
}
}
public static string GetDateTimeNow()
{
return DateTime.Now.ToString("yyyyMMdd");
}
public static void CopyFile(string SourceFile, string ObjectFile)
{
string sourceFile = HttpContext.Current.Server.MapPath(SourceFile);
string objectFile = HttpContext.Current.Server.MapPath(ObjectFile);
if (System.IO.File.Exists(sourceFile))
{
System.IO.File.Copy(sourceFile, objectFile, true);
}
}
/// <summary>
/// 上传图片
/// </summary>
public static string UpImage(HttpPostedFile ImageFile, string TmpPath, string MainName)
{
if (ImageFile.FileName.Trim().Length < 4)
{
return "";
}
if (TestDisplayFile(ImageFile.FileName) == false)
{
return "";
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
}
catch { }
ImageFile.SaveAs(Path + "\\" + filename);
return filename;
}
/// <summary>
/// 上传文件
/// </summary>
public static string UpFile(HttpPostedFile ImageFile, string TmpPath, string MainName)
{
if (ImageFile.FileName.Trim().Length < 4)
{
return "";
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
}
catch
{
}
ImageFile.SaveAs(Path + "\\" + filename);
return filename;
}
/// <summary>
/// 上传图片
/// </summary>
public static string UpImage(HttpPostedFile ImageFile, string TmpPath, string MainName, string name)
{
int num = ImageFile.FileName.Trim().Length;
if (ImageFile.FileName.Trim().Length < 4)
{
return NoImagePath;
}
if (TestDisplayFile(ImageFile.FileName) == false)
{
return NoImagePath;
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + name + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
ImageFile.SaveAs(Path + "\\" + filename);
}
catch { }
return filename;
}
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="originalImagePath">源图路径(物理路径)</param>
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">生成缩略图的方式</param>
public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);
int towidth = width;
int toheight = height;
int x = 0;
int y = 0;
int ow = originalImage.Width;
int oh = originalImage.Height;
switch (mode)
{
case "HW"://指定高宽缩放(可能变形)
break;
case "W"://指定宽,高按比例
toheight = originalImage.Height * width / originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height / originalImage.Height;
break;
case "Cut"://指定高宽裁减(不变形)
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
{
oh = originalImage.Height;
ow = originalImage.Height * towidth / toheight;
y = 0;
x = (originalImage.Width - ow) / 2;
}
else
{
ow = originalImage.Width;
oh = originalImage.Width * height / towidth;
x = 0;
y = (originalImage.Height - oh) / 2;
}
break;
default:
break;
}
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);
try
{
//以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception)
{
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
/// <summary>
/// 判断上传文件的类型
/// </summary>
public static bool TestDisplayFile(string filename)
{
string[] extendname = { ".gif", "jpeg", ".jpg", ".bmp", ".png", ".swf", ".eps", ".flash", ".xls" };
string transname = filename.Substring(filename.Length - 4, 4);
for (int i = 0; i < extendname.Length; i++)
{
if (extendname[i] == transname.ToLower())
{
return true;
}
}
return false;
}
/// <summary>
/// 生成随机字母字符串(数字字母混和)
/// </summary>
/// <param name="codeCount">待生成的位数</param>
/// <returns>生成的字母字符串</returns>
public static string GenerateCheckCode(int codeCount)
{
string str = string.Empty;
long num2 = DateTime.Now.Ticks + rep;
rep++;
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep)));
for (int i = 0; i < codeCount; i++)
{
char ch;
int num = random.Next();
if ((num % 2) == 0)
{
ch = (char)(0x30 + ((ushort)(num % 10)));
}
else
{
ch = (char)(0x41 + ((ushort)(num % 0x1a)));
}
str = str + ch.ToString();
}
return str;
}
/// <summary>
/// 获得数字形式的随机字符串
/// </summary>
/// <returns>数字形式的随机字符串</returns>
public static string mikecat_GetNumberRandom()
{
int mikecat_intNum;
long mikecat_lngNum;
string mikecat_strNum = System.DateTime.Now.ToString();
mikecat_strNum = mikecat_strNum.Replace(":", "");
mikecat_strNum = mikecat_strNum.Replace("-", "");
mikecat_strNum = mikecat_strNum.Replace(" ", "");
mikecat_strNum = mikecat_strNum.Replace("/", "");
mikecat_lngNum = long.Parse(mikecat_strNum);
System.Random mikecat_ran = new Random();
mikecat_intNum = mikecat_ran.Next(1, 99999);
mikecat_ran = null;
mikecat_lngNum += mikecat_intNum;
return mikecat_lngNum.ToString();
}
/// <summary>
/// 文件后缀名的枚举
/// </summary>
public enum FileExtension
{
XLS = 208207,
JPG = 255216,
GIF = 7173,
BMP = 6677,
PNG = 13780
}
/// <summary>
/// 顾客类型的枚举
/// </summary>
public enum MemberType
{
pub = 0,
member = 1,
network = 2
}
/// <summary>
/// 判断文件的后缀名
/// </summary>
/// <param name="fu"></param>
/// <param name="fileEx"></param>
/// <returns></returns>
public static bool IsAllowedExtension(FileUpload fu, FileExtension[] fileEx)
{
int fileLen = fu.PostedFile.ContentLength;
byte[] imgArray = new byte[fileLen];
fu.PostedFile.InputStream.Read(imgArray, 0, fileLen);
MemoryStream ms = new MemoryStream(imgArray);
System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
string fileclass = "";
byte buffer;
try
{
buffer = br.ReadByte();
fileclass = buffer.ToString();
buffer = br.ReadByte();
fileclass += buffer.ToString();
}
catch (Exception)
{
}
br.Close();
ms.Close();
foreach (FileExtension fe in fileEx)
{
if (Int32.Parse(fileclass) == (int)fe)
return true;
}
return false;
}
/// <summary>
/// 绑定类型 下拉列表
/// </summary>
/// <param name="ddl"></param>
/// <param name="typeID"></param>
/// <param name="Texts"></param>
//public static void BindTypeDropDownList(DropDownList ddl, int typeID, string Texts,bool TextIsText)
//{
// PanSoft.BLL.TypeInfo b = new PanSoft.BLL.TypeInfo();
// ddl.DataSource = b.GetList("parentID=" + typeID + "");
// ddl.DataTextField = "typeName";
// if (TextIsText)
// {
// ddl.DataValueField = "typeName";
// }
// else
// {
// ddl.DataValueField = "ID";
// }
// ddl.DataBind();
// ddl.Items.Insert(0, new ListItem("请选择"+Texts, "-1"));
//}
//public static void SelectDropDownListItems(DropDownList ddl,string SelectValue,bool isFindText)
//{
// try
// {
// ListItem d = new ListItem();
// if (isFindText)
// {
// d = ddl.Items.FindByText(SelectValue);
// }
// else
// {
// d = ddl.Items.FindByValue(SelectValue);
// }
// if (d.Value != null)
// {
// d.Selected = true;
// }
// }
// catch
// {
// }
//}
//天干
private static string[] TianGan = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
//地支
private static string[] DiZhi = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
//十二生肖
private static string[] ShengXiao = { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
//农历日期
//private static string[] DayName = {"*","初一","初二","初三","初四","初五",
// "初六","初七","初八","初九","初十",
// "十一","十二","十三","十四","十五",
// "十六","十七","十八","十九","二十",
// "廿一","廿二","廿三","廿四","廿五",
// "廿六","廿七","廿八","廿九","三十"};
private static string[] DayName = {"*","1","2","3","4","5",
"6","7","8","9","10",
"11","12","13","14","15",
"16","17","18","19","20",
"21","22","23","24","25",
"26","27","28","29","30"};
//农历月份
//private static string[] MonthName = { "*", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊" };
private static string[] MonthName = { "*", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
//公历月计数天
private static int[] MonthAdd = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
//农历数据
private static int[] LunarData = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395
,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031
,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222
,268949,3402,3493,133973,1386,464219,605,2349,334123,2709
,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
/// <summary>
/// 获取对应日期的农历
/// </summary>
/// <param name="dtDay">公历日期</param>
/// <returns></returns>
public static string GetLunarCalendar(DateTime dtDay)
{
string sYear = dtDay.Year.ToString();
string sMonth = dtDay.Month.ToString();
string sDay = dtDay.Day.ToString();
int year;
int month;
int day;
try
{
year = int.Parse(sYear);
month = int.Parse(sMonth);
day = int.Parse(sDay);
}
catch
{
year = DateTime.Now.Year;
month = DateTime.Now.Month;
day = DateTime.Now.Day;
}
int nTheDate;
int nIsEnd;
int k, m, n, nBit, i;
string calendar = string.Empty;
//计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
nTheDate = (year - 1921) * 365 + (year - 1921) / 4 + day + MonthAdd[month - 1] - 38;
if ((year % 4 == 0) && (month > 2))
nTheDate += 1;
//计算天干,地支,月,日
nIsEnd = 0;
m = 0;
k = 0;
n = 0;
while (nIsEnd != 1)
{
if (LunarData[m] < 4095)
k = 11;
else
k = 12;
n = k;
while (n >= 0)
{
//获取LunarData[m]的第n个二进制位的值
nBit = LunarData[m];
for (i = 1; i < n + 1; i++)
nBit = nBit / 2;
nBit = nBit % 2;
if (nTheDate <= (29 + nBit))
{
nIsEnd = 1;
break;
}
nTheDate = nTheDate - 29 - nBit;
n = n - 1;
}
if (nIsEnd == 1)
break;
m = m + 1;
}
year = 1921 + m;
month = k - n + 1;
day = nTheDate;
//return year + "-" + month + "-" + day;
if (k == 12)
{
if (month == LunarData[m] / 65536 + 1)
month = 1 - month;
else if (month > LunarData[m] / 65536 + 1)
month = month - 1;
}
//年
// calendar = year + ".";
//生肖
//calendar += ShengXiao[(year - 4) % 60 % 12].ToString() + ". ";
// //天干
// calendar += TianGan[(year - 4) % 60 % 10].ToString();
// //地支
//calendar += DiZhi[(year - 4) % 60 % 12].ToString() + " ";
//农历月
if (month < 1)
calendar += "闰" + MonthName[-1 * month].ToString() + ".";
else
calendar += MonthName[month].ToString() + "-";
//农历日
calendar += DayName[day].ToString() + "";
string[] shijianS = calendar.Split('-');
string yue = shijianS[0];
if (shijianS[0].Length == 1)
{
yue="0"+shijianS[0];
}
string tian = shijianS[1];
if (shijianS[1].Length == 1)
{
tian="0"+shijianS[1];
}
return yue+"-"+tian;
}
/// <summary>
/// 加密
/// </summary>
/// <param name="rs"></param>
/// <returns></returns>
public static string DESEncryptMethod(string rs)
{
byte[] desKey = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
byte[] desIV = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
try
{
byte[] inputByteArray = Encoding.Default.GetBytes(rs);
//byte[] inputByteArray=Encoding.Unicode.GetBytes(rs);
des.Key = desKey; // ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = desIV; //ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),
CryptoStreamMode.Write);
//Write the byte array into the crypto stream
//(It will end up in the memory stream)
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the data back from the memory stream, and into a string
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
//Format as hex
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
catch
{
return rs;
}
finally
{
des = null;
}
}
/// <summary>
/// 解密
/// </summary>
/// <param name="rs"></param>
/// <returns></returns>
public static string DESDecryptMethod(string rs)
{
byte[] desKey = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
byte[] desIV = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
try
{
//Put the input string into the byte array
byte[] inputByteArray = new byte[rs.Length / 2];
for (int x = 0; x < rs.Length / 2; x++)
{
int i = (Convert.ToInt32(rs.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = desKey; //ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = desIV; //ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
//Flush the data through the crypto stream into the memory stream
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the decrypted data back from the memory stream
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
catch
{
return rs;
}
finally
{
des = null;
}
}
//public static void checkAdmin(Page page)
//{
// if(HttpContext.Current.Session["admin"]==null)
// {
// AlertDialog_Prompt_Refresh("登录时间超时或者未登录,请登录",page,"login.aspx");
// }
//}
}
}
#endregion
只要添加引用System.Web.Extensions
在项目引用里添加 system.drawing.dll
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.Security.Cryptography;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Globalization;
using System.Text.RegularExpressions;
namespace PanSoft.Web
{
public class GUI
{
public GUI()
{
}
#region 参数
// public static string Constr = PubConstant.ConnectionString;//数据库连接字符串
public static string NoImagePath = "";
public static string IcoImagePath = "../Images/Ico";
public static string ProductImagePath = "/images/product";
public static int rep = 0;
//public static string OrderType = "ZD";
//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;
}
//url里有key的值,就替换为value,没有的话就追加.(去除关键字)
public static string BuildUrlNoKey(string url, string ParamText, string ParamValue)
{
string url1 = BuildUrl(url, "k", "");
url1 = BuildUrl(url1, ParamText, ParamValue);
return url1;
}
/// <summary>
/// 跳转错误页面
/// </summary>
/// <param name="page"></param>
public static void RedirectErorPage(Page page)
{
page.Response.Redirect("/error.htm");
}
/// <summary>
/// 没有权限访问页面
/// </summary>
/// <param name="page"></param>
public static void RedirectNoPower(Page page)
{
page.Response.Redirect("/nopwoer.htm");
}
/// <summary>
/// 获取客户端ip
/// </summary>
/// <returns></returns>
public static string getClientIP()
{
string userIP = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] == null)
{
userIP = HttpContext.Current.Request.UserHostAddress;
}
else
{
userIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
}
return userIP;
// return HttpContext.Current.Request.UserHostAddress.ToString().Trim();
}
/// <summary>
/// 写入文件
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <param name="contents"></param>
public static void WriteFile(string path, string filename, string contents, Page page)
{
//写入文件
//创建文件夹
AutoCreatDir(page.Server.MapPath(path));
path = path + "/" + filename;
//打开或者创建文件
FileStream fs = new FileStream(page.Server.MapPath(path), FileMode.OpenOrCreate);
//如果原来存在文件则 清空原来文件的内容
fs.SetLength(0);
//创建文本写入流
StreamWriter st = new StreamWriter(fs, Encoding.UTF8);
//将字符串写入文件
st.WriteLine(contents);
//关闭流
st.Close();
fs.Close();
}
/// <summary>
/// 删除指定的html标签
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
public static string RemoveSpecifyHtml(string ctx)
{
string[] holdTags = { "a", "img", "br", "strong", "b", "span", "li" };//保留的 tag
// <(?!((/?\s?li\b)|(/?\s?ul\b)|(/?\s?a\b)|(/?\s?img\b)|(/?\s?br\b)|(/?\s?span\b)|(/?\s?b\b)))[^>]+>
string regStr = string.Format(@"<(?!((/?\s?{0})))[^>]+>", string.Join(@"\b)|(/?\s?", holdTags));
Regex reg = new Regex(regStr, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
return reg.Replace(ctx, "");
}
//判断是否整数
/// <summary>
/// 判断是否整数
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsInteger(object sNum)
{
int num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (int.TryParse(sNum.ToString(), out num))
{
//成功返回True
return true;
}
else
{
//失败返回False
return false;
}
}
//
/// <summary>
/// 判断是否正数包含正小数
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsPositiveNumber(object sNum)
{
decimal num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (decimal.TryParse(sNum.ToString(), out num))
{
if (num > 0)
{
//成功返回True
return true;
}
else
{
return false;
}
}
else
{
//失败返回False
return false;
}
}
//判断是否正数
public static bool IsPositiveNumberOrLing(object sNum)
{
decimal num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (decimal.TryParse(sNum.ToString(), out num))
{
if (num >= 0)
{
//成功返回True
return true;
}
else
{
return false;
}
}
else
{
//失败返回False
return false;
}
}
/// <summary>
/// 判断是否为时间格式
/// </summary>
/// <param name="sNum"></param>
/// <returns></returns>
public static bool IsDateTime(object sNum)
{
DateTime num; //临时变量
if (sNum == null)
{
//如果传入的值为NULL,返回False
return false;
}
//尝试转换传入的值
if (DateTime.TryParse(sNum.ToString(), out num))
{
//成功返回True
return true;
}
else
{
//失败返回False
return false;
}
}
/// <summary>
/// 验证是否为手机号
/// </summary>
/// <param name="str_handset"></param>
/// <returns></returns>
public static bool IsHandset(string str_handset)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^[1]+[3,5,8]+\d{9}");
}
/// <summary>
/// 验证邮政编码
/// </summary>
/// <param name="str_postalcode"></param>
/// <returns></returns>
public bool IsPostalcode(string str_postalcode)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$");
}
/// <summary>
/// 判断是否为正整数
/// </summary>
/// <param name="strValue"></param>
/// <returns>是正整数返回true,不是返回false</returns>
public static bool isNumber(string strValue)
{
Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
return regex.IsMatch(strValue.Trim());
}
/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name="Htmlstring">包括HTML标签的源码</param>
/// <returns>已经去除后的文字</returns>
public static string NoHTML(string Htmlstring)
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
/// <summary>
/// 脏字过滤
/// </summary>
/// <param name="content"></param>
/// <param name="dirty"></param>
/// <returns></returns>
public static string Dirty_Filter(string content, string dirty)
{
return Regex.Replace(content, dirty, "***", RegexOptions.IgnoreCase);
}
/// <summary>
/// 换行替换
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string Line_Replace(string content)
{
return content.Replace("<br>", "\n").Replace("<br />", "\n").Replace("<br/>", "\n");
}
/// <summary>
/// 换行反替换
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string Line_UnReplace(string content)
{
return content.Replace("\n", "<br />");
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(object obj, object count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(object obj, string count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 根据内容和页面上显示的字数进行截取
/// </summary>
public static string get_Content(string obj, string count)
{
int num = int.Parse(count.ToString());//要截取的字数
string content = "";
if (obj == null)
{
content = "";
}
else
{
content = NoHTML(obj.ToString());
if (content.Length > num)
{
content = content.Substring(0, num);
}
}
return content;
}
/// <summary>
/// 获取CheckBoxList选中的值
/// </summary>
/// <param name="cbk"></param>
/// <returns></returns>
public static string get_CheckBoxList_Select(CheckBoxList cbk)
{
string ss = ",";
foreach (ListItem item in cbk.Items)
{
if (item.Selected == true)
{
ss = ss + item.Value + ",";
}
}
if (ss.Length == 1)
{
return "";
}
else
{
return ss.Substring(1, ss.Length - 2);
}
}
/// <summary>
/// 换行替换
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strHHReplace(string str)
{
return str.Replace("\n", "<br />");
}
/// <summary>
/// 换行反替换
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strHHUnRelpace(string str)
{
return str.Replace("<br />", "\n");
}
/// <summary>
/// 发送邮件
/// </summary>
/// <returns></returns>
public static string PostMail(string Smtp, int Port, string Usr, string Pwd, string From, string FromName, string To, string ToName, string Subject, string Body)
{
MailMessage email = new MailMessage(new MailAddress(From, FromName), new MailAddress(To, ToName));
email.BodyEncoding = Encoding.UTF8;
email.IsBodyHtml = true;
email.Subject = Subject;
email.Body = Body;
SmtpClient Client = new SmtpClient(Smtp, Port);
Client.UseDefaultCredentials = false;
Client.Credentials = new NetworkCredential(Usr, Pwd);
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
Client.Send(email);
return "true";
}
catch
{
return "发送失败!";
}
}
/// <summary>
/// ajax弹出提示框
/// </summary>
public static void Alert(string key, string info, UpdatePanel up)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');</script>", false);
}
/// <summary>
/// ajax弹出Dialog_Prompt提示框
/// </summary>
public static void AlertDialog_Prompt(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'提示',content: '" + message + "',max: false,min: false,lock:true});</script>");
}
/// <summary>
/// ajax弹出Dialog_Prompt 2s自动关闭提示框
/// </summary>
public static void AlertDialog_Prompt_2s(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'2秒自动关闭',content: '" + message + "',max: false,min: false,lock:true,time:2});</script>");
}
public static void AlertDialog_Prompt_Refresh(string message, Page page,string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '" + message + "',max: false,min: false,lock:true,ok:function(){window.location.href='"+url+"'}});</script>");
}
/// <summary>
/// ajax框架页面跳转
/// </summary>
public static void AlertAndRedirect(string key, string info, UpdatePanel up, string url)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');parent.location.href='" + url + "'</script>", false);
}
/// <summary>
/// 弹出提示框并跳转页面
/// </summary>
public static void AlertAndRedirect(string key, string info, UpdatePanel up, string url, bool bn)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>alert('" + info + "');window.location.href='" + url + "'</script>", bn);
}
/// <summary>
/// ajax执行js方法
/// </summary>
public static void RunJs(string key, UpdatePanel up, string method)
{
ScriptManager.RegisterStartupScript(up, typeof(string), key, "<script>" + method + "</script>", false);
}
/// <summary>
/// 弹出提示框
/// </summary>
public static void Alert(string message, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + message.Trim() + "\");</script>");
//page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'警告',content: '" + message.Trim() + "',max: false,min: false,lock:true,heigt:300,width:400});;</script>");
}
/// <summary>
/// 执行js
/// </summary>
/// <param name="js"></param>
/// <param name="page"></param>
public static void RunJs(string js, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>" + js + "</script>");
}
/// <summary>
/// 弹出提示框,并跳转页面
/// </summary>
public static void AlertAndRedirect(string message, string url, Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + message.Trim() + "\");window.location.href='" + url + "'</script>");
}
public static void CloseAndRefreshParent(Page page, string msg)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href=window.parent.location.href</script>");
}
public static void CloseAndRefreshParent(UpdatePanel up, string msg)
{
//保存完成后弹出提示并刷新父窗口
GUI.RunJs("a0", up, "alert('" + msg + "');window.parent.location.href=window.parent.location.href");
}
public static void Dialog_Session_Index(Page page)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>window.parent.location.href='login.aspx'</script>");
// page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '长时间未进行操作,为安全期间请重新登录',max: false,min: false,lock:true,ok: function(){window.parent.location.href='login.aspx'}});</script>");
}
public static void CloseAndRefreshParent(Page page, string msg, string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href='" + url + "'</script>");
}
public static void Dialog_CloseAndRefreshParent(Page page, string msg, string url)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>alert(\"" + msg.Trim() + "\");window.parent.location.href='" + url + "'</script>");
// page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script>$.dialog({title:'消息提示',content: '" + msg.Trim() + "',max: false,min: false,lock:true,ok: function(){window.parent.location.href='" + url + "'}});</script>");
}
public static void CloseAndRefreshParent(UpdatePanel up, string msg, string url)
{
//保存完成后弹出提示并刷新父窗口
GUI.RunJs("a0", up, "alert('" + msg + "');window.parent.location.href='" + url + "'"); ;
}
/// <summary>
/// md5加密
/// </summary>
public static string MD5(string Scode)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Scode.Trim(), "MD5").ToLower();
}
/// <summary>
/// 自动创建文件夹
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public static bool AutoCreatDir(string Path)
{
if (Directory.Exists(Path) == false) //检查主目录File是否存在
{
try
{
DirectoryInfo info = new DirectoryInfo(Path);
info.Create();
return true;
}
catch
{
return false;
}
}
else
{
return true;
}
}
/// <summary>
/// 获取文件夹大小
/// </summary>
/// <param name="dirPath"></param>
/// <returns></returns>
public static long GetDirectoryLength(string dirPath)
{
if (!Directory.Exists(dirPath))
{
return 0;
}
long len = 0;
DirectoryInfo di = new DirectoryInfo(dirPath);
foreach (FileInfo fi in di.GetFiles())
{
len += fi.Length;
}
DirectoryInfo[] dis = di.GetDirectories();
if (dis.Length > 0)
{
for (int i = 0; i < dis.Length; i++)
{
len += GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
/// <summary>
/// 根据文本选中dropdownlist
/// </summary>
/// <param name="DDL"></param>
/// <param name="Title"></param>
public static void DropDownListSelByTitle(DropDownList DDL, string Title)
{
for (int i = 0; i < DDL.Items.Count; i++)
{
DDL.Items[i].Selected = false;
}
for (int i = 0; i < DDL.Items.Count; i++)
{
if (DDL.Items[i].Text == Title)
{
DDL.Items[i].Selected = true;
break;
}
}
}
public static string GetDateTimeNow()
{
return DateTime.Now.ToString("yyyyMMdd");
}
public static void CopyFile(string SourceFile, string ObjectFile)
{
string sourceFile = HttpContext.Current.Server.MapPath(SourceFile);
string objectFile = HttpContext.Current.Server.MapPath(ObjectFile);
if (System.IO.File.Exists(sourceFile))
{
System.IO.File.Copy(sourceFile, objectFile, true);
}
}
/// <summary>
/// 上传图片
/// </summary>
public static string UpImage(HttpPostedFile ImageFile, string TmpPath, string MainName)
{
if (ImageFile.FileName.Trim().Length < 4)
{
return "";
}
if (TestDisplayFile(ImageFile.FileName) == false)
{
return "";
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
}
catch { }
ImageFile.SaveAs(Path + "\\" + filename);
return filename;
}
/// <summary>
/// 上传文件
/// </summary>
public static string UpFile(HttpPostedFile ImageFile, string TmpPath, string MainName)
{
if (ImageFile.FileName.Trim().Length < 4)
{
return "";
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
}
catch
{
}
ImageFile.SaveAs(Path + "\\" + filename);
return filename;
}
/// <summary>
/// 上传图片
/// </summary>
public static string UpImage(HttpPostedFile ImageFile, string TmpPath, string MainName, string name)
{
int num = ImageFile.FileName.Trim().Length;
if (ImageFile.FileName.Trim().Length < 4)
{
return NoImagePath;
}
if (TestDisplayFile(ImageFile.FileName) == false)
{
return NoImagePath;
}
string Path = System.Web.HttpContext.Current.Server.MapPath(TmpPath);
string Expname = ImageFile.FileName.Substring(ImageFile.FileName.Trim().Length - 4, 4);
Expname = Expname.Replace(".", "");
string filename = MainName + name + "." + Expname;
AutoCreatDir(Path);
try
{
System.IO.File.Delete(Path + "\\" + filename);
ImageFile.SaveAs(Path + "\\" + filename);
}
catch { }
return filename;
}
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="originalImagePath">源图路径(物理路径)</param>
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="mode">生成缩略图的方式</param>
public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);
int towidth = width;
int toheight = height;
int x = 0;
int y = 0;
int ow = originalImage.Width;
int oh = originalImage.Height;
switch (mode)
{
case "HW"://指定高宽缩放(可能变形)
break;
case "W"://指定宽,高按比例
toheight = originalImage.Height * width / originalImage.Width;
break;
case "H"://指定高,宽按比例
towidth = originalImage.Width * height / originalImage.Height;
break;
case "Cut"://指定高宽裁减(不变形)
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
{
oh = originalImage.Height;
ow = originalImage.Height * towidth / toheight;
y = 0;
x = (originalImage.Width - ow) / 2;
}
else
{
ow = originalImage.Width;
oh = originalImage.Width * height / towidth;
x = 0;
y = (originalImage.Height - oh) / 2;
}
break;
default:
break;
}
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
new System.Drawing.Rectangle(x, y, ow, oh),
System.Drawing.GraphicsUnit.Pixel);
try
{
//以jpg格式保存缩略图
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.Exception)
{
}
finally
{
originalImage.Dispose();
bitmap.Dispose();
g.Dispose();
}
}
/// <summary>
/// 判断上传文件的类型
/// </summary>
public static bool TestDisplayFile(string filename)
{
string[] extendname = { ".gif", "jpeg", ".jpg", ".bmp", ".png", ".swf", ".eps", ".flash", ".xls" };
string transname = filename.Substring(filename.Length - 4, 4);
for (int i = 0; i < extendname.Length; i++)
{
if (extendname[i] == transname.ToLower())
{
return true;
}
}
return false;
}
/// <summary>
/// 生成随机字母字符串(数字字母混和)
/// </summary>
/// <param name="codeCount">待生成的位数</param>
/// <returns>生成的字母字符串</returns>
public static string GenerateCheckCode(int codeCount)
{
string str = string.Empty;
long num2 = DateTime.Now.Ticks + rep;
rep++;
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep)));
for (int i = 0; i < codeCount; i++)
{
char ch;
int num = random.Next();
if ((num % 2) == 0)
{
ch = (char)(0x30 + ((ushort)(num % 10)));
}
else
{
ch = (char)(0x41 + ((ushort)(num % 0x1a)));
}
str = str + ch.ToString();
}
return str;
}
/// <summary>
/// 获得数字形式的随机字符串
/// </summary>
/// <returns>数字形式的随机字符串</returns>
public static string mikecat_GetNumberRandom()
{
int mikecat_intNum;
long mikecat_lngNum;
string mikecat_strNum = System.DateTime.Now.ToString();
mikecat_strNum = mikecat_strNum.Replace(":", "");
mikecat_strNum = mikecat_strNum.Replace("-", "");
mikecat_strNum = mikecat_strNum.Replace(" ", "");
mikecat_strNum = mikecat_strNum.Replace("/", "");
mikecat_lngNum = long.Parse(mikecat_strNum);
System.Random mikecat_ran = new Random();
mikecat_intNum = mikecat_ran.Next(1, 99999);
mikecat_ran = null;
mikecat_lngNum += mikecat_intNum;
return mikecat_lngNum.ToString();
}
/// <summary>
/// 文件后缀名的枚举
/// </summary>
public enum FileExtension
{
XLS = 208207,
JPG = 255216,
GIF = 7173,
BMP = 6677,
PNG = 13780
}
/// <summary>
/// 顾客类型的枚举
/// </summary>
public enum MemberType
{
pub = 0,
member = 1,
network = 2
}
/// <summary>
/// 判断文件的后缀名
/// </summary>
/// <param name="fu"></param>
/// <param name="fileEx"></param>
/// <returns></returns>
public static bool IsAllowedExtension(FileUpload fu, FileExtension[] fileEx)
{
int fileLen = fu.PostedFile.ContentLength;
byte[] imgArray = new byte[fileLen];
fu.PostedFile.InputStream.Read(imgArray, 0, fileLen);
MemoryStream ms = new MemoryStream(imgArray);
System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
string fileclass = "";
byte buffer;
try
{
buffer = br.ReadByte();
fileclass = buffer.ToString();
buffer = br.ReadByte();
fileclass += buffer.ToString();
}
catch (Exception)
{
}
br.Close();
ms.Close();
foreach (FileExtension fe in fileEx)
{
if (Int32.Parse(fileclass) == (int)fe)
return true;
}
return false;
}
/// <summary>
/// 绑定类型 下拉列表
/// </summary>
/// <param name="ddl"></param>
/// <param name="typeID"></param>
/// <param name="Texts"></param>
//public static void BindTypeDropDownList(DropDownList ddl, int typeID, string Texts,bool TextIsText)
//{
// PanSoft.BLL.TypeInfo b = new PanSoft.BLL.TypeInfo();
// ddl.DataSource = b.GetList("parentID=" + typeID + "");
// ddl.DataTextField = "typeName";
// if (TextIsText)
// {
// ddl.DataValueField = "typeName";
// }
// else
// {
// ddl.DataValueField = "ID";
// }
// ddl.DataBind();
// ddl.Items.Insert(0, new ListItem("请选择"+Texts, "-1"));
//}
//public static void SelectDropDownListItems(DropDownList ddl,string SelectValue,bool isFindText)
//{
// try
// {
// ListItem d = new ListItem();
// if (isFindText)
// {
// d = ddl.Items.FindByText(SelectValue);
// }
// else
// {
// d = ddl.Items.FindByValue(SelectValue);
// }
// if (d.Value != null)
// {
// d.Selected = true;
// }
// }
// catch
// {
// }
//}
//天干
private static string[] TianGan = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
//地支
private static string[] DiZhi = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
//十二生肖
private static string[] ShengXiao = { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
//农历日期
//private static string[] DayName = {"*","初一","初二","初三","初四","初五",
// "初六","初七","初八","初九","初十",
// "十一","十二","十三","十四","十五",
// "十六","十七","十八","十九","二十",
// "廿一","廿二","廿三","廿四","廿五",
// "廿六","廿七","廿八","廿九","三十"};
private static string[] DayName = {"*","1","2","3","4","5",
"6","7","8","9","10",
"11","12","13","14","15",
"16","17","18","19","20",
"21","22","23","24","25",
"26","27","28","29","30"};
//农历月份
//private static string[] MonthName = { "*", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊" };
private static string[] MonthName = { "*", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
//公历月计数天
private static int[] MonthAdd = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
//农历数据
private static int[] LunarData = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395
,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031
,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222
,268949,3402,3493,133973,1386,464219,605,2349,334123,2709
,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
/// <summary>
/// 获取对应日期的农历
/// </summary>
/// <param name="dtDay">公历日期</param>
/// <returns></returns>
public static string GetLunarCalendar(DateTime dtDay)
{
string sYear = dtDay.Year.ToString();
string sMonth = dtDay.Month.ToString();
string sDay = dtDay.Day.ToString();
int year;
int month;
int day;
try
{
year = int.Parse(sYear);
month = int.Parse(sMonth);
day = int.Parse(sDay);
}
catch
{
year = DateTime.Now.Year;
month = DateTime.Now.Month;
day = DateTime.Now.Day;
}
int nTheDate;
int nIsEnd;
int k, m, n, nBit, i;
string calendar = string.Empty;
//计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
nTheDate = (year - 1921) * 365 + (year - 1921) / 4 + day + MonthAdd[month - 1] - 38;
if ((year % 4 == 0) && (month > 2))
nTheDate += 1;
//计算天干,地支,月,日
nIsEnd = 0;
m = 0;
k = 0;
n = 0;
while (nIsEnd != 1)
{
if (LunarData[m] < 4095)
k = 11;
else
k = 12;
n = k;
while (n >= 0)
{
//获取LunarData[m]的第n个二进制位的值
nBit = LunarData[m];
for (i = 1; i < n + 1; i++)
nBit = nBit / 2;
nBit = nBit % 2;
if (nTheDate <= (29 + nBit))
{
nIsEnd = 1;
break;
}
nTheDate = nTheDate - 29 - nBit;
n = n - 1;
}
if (nIsEnd == 1)
break;
m = m + 1;
}
year = 1921 + m;
month = k - n + 1;
day = nTheDate;
//return year + "-" + month + "-" + day;
if (k == 12)
{
if (month == LunarData[m] / 65536 + 1)
month = 1 - month;
else if (month > LunarData[m] / 65536 + 1)
month = month - 1;
}
//年
// calendar = year + ".";
//生肖
//calendar += ShengXiao[(year - 4) % 60 % 12].ToString() + ". ";
// //天干
// calendar += TianGan[(year - 4) % 60 % 10].ToString();
// //地支
//calendar += DiZhi[(year - 4) % 60 % 12].ToString() + " ";
//农历月
if (month < 1)
calendar += "闰" + MonthName[-1 * month].ToString() + ".";
else
calendar += MonthName[month].ToString() + "-";
//农历日
calendar += DayName[day].ToString() + "";
string[] shijianS = calendar.Split('-');
string yue = shijianS[0];
if (shijianS[0].Length == 1)
{
yue="0"+shijianS[0];
}
string tian = shijianS[1];
if (shijianS[1].Length == 1)
{
tian="0"+shijianS[1];
}
return yue+"-"+tian;
}
/// <summary>
/// 加密
/// </summary>
/// <param name="rs"></param>
/// <returns></returns>
public static string DESEncryptMethod(string rs)
{
byte[] desKey = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
byte[] desIV = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
try
{
byte[] inputByteArray = Encoding.Default.GetBytes(rs);
//byte[] inputByteArray=Encoding.Unicode.GetBytes(rs);
des.Key = desKey; // ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = desIV; //ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),
CryptoStreamMode.Write);
//Write the byte array into the crypto stream
//(It will end up in the memory stream)
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the data back from the memory stream, and into a string
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
//Format as hex
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
catch
{
return rs;
}
finally
{
des = null;
}
}
/// <summary>
/// 解密
/// </summary>
/// <param name="rs"></param>
/// <returns></returns>
public static string DESDecryptMethod(string rs)
{
byte[] desKey = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
byte[] desIV = new byte[] { 0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08 };
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
try
{
//Put the input string into the byte array
byte[] inputByteArray = new byte[rs.Length / 2];
for (int x = 0; x < rs.Length / 2; x++)
{
int i = (Convert.ToInt32(rs.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = desKey; //ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = desIV; //ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
//Flush the data through the crypto stream into the memory stream
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the decrypted data back from the memory stream
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
catch
{
return rs;
}
finally
{
des = null;
}
}
//public static void checkAdmin(Page page)
//{
// if(HttpContext.Current.Session["admin"]==null)
// {
// AlertDialog_Prompt_Refresh("登录时间超时或者未登录,请登录",page,"login.aspx");
// }
//}
}
}
#endregion
0 0
- GUI
- GUI
- GUI+
- GUI
- GUI
- GUI
- gui
- gui
- GUI
- GUI
- GUI
- GUI
- GUI
- GUI
- GUI
- GUI
- GUI
- GUI
- C位域的初步了解
- 手持平台纹理格式说明
- 建立拖动控制条不动的浮动DIV,类似京东淘宝产品详情描述
- UVa 11300 Spreading the Wealth 分金币 (中位数)
- Java Socket 编程学习(4)
- GUI
- Mongodb(mapreduce)
- 递推数列
- java并发之原子性与可见性(一)
- 5道最基本的并查集- -!
- nodejs npm安装expressjs
- Let 与 Set 的不同用法
- Ubuntu 系统 Update-rc.d 命令
- 解决HibernateException: Illegal attempt to associate a collection with two open sessions