📄 msgview.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
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;
public partial class MsgView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{//SELECT UserInfo.PicName, MsgInfo.Title, MsgInfo.Content, MsgInfo.SubTime, MsgInfo.AcceptMan, MsgInfo.UserID FROM UserInfo INNER JOIN MsgInfo ON UserInfo.UserID = MsgInfo.UserID
// <asp:Label ID="Label1" runat="server" Text='<%# Eval("UserID") %>' Font-Bold="True" Font-Size="Large" ForeColor="Fuchsia"></asp:Label>
// Session["UserID"] = "04157008";
if(Session["UserID"]==null)
Response.Redirect("index.aspx");
// Session["UserID"] ="04157008";
if (!this.IsPostBack)
{
BindView();
}
}
public void BindView()
{
//SELECT UserInfo.PicName, MsgInfo.Title, MsgInfo.Content, MsgInfo.SubTime, MsgInfo.AcceptMan, MsgInfo.UserID FROM UserInfo INNER JOIN MsgInfo ON UserInfo.UserID = MsgInfo.UserID
// string cmd = " SELECT [UserID], [Email], [Tele], [MobilePh], [PicName], [QQ], [StudentID] FROM [UserInfo] where StudentID IN (select StudentID from StudentInfo where Name LIKE '" + "%" + this.SerchText.Text.ToString() + "%" + "')";//"+this.Province.Text.ToString()+" ; //设置SQL命令
string cmd = "SELECT UserInfo.PicName, MsgInfo.Title, MsgInfo.Content, MsgInfo.SubTime, MsgInfo.AcceptMan, MsgInfo.UserID , MsgInfo.BBSNum FROM UserInfo INNER JOIN MsgInfo ON UserInfo.UserID = MsgInfo.UserID where MsgInfo.AcceptMan ='" + Session["UserID"].ToString().Trim() + "'";
this.SqlDataSource1.SelectCommand=cmd;
this.SqlDataSource1.DataBind(); //将SqlDataSource重新绑定
this.GridView1.DataBind();
// this.countlab.Text=this.GridView1.
} //对GridView进行绑定
public string UToH(object source)
{
string str=source.ToString();
return UBBToHTML(str);
}
public string UBBToHTML(string sDetail)
{
Regex r;
Match m;
//#region 处理空格
// sDetail = sDetail.Replace(" ", " ");
// #endregion
#region 处理单引号
sDetail = sDetail.Replace("'", "’");
#endregion
#region 处理双引号
sDetail = sDetail.Replace("\"", """);
#endregion
#region html标记符
sDetail = sDetail.Replace("<", "<");
sDetail = sDetail.Replace(">", ">");
#endregion
// 处理换行,在每个新行的前面添加两个全角空格
r = new Regex(@"(\r\n(( )| )+)(?<正文> +)", RegexOptions.IgnoreCase);
#region 处理换行
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<BR> " + m.Groups["正文"].ToString());
}
// 处理换行,在每个新行的前面添加两个全角空格
sDetail = sDetail.Replace("\r\n", "<BR>");
#endregion
#region 处[b][/b]标记
r = new Regex(@"(\[B\])([^\t]*?)(\[\/B\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<b>" + m.Groups[2].ToString() + "</b>");
}
#endregion
#region 处[i][/i]标记
r = new Regex(@"(\[I\])([^\t]*?)(\[\/I\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<i>" + m.Groups[2].ToString() + "</i>");
}
#endregion
#region 处[u][/u]标记
r = new Regex(@"(\[U\])([^\t]*?)(\[\/U\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<u>" + m.Groups[2].ToString() + "</u>");
}
#endregion
#region 处[p][/p]标记
// 处[p][/p]标记
r = new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])", RegexOptions.IgnoreCase | RegexOptions.Singleline);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
}
#endregion
#region 处[sup][/sup]标记
// 处[sup][/sup]标记
r = new Regex(@"(\[sup\])([ \t]*?)(\[\/sup\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<SUP>" + m.Groups[2].ToString() + "</SUP>");
}
#endregion
#region 处[sub][/sub]标记
/// 处[sub][/sub]标记
r = new Regex(@"(\[sub\])([ \t]*?)(\[\/sub\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<SUB>" + m.Groups[2].ToString() + "</SUB>");
}
#endregion
//#region 处[url][/url]标记
///// 处[url][/url]标记
////处[url][/url]标记
//r = new Regex(@"(\[URL\])([^\t]*?)(\[\/URL\])", RegexOptions.IgnoreCase);
//for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
//{
// sDetail = sDetail.Replace(m.Groups[0].ToString(),
// "<a href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\">" +
// m.Groups[2].ToString() + "</a>");
//}
//#endregion
//#region 处[url=xxx][/url]标记
//// 处[url=xxx][/url]标记
////处[url=xxx][/url]标记
//r = new Regex(@"(\[URL=([^\t]+)\])([^\t]*?)(\[\/URL\])", RegexOptions.IgnoreCase);
//for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
//{
// sDetail = sDetail.Replace(m.Groups[0].ToString(),
// "<a href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\">" +
// m.Groups[3].ToString() + "</a>");
//}
//#endregion
//////////////////////////////////
r = new Regex(@"(\[URL\])(.[^\[]*)(\[\/URL\])", RegexOptions.IgnoreCase);
sDetail = r.Replace(sDetail, @"<A HREF=""http://$2"" TARGET=_blank>$2</A>");
r = new Regex(@"(\[URL=(http:\/\/.[^\[]*)\])(.[^\[]*)(\[\/URL\])", RegexOptions.IgnoreCase);
sDetail = r.Replace(sDetail, @"<A HREF=""$2"" TARGET=_blank>$3</A>");
r = new Regex(@"(\[URL=(.[^\[]*)\])(.[^\[]*)(\[\/URL\])", RegexOptions.IgnoreCase);
sDetail = r.Replace(sDetail, @"<A HREF=""http://$2"" TARGET=_blank>$3</A>");
////////////////////////////////////////////////
#region 处[email][/email]标记
// 处[email][/email]标记
r = new Regex(@"(\[email\])([ \t]*?)(\[\/email\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\">" +
m.Groups[2].ToString() + "</A>");
}
#endregion
#region 处[email=xxx][/email]标记
// 处[email=xxx][/email]标记
r = new Regex(@"(\[email=([ \t]+)\])([ \t]*?)(\[\/email\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\">" +
m.Groups[3].ToString() + "</A>");
}
#endregion
#region 处[size=x][/size]标记
// 处[size=x][/size]标记
r = new Regex(@"(\[SIZE=([1-7])\])([ \S\t]*?)(\[\/SIZE\])", RegexOptions.IgnoreCase);
//@"(\[SIZE=([1-7])\])([^\t]*?)(\[\/SIZE\])"
//@"(\[SIZE=([1-7])\])([ \S\t]*?)(\[\/SIZE\])"
//@"(\[SIZE=4\])(.[^\[]*)(\[\/SIZE\])"
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT SIZE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处[color=x][/color]标记
/// 处[color=x][/color]标记 (,
r = new Regex(@"(\[COLOR=([\S]+)\])([ \S\t]*?)(\[\/COLOR\])", RegexOptions.IgnoreCase);
//@"(\[COLOR=([ ]+)\])([^\t]*?)(\[\/COLOR\])"
//@"(\[COLOR=([\S]+)\])([ \S\t]*?)(\[\/COLOR\])"---VERY GOOD
// @"(\[COLOR=(.[^\[]*)\])(.[^\[]*)(\[\/COLOR\])"
//@"(\[COLOR=(.[^\[]*)\])([^\t]*?)(\[\/COLOR\])"------------------good
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT COLOR=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处[font=x][/font]标记
// 处[font=x][/font]标记//(,
r = new Regex(@"(\[FACE=(.[^\[]*)\])(.[^\[]*)(\[\/FACE\])", RegexOptions.IgnoreCase);
//@"(\[FACE=([ ]+)\])([^\t]*?)(\[\/FACE\])"
//(@"(\[font=([\S]+)\])([ \S\t]*?)(\[\/font\])",
//@"(\[FACE=([\S]+)\])([ \S\t]*?)(\[\/FACE\])"
//@"(\[FACE=([\S]+)\])([^\t]*?)(\[\/FACE\])"
//@"(\[font=([ ]+)\])([ \t]*?)(\[\/font\])"
//@"(\[FACE=(.[^\[]*)\])(.[^\[]*)(\[\/FACE\])"
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<FONT FACE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
// #region 处理图片链接
//// 处理图片链接
// r = new Regex("\\[picture\\](\\d+?)\\[\\/picture\\]", RegexOptions.IgnoreCase);
// for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
// {
// sDetail = sDetail.Replace(m.Groups[0].ToString(),
// "<IMG border=0 src=\"~/Upload/" + m.Groups[1].ToString() +
// "\">");
// //"~/Upload/" + picpath + FU.FileName;
// }
// #endregion
#region 处理[align=x][/align]
// 处理[align=x][/align]
r = new Regex(@"(\[align=([ ]+)\])([ \t]*?)(\[\/align\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<P align=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</P>");
}
#endregion
#region 处[H=x][/H]标记
// 处[H=x][/H]标记
r = new Regex(@"(\[H=([1-6])\])([ \t]*?)(\[\/H\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<H" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</H" + m.Groups[2].ToString() + ">");
}
#endregion
#region 处理[list=x][*][/list]
// 处理[list=x][*][/list]
r = new Regex(@"(\[list(=(A|a|I|i| ))?\]([ \t]*)\r\n)((\[\*\]([ \t]*\r\n))*?)(\[\/list\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
string strLI = m.Groups[5].ToString();
Regex rLI = new Regex(@"\[\*\]([ \t]*\r\n?)", RegexOptions.IgnoreCase);
Match mLI;
for (mLI = rLI.Match(strLI); mLI.Success; mLI = mLI.NextMatch())
{
strLI = strLI.Replace(mLI.Groups[0].ToString(), "<LI>" + mLI.Groups[1]);
}
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<UL TYPE=\"" + m.Groups[3].ToString() + "\"><B>" + m.Groups[4].ToString() + "</B>" +
strLI + "</UL>");
}
#endregion
#region 处[SHADOW=x][/SHADOW]标记
// 处[SHADOW=x][/SHADOW]标记
r = new Regex(@"(\[SHADOW=)(\d*?),(#*\w*?),(\d*?)\]([ \t]*?)(\[\/SHADOW\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<TABLE WIDTH=" + m.Groups[2].ToString() + " STYLE=FILTER:SHADOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
m.Groups[5].ToString() + "</TABLE>");
}
#endregion
#region 处[glow=x][/glow]标记
// 处[glow=x][/glow]标记
r = new Regex(@"(\[glow=)(\d*?),(#*\w*?),(\d*?)\]([ \t]*?)(\[\/glow\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(),
"<TABLE WIDTH=" + m.Groups[2].ToString() + " STYLE=FILTER:GLOW(COLOR=" + m.Groups[3].ToString() + ", STRENGTH=" + m.Groups[4].ToString() + ")>" +
m.Groups[5].ToString() + "</TABLE>");
}
#endregion
#region 处[center][/center]标记
r = new Regex(@"(\[center\])([ \t]*?)(\[\/center\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<CENTER>" + m.Groups[2].ToString() + "</CENTER>");
}
#endregion
#region 处[IMG][/IMG]标记
r = new Regex(@"(\[IMG\])(http|https|ftp):\/\/([^\t]*?)(\[\/IMG\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<a onfocus=this.blur() href=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " target=_blank><IMG SRC=" + m.Groups[2].ToString() + "://" + m.Groups[3].ToString() + " border=0 alt=按此在新窗口浏览图片 onload=javascript:if(screen.width-333<this.width)this.width=screen.width-333></a>");
}
#endregion
#region 处[em]标记
r = new Regex(@"(\[em([ \t]*?)\])", RegexOptions.IgnoreCase);
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -