///
/// md5加密方式
///
/// 原字符串
/// 16,32 位
/// 加密后的字符串
public static string MD5(string str, int code)
{
if (code == 16)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToLower().Substring(8, 16);
}
if (code == 32)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper();
}
return str;
}
// 返回指定字符串的值
public static string TagVal(string Tag, string TagName)
{
string[] strArray = Tag.Split(new char[] { ',' });
for (int i = 0; i < strArray.Length; i++)
{
Regex regex = new Regex(@"(?\w+)\s*=\s*(?.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match = regex.Match(strArray[i]); match.Success; match = match.NextMatch())
{
if (match.Groups["Keyword"].ToString().ToLower().IndexOf(TagName.ToLower()) != -1)
{
return match.Groups["Value"].ToString();
}
}
}
return "";
}
///
/// 弹出消息框
///
/// 消息内容
public static void Alert(string message, System.Web.UI.Page page)
{
string js = "<script language=javascript>alert('{0}');</script>";
if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "AlertAndRedirect"))
{
page.ClientScript.RegisterStartupScript(page.GetType(), "Alert", string.Format(js, message));
}
}
///
/// 重写URL,分页函数
///
/// 记录总数
/// 分页大小
/// 当前页
/// 循环页码个数
/// 参数
/// 页面
/// 分页字符串
public static string GetPageListManage(string url, int RecordCount, int PageSize, int PageIndex, int PageList, string strWhere)
{
StringBuilder strPage = new StringBuilder();
if (PageSize <= 0) PageSize = 1;
int PageCount = (RecordCount + PageSize - 1) / PageSize;
int PageTemp = 0;
if (PageIndex > PageCount)
{
PageIndex = PageCount;
}
else if (PageIndex <= 0)
{
PageIndex = 1;
}
//新的分页
strPage.AppendFormat("");
strPage.AppendFormat("
上一页", PageIndex - 1 <= 0 ? 1 : PageIndex - 1, strWhere);
PageTemp = ((PageIndex - 1) / PageList) * PageList + 1;
int i = 1;
while (i <= PageList && PageTemp <= PageCount)
{
i++;
strPage.AppendFormat(PageTemp == PageIndex ? "
{0}" : "
{0}", PageTemp++);
}
if (PageCount > 10)
{
strPage.AppendFormat("
...");
}
strPage.AppendFormat("
下一页", PageIndex + 1 > PageCount ? PageCount : PageIndex + 1, strWhere);
strPage.AppendFormat("
");
return strPage.ToString();
}