⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfunction.cs

📁 开发环境:VS2005、C#、.net2.0、Access、AJAX引擎是自己写的
💻 CS
字号:
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.RegularExpressions;
using System.Globalization;
using System.Text;

/// <summary>
/// 主程序类
/// </summary>
public class mainFunction
{
    //********************
    //**     UBB转换    **
    //********************
    public string ubb(String str, String imgWidth, String imgHeight, String emote)
    {
        Regex r;
        Match m;
        r = new Regex(@"(\[图片\])([ \S\t]*?)(\[\/图片\])", RegexOptions.IgnoreCase);
        for (m = r.Match(str); m.Success; m = m.NextMatch())
        {
            str = str.Replace(m.Groups[0].ToString(), "<img style=\"cursor:hand\" src=\"" + m.Groups[2].ToString() + "\" border=0 alt=\"点击在新窗口中浏览原始图片!\" onclick=\"javascript:window.open('" + m.Groups[2].ToString() + "')\" onload=\"if(this.height>" + imgHeight + "||this.width>" + imgWidth + "){if((this.height/" + imgHeight + ")>(this.width/" + imgWidth + ")){this.height=" + imgHeight + "}else{this.width=" + imgWidth + "}}\" >");
        }
        for (int i = 1; i <= 14; i++)
        {
            str = str.Replace("[表情" + i + "]", "<img border=0 width=32 height=32 SRC=FaceOrEmt/Emote" + emote + "/em" + i + ".gif>");
        }
            return str;
    }

    //*******************
    //**    过滤脏话   **
    //*******************
    public string FilterBadWords(string msg, string badwords)
    {
        string[] tempstr = badwords.Split('|');
        string finalstr = msg;
        for (int i = 0; i < tempstr.Length; i++)
        {
            finalstr = finalstr.Replace(tempstr[i], new String('*', tempstr[i].Length));
        }
        return finalstr;

    }

    //********************
    //**  显示联系方式  **
    //********************
    public string DisContact(object QQ, object Email, object Http)
    {
        string TempStr = "";
        if (QQ.ToString() != "")
        {
            TempStr = "<span title='号码:" + QQ + "' class='font_13'>QQ</span>&nbsp;";
        }
        if (Email.ToString() != "")
        {
            TempStr = TempStr + "<a href='mailto:" + Email + "' title='点击给 " + Email + "写信' class='font_13'>E-Mail</a>&nbsp;";
        }
        if (Http.ToString() != "")
        {
            TempStr = TempStr + "<a href='#' onclick=javascript:window.open('" + Http + "');return false title='地址是:" + Http + " 点击在新窗口中浏览!' class='font_13'>主页</a>";
        }
        return TempStr;
    }

    //******************
    //**   错误信息   **
    //******************
    public string errorMsg(string msg)
    {
        string tempHtml = "";
        tempHtml = tempHtml + "<table border='0' cellpadding='0' cellspacing='0'>";
        tempHtml = tempHtml + "<tr><td style='width: 300px; height: 120px'></td></tr>";
        tempHtml = tempHtml + "<tr><td style='width: 300px'><img src='skins/Error.gif' /></td></tr>";
        tempHtml = tempHtml + "<tr><td style='width: 300px; height: 21px'><b class=font_12>" + msg + "</b></td></tr>";
        tempHtml = tempHtml + "</table>";
        return tempHtml;
    }

    //**************************
    //**  判断是否是数字组合  **
    //**************************
    public bool IsNumber(string strDate)
    {
        if (strDate == null)
        {
            return false;
        }
        if (strDate.Equals(string.Empty))
        {
            return false;
        }

        Regex numRegex = new Regex(@"0*[0-9][0-9]*$");
        return numRegex.IsMatch(strDate);
    }

    //************************
    //**  判断合法的E-Mail  **
    //************************
    public bool IsValidEmail(string strIn)
    {
        return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
    }

    //*********************
    //**  判断合法的URL  **
    //*********************
    public bool IsValidUrl(string strIn)
    {
        return Regex.IsMatch(strIn, @"^http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$");
    }

    //**************************
    //**  判断是否有非法字符  **
    //**************************
    public bool CheckBidStr(string strString)
    {
        bool outValue = false;
        if (strString != null && strString.Length > 0)
        {
            string[] bidStrlist = new string[20];
            bidStrlist[0] = "'";
            bidStrlist[1] = ";";
            bidStrlist[2] = ":";
            bidStrlist[3] = "%";
            bidStrlist[4] = "@";
            bidStrlist[5] = "&";
            bidStrlist[6] = "#";
            bidStrlist[7] = "\"";
            bidStrlist[8] = "net user";
            bidStrlist[9] = "exec";
            bidStrlist[10] = "net localgroup";
            bidStrlist[11] = "select";
            bidStrlist[12] = "asc";
            bidStrlist[13] = "char";
            bidStrlist[14] = "mid";
            bidStrlist[15] = "insert";
            bidStrlist[16] = "delete";
            bidStrlist[17] = "drop";
            bidStrlist[18] = "truncate";
            bidStrlist[19] = "xp_cmdshell";

            string tempStr = strString.ToLower();
            for (int i = 0; i < bidStrlist.Length; i++)
            {
                if (tempStr.IndexOf(bidStrlist[i]) != -1)
                {
                    outValue = true;
                    break;
                }
            }
        }
        return outValue;
    }

    //******************
    //**  过滤'"符号  **
    //******************
    public string MoveBidStr(string strString, int isForm)
    {
        string str;
        str = strString;
        if (str != null)
        {
            str = str.Replace("'", "''");
            str = str.Replace(((char)39).ToString(), ((char)39 + (char)39).ToString());
        }
        return str;
    }

    //********************
    //**  过滤HTML代码  **
    //********************
    public string Keep(string strString,int isForm)
    {
        string str;
        str = strString;
        if (str != null)
        {
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("<", "&lt");
            str = str.Replace(">", "&gt");
            str = str.Replace("|", "");
            if (isForm == 0)
            {
                str = str.Replace(((char)9).ToString(), "&nbsp;");
            }
            str = str.Replace(((char)34).ToString(), "&quot;");
            str = str.Replace(((char)39).ToString(), "&#39;");
            str = str.Replace(((char)13).ToString() + ((char)10).ToString(), "<br>");
            //str = str.Replace(((char)10).ToString(),"");
        }
        return str;
    }


    //******************
    //**  过滤JS代码  **
    //******************
    public string Fixjs(string strString)
    {
        string str;
        str = strString;
        if (str != null)
        {
            str = str.Replace("\\", "\\\\");
            str = str.Replace(((char)34).ToString(), "\\\"");
            str = str.Replace(((char)39).ToString(), "\\'");
            str = str.Replace(((char)13).ToString(), "\\n");
            str = str.Replace(((char)10).ToString(), "\\r");
            str = str.Replace("'", "&#39;");
        }
        return str;
    }

    //******************
    //**   Hash编码   **
    //******************
    public string EncryptStr(string strString, string strFormat)
    {
        if (strString.Length != 0)
        {
            switch (strFormat.ToUpper())
            {
                case "SHA1":
                    return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strString, "SHA1");
                case "MD5":
                    return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strString, "MD5");
                default:
                    return strString;
            }
        }
        else
        {
            return strString;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -