我的晋级:递归栈、栈的小应用及 留言版多级嵌套。
2011-04-07 10:37 沐海 阅读(731) 评论(0) 编辑 收藏 举报
首先,此代码只是功能性的。没有按照规定整理一下。这是自己做的一个小项目
用来巩固所学的。需求:一个留言版,利用Jquery留言,实现留言的多级回复,
并针对回复进行多级的DIV输出。未完成:把每一个 标题楼 加上 ‘+’ ‘—’
号。实现展开和缩放。其实挺简单的。就不做了。思路如下:div的display进行
操作就可以了。整体思路:利用后台,把前台的所有信息进行输出。递归栈的应
用思路:1.产生每一个div进行的步骤都一样。所以可以独立一个方法。2.针对
评论进行回复的div是嵌套在评论的div中的。所以有多级嵌套。总结:针对多级
嵌套和步骤的重复性。利用 递归来进行操作生成。在生产的过程中要对每一层
嵌套的属性进行放置;这里应用了栈。
1.UsedCarDetail.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UsedCarDetail.aspx.cs" Inherits="Web.Mpanel.UsedCarDetail" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <link href="images/css.css" type="text/css" rel="stylesheet" /> <link href="css/use_style-20110316164706.css" rel="stylesheet" type="text/css" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var GB_ROOT_DIR = "http://www.cnblogs.com/js/greybox/"; //设置GreyBox组件根目录 </script> <script src="http://www.cnblogs.com/js/greybox/AJS.js" type="text/javascript"></script> <script src="http://www.cnblogs.com/js/greybox/AJS_fx.js" type="text/javascript"></script> <link href="http://www.cnblogs.com/js/greybox/gb_styles.css" rel="stylesheet" type="text/css" /> <link href="css/guestbook.css" rel="stylesheet" type="text/css" /> <script src="js/Login.js" type="text/javascript"></script> <%-- <script src="http://www.cnblogs.com/js/common/jsHelper.js" type="text/javascript"></script> --%> <script src="http://www.cnblogs.com/js/greybox/gb_scripts.js" type="text/javascript"></script> <script src="http://www.cnblogs.com/js/jquery/jquery.js" type="text/javascript"></script> <script src="../js/jquery/jquery.form.js" type="text/javascript"></script> <script src="js/jquery.zxxbox.3.0-min.js" type="text/javascript"></script> <script src="js/Common2010.js" type="text/javascript"></script> <script src="js/main.js" type="text/javascript"></script> <style type="text/css"> .STYLE1 { font-size: 11px; color: #3fa3bc; font-family: Arial, Helvetica, sans-serif; } .STYLE3 { font-size: 14px; } </style> < <script type="text/javascript"> function LoadAll() { getUsedCar(7, "Util/UsedCarUtil.aspx", "usedCar"); getGroup(6, "Util/GroupUtil.aspx", "Group"); //获得左栏 } </script> <script type="text/javascript"> //提交评论 function testForm() {//提交前验证 var tmp=document.getElementById("CContent").value; if(tmp==""){ alert("请填写您的回答!"); return false; } } $(document).ready(function() { var options = {//提交时参数 dataType: 'json', beforeSubmit: testForm, success: function(data) { if (data.result == "true") { $(document).ready(function() { msgBox('发布成功!') }); // document.location.reload();//当前页面 window.location.reload(); } else { alert('发布失败!'); document.getElementById("CContent").focus(); } } }; //提交时绑定 $('#Register').ajaxForm(options); }); </script> <script type="text/javascript"> function Replay(id){ document.getElementById("Id1").value=id; } function testForm2() {//提交前验证 var tmp=document.getElementById("CommentReplay").value; if(tmp==""){ alert("请填写您的回答!"); return false; } } $(document).ready(function() { var options = {//提交时参数 dataType: 'json', beforeSubmit: testForm2, success: function(data) { if (data.result == "true") { $(document).ready(function() { msgBox('发布成功!') }); // document.location.reload();//当前页面 window.location.reload(); } else { alert('发布失败!'); document.getElementById("CommentReplay").focus(); } } }; //提交时绑定 $('#Replayform').ajaxForm(options); }); </script> </head> <body onload="LoadAll();"> <table cellspacing="0" cellpadding="0" width="1003" align="center" border="0"> <tbody> <tr> <td valign="top"> <table cellspacing="0" cellpadding="0" width="1003" align="center" border="0"> <tbody> <tr> <td width="18" height="46"> <img height="97" src="images/top1.gif" width="18" /> </td> <td width="18"> <img height="97" src="images/top2.gif" width="18" /> </td> <td valign="bottom" width="967" background="images/topbj.jpg"> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td align="right" width="60%" height="31"> <%-- <a class="bottom2" href="">收藏我们</a> | <a class="bottom2" href="">关于我们</a> | <a class="bottom2" href="">联系我们</a> |--%> </td> <td align="right" width="40%"> 用户名:<input type="text" id="username" style="width: 20%;" />密码<input type="text" id="password" style="width: 20%;" /> <button id="Login" type="button" class="bottom2 " onclick="Login('username','password');"> 登录</button> <button id="Button1" type="button" class="bottom2 " onclick="register();"> 注册</button> </td> </tr> </tbody> </table> <table height="37" cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td width="883" background="images/menubj.gif" height="27"> <table height="26" cellspacing="0" cellpadding="0" width="764" align="center" border="0"> <tbody> <tr> <td class="menul" align="middle"> <a href="index.asp"> <img src="images/m1.gif" height="19" border="0" /></a> </td> <td class="menul" align="middle"> <a href="xw.asp"> <img height="19" src="images/m2.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="qccj.asp"> <img height="19" src="images/m3.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="qiwx.asp"> <img height="19" src="images/m4.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="pjsc.asp"> <img height="19" src="images/m5.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="qybk.asp"> <img height="19" src="images/m6.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="network1.asp"> <img height="19" src="images/m7.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="http://www.cmcwt.com/" target="_blank"> <img height="19" src="images/m8.gif" width="60" border="0" /></a> </td> <td class="menul" align="middle"> <a href="jsbz.asp"> <img height="19" src="images/m9.gif" width="60" border="0" /></a> </td> </tr> </tbody> </table> </td> <td width="84" background="images/menubj.gif"> <img height="37" src="images/menur.gif" width="104" /> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <table style="margin-top: 8px" cellspacing="0" cellpadding="0" width="1003" align="center" border="0"> <tbody> <tr> <td height="68"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1000" height="198"> <param name="movie" value="images/BAN.swf" /> <param name="quality" value="high" /> <embed src="images/BAN.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1000" height="198"></embed> </object> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <table cellspacing="0" cellpadding="0" align="center" border="0"> <tbody> <tr> <td width="18" height="144"> <img height="1" src="images/zw.gif" width="18"> </td> <td style="padding-top: 12px" valign="top" width="261"> <table style="margin-top: 8px" cellspacing="0" cellpadding="0" width="100" border="0"> <tbody> <tr> <td> <img height="57" src="images/tela1.gif" width="251" border="0"> </td> </tr> <tr> <td valign="top" background="images/tela2.gif" id="usedCar"> <%-- <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=204">夏天用车知识汇总</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2010-4-17]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=203">定期保养让车辆永葆青</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2010-4-17]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=170">驾车出行六种故障意外</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2010-1-11]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=163">汽车救援服务市场空间</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-12-9]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=162">汽车救援期待登高望远</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-12-9]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=161">市交通局检查汽车救援</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-12-9]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=129">中联车盟掀整合浪潮 </a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-4-23]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=128">汽车救援路在何方</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-4-23]</font> </td> </tr> </table> <table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" class="db"> <tr> <td width="64%" height="23" align="left" valign="middle" class="bottom2"> ·<a href="shownews.asp?id=126">汽车救援,谁做老大</a> </td> <td width="36%" valign="bottom" class="black"> <font color="#5e5e5e">[2009-4-22]</font> </td> </tr> </table>--%> </td> <tr> <td> <img height="25" src="images/se4.gif" width="251" border="0"> </td> </tr> </tbody> </table> <table width="10%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="7"> </td> </tr> </table> <table width="100" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <img height="42" src="images/yxlj.gif" width="251" border="0"> </td> </tr> <tr> <td valign="top" background="images/tela2.gif" id="Group"> <%-- <table width="97%" border="0" align="center" cellpadding="3" cellspacing="0"> <tbody> <tr> <td height="23" align="left" nowrap="nowrap"> <span style="padding-bottom: 1px; padding-top: 4px">·</span><a href="http://www.dlqcjy.com" target="_blank" class="rec_st">大连迅捷汽车救援</a> </td> </tr> <tr> <td height="23" align="left" nowrap="nowrap"> <span style="padding-bottom: 1px; padding-top: 4px">·</span><a href="http://www.dalian.net.cn" target="_blank" class="rec_st">大连便民网</a> </td> </tr> <tr> <td height="23" align="left" nowrap="nowrap"> <span style="padding-bottom: 1px; padding-top: 4px">·</span><a href="http://www.cpab.dl.gov.cn/" target="_blank" class="rec_st">大连市交通局</a> </td> </tr> <tr> <td height="23" align="left" nowrap="nowrap"> <span style="padding-bottom: 1px; padding-top: 4px">·</span><a href="http://www.dlbii.gov.cn/" target="_blank" class="rec_st">大连市信息产业局</a> </td> </tr> <tr> </tr> </tbody> </table>--%> </td> <tr> <td> <a href="#search.asp" target="_blank"></a> </td> </tr> <tr> <td> <img height="25" src="images/se4.gif" width="251" border="0"> </td> </tr> </tbody> </table> </td> <td valign="top" style="padding-left: 3px; padding-top: 12px"> <table cellspacing="0" cellpadding="0" width="98%" border="0"> <tbody> <tr> <td width="95" background="images/teln2.gif"> <img height="20" src="images/xxxx.gif" width="95" runat="server" id="selectinfo"> </td> <td width="181" background="images/teln2.gif"> </td> <td align="right" width="148" background="images/teln2.gif"> </td> </tr> </tbody> </table> <table style="margin-top: 8px" cellspacing="0" cellpadding="0" width="98%" border="0"> <tbody> <tr> <td height="160" align="right" valign="top"> <table width="97%" border="0" align="center"> <tr> <td align="left"> <fieldset> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="ziti"> <tr> <td colspan="2" align="center" valign="middle"> </td> </tr> <tr> <td colspan="2" align="left" valign="top" id="list" runat="server"> </td> </tr> <tr> <td colspan="5" align="left" valign="top" id="GMSG" runat="server"> </td> </tr> <tr> <td colspan="2" align="left" valign="top"> <div id="contents" runat="server"> </div> </td> </tr> <tr> <td colspan="5" align="left" valign="top" id="replay" runat="server"> </td> </tr> </table> </fieldset> </td> </tr> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <div id="Command" style="display: none; position: static; width: 600px; height: 200px; top: 405px; left: 330px"> <form action="Commandwindow.aspx" method="post" id="Register"> <input id="BuyID" type="hidden" runat="server" /> <input id="parameter" type="hidden" runat="server" /> <table cellpadding="0" cellspacing="3" border="0" id="searchTb"> <tr> <td id="Td1" align="center" runat="server"> <textarea rows="10" cols="81" id="CContent" runat="server"></textarea> </td> </tr> <tr> <td colspan="5" align="center"> <input type="submit" id="btnSubmit" class="input_button" value="提交" /> </td> </tr> </table> </form> </div> <div id="Repaly" style="display: none; position: static; width: 600px; height: 200px; top: 405px; left: 330px"> <form action="Util/ReplayUtil.aspx" method="post" id="Replayform"> <input id="BuyID1" type="hidden" runat="server" /> <input id="parameter1" type="hidden" runat="server" /> <input id="Id1" type="hidden" runat="server" /> <table cellpadding="0" cellspacing="3" border="0" id="Table1"> <tr> <td id="Td2" align="center" runat="server"> <textarea rows="10" cols="81" id="CommentReplay" runat="server"></textarea> </td> </tr> <tr> <td colspan="5" align="center"> <input type="submit" id="Submit1" class="input_button" value="提交" /> </td> </tr> </table> </form> </div> <table width="1003" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top: 5px"> <tbody> <tr> <td> <style type="text/css"> <! -- .STYLE1 { font-size: 11px; color: #3fa3bc; font-family: Arial, Helvetica, sans-serif; } -- ></style> <table width="1003" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top: 5px"> <tbody> <tr> <td background="images/bot.gif" height="20"> </td> </tr> <tr> <td height="68" align="center" valign="top" bgcolor="#f6f6f6"> <span class="STYLE1">版权所有 © 马海淞</span> 2009 </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </body> </html>
2.
UsedCarDetail.aspx.cs
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; namespace Web.Mpanel { public partial class UsedCarDetail : System.Web.UI.Page { database.BLL.UsedCar uBll = new database.BLL.UsedCar(); database.Model.UsedCar uModel = new database.Model.UsedCar();//二手车信息 database.BLL.UsedCarComment uCBll = new database.BLL.UsedCarComment(); database.Model.UsedCarComment uCModel = new database.Model.UsedCarComment();//二手车评论 database.Model.D_Dics model = new database.Model.D_Dics();// //省市的字典表 database.BLL.D_IBll dcBll = new database.BLL.D_City();// D_IBLL本身是一个接口。只是实现共有的方法体。在方法体中参数的MODEL模型是 D——Dics的模型。因为此模型只是用做数据封装。只要是相同属性的数据都可以封装。不论哪个类。 database.BLL.D_IBll dpBll = new database.BLL.D_Province();//而后面的BLL 是针对 继承此接口的 方法 来实现的 具体的 相应的操作。 string DetailTyle; string Login; int parame; string loginname; string save; int jilu = 0; int biaojie = 0; int lou = 0; bool ding = false; Stack<int> numStack = new Stack<int>(); //这个栈又来存放算数 protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { int Idkey = int.Parse(Request["Id"].ToString()); uModel = uBll.GetModel(Idkey);//得到 数据 uModel.ViewNum += 1; uBll.Update(uModel); } if (Session["UserInfo"] == null) { Login = "0";// 用于 添加好友 时提示 是否登录 } else { Login = "1";//用户已经登录 } DetailTyle = Request["DetailTyle"].ToString(); int Id = int.Parse(Request["Id"].ToString()); parame = int.Parse(Request["parameter"].ToString());// 0,求购信息;1,供应信息。 if (parame == 0) { loginname = "求购"; } if (parame == 1) { loginname = "供应"; } BuyID.Value = Id.ToString(); BuyID1.Value = Id.ToString(); switch (DetailTyle) { case "2"://加载二手车市活动 Loadusedcar(); break; default: break; } } catch { } } /// <summary> /// 二手车市 /// </summary> private void Loadusedcar() { try { bool k = false; switch (parame) { case 0: k = true; selectinfo.Src = "images/qiugou.gif"; //还要做 一些对于图片的控制 。显示 是求购信息的 还是 供应的 信息 //selectinfo 控制 其 src break; case 1: k = true; selectinfo.Src = "images/gongying.gif"; //还要做 一些对于图片的控制 。显示 是求购信息的 还是 供应的 信息 break; default: break; } if (k) { //传递参数正确 int id = int.Parse(Request["Id"].ToString()); parameter.Value = "2"; parameter1.Value = "2"; uModel = uBll.GetModel(id);//得到 数据 //uModel.ViewNum += 1; //uBll.Update(uModel); string Province = ""; string City = ""; //针对省市进行判断。 if (uModel.Province != 1 && dpBll.Exists(uModel.Province)) { //字典表中有此记录。而且还不是 请选择 这一项。 model = dpBll.GetModel(uModel.Province); Province = model.Caption; } if (uModel.City != 1 && dcBll.Exists(uModel.City)) { model = dcBll.GetModel(uModel.City); //省市的变化一般比较小。如果原有数据为4,又被删除了。这种异常现在不考虑。 } var str = ""; str += " <div class='play_list1'><table> <tr><td><a href=''target='_blank'><img alt='" + uModel.Title + "' border='0' height='98' width='148' src='" + uModel.Photo + "' /></a></td>"; str += " <td><table><th><h4 style='float: left; text-align: left;'><small>[" + loginname + "]</small> <span><a href='' target='_blank'>" + uModel.Title + "</a></span></h4></th> <tr>"; str += " <td><div class='xq'><table><tr><td><div style='width: 400px'> <dl> <dt>时 间:</dt><dd style='text-align: left;'>" + uModel.CreatTime.ToShortDateString() + "</dd></dl>"; str += " <dl> <dt>地 点:</dt> <dd style='text-align: left;'> " + Province + "" + City + "</dd></dl> <dl><dt>发布人:</dt><dd style='text-align: left;'> " + uModel.Creater.ToString() + " "; if (Context.User.Identity.Name.ToString().Equals(uModel.Creater.ToString()) || Context.User.Identity.Name.ToString() == uModel.Creater.ToString()) { str += "</dd></dl></div></td> </tr></table></div></td> <td><div style='width: 100px;'><div style=' font-style:italic;'><span style='font-size:small'>关注次数:</span><span style='color:Red;font-size:large; font-weight:500'>" + uModel.ViewNum + "</span></div></div></td></tr></table><div> <div class='time'> <a href='javascript:void(0);' onclick=\"show('Command');\" >发布通知>></a> </div></div></td></tr></table> </div>"; //作者 } else { str += " <a href='javascript:addfriend(\"" + uModel.Creater + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button' >加为好友</a></dd></dl></div></td> <td><div style='width: 100px;'><div style=' font-style:italic;'><span style='font-size:small'>关注次数:</span><span style='color:Red;font-size:large; font-weight:500'>" + uModel.ViewNum + "</span></div></div></td> </tr></table></div></td> </tr></table><div> <div class='time'> <a href='javascript:void(0);' onclick=\"show('Command');\" >我来说两句>></a> </div></div></td></tr></table> </div>"; //参与人 } list.InnerHtml = str; DataSet ds2 = uCBll.GetList("Creater='" + uModel.Creater + "' And UsedCarId='" + id + "'");//对应活动ID编号 对应创建人 DataTable dt3 = ds2.Tables[0]; if (dt3.Rows.Count > 0) { var d = "<div class='wenxintishi'style='dispaly:block'><h5>通知公告:</h5></div>"; for (int l = 0; l < dt3.Rows.Count; l++) { d += "<div><p><label>" + dt3.Rows[l]["Contents"].ToString() + "</label></p> <div style='margin-left:430px'><p>发布时间<label>" + dt3.Rows[l]["CreatTime"].ToString() + "</label></p> </div><hr style='background-color:Gray' /></div>"; } GMSG.InnerHtml = d; } else { GMSG.Visible = false; } var str1 = ""; str1 += "<div class='wenxintishi'><p><strong>温馨提示:</strong><em><a>参加会员活动得精美礼品或易车币</a></em></p></div>"; str1 += "<h4> 详情介绍:</h4>"; str1 += "<p>" + Server.HtmlDecode(uModel.Contents) + "</p>"; contents.InnerHtml = str1; DataTable dtTmp = uCBll.GetList("UsedCarId='" + id + "' And Creater<>'" + uModel.Creater + "' And CommentId='0' order by creattime asc").Tables[0]; if (dtTmp.Rows.Count > 0) { var ssHtml = "<div class='wenxintishi'style='dispaly:block'><h5>大家来说道:</h5></div>"; for (int i = 0; i < dtTmp.Rows.Count; i++) { lou = i + 1; biaojie = 0; fun(int.Parse(dtTmp.Rows[i]["Id"].ToString())); } ssHtml += save; //for (int i = 0; i < dtTmp.Rows.Count; i++) //{ // ssHtml += "<div><p><label>" + dtTmp.Rows[i]["Contents"].ToString() + "</label></p> <div style='margin-left:380px'><p>发布时间<label>" + dtTmp.Rows[i]["CreatTime"].ToString() + "</label> | 发布者:<label>" + dtTmp.Rows[i]["Creater"].ToString() + "</label> "; // if (dtTmp.Rows[i]["Creater"].ToString().Trim().Equals("游客") || dtTmp.Rows[i]["Creater"].ToString().Trim() == "游客") // { // ssHtml += "</p></div> <hr style='background-color:Gray' /></div>"; // } // else // { // ssHtml += " <a href='javascript:addfriend(\"" + dtTmp.Rows[i]["Creater"].ToString().Trim() + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button'><img src='images/plus-green.png' />加为好友</a></p> </div> <hr style='background-color:Gray' /></div>"; // } //} replay.InnerHtml = ssHtml; } else { replay.Visible = false; } //回复的思想: 传递此留言的ID 。回复时。把此留言的ID 放在 对应的数据表的列中。 } else { //传递参数不正确。用于提示,数据加载异常。 } } catch { } } private void fun(int id) { try { uCModel = uCBll.GetModel(id); string replaystring; if (jilu % 2 == 0) { if (biaojie == 0) { jilu = 1;//首次 评论 红色标识 if (uCModel.Creater.Trim().Equals("游客") || uCModel.Creater.Trim() == "游客") { replaystring = "<div class='gbook_msg_list'> <div class='msg_bar'><div class='gbook_usrname'> #" + lou + "楼 " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " </div><div class='clear'></div> </div> <div class='msg_content'> <br /> " + uCModel.Contents + "</div>"; } else { replaystring = "<div class='gbook_msg_list'> <div class='msg_bar'><div class='gbook_usrname'> #" + lou + "楼 " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " <a href='javascript:addfriend(\"" + uCModel.Creater.Trim() + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button'><img src='images/plus-green.png' alt='加为好友' /></a></div><div class='clear'></div> </div> <div class='msg_content'> <br /> " + uCModel.Contents + "</div>"; } } else { jilu = 1;//首次 评论 红色标识 if (uCModel.Creater.Trim().Equals("游客") || uCModel.Creater.Trim() == "游客") { replaystring = "<div class='gbook_msg_list'> <div class='msg_bar'><div class='gbook_usrname'> " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " </div><div class='clear'></div> </div> <div class='msg_content'> <br /> " + uCModel.Contents + "</div>"; } else { replaystring = "<div class='gbook_msg_list'> <div class='msg_bar'><div class='gbook_usrname'> " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " <a href='javascript:addfriend(\"" + uCModel.Creater.ToString().Trim() + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button'><img src='images/plus-green.png' alt='加为好友' /></a></div><div class='clear'></div> </div> <div class='msg_content'> <br /> " + uCModel.Contents + "</div>"; } } } else { if (biaojie == 0) { jilu = 0; if (uCModel.Creater.Trim().Equals("游客") || uCModel.Creater.Trim() == "游客") { replaystring = "<div class='reply_content'> <div class='msg_bar' style='background-color:#f5f4fa'> <div class='gbook_usrname'> #" + lou + "楼 " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " </div><div class='clear'></div></div>" + uCModel.Contents + ""; } else { replaystring = "<div class='reply_content'> <div class='msg_bar' style='background-color:#f5f4fa'> <div class='gbook_usrname'> #" + lou + "楼 " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " <a href='javascript:addfriend(\"" + uCModel.Creater.Trim() + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button'><img src='images/plus-green.png' alt='加为好友' /></a></div><div class='clear'></div></div>" + uCModel.Contents + ""; } } else { jilu = 0; if (uCModel.Creater.Trim().Equals("游客") || uCModel.Creater.Trim() == "游客") { replaystring = "<div class='reply_content'> <div class='msg_bar' style='background-color:#f5f4fa'> <div class='gbook_usrname'> " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " </div><div class='clear'></div></div>" + uCModel.Contents + ""; } else { replaystring = "<div class='reply_content'> <div class='msg_bar' style='background-color:#f5f4fa'> <div class='gbook_usrname'> " + uCModel.Creater + " </div><div class='msg_time'><a href='javascript:void(0);' onclick=\"Replay('" + uCModel.Id + "');show('Repaly');\" >回复</a> " + uCModel.CreatTime + " <a href='javascript:addfriend(\"" + uCModel.Creater.Trim() + "\",\"" + Login + "\",\"Util/FriendUtil.aspx\")' class='wycj_button'><img src='images/plus-green.png' alt='加为好友' /></a></div><div class='clear'></div></div>" + uCModel.Contents + ""; } } } biaojie++; save += replaystring; //首先添加String id replaystring DataTable dt = uCBll.GetList("CommentId='" + id + "'order by creattime asc").Tables[0]; if (dt.Rows.Count > 0) { numStack.Push(dt.Rows.Count); for (int i = 0; i < dt.Rows.Count; i++) { ding = false; int ll = numStack.Pop();// if (ll != 1) { numStack.Push(ll - 1); } else { ding = true; } fun(int.Parse(dt.Rows[i]["Id"].ToString())); if (ding) { save += "</div>"; if (numStack.Count == 0) { biaojie = 0; } ding = false; } } } else {//递归进行时,下一个回复的div是嵌套在 内容里的。所以我们不可能封死DIV 。要进行对应的记录。并补全。 //for (int d = 0; d < biaojie - 1; d++) //{ save += "</div>"; //} //if (numStack.Count == 0) //{ // biaojie = 0; //} } } catch { } finally { } } } }
3.其 调用的留言是利用的
jquery.zxxbox.3.0-min.js
后台是ReplayUtil.aspx.cs
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace Web.Mpanel.Util { public partial class ReplayUtil : System.Web.UI.Page { database.BLL.UsedCarComment uBll = new database.BLL.UsedCarComment(); database.Model.UsedCarComment uModel = new database.Model.UsedCarComment(); protected void Page_Load(object sender, EventArgs e) { try { string param = Request["parameter1"].ToString(); switch (param) { //case "1": // Choose();//团购的回答问题 // break; case "2": UsedCaeChoose();//二手车市的留言板功能 break; //case "3": // actChoose();//活动回答的问题 // break; default: break; } } catch { } } /// <summary> /// 回复 /// </summary> private void UsedCaeChoose() { Response.ContentType = "application/json"; string result = string.Empty; try { string Contents = Request["CommentReplay"].ToString(); int GroupId = int.Parse(Request["BuyID1"].ToString()); int CommentId = int.Parse(Request["Id1"].ToString());//回复编号 uModel.UsedCarId = GroupId; uModel.Contents = Contents; uModel.CommentId = CommentId;//评论编号为0 代表 不是回复 若评论编号 不为0 则去查找对应的ID 号码 if (Context.User.Identity.Name.ToString() == "" || Context.User.Identity.Name.ToString() == null) { uModel.Creater = "游客"; } else { uModel.Creater = Context.User.Identity.Name.ToString(); } uModel.CreatTime = DateTime.Now; uModel.UpdateTime = DateTime.Now; uModel.Memo = "memo"; uBll.Add(uModel); result = "{result:'true'}"; } catch { result = "{result:'false'}"; } finally { Response.Write(result); Response.Flush(); Response.End(); } } } }
本人声明:
个人主页:沐海(http://www.cnblogs.com/mahaisong)
以上文章都是经过本人设计实践和阅读其他文档得出。如果需要探讨或指教可以留言或加我QQ!欢迎交流!