用户名:  密码:
兄弟在线   

标题:asp.net一些验证函数类

作者:agui005 来源:http://www.xdlmn.com 时间:2011-09-08

using System;
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;

/// <summary>
/// WebHelper 的摘要描述
/// </summary>
public class WebHelper
{
    public WebHelper()
    {
        //
        // TODO: 在此加入建構函式的程式碼
        //
    }   
    #region double類型的檢驗
    /// <summary>
    /// double類型的檢驗
    /// </summary>
    /// <param name="str">str</param>
    /// <returns></returns>
    public static bool Numcheck(string str)
    {

        if (str.Trim() == "")
        {
            return false;
        }
        else
        {
            return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$");
        }

    }
    public static bool Intcheck(string str)
    {

        if (str.Trim() == "")
        {
            return false;
        }
        else
        {
            return Regex.IsMatch(str, @"^[+-]?\d*$");
        }

    }
    #endregion
    #region 顯示提示框 flase為可視
    /// <summary>
    /// 顯示提示框 flase為可視
    /// </summary>
    /// <param name="msg">字符串</param>
    /// <param name="isInHead">flase為可視</param>
    public static void JsAlert(string msg, bool isInHead)
    {

        string m = string.Format("alert(\"{0}\");", msg.Replace(@"\", @"\\").Replace("\"", "\\\"").Replace("\n", @"\n"));
        ExecuteJs(m, isInHead);

    }
    #endregion
    #region 執行JS
    public static void ExecuteJs(string script, bool isInHead)
    {

        string str = string.Format("\n<script  type=\"text/javascript\">\n{0}\n</script>\n", script);
        if (!isInHead)
        {
            ((Page)HttpContext.Current.Handler).ClientScript.RegisterStartupScript(Type.GetType("System.String"), Guid.NewGuid().ToString(), str);
        }
        else
        {
            HtmlGenericControl child = new HtmlGenericControl("script");
            child.Attributes.Add("type", "text/javascript");
            child.InnerHtml = "\n" + script + "\n";
            Page handler = (Page)HttpContext.Current.Handler;
            handler.Header.Controls.Add(child);
        }

    }
    #endregion

    #region 字符格式處理
    //解碼JS過濾危險字符函數
    public string strHTMLDecode(string str)
    {
        return str.Replace("&amp;", "&").Replace("&gt;", ">").Replace("&lt;", "<").Trim();
    }
    /// <summary>
    /// 去掉所有的特殊字符
    /// </summary>
    /// <param name="tt"></param>
    /// <returns></returns>
    public string strReplacenoall(string tt)
    {
   
            tt = tt.Replace( "'", "");
        tt = tt.Replace("&", "");
        tt = tt.Replace("<", "");
        tt = tt.Replace(">", "");
        tt = tt.Replace("@", "");
        return tt;
    }
    //處理字符格式
    public string strFormatEncode(string str)
    {
        str = str.Trim().Replace("'", "''");//特殊字符處理:空格 和 單引號,在SQL语法中将连续两个单引号"''"视为一个单引号"'"
        //處理換行,在每個新行的前面添加兩個全角空格
        //****************
        Regex r = new Regex(@"(\r\n((&nbsp;)| )+)(?<正文> +)", RegexOptions.IgnoreCase);
        Match m = null;
        for (m = r.Match(str); m.Success; m = m.NextMatch())
        {
            str = str.Replace(m.Groups[0].ToString(), "<br />" + m.Groups["正文"].ToString());
        }
        //****************
        str = str.Replace("\r\n", "<br />");
        return str;
    }
    //處理字符格式
    public string strFormatDecode(string str)
    {
        str = str.Replace("<br />", "\r\n");
        return str;
    }
    #endregion
   
    #region 合并欄位
    /// <summary>
    /// 合并欄位
    /// </summary>
    /// <param name="vTip"></param>
    /// <param name="vHeight"></param>
    /// <param name="vWidth"></param>
    /// <returns></returns>
    public static void VSort(GridView gdv, string str_label, int begincol, int endcol)
    {
        int i;
        int j;
        int intSpan, NowSpan = 0;
        string strTemp;
        for (i = 0; i <= gdv.Rows.Count - 1; )
        {
            intSpan = 1;
            Label l_bill_no = (Label)gdv.Rows[i].FindControl(str_label);
            strTemp = l_bill_no.Text;
            for (j = i + 1; j <= gdv.Rows.Count - 1; j++)
            {
                string str_row = "";
                Label l_bill_no1 = (Label)gdv.Rows[j].FindControl(str_label);
                str_row = l_bill_no1.Text;
                if (strTemp == str_row)
                {
                    intSpan++;
                    for (int k = begincol; k <= endcol; k++)
                    {
                        gdv.Rows[i].Cells[k].RowSpan = intSpan;
                        gdv.Rows[j].Cells[k].Visible = false;
                    }
                }
                else
                {
                    break;
                }
            }
            NowSpan += intSpan;
            i = NowSpan - 1;
        }
    }
    public static void VSortHylink(GridView gdv, string str_label, int begincol, int endcol)
    {
        int i;
        int j;
        int intSpan, NowSpan = 0;
        string strTemp;
        for (i = 0; i <= gdv.Rows.Count - 1; )
        {
            intSpan = 1;
            HyperLink l_bill_no = (HyperLink)gdv.Rows[i].FindControl(str_label);
            strTemp = l_bill_no.Text;
            for (j = i + 1; j <= gdv.Rows.Count - 1; j++)
            {
                string str_row = "";
                HyperLink l_bill_no1 = (HyperLink)gdv.Rows[j].FindControl(str_label);
                str_row = l_bill_no1.Text;
                if (strTemp == str_row)
                {
                    intSpan++;
                    for (int k = begincol; k <= endcol; k++)
                    {
                        gdv.Rows[i].Cells[k].RowSpan = intSpan;
                        gdv.Rows[j].Cells[k].Visible = false;
                    }
                }
                else
                {
                    break;
                }
            }
            NowSpan += intSpan;
            i = NowSpan - 1;
        }
    }
    #endregion
}
 



总点击 [2924]   评论  0 查看评论
上一篇:sqlHelper.cs 类函数
下一篇:asp.net ProcessBar.cs类
【关闭窗口】
您可能感兴趣的文章
我要评论
          
评论标题:   可以输入250
 
验证数字: 6 + 4 =
兄弟友情提示
· 请自觉遵守国家有关法律、法规,尊重网上道德。
· 兄弟在线坚决抵制不良言行,违者文责自负。
· 如果文章有版权或其他问题等,请联系我们,我们会尽快处理。
· 文章注名来自网络的旨在传播共享信息,不做其它用途;注名原创的本站支持原创,但不代表同意其观点。
· 兄弟在线拥有管理用户与其文章和评论的一切权利,并有权在网站内转载或引用。
兄弟在线
兄弟热门文章
兄弟推荐文章
兄弟站内搜索

兄弟感兴趣的文章
兄弟最新影视