.net中xml留言本

project.xml
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='project.xsl'?>
<project>
 <info>
  <download>361</download>
  <view>655</view>
 </info>
 <comment>
  <sender>silenfir(220.169.150.87)</sender>
  <time>2007-5-2 13:57:07</time>
  <content>坐个沙发先~~</content>
 </comment>
 <comment>
</project>
           

project.aspx.cs
using System;
using System.Data;
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;

public partial class system_project : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (Request.QueryString["operate"!= null)
        
{
            
lock (typeof(system_project))
            
{
                
switch ((string)Request.QueryString["operate"])
                
{
                    
case "download":
                        AddDownload();
                        Response.Redirect(
"project.rar");
                        
break;
                    
case "view":
                        AddView();
                        Response.End();
                        
break;
                    
case "comment":
                        AddComment();
                        Response.Redirect(
"project.xml");
                        
break;
                    
case "suggest":
                        AddSuggest();
                        Response.Redirect(
"suggest.xml");
                        
break;
                }

            }

        }

    }

    
protected void AddDownload()
    
{
        DataSet dataset 
= new DataSet();
        
string path = this.Server.MapPath("project.xml");
        dataset.ReadXml(path);
        dataset.Tables[
"info"].Rows[0]["download"= int.Parse(dataset.Tables["info"].Rows[0]["download"].ToString()) + 1;//文件下载次数
        System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(path, null);
        xtw.WriteProcessingInstruction(
"xml""version='1.0' encoding='UTF-8'");
        xtw.WriteProcessingInstruction(
"xml-stylesheet""type='text/xsl' href='project.xsl'");
        dataset.WriteXml(xtw);
        xtw.Flush();
        xtw.Close();
    }

    
protected void AddView()
    
{
        DataSet dataset 
= new DataSet();
        
string path = this.Server.MapPath("project.xml");
        dataset.ReadXml(path);
        dataset.Tables[
"info"].Rows[0]["view"= int.Parse(dataset.Tables["info"].Rows[0]["view"].ToString()) + 1;//页面浏览次数
        System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(path, null);
        xtw.WriteProcessingInstruction(
"xml""version='1.0' encoding='UTF-8'");
        xtw.WriteProcessingInstruction(
"xml-stylesheet""type='text/xsl' href='project.xsl'");
        dataset.WriteXml(xtw);
        xtw.Flush();
        xtw.Close();
    }

    
protected void AddComment()
    
{
        
if (Request.Form["Text_Sender"== null || Request.Form["Text_Content"== nullreturn;
        DataSet dataset 
= new DataSet();
        
string path = this.Server.MapPath("project.xml");
        dataset.ReadXml(path);
        
if (dataset.Tables["comment"== null)//评论表若不存在则添加该表
        {
            dataset.Tables.Add(
"comment");
            dataset.Tables[
"comment"].Columns.Add("sender");//评论者
            dataset.Tables["comment"].Columns.Add("time");//发表时间
            dataset.Tables["comment"].Columns.Add("content");//内容
        }

        dataset.Tables[
"comment"].Rows.Add(new string[22{ Regular.Filtrate(Request.Form["Text_Sender"].ToString()) + "(" + Request.UserHostAddress + ")", DateTime.Now.ToString(),Regular.Filtrate(Request.Form["Text_Content"].ToString()) });//新增评论
        System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(path, null);
        xtw.WriteProcessingInstruction(
"xml""version='1.0' encoding='UTF-8'");
        xtw.WriteProcessingInstruction(
"xml-stylesheet""type='text/xsl' href='project.xsl'");
        dataset.WriteXml(xtw);
        xtw.Flush();
        xtw.Close();
    }

    
protected void AddSuggest()
    
{
        
if (Request.Form["Text_Sender"== null || Request.Form["Text_Content"== nullreturn;
        DataSet dataset 
= new DataSet();
        
string path = this.Server.MapPath("suggest.xml");
        dataset.ReadXml(path);
        
if (dataset.Tables["suggest"== null)//评论表若不存在则添加该表
        {
            dataset.Tables.Add(
"suggest");
            dataset.Tables[
"suggest"].Columns.Add("sender");//评论者
            dataset.Tables["suggest"].Columns.Add("time");//发表时间
            dataset.Tables["suggest"].Columns.Add("content");//内容
        }

        dataset.Tables[
"suggest"].Rows.Add(new string[22{ Regular.Filtrate(Request.Form["Text_Sender"].ToString()) + "(" + Request.UserHostAddress + ")", DateTime.Now.ToString(), Regular.Filtrate(Request.Form["Text_Content"].ToString()) });//新增评论
        System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(path, null);
        xtw.WriteProcessingInstruction(
"xml""version='1.0' encoding='UTF-8'");
        xtw.WriteProcessingInstruction(
"xml-stylesheet""type='text/xsl' href='suggest.xsl'");
        dataset.WriteXml(xtw);
        xtw.Flush();
        xtw.Close();
    }

}


project.xsl
<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="project">
    
<html>
      
<head>
        
<link rel="Stylesheet" href="Style.css" type="text/css" />
        
<script type="text/javascript">
          function checksubmit()
          {
            if(document.getElementById('Text_Sender').value=='')
            {
              alert('评论者名称不得为空!');
              return false;
            }
            if(document.getElementById('Text_Content').value=='' || document.getElementById("Text_Content").value.replace(/\s/g, "").length>2000)
            {
              alert('评论内容不的为空或超出2000字符!');
              return false;
            }
          }
        
</script>
      
</head>
    
<body>
    
<!--
        This is an XSLT template file. Fill in this area with the
        XSL elements which will transform your XML to XHTML.
    
-->
      
<script src="project.aspx?operate=view" type="text/javascript"></script>
      
<div style="width:760px; text-align:center;border:#9ED3D9 1px solid;">
        
<div style="border-bottom:#9ED3D9 1px solid; height:40px; width:760px;">
          
<div style="float:left; margin-top:10px; text-align:left; margin-left:6px; width:400px;">大众小说网(c#,asp.net2.0)源码 Beta</div>
          
<div style="float:left; margin-top:10px; text-align:right; width:330px;"><span style="color:red;"><xsl:value-of select="info/download"/></span>/<xsl:value-of select="info/view"/></div>
        
</div>
        
<div>
          
<div style="float:left; width:220px;">
            
<div style="margin-top:30px;"><b><href="project.aspx?operate=download" style="color:#cc0000;" target="_blank">项目源码下载</a></b></div>
            
<div style="margin-top:10px;">涉及面:正则表达式、SQL(分页存储过程)、xml+xsl、Javascript(ajax)、用户控件、采集等</div>
          
</div>
          
<div style="float:left; width:530px; border-left:#9ED3D9 1px solid;">
            
<div style="font-weight:bold; margin-top:6px;">版权声明</div>
            
<div style="margin-top:5px; text-align:left; margin-left:6px;">
                源码版权归本站所有
<br />
                如果想将此源码用于商业用途或者在互联网上传播请先经过本站同意,谢谢!
<br />
                该源码适合初学者入门及提升(注:某些功能用两种写法实现,请加以区别)!
<br />
                本人水平有限,编码不足之处与BUG,还望指出!
<br />
                
<span style="color:red;">源码已经更新,加入采集、部分SQL数据</span><br /><br />
                联系方式:
<br />
                E-mail:qiezic@hotmail.com
<br />
                QQ:12471944
            
</div>
            
<div style="text-align:center; margin-bottom:5px; margin-top:5px;"><input onclick="opener=null;window.close();" type="button" value="我不同意此协议" style="height:26;" /></div>
          
</div>
        
</div>
      
</div>
      
<br />
      
<div style="width:760px; text-align:left;">
        
<form action="project.aspx?operate=comment" method="post" onsubmit="return checksubmit();">
          评论者:
          
<br />
          
<input id="Text_Sender" name="Text_Sender" type="text" value="匿名"  style="width:80px;" />
          
<br />
          
<br />
          
<textarea id="Text_Content" name="Text_Content" cols="20" rows="2" style="width:760px;height:60px;"></textarea>
          
<br />
          
<input id="Submit_" type="submit" value="发表评论" />
        
</form>
        
<xsl:for-each select="comment">
          
<div>
            
<hr style="color:Green;" />
            
<div style="width:100%;">
              
<div style="width:400px; float:left; text-align:left;"><xsl:value-of select="sender"/></div>
              
<div style="width:350px; float:left; text-align:right;"><xsl:value-of select="time"/></div>
            
</div>
            
<hr style="color:Gray; height:0;" />
            
<div style="margin-left:6px;word-wrap:break-word;">
              
<xsl:value-of select="content"/>
            
</div>
          
</div>
        
</xsl:for-each>
      
</div>
    
</body>
    
</html>
</xsl:template>

</xsl:stylesheet>
posted @ 2007-07-11 16:04  子午  阅读(495)  评论(0编辑  收藏  举报