📄 pagehelp.cs
字号:
using System;
using System.Collections;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;
// ********************
// PageHelp页面辅助类
// Author:Linhuanhuan
// CreateTime:2007-6-15
// LastModify:2007-6-25
// ********************
//5_1_a_s_p_x.c_o_m
public class PageHelp {
private static readonly string POSITIVE_INT = @"^\+?\d+$"; //正整数,可以有一个“+”号
private static readonly string SIGN_INT = @"^[+-]?\d$"; //整数,可以有“+”、“-”号
private static readonly string POSITIVE_DECIMAL = @"^[+]?\d+[.]?\d+$"; //正数值型
private static readonly string SIGN_DECIMAL = @"^[+-]?\d+[.]?\d+$"; //数值型
public PageHelp() {
}
/// <summary>
/// 很多数据库中nvarchar都有长度限制,所以必须进行长度判断
/// 判断字符串长度是否符合minLength到maxLength的要求
/// </summary>
/// <param name="text">输入的字符串</param>
/// <param name="minLength">最小长度,大于等于0</param>
/// <param name="maxLength">最大长度,一般为数据库内字段的长度</param>
/// <returns>bool</returns>
public static bool IsValidLengthText(string text, int minLength,int maxLength) {
if (minLength < 0) {
minLength = 0;
}
int curLength = text.Length;
if (curLength >= minLength && curLength <= maxLength) {
return true;
} else {
return false;
}
}
/// <summary>
/// 使用JS显示对话框
/// </summary>
/// <param name="page">page对象</param>
/// <param name="strMessage">要显示的内容</param>
public static void ShowMessage(System.Web.UI.Page page, string strMessage) {
strMessage = strMessage.Replace("'", "\\\'");
page.ClientScript.RegisterStartupScript(page.GetType(),"key1","<script>alert('"+strMessage+"');</script>");
}
/// <summary>
/// 显示对话框并客户端转向
/// </summary>
/// <param name="page">page对象</param>
/// <param name="strMessage">要显示的内容</param>
/// <param name="url">需要转向的地址</param>
public static void ShowAndRedirect(System.Web.UI.Page page, string strMessage, string url) {
StringBuilder buffer = new StringBuilder();
buffer.Append("<script language='javascript'>");
if (!string.IsNullOrEmpty(strMessage)) {
strMessage = strMessage.Replace("'", "\\\'");
buffer.AppendFormat("alert('{0}');",strMessage);
}
buffer.AppendFormat("top.location.href='{0}'", url);
buffer.Append("</script>");
page.Response.Write(buffer.ToString());
}
/// <summary>
/// 判断是否为正整数
/// </summary>
/// <param name="input">输入的字符串</param>
/// <returns>bool型结果</returns>
public static bool IsPositiveInt(string input) {
Regex regex = new Regex(POSITIVE_INT);
return regex.Match(input).Success;
}
/// <summary>
/// 是否为整数
/// </summary>
/// <param name="input">输入的字符串</param>
/// <returns>bool型结果</returns>
public static bool IsSignInt(string input) {
Regex regex = new Regex(SIGN_INT);
return regex.Match(input).Success;
}
/// <summary>
/// 是否为正数值型
/// </summary>
/// <param name="input">输入的字符串</param>
/// <returns>bool型结果</returns>
public static bool IsPositiveDecimal(string input) {
Regex regex = new Regex(POSITIVE_DECIMAL);
return regex.Match(input).Success;
}
/// <summary>
/// 是否为数值型
/// </summary>
/// <param name="input">输入的字符串</param>
/// <returns>bool型结果</returns>
public static bool IsSignDecimal(string input) {
Regex regex = new Regex(SIGN_DECIMAL);
return regex.Match(input).Success;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -