用asp.net写的论坛程序--论坛主页

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
e main forum page

<%@ Page Language="C#" Debug="true" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<html><head>
<title>Welcome to My Forum!</title>
<script language="C#" runat="server" >
//execute this script when the page loads
void Page_Load(Object Src, EventArgs E)
{
//Call the Method to DataBind the DataGrid
Binding() ;
}
//This Method Connects to the Database, and DataBinds the Database to the DataGrid
public void Binding()
{
//String to connect to the database, If your Database is in some other directory then change the path
//To the Database below
string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" Server.MapPath(".//db//board.mdb") ;
//Make a Connection to the Database
ADOConnection myConn = new ADOConnection(strConn) ;
//String to select records from the Database. newpost Table
//I have used "ORDER BY postid DESC" since I want to show the latest post on the top
//If you remove this clause then the oldest message will be shown first
string strCom = "SELECT postid ,subject ,name ,replies ,views ,date FROM newpost ORDER BY postid DESC" ;
//Open the Connection, Always remember to Open the connection before doing anything else
myConn.Open();
DataSet myDataSet = new DataSet();
//Create a ADODataSetCommand and a DataSet
ADODataSetCommand myCommand =new ADODataSetCommand(strCom,myConn);
//Fill the DataSet
myCommand.FillDataSet(myDataSet,"newpost") ;
//Connection is closed
myConn.Close();
//Set the DataView of the Table "newpost" contained in the DataSet for the DataGrid
DataGrid1.DataSource = myDataSet.Tables["newpost"].DefaultView ;
//DataBind the DataGrid
DataGrid1.DataBind();
}
//This method is called when the DataGrid is Paged (i.e. when you change from Page 1 to Page 2 etc.. )
public void DataGrid_Updt(Object sender, DataGridPageChangedEventArgs e)
{
//Call the Method to Databind
Binding();
}
//This Method is called when the form is submitted to make a new Post
public void Submit_Click(Object sender, EventArgs e)
{
//proceed only if all the required fields are filled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
//Get the Current Date and Time
DateTime now = DateTime.Now ;
errmess.Text="" ;
//I am building a custom query which will be used to call the postmessage. aspx page.
//Since it will be a query we have to encode the query into UTF8 format.
//So I get all the fields from the form and encode them into UTF8 format
string req = "name=" System.Web.HttpUtility.UrlEncodeToString(name.Text, System.Text.Encoding.UTF8);
req ="&&email=" System.Web.HttpUtility.UrlEncodeToString(email.Text, System.Text.Encoding.UTF8);
req ="&&subject=" System.Web.HttpUtility.UrlEncodeToString(subject.Text, System.Text.Encoding.UTF8);
//Get the HostAddress of the Author
req ="&&ip=" System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
req ="&&date=" System.Web.HttpUtility.UrlEncodeToString(now.ToString(), System.Text.Encoding.UTF8);
req ="&&message=" System.Web.HttpUtility.UrlEncodeToString(message.Text, System.Text.Encoding.UTF8);
//A 'yes' is used below to tell the postmessage page that this is a new topic post
req ="&&newpost=" System.Web.HttpUtility.UrlEncodeToString("yes", System.Text.Encoding.UTF8);
//call the postmessage. aspx page and append the query to it.
Page.Navigate("postmessage. aspx?" req);
}
else
{
errmess.Text="Fill in all the Required Fields before Posting!<br>" ;
}
}
</script>
<LINK href="mystyle.CSS" type=text/css rel=stylesheet></head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- #Include File="header.inc" -->
<center>
< asp:label id="errmess" text="" style="COLOR:#ff0000" runat="server" />
< asp:Label class=fodark text="<font color=#00000 >Welcome to My Discussion Forum</font>" runat=server />
<br>
<br>
<form method="post" runat="server" ID=Form1>
<%-- The DataGrid settings. Its very interesting how much you can play with it --%>
< asp:DataGrid id=DataGrid1 runat="server" ForeColor="Black"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_Updt" PageSize="20" AllowPaging="True" width="80%" autogeneratecolumns="False">
<property name="PagerStyle">
< asp:DataGridPagerStyle BackColor="Coral" Mode="NumericPages">
</ asp:DataGridPagerStyle>
</property>

<property name="AlternatingItemStyle">
< asp:TableItemStyle BorderColor="#FFC080" BackColor="#FF9966">
</ asp:TableItemStyle>
</property>

<property name="FooterStyle">
< asp:TableItemStyle ForeColor="White" BackColor="DarkOrange">
</ asp:TableItemStyle>
</property>

<property name="ItemStyle">
< asp:TableItemStyle BackColor="Moccasin">
</ asp:TableItemStyle>
</property>

<property name="HeaderStyle">
< asp:TableItemStyle Font-Bold="True" ForeColor="White" BackColor="Coral">
</ asp:TableItemStyle>
</property>
<%-- I am setting up the Individual columns myself using Templates --%>
<property name="Columns">
<%-- Manipulate the subject entry so that it contains a link to the reply page --%>
< asp:TemplateColumn HeaderText="Subject" itemstyle-width=50%>
<template name="ItemTemplate" >
< asp:Label runat="server" Text='<%#"<a href=reply. aspx?postid=" DataBinder.Eval(Container, "DataItem.postid") ">"
DataBinder.Eval(Container, "DataItem.subject") "</a>" %>' ID=Label2></ asp:Label>
</template>
</ asp:TemplateColumn>

< asp:TemplateColumn HeaderText="Author Name" itemstyle-width=20%>
<template name="ItemTemplate">
< asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' ID=Label3></ asp:Label>
</template>
</ asp:TemplateColumn>


< asp:TemplateColumn HeaderText="Replies" itemstyle-width=10%>
<template name="ItemTemplate">
< asp:Label runat="server" width=10% Text='<%# DataBinder.Eval(Container, "DataItem.replies") %>' ID=Label4>
</ asp:Label>
</template>
</ asp:TemplateColumn>

< asp:TemplateColumn HeaderText="Views" itemstyle-width=10%>
<template name="ItemTemplate">
< asp:Label runat="server" width=10% Text='<%# DataBinder.Eval(Container, "DataItem.views") %>' ID=Label5>
</ asp:Label>
</template>
</ asp:TemplateColumn>

< asp:TemplateColumn HeaderText="Date of Post" itemstyle-width=10%>
<template name="ItemTemplate">
< asp:Label runat="server" width=10% Text='
<%# DataBinder.Eval(Container, "DataItem.date").ToString().ToDateTime().ToShortDateString() %>' ID=Label6>
</ asp:Label>

</template>
</ asp:TemplateColumn>
</property>
</ asp:DataGrid>
<br>
<br>
< asp:Label class=fodark text="<font color=#00000 >Post New Topic</font>" runat=server />
<br>
<table border="0" width="80%" align="center">
<tr >
<td class="fohead" colspan=2><b>Post New Topic</b></td>
</tr>
<tr class="folight" >
<td>Name :</td>
<td >< asp:textbox text="" id="name" runat="server" /> <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td>E-Mail :</td>
<td>< asp:textbox text="" id="email" runat="server"/> <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td> Subject:</td>
<td>< asp:textbox test="" id="subject" width=200 runat="server"/> <font color=#ff0000>*</font>
</td></tr>
<tr class="folight">
<td>Message :</td>
<td>
< asp:TextBox id=message runat="server"
Columns="30" Rows="15" TextMode="MultiLine"></ asp:TextBox></td>
</tr>
<tr class=folight>
<td colspan=2>
< asp:Button class=fodark id=write onClick=Submit_Click runat="server" Text="Submit"></ asp:Button></td></tr>
</table>
</form>
</center>
<!-- #Include File="footer.inc" -->
</body></html>

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
论坛演示地址: http://netfocus.b13.cnwg.cn 论坛功能设计  论坛前台: 1. 用户注册、登陆、注销; 2. 版块导航:显示所有的版块分组和版块; 3. 帖子列表:显示当前版块下所有的帖子,可以区分置顶帖子、精华帖子、推荐帖子; 4. 帖子内容:显示帖子内容; 5. 帖子回复:显示帖子的回复列表; 6. 添加帖子:用户添加新帖; 7. 添加回复:用户添加回复; 8. 精华帖子列表:显示所有的精华帖子; 9. 推荐帖子列表:显示所有的推荐帖子; 10. 帖子管理:具有帖子管理权限的人对帖子进行管理; 11. 回复管理:具有帖子回复管理权限的人对帖子回复进行管理;  论坛后台: 1. 版块组管理:添加、删除、修改; 2. 版块管理:添加、删除、修改,添加或修改时通过下拉框选择版块组; 3. 版主管理:可以管理论坛中每个版块的版主,如添加、删除版主; 4. 用户管理:查看用户资料、删除用户、封锁用户、解锁用户、重置密码; 5. 角色管理:添加、删除、修改; 默认定义如下角色: 系统管理员、用户管理员、角色管理员、版块管理员、版主管理员、版主、所有者、注册用户、所有人;其中所有者指发帖人,回复人;另外系统管理员、注册用户、所有者、所有人是内置角色,不能修改或删除;下面分别对每种角色的含义进行说明: 1) 系统管理员:拥有论坛所有权限; 2) 用户管理员:拥有用户管理权限; 3) 角色管理员:拥有角色管理权限; 4) 版块管理员:拥有版块管理权限; 5) 版主管理员:拥有版主管理权限; 6) 版主:拥有所有论坛事务管理权限; 7) 所有者:拥有对自己发表的帖子或回复的内容进行修改的权限;(此角色可以考虑禁用,出于数据真实性考虑,因为任何人都要对他或她所说的言行负责,不允许随便修改); 8) 注册用户:拥有一部分论坛事务,如看帖,发帖,回帖,管理和自己相关的一些帖子; 9) 所有人:这个角色只是一个映射角色,任何登陆网站的人都自动拥有此角色;此角色可以表示匿名用户;仅拥有此角色的人一般只能看帖,不能做其他任何事情。当然如果愿意,我们也可以给它分配更多的权限,如发帖,回帖。如果这样,那就意味着运行匿名用户发帖或回帖了。 6. 用户角色管理:对任意一个用户的所属角色进行管理(包括添加和删除用户所属角色); 7. 角色权限管理:分为两类进行管理; 系统管理权限:用户管理、角色管理、版块管理、版主管理; 论坛事务管理权限:浏览帖子、发表帖子、编辑帖子、置顶帖子、设为推荐帖子、设为精华帖子、删除帖子、修改回复、删除回复; 因为权限分为两种,所以角色权限管理也可以采用两个界面实现。这两个界面的行就是所有角色,列就是当前权限类型下的所有权限点。 8. 头像设置:设置用户的头像; 9. 密码修改; 10. 我的帖子管理:有我发布的帖子,我回复的帖子; 另外,一个论坛可能还常常有星级评定,积分设置,界面管理,等等其他辅助功能。这些东西可以在日后慢慢补充。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值