.NET学习笔记
来源:互联网 发布:淘宝代金券用不了 编辑:程序博客网 时间:2024/06/05 22:50
文件web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<customErrors mode="Off" />
<compilation debug="true" />
<globalization responseEncoding="gb2312" requestEncoding="gb2312" />
<pages validateRequest="false" />
</system.web>
<appSettings>
<add key="名称" value="新手" />
<add key="声明" value="我是菜鸟,请各前辈高人多指教。" />
</appSettings>
</configuration>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<customErrors mode="Off" />
<compilation debug="true" />
<globalization responseEncoding="gb2312" requestEncoding="gb2312" />
<pages validateRequest="false" />
</system.web>
<appSettings>
<add key="名称" value="新手" />
<add key="声明" value="我是菜鸟,请各前辈高人多指教。" />
</appSettings>
</configuration>
1.用户控件的调用方法
文件s.aspx
<%...@ Register TagPrefix="kjX" TagName="db" Src="db.ascx" %>
<kjX:db id="db1" runat="server"></kjX:db>
<kjX:db id="db2" runat="server"></kjX:db>
<kjX:db id="db1" runat="server"></kjX:db>
<kjX:db id="db2" runat="server"></kjX:db>
文件db.ascx
<div id="h_db" align="center">www.baidu.com</div>
2.Title
<title id="a_bt" runat="server"></title>
<script language="c#" runat="server">...
void Page_Load() ...{
a_bt.InnerHtml=ConfigurationSettings.AppSettings["名称"];
}
</script>
<script language="c#" runat="server">...
void Page_Load() ...{
a_bt.InnerHtml=ConfigurationSettings.AppSettings["名称"];
}
</script>
3.XMl文件
dht.xml
<?xml version="1.0" encoding="gb2312"?>
<导航条>
<项>
<文本>网站首页</文本>
<链接>http://www.baidu.com</链接>
</项>
<项>
<文本>我的资料</文本>
<链接>http://www.baidu.com/</链接>
</项>
<项>
<文本>给我写信</文本>
<链接>mail:hongjianghong@163.com</链接>
</项>
</导航条>
<导航条>
<项>
<文本>网站首页</文本>
<链接>http://www.baidu.com</链接>
</项>
<项>
<文本>我的资料</文本>
<链接>http://www.baidu.com/</链接>
</项>
<项>
<文本>给我写信</文本>
<链接>mail:hongjianghong@163.com</链接>
</项>
</导航条>
<%@ Import NameSpace="System.Data" %>
DataSet dht = new DataSet();
dht.ReadXml(Server.MapPath("dht.xml"));
foreach(DataRow h in dht.Tables[0].Rows)
a_dh.Text+="<a href=""+h["链接"].ToString()+"" target="_blank">"+h["文本"].ToString()+"</a> ";
DataSet dht = new DataSet();
dht.ReadXml(Server.MapPath("dht.xml"));
foreach(DataRow h in dht.Tables[0].Rows)
a_dh.Text+="<a href=""+h["链接"].ToString()+"" target="_blank">"+h["文本"].ToString()+"</a> ";
X.
<%...@ Import NameSpace="System.Data" %>
<%...@ Import NameSpace="System.Data.OleDb" %>
<%...@ Register TagPrefix="kj" TagName="tb" Src="tb.ascx" %>
<%...@ Register TagPrefix="kj" TagName="db" Src="db.ascx" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title id="a_bt" runat="server">dotnet.2xd.cn</title>
<link href="ys.css" rel="stylesheet" type="text/css" />
<script src="jb.js"></script>
</head>
<body>
<form runat="server">
<kj:tb runat="server" />
<div id="h_zt">
<div id="h_zt1">
<asp:Repeater ID="a_xsly" runat="server">
<headertemplate>
<div align="center">显示留言</div>
</headertemplate>
<itemtemplate>
<table width="520" border="0" align="center" cellpadding="0" cellspacing="1" class="xsly">
<tr>
<td width="150" valign="top">
<dl class="lb1">
<dt>第 <asp:Label ID="a_bh" CssClass="hsz" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"编号") %>' /> 号留言</dt>
<dt><asp:Image ID="a_tx" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"头像","images/tx/{0}.gif") %>' ToolTip="头像" runat="server" /></dt>
<dt>用户:<%...# DataBinder.Eval(Container.DataItem,"作者") %></dt>
<dt>邮箱:<asp:HyperLink ToolTip="给我写信" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"邮箱","mailto:{0}") %>' Text="发送邮件" runat="server" /></dt>
<dt>主页:<asp:HyperLink ToolTip="访问我的主页" Target="_blank" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"主页") %>' Text="点此访问" runat="server" /></dt>
<dt>我QQ:<asp:HyperLink ToolTip='<%# DataBinder.Eval(Container.DataItem,"QQ") %>' Text="给我留言" NavigateUrl='<%...# DataBinder.Eval(Container.DataItem,"QQ","http://wpa.qq.com/msgrd?V=1&Uin={0}&Site=www.2xd.cn&Menu=yes") %>' Target="_blank" runat="server" /></dt>
<dt>电话:<%...# DataBinder.Eval(Container.DataItem,"电话") %></dt>
</dl>
</td>
<td>
<div class="ly1">
<div><%...# ubb(DataBinder.Eval(Container.DataItem,"内容")) %></div>
<div align="right"><%...# DataBinder.Eval(Container.DataItem,"发表时间") %></div>
</div>
<%...# glyhf(ubb(DataBinder.Eval(Container.DataItem,"回复内容")),DataBinder.Eval(Container.DataItem,"回复时间")) %>
</td>
</tr>
</table>
<p />
</itemtemplate>
<footertemplate>
<div align="center"><asp:Label ID="a_sltj" runat="server" /> <asp:HyperLink ID="a_sy" Text="上一页" runat="server" /><asp:HyperLink ID="a_xy" Text="下一页" runat="server" /></div>
</footertemplate>
</asp:Repeater>
</div>
<div id="h_zt2">
<div id="h_zt2_1">发布留言</div>
<div id="h_zt2_2">
<div id="h_zt2_2_1">
<dl class="lb1">
<dt>作者:<asp:TextBox ID="a_zz" CssClass="zl" runat="server" MaxLength="8" /><asp:RequiredFieldValidator ControlToValidate="a_zz" ErrorMessage="*" ID="a_yzzz1" runat="server" /><asp:RegularExpressionValidator ControlToValidate="a_zz" ErrorMessage="中英文" ID="a_yzzz2" runat="server" ValidationExpression="^[一-龥A-Za-z0-9-]{1,8}" /></dt>
<dt>邮箱:<asp:TextBox ID="a_yx" CssClass="zl" runat="server" MaxLength="50" /><asp:RegularExpressionValidator ControlToValidate="a_yx" ErrorMessage="邮箱?" ID="a_yzyx" runat="server" ValidationExpression="w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*" /></dt>
<dt>主页:<asp:TextBox ID="a_zy" CssClass="zl" runat="server" MaxLength="50" /><asp:RegularExpressionValidator ControlToValidate="a_zy" ErrorMessage="网址?" ID="a_yzzy" runat="server" ValidationExpression="http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?" /></dt>
<dt>电话:<asp:TextBox ID="a_dh" CssClass="zl" runat="server" MaxLength="13" /><asp:RegularExpressionValidator ControlToValidate="a_dh" ErrorMessage="电话?" ID="a_yzdh" runat="server" ValidationExpression="[0-9]{7,13}" /></dt>
<dt>我QQ:<asp:TextBox ID="a_qq" CssClass="zl" runat="server" MaxLength="11" /><asp:RegularExpressionValidator ControlToValidate="a_qq" ErrorMessage="QQ?" ID="a_yzqq" runat="server" ValidationExpression="[0-9]{4,13}" /></dt>
<dt>头像:<asp:DropDownList ID="a_tx" onchange="h_tx.src='images/tx/'+(this.options.selectedIndex)+'.gif';" runat="server" /><img name="h_tx" src="images/tx/0.gif" /> <asp:RequiredFieldValidator ControlToValidate="a_lynr" ErrorMessage="留言不能为空!" ID="a_yzly" runat="server" /></dt>
</dl>
</div>
<div id="h_zt2_2_2"><asp:TextBox ID="a_lynr" onclick="storeCaret(this);" onselect="storeCaret(this);" onkeyup="storeCaret(this);" runat="server" Width="395" Height="90" BorderWidth="0" MaxLength="1000" TextMode="MultiLine" /></div>
<div id="h_zt2_2_3">
<div id="h_zt2_2_3_1">
<asp:ImageButton ID="a_tjly" ToolTip="发布留言" runat="server" ImageUrl="images bly.gif" OnClick="tjly" />
</div>
<div id="h_zt2_2_3_2"><input type="image" src="imagesqknr.gif" alt="清空留言" onClick="a_lynr.value='';return false;" /></div>
</div>
<div id="h_zt2_2_4">
<div id="h_zt2_2_4_1"><asp:Label ID="a_tb" ToolTip="表情图标" runat="server" /></div>
<div id="h_zt2_2_4_2" align="center">
<dl>
<dt><a href="#" onClick="cr(a_lynr,'strong','1');return false;">粗体</a> <a href="#" onClick="cr(a_lynr,'em','1');return false;">斜体</a> <a href="#" onClick="cr(a_lynr,'u','1');return false;">划线</a> <a href="#" onClick="cr(a_lynr,'url','1');return false;">链接</a></dt>
<dt><a href="#" onClick="cr(a_lynr,'img','1');return false;">贴图</a> <a href="#" onClick="cr(a_lynr,'mail','1');return false;">邮件</a> <a href="#" onClick="cr(a_lynr,'move','1');return false;">飞字</a> <a href="#" onClick="cr(a_lynr,'flash','1');return false;">flash</a></dt>
</dl>
</div>
</div>
</div>
</div>
</div>
<kj:db runat="server" />
</form>
</body>
</html>
<script language="c#" runat="server">...
void Page_Load() ...{
if(!Page.IsPostBack) ...{
if(Session["管理"]!=null)
a_zz.Text=Session["管理"].ToString();
sjtc();
ymtc();
a_bt.InnerHtml=ConfigurationSettings.AppSettings["留言本名称"];
}
}
void sjtc() ...{
OleDbConnection lj = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("lyb.mdb"));
OleDbDataAdapter ml = new OleDbDataAdapter("select * from 留言 order by 编号 desc",lj);
DataSet sj = new DataSet();
ml.Fill(sj);
int zs=sj.Tables[0].Rows.Count; //总记录数
int fys=int.Parse(ConfigurationSettings.AppSettings["每页记录数"]);
int ys=zs/fys; //总页数
if(zs%fys!=0)
ys++;
PagedDataSource fy = new PagedDataSource();
fy.DataSource = sj.Tables[0].DefaultView;
fy.AllowPaging = true;
fy.PageSize = fys;
int y;
try ...{
y=int.Parse(Request.QueryString["y"]);
}
catch ...{
y=1;
}
fy.CurrentPageIndex=y-1;
a_xsly.DataSource=fy;
a_xsly.DataBind();
HyperLink s=null,x=null;
s=(HyperLink)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_sy");
x=(HyperLink)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_xy");
if(!fy.IsFirstPage)
s.NavigateUrl="index.aspx?y="+(y-1);
if(!fy.IsLastPage)
x.NavigateUrl="index.aspx?y="+(y+1);
((Label)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_sltj")).Text="共有 <span class="hsz">"+zs+"</span> 条留言/ <span class="hsz">"+ys+"</span> 个页面 当前是第 <span class="hsz">"+y+"</span> 页(<span class="hsz">"+a_xsly.Items.Count+"</span> 条留言) <a href="index.aspx">首页</a> <a href="index.aspx?y="+ys+"">尾页</a>";
}
void ymtc() ...{
a_tb.Text="";
for(int i=1;i<=48;i++)
a_tb.Text+="<input type="image" src="images/tb/"+i+".gif" onclick="cr(this.form.a_lynr,'"+i+"',2);return false;" /> ";
for(int i=0;i<=int.Parse(ConfigurationSettings.AppSettings["头像数"]);i++)
a_tx.Items.Add(i.ToString());
a_tx.DataBind();
}
string glyhf(string bl1,object bl2) ...{
if(bl1!="")
return "<div class="ly2"><div>管理员回复:</div><div>"+bl1+"</div><div align="right">"+bl2.ToString()+"</div></div>";
return "";
}
void tjly(object sender,ImageClickEventArgs e) ...{
if(Page.IsValid) ...{
string mlwb="insert into 留言(内容,作者,邮箱,主页,电话,QQ,头像) values(@nr,@zz,@yx,@zy,@dh,@qq,@tx)";
int bl=0;
try ...{
bl=Convert.ToInt32(Regex.Match(a_lynr.Text,"SC=[0-9]+;").ToString().Replace("SC=","").Replace(";",""));
}catch ...{}
if(bl!=0)
mlwb="delete from 留言 where 编号="+bl;
else ...{
try ...{ bl=Convert.ToInt32(Regex.Match(a_lynr.Text,"HF=[0-9]+;").ToString().Replace("HF=","").Replace(";","")); }
catch ...{}
if(bl!=0)
mlwb="update 留言 set 回复内容='"+Regex.Replace(a_lynr.Text.Replace("'","''"),"HF=[0-9]+;","")+"',回复时间=now() where 编号="+bl;
}
OleDbConnection lj = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("lyb.mdb"));
OleDbCommand ml = new OleDbCommand(mlwb,lj);
lj.Open();
if(bl==0) ...{
ml.Parameters.Add("@nr",OleDbType.VarChar,5000,"内容");
ml.Parameters.Add("@zz",OleDbType.VarChar,8,"作者");
ml.Parameters.Add("@yx",OleDbType.VarChar,50,"邮箱");
ml.Parameters.Add("@zy",OleDbType.VarChar,50,"主页");
ml.Parameters.Add("@dh",OleDbType.VarChar,13,"电话");
ml.Parameters.Add("@qq",OleDbType.VarChar,13,"QQ");
ml.Parameters.Add("@tx",OleDbType.Integer);
ml.Parameters["@nr"].Value=a_lynr.Text.Replace("'","''");
ml.Parameters["@zz"].Value=a_zz.Text;
ml.Parameters["@yx"].Value=a_yx.Text;
ml.Parameters["@zy"].Value=a_zy.Text;
ml.Parameters["@dh"].Value=a_dh.Text;
ml.Parameters["@qq"].Value=a_qq.Text;
ml.Parameters["@tx"].Value=a_tx.SelectedIndex;
}
ml.ExecuteNonQuery();
lj.Close();
Response.Redirect("index.aspx");
}
}
string ubb(object bl)
...{
string [] dx = ConfigurationSettings.AppSettings["缩略图大小"].Split(',');
string fh=bl.ToString().Replace("&","&").Replace("<","<").Replace(">",">").Replace("''","'");
fh=Regex.Replace(fh,@"[strong](.*?)[/strong]","<strong>$1</strong>");
fh=Regex.Replace(fh,@"[u](.*?)[/u]","<u>$1</u>");
fh=Regex.Replace(fh,@"[em](.*?)[/em]","<em>$1</em>");
fh=Regex.Replace(fh,@"[color=W?(.*?)W?](.*?)[/color]","<span style="color:$1;">$2</span>");
fh=Regex.Replace(fh,@"[img,([0-9]*),([0-9]*)](.*?)[/img]","<img src="$3" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);" alt="" /><a href="$3" target="_blank" alt="$3">浏览原图</a>");
fh=Regex.Replace(fh,@"[img](.*?)[/img]","<img src="$1" alt="" style="border:0;width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);" /><a href="$1" target="_blank" alt="$1">浏览原图</a>");
fh=Regex.Replace(fh,@"[T([0-9]+)]","<img src="images/tb/$1.gif" alt="" />");
fh=Regex.Replace(fh,@"[url](http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?)[/url]","<a href="$1" target="_blank" title="$1">$1</a>");
fh=Regex.Replace(fh,@"[url=W?(http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?)W?](.*?)[/url]","<a href="$1" target="_blank" title="$1">$4</a>");
fh=Regex.Replace(fh,@"[mail](w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*)[/mail]","<a href="mailto:$1" title="$1">$1</a>");
fh=Regex.Replace(fh,@"[mail=W?(w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*)W?](.*?)[/mail]","<a href="mailto:$1" title="$1">$5</a>");
fh=Regex.Replace(fh,@"[move](.*?)[/move]","<marquee>$1</marquee>");
fh=Regex.Replace(fh,@"[flash,([0-9]*),([0-9]*)](.*?.swf)[/flash]","<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);"> <param name="movie" value="$3" /> <param name="quality" value="high" /> <embed src="$3" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);"></embed> </object><a href="$3" target="_blank">浏览flash</a><br />");
fh=Regex.Replace(fh,@"[flash](.*?.swf)[/flash]","<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" style="width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);"> <param name="movie" value="$1" /> <param name="quality" value="high" /> <embed src="$1" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" style="width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);"></embed> </object><br /><a href="$1" target="_blank">浏览flash</a><br />");
//return fh.Replace(" ","<br />");
return fh.Replace(" ","").Replace(" ","<br />");
}
</script>
<%...@ Import NameSpace="System.Data.OleDb" %>
<%...@ Register TagPrefix="kj" TagName="tb" Src="tb.ascx" %>
<%...@ Register TagPrefix="kj" TagName="db" Src="db.ascx" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title id="a_bt" runat="server">dotnet.2xd.cn</title>
<link href="ys.css" rel="stylesheet" type="text/css" />
<script src="jb.js"></script>
</head>
<body>
<form runat="server">
<kj:tb runat="server" />
<div id="h_zt">
<div id="h_zt1">
<asp:Repeater ID="a_xsly" runat="server">
<headertemplate>
<div align="center">显示留言</div>
</headertemplate>
<itemtemplate>
<table width="520" border="0" align="center" cellpadding="0" cellspacing="1" class="xsly">
<tr>
<td width="150" valign="top">
<dl class="lb1">
<dt>第 <asp:Label ID="a_bh" CssClass="hsz" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"编号") %>' /> 号留言</dt>
<dt><asp:Image ID="a_tx" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"头像","images/tx/{0}.gif") %>' ToolTip="头像" runat="server" /></dt>
<dt>用户:<%...# DataBinder.Eval(Container.DataItem,"作者") %></dt>
<dt>邮箱:<asp:HyperLink ToolTip="给我写信" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"邮箱","mailto:{0}") %>' Text="发送邮件" runat="server" /></dt>
<dt>主页:<asp:HyperLink ToolTip="访问我的主页" Target="_blank" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"主页") %>' Text="点此访问" runat="server" /></dt>
<dt>我QQ:<asp:HyperLink ToolTip='<%# DataBinder.Eval(Container.DataItem,"QQ") %>' Text="给我留言" NavigateUrl='<%...# DataBinder.Eval(Container.DataItem,"QQ","http://wpa.qq.com/msgrd?V=1&Uin={0}&Site=www.2xd.cn&Menu=yes") %>' Target="_blank" runat="server" /></dt>
<dt>电话:<%...# DataBinder.Eval(Container.DataItem,"电话") %></dt>
</dl>
</td>
<td>
<div class="ly1">
<div><%...# ubb(DataBinder.Eval(Container.DataItem,"内容")) %></div>
<div align="right"><%...# DataBinder.Eval(Container.DataItem,"发表时间") %></div>
</div>
<%...# glyhf(ubb(DataBinder.Eval(Container.DataItem,"回复内容")),DataBinder.Eval(Container.DataItem,"回复时间")) %>
</td>
</tr>
</table>
<p />
</itemtemplate>
<footertemplate>
<div align="center"><asp:Label ID="a_sltj" runat="server" /> <asp:HyperLink ID="a_sy" Text="上一页" runat="server" /><asp:HyperLink ID="a_xy" Text="下一页" runat="server" /></div>
</footertemplate>
</asp:Repeater>
</div>
<div id="h_zt2">
<div id="h_zt2_1">发布留言</div>
<div id="h_zt2_2">
<div id="h_zt2_2_1">
<dl class="lb1">
<dt>作者:<asp:TextBox ID="a_zz" CssClass="zl" runat="server" MaxLength="8" /><asp:RequiredFieldValidator ControlToValidate="a_zz" ErrorMessage="*" ID="a_yzzz1" runat="server" /><asp:RegularExpressionValidator ControlToValidate="a_zz" ErrorMessage="中英文" ID="a_yzzz2" runat="server" ValidationExpression="^[一-龥A-Za-z0-9-]{1,8}" /></dt>
<dt>邮箱:<asp:TextBox ID="a_yx" CssClass="zl" runat="server" MaxLength="50" /><asp:RegularExpressionValidator ControlToValidate="a_yx" ErrorMessage="邮箱?" ID="a_yzyx" runat="server" ValidationExpression="w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*" /></dt>
<dt>主页:<asp:TextBox ID="a_zy" CssClass="zl" runat="server" MaxLength="50" /><asp:RegularExpressionValidator ControlToValidate="a_zy" ErrorMessage="网址?" ID="a_yzzy" runat="server" ValidationExpression="http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?" /></dt>
<dt>电话:<asp:TextBox ID="a_dh" CssClass="zl" runat="server" MaxLength="13" /><asp:RegularExpressionValidator ControlToValidate="a_dh" ErrorMessage="电话?" ID="a_yzdh" runat="server" ValidationExpression="[0-9]{7,13}" /></dt>
<dt>我QQ:<asp:TextBox ID="a_qq" CssClass="zl" runat="server" MaxLength="11" /><asp:RegularExpressionValidator ControlToValidate="a_qq" ErrorMessage="QQ?" ID="a_yzqq" runat="server" ValidationExpression="[0-9]{4,13}" /></dt>
<dt>头像:<asp:DropDownList ID="a_tx" onchange="h_tx.src='images/tx/'+(this.options.selectedIndex)+'.gif';" runat="server" /><img name="h_tx" src="images/tx/0.gif" /> <asp:RequiredFieldValidator ControlToValidate="a_lynr" ErrorMessage="留言不能为空!" ID="a_yzly" runat="server" /></dt>
</dl>
</div>
<div id="h_zt2_2_2"><asp:TextBox ID="a_lynr" onclick="storeCaret(this);" onselect="storeCaret(this);" onkeyup="storeCaret(this);" runat="server" Width="395" Height="90" BorderWidth="0" MaxLength="1000" TextMode="MultiLine" /></div>
<div id="h_zt2_2_3">
<div id="h_zt2_2_3_1">
<asp:ImageButton ID="a_tjly" ToolTip="发布留言" runat="server" ImageUrl="images bly.gif" OnClick="tjly" />
</div>
<div id="h_zt2_2_3_2"><input type="image" src="imagesqknr.gif" alt="清空留言" onClick="a_lynr.value='';return false;" /></div>
</div>
<div id="h_zt2_2_4">
<div id="h_zt2_2_4_1"><asp:Label ID="a_tb" ToolTip="表情图标" runat="server" /></div>
<div id="h_zt2_2_4_2" align="center">
<dl>
<dt><a href="#" onClick="cr(a_lynr,'strong','1');return false;">粗体</a> <a href="#" onClick="cr(a_lynr,'em','1');return false;">斜体</a> <a href="#" onClick="cr(a_lynr,'u','1');return false;">划线</a> <a href="#" onClick="cr(a_lynr,'url','1');return false;">链接</a></dt>
<dt><a href="#" onClick="cr(a_lynr,'img','1');return false;">贴图</a> <a href="#" onClick="cr(a_lynr,'mail','1');return false;">邮件</a> <a href="#" onClick="cr(a_lynr,'move','1');return false;">飞字</a> <a href="#" onClick="cr(a_lynr,'flash','1');return false;">flash</a></dt>
</dl>
</div>
</div>
</div>
</div>
</div>
<kj:db runat="server" />
</form>
</body>
</html>
<script language="c#" runat="server">...
void Page_Load() ...{
if(!Page.IsPostBack) ...{
if(Session["管理"]!=null)
a_zz.Text=Session["管理"].ToString();
sjtc();
ymtc();
a_bt.InnerHtml=ConfigurationSettings.AppSettings["留言本名称"];
}
}
void sjtc() ...{
OleDbConnection lj = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("lyb.mdb"));
OleDbDataAdapter ml = new OleDbDataAdapter("select * from 留言 order by 编号 desc",lj);
DataSet sj = new DataSet();
ml.Fill(sj);
int zs=sj.Tables[0].Rows.Count; //总记录数
int fys=int.Parse(ConfigurationSettings.AppSettings["每页记录数"]);
int ys=zs/fys; //总页数
if(zs%fys!=0)
ys++;
PagedDataSource fy = new PagedDataSource();
fy.DataSource = sj.Tables[0].DefaultView;
fy.AllowPaging = true;
fy.PageSize = fys;
int y;
try ...{
y=int.Parse(Request.QueryString["y"]);
}
catch ...{
y=1;
}
fy.CurrentPageIndex=y-1;
a_xsly.DataSource=fy;
a_xsly.DataBind();
HyperLink s=null,x=null;
s=(HyperLink)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_sy");
x=(HyperLink)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_xy");
if(!fy.IsFirstPage)
s.NavigateUrl="index.aspx?y="+(y-1);
if(!fy.IsLastPage)
x.NavigateUrl="index.aspx?y="+(y+1);
((Label)a_xsly.Controls[a_xsly.Controls.Count-1].FindControl("a_sltj")).Text="共有 <span class="hsz">"+zs+"</span> 条留言/ <span class="hsz">"+ys+"</span> 个页面 当前是第 <span class="hsz">"+y+"</span> 页(<span class="hsz">"+a_xsly.Items.Count+"</span> 条留言) <a href="index.aspx">首页</a> <a href="index.aspx?y="+ys+"">尾页</a>";
}
void ymtc() ...{
a_tb.Text="";
for(int i=1;i<=48;i++)
a_tb.Text+="<input type="image" src="images/tb/"+i+".gif" onclick="cr(this.form.a_lynr,'"+i+"',2);return false;" /> ";
for(int i=0;i<=int.Parse(ConfigurationSettings.AppSettings["头像数"]);i++)
a_tx.Items.Add(i.ToString());
a_tx.DataBind();
}
string glyhf(string bl1,object bl2) ...{
if(bl1!="")
return "<div class="ly2"><div>管理员回复:</div><div>"+bl1+"</div><div align="right">"+bl2.ToString()+"</div></div>";
return "";
}
void tjly(object sender,ImageClickEventArgs e) ...{
if(Page.IsValid) ...{
string mlwb="insert into 留言(内容,作者,邮箱,主页,电话,QQ,头像) values(@nr,@zz,@yx,@zy,@dh,@qq,@tx)";
int bl=0;
try ...{
bl=Convert.ToInt32(Regex.Match(a_lynr.Text,"SC=[0-9]+;").ToString().Replace("SC=","").Replace(";",""));
}catch ...{}
if(bl!=0)
mlwb="delete from 留言 where 编号="+bl;
else ...{
try ...{ bl=Convert.ToInt32(Regex.Match(a_lynr.Text,"HF=[0-9]+;").ToString().Replace("HF=","").Replace(";","")); }
catch ...{}
if(bl!=0)
mlwb="update 留言 set 回复内容='"+Regex.Replace(a_lynr.Text.Replace("'","''"),"HF=[0-9]+;","")+"',回复时间=now() where 编号="+bl;
}
OleDbConnection lj = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("lyb.mdb"));
OleDbCommand ml = new OleDbCommand(mlwb,lj);
lj.Open();
if(bl==0) ...{
ml.Parameters.Add("@nr",OleDbType.VarChar,5000,"内容");
ml.Parameters.Add("@zz",OleDbType.VarChar,8,"作者");
ml.Parameters.Add("@yx",OleDbType.VarChar,50,"邮箱");
ml.Parameters.Add("@zy",OleDbType.VarChar,50,"主页");
ml.Parameters.Add("@dh",OleDbType.VarChar,13,"电话");
ml.Parameters.Add("@qq",OleDbType.VarChar,13,"QQ");
ml.Parameters.Add("@tx",OleDbType.Integer);
ml.Parameters["@nr"].Value=a_lynr.Text.Replace("'","''");
ml.Parameters["@zz"].Value=a_zz.Text;
ml.Parameters["@yx"].Value=a_yx.Text;
ml.Parameters["@zy"].Value=a_zy.Text;
ml.Parameters["@dh"].Value=a_dh.Text;
ml.Parameters["@qq"].Value=a_qq.Text;
ml.Parameters["@tx"].Value=a_tx.SelectedIndex;
}
ml.ExecuteNonQuery();
lj.Close();
Response.Redirect("index.aspx");
}
}
string ubb(object bl)
...{
string [] dx = ConfigurationSettings.AppSettings["缩略图大小"].Split(',');
string fh=bl.ToString().Replace("&","&").Replace("<","<").Replace(">",">").Replace("''","'");
fh=Regex.Replace(fh,@"[strong](.*?)[/strong]","<strong>$1</strong>");
fh=Regex.Replace(fh,@"[u](.*?)[/u]","<u>$1</u>");
fh=Regex.Replace(fh,@"[em](.*?)[/em]","<em>$1</em>");
fh=Regex.Replace(fh,@"[color=W?(.*?)W?](.*?)[/color]","<span style="color:$1;">$2</span>");
fh=Regex.Replace(fh,@"[img,([0-9]*),([0-9]*)](.*?)[/img]","<img src="$3" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);" alt="" /><a href="$3" target="_blank" alt="$3">浏览原图</a>");
fh=Regex.Replace(fh,@"[img](.*?)[/img]","<img src="$1" alt="" style="border:0;width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);" /><a href="$1" target="_blank" alt="$1">浏览原图</a>");
fh=Regex.Replace(fh,@"[T([0-9]+)]","<img src="images/tb/$1.gif" alt="" />");
fh=Regex.Replace(fh,@"[url](http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?)[/url]","<a href="$1" target="_blank" title="$1">$1</a>");
fh=Regex.Replace(fh,@"[url=W?(http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?)W?](.*?)[/url]","<a href="$1" target="_blank" title="$1">$4</a>");
fh=Regex.Replace(fh,@"[mail](w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*)[/mail]","<a href="mailto:$1" title="$1">$1</a>");
fh=Regex.Replace(fh,@"[mail=W?(w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*)W?](.*?)[/mail]","<a href="mailto:$1" title="$1">$5</a>");
fh=Regex.Replace(fh,@"[move](.*?)[/move]","<marquee>$1</marquee>");
fh=Regex.Replace(fh,@"[flash,([0-9]*),([0-9]*)](.*?.swf)[/flash]","<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);"> <param name="movie" value="$3" /> <param name="quality" value="high" /> <embed src="$3" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" style="width:expression($1>"+dx[0]+"?"+dx[0]+":$1);height:expression($2>"+dx[1]+"?"+dx[1]+":$2);"></embed> </object><a href="$3" target="_blank">浏览flash</a><br />");
fh=Regex.Replace(fh,@"[flash](.*?.swf)[/flash]","<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" style="width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);"> <param name="movie" value="$1" /> <param name="quality" value="high" /> <embed src="$1" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" style="width:expression(width>"+dx[0]+"?"+dx[0]+":width);height:expression(height>"+dx[1]+"?"+dx[1]+":height);"></embed> </object><br /><a href="$1" target="_blank">浏览flash</a><br />");
//return fh.Replace(" ","<br />");
return fh.Replace(" ","").Replace(" ","<br />");
}
</script>
- .Net WinForm学习笔记
- .Net WinForm学习笔记
- .NET Framework学习笔记
- .NET Framework学习笔记
- .net 学习笔记
- ASP.NET学习笔记
- ASP.NET学习笔记
- ADO.NET学习笔记
- .NET学习笔记
- asp.net 学习笔记
- .Net学习笔记(1)
- .Net WinForm学习笔记
- .Net WinForm学习笔记
- .Net WinForm学习笔记
- asp.net学习笔记
- .Net WinForm学习笔记
- ADO.NET学习笔记
- vb.net学习笔记
- DataGridView新特色(vs2005)
- 关于LD_LIBRARY_PATH
- 【转贴】程序员修身养性的十大原则
- 关于VS2005 WinForm下DataGridView单元格合并,背景色设置
- c#.net 中生成GUID
- .NET学习笔记
- Visual Studio 2005(C#)中只允许一个实例运行的一种方法
- 你的信用卡是什么颜色?由buyblue.org乱侃美国公司的红与蓝
- 使用java.nio读取网页的程序
- 美国房市还能火多久?看看最新预测怎么说。
- DropDownList绑定枚举类型
- 分析:华为辞职门事件赔了夫人又折兵
- 会出错的程序员才是出色的程序员
- 我的华为面试经历