first commit
This commit is contained in:
71
App_Code/DbManager.cs
Normal file
71
App_Code/DbManager.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Configuration;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// DbManager 的摘要说明
|
||||
/// </summary>
|
||||
public class DbManager
|
||||
{
|
||||
private static string strConn = "Server=localhost\\SQLEXPRESS;Database=bbs;Integrated Security=True";
|
||||
private static SqlConnection conn;
|
||||
public DbManager()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public static SqlCommand getCommand()
|
||||
{
|
||||
openConnection();
|
||||
SqlCommand comm = new SqlCommand();
|
||||
comm.Connection = conn;
|
||||
return comm;
|
||||
}
|
||||
public static SqlCommand getCommand(string sql)
|
||||
{
|
||||
openConnection();
|
||||
SqlCommand comm = new SqlCommand(sql, conn);
|
||||
return comm;
|
||||
}
|
||||
public static DataSet getDataSet(string sql, string dbName)
|
||||
{
|
||||
openConnection();
|
||||
DataSet myDataSet = new DataSet();
|
||||
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
|
||||
da.Fill(myDataSet, dbName);
|
||||
return myDataSet;
|
||||
}
|
||||
public static SqlDataReader getReader(string sql)
|
||||
{
|
||||
SqlCommand myComm = getCommand(sql);
|
||||
return myComm.ExecuteReader();
|
||||
}
|
||||
public static int getNonQuery(string sql)
|
||||
{
|
||||
SqlCommand comm = getCommand();
|
||||
comm.CommandText = sql;
|
||||
return comm.ExecuteNonQuery();
|
||||
}
|
||||
public static void closeConnection()
|
||||
{
|
||||
if(conn.State==ConnectionState.Open)
|
||||
conn.Close();
|
||||
}
|
||||
public static void openConnection()
|
||||
{
|
||||
if (conn == null)
|
||||
conn = new SqlConnection(strConn);
|
||||
if (conn.State == ConnectionState.Closed)
|
||||
conn.Open();
|
||||
}
|
||||
|
||||
}
|
||||
36
App_Code/function.cs
Normal file
36
App_Code/function.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// function 的摘要说明
|
||||
/// </summary>
|
||||
public class function
|
||||
{
|
||||
public function()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
public static string redirect(string url, string message)
|
||||
{
|
||||
string str = "";
|
||||
if (message != null && message != "")
|
||||
{
|
||||
str = "<div id='warning'>" + message + "</div>";
|
||||
str += "<script>setTimeout(function(){location.href='" + url + "'},1000)</script>";
|
||||
}
|
||||
else
|
||||
{
|
||||
str = "<script>self.location.href='" + url + "'</script>";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
38
BBS.sln
Normal file
38
BBS.sln
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "论坛", "http://localhost:3547", "{A8B129EE-780A-424F-B0E8-16EE9759AE4B}"
|
||||
ProjectSection(WebsiteProperties) = preProject
|
||||
UseIISExpress = "true"
|
||||
TargetFrameworkMoniker = ".NETFramework,Version%3Dv2.0"
|
||||
Debug.AspNetCompiler.VirtualPath = "/localhost_3547"
|
||||
Debug.AspNetCompiler.PhysicalPath = "D:\工作代码\咸鱼项目\1.bs项目\5.ASP+SQLSERVER 论坛系统\论坛\"
|
||||
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_3547\"
|
||||
Debug.AspNetCompiler.Updateable = "true"
|
||||
Debug.AspNetCompiler.ForceOverwrite = "true"
|
||||
Debug.AspNetCompiler.FixedNames = "false"
|
||||
Debug.AspNetCompiler.Debug = "True"
|
||||
Release.AspNetCompiler.VirtualPath = "/localhost_3547"
|
||||
Release.AspNetCompiler.PhysicalPath = "D:\工作代码\咸鱼项目\1.bs项目\5.ASP+SQLSERVER 论坛系统\论坛\"
|
||||
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_3547\"
|
||||
Release.AspNetCompiler.Updateable = "true"
|
||||
Release.AspNetCompiler.ForceOverwrite = "true"
|
||||
Release.AspNetCompiler.FixedNames = "false"
|
||||
Release.AspNetCompiler.Debug = "False"
|
||||
SlnRelativePath = "D:\工作代码\咸鱼项目\1.bs项目\5.ASP+SQLSERVER 论坛系统\论坛\"
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A8B129EE-780A-424F-B0E8-16EE9759AE4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A8B129EE-780A-424F-B0E8-16EE9759AE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
27
Default.aspx
Normal file
27
Default.aspx
Normal file
@@ -0,0 +1,27 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="10228宿舍论坛" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
<div id="page" class="page">
|
||||
<h2 runat=server id="h2"></h2>
|
||||
<asp:GridView ID="articlelist" runat="server" CellPadding="4" ForeColor="#6C7E4A" GridLines="Horizontal" AllowPaging="True" AutoGenerateColumns="False" Width="100%">
|
||||
<FooterStyle BackColor="#4ca8e5" Font-Bold="True" ForeColor="#ffffff" />
|
||||
<RowStyle BackColor="#F9F9F9" BorderColor="#4ca8e5" BorderStyle="Solid" BorderWidth="1px" />
|
||||
<PagerStyle BackColor="#BCD988" ForeColor="#ffffff" HorizontalAlign="Left"/>
|
||||
<HeaderStyle BackColor="#4ca8e5" Font-Bold="True" ForeColor="#ffffff" HorizontalAlign="Center" VerticalAlign="Middle" />
|
||||
<AlternatingRowStyle BackColor="White" />
|
||||
<PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
|
||||
NextPageText="下一页" PreviousPageText="上一页" />
|
||||
<Columns>
|
||||
<asp:BoundField DataField="id" HeaderText="文章编号" ReadOnly="True" Visible="False" />
|
||||
<asp:BoundField DataField="replaynum" HeaderText="回复" />
|
||||
<asp:BoundField DataField="readnum" HeaderText="阅读" />
|
||||
<asp:BoundField DataField="title" HeaderText="题目" />
|
||||
<asp:BoundField DataField="username" HeaderText="作者" />
|
||||
<asp:BoundField DataField="classname" HeaderText="类别" />
|
||||
<asp:BoundField DataField="time" HeaderText="发表时间" />
|
||||
<asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="article.aspx?id={0}"
|
||||
HeaderText="查看" Text="View" />
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
27
Default.aspx.cs
Normal file
27
Default.aspx.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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 _Default : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
h2.InnerHtml = "最近的发表的帖子";
|
||||
string sql = "select top 10 article.id,replaynum,readnum,title,username,classname,time from article,[user] where " +
|
||||
"userid=authorid order by article.id desc";
|
||||
DataSet ds = DbManager.getDataSet(sql, "newArticle");
|
||||
this.articlelist.DataSource = ds.Tables["newArticle"];
|
||||
this.DataBind();
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Manager.aspx
Normal file
35
Manager.aspx
Normal file
@@ -0,0 +1,35 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Manager.aspx.cs" Inherits="Manager" Title="10228宿舍论坛" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
<div class="page" id="page">
|
||||
<div id="table" runat=server class="table">
|
||||
<h2 runat=server id="h2"></h2>
|
||||
<asp:GridView ID="articlelist" runat="server" CellPadding="4" ForeColor="#6C7E4A" GridLines="Horizontal" AllowPaging="True" AutoGenerateColumns="False" Width="100%" OnRowDeleting="articlelist_RowDeleting" >
|
||||
<FooterStyle BackColor="#BCD988" Font-Bold="True" ForeColor="#996600" />
|
||||
<RowStyle BackColor="#F9F9F9" BorderColor="#BCD988" BorderStyle="Solid" BorderWidth="1px" />
|
||||
<PagerStyle BackColor="#BCD988" ForeColor="#996600" HorizontalAlign="Left"/>
|
||||
<HeaderStyle BackColor="#BCD988" Font-Bold="True" ForeColor="#996600" HorizontalAlign="Center" VerticalAlign="Middle" />
|
||||
<AlternatingRowStyle BackColor="White" />
|
||||
<PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
|
||||
NextPageText="下一页" PreviousPageText="上一页" />
|
||||
<Columns>
|
||||
<asp:BoundField DataField="id" HeaderText="文章编号" ReadOnly="True" >
|
||||
<ItemStyle CssClass="hidden" />
|
||||
<HeaderStyle CssClass="hidden" />
|
||||
<FooterStyle CssClass="hidden" />
|
||||
</asp:BoundField>
|
||||
<asp:BoundField DataField="replaynum" HeaderText="回复" />
|
||||
<asp:BoundField DataField="readnum" HeaderText="阅读" />
|
||||
<asp:BoundField DataField="title" HeaderText="题目" />
|
||||
<asp:BoundField DataField="username" HeaderText="作者" />
|
||||
<asp:BoundField DataField="classname" HeaderText="类别" />
|
||||
<asp:BoundField DataField="time" HeaderText="发表时间" />
|
||||
<asp:CommandField HeaderText="管理" ShowDeleteButton="True" />
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
</div>
|
||||
<div id="message" runat="server">
|
||||
<asp:HiddenField ID="classValue" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
100
Manager.aspx.cs
Normal file
100
Manager.aspx.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
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;
|
||||
|
||||
public partial class Manager : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
//非法url链接
|
||||
if (Request.QueryString["class"] == null)
|
||||
{
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "请确认要管理的社区!");
|
||||
}
|
||||
else
|
||||
{
|
||||
string classname = Server.UrlDecode(Request.QueryString["class"].ToString());
|
||||
classValue.Value = classname;
|
||||
if (Session["userid"] != null && Session["userid"].ToString() != "")
|
||||
{
|
||||
//确认该用户是否为版主
|
||||
int i = Convert.ToInt32(Session["banzhu"].ToString());
|
||||
bool flag = false;
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
string banzhu = "banzhu" + j;
|
||||
if (Session[banzhu]!=null&&Session[banzhu].ToString() == classname)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//不是版主,退出到主页
|
||||
if (!flag)
|
||||
{
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "您不是该版的版主!");
|
||||
}
|
||||
//是版主,载入该类信息
|
||||
h2.InnerHtml = "管理 <b>" + classname + "</b> 信息";
|
||||
string sql = "select article.id,replaynum,readnum,title,username,classname,time from article,[user] " +
|
||||
"where classname='" + classname + "' and userid=authorid order by article.id desc";
|
||||
DataSet ds = DbManager.getDataSet(sql, "manArticle");
|
||||
this.articlelist.DataSource = ds.Tables["manArticle"];
|
||||
this.articlelist.DataKeyNames = new string[] { "id" }; //绑定主键
|
||||
this.articlelist.DataBind();
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "身份有误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void articlelist_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
||||
{
|
||||
string id = this.articlelist.DataKeys[e.RowIndex].Value.ToString(); //获取article主键id
|
||||
//首先查询出作者id即authorid,并使得该作者的帖子数目减一
|
||||
string selectSql = "select authorid from article where id=" + id;
|
||||
SqlDataReader reader = DbManager.getReader(selectSql);
|
||||
if (reader.HasRows)
|
||||
{
|
||||
reader.Read();
|
||||
string userid = reader["authorid"].ToString();
|
||||
reader.Close();
|
||||
//删除一个帖子
|
||||
string sql = "delete from article where id=" + id;
|
||||
if (DbManager.getNonQuery(sql) > 0)
|
||||
{
|
||||
string subBlog = "update [user] set blognum=blognum-1 where userid='" + userid + "'";
|
||||
DbManager.getNonQuery(subBlog);
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Manager.aspx?class=" + Server.UrlEncode(classValue.Value).ToString(), "删除成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "删除过程出错!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//屏蔽table
|
||||
table.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "删除过程出错!");
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Web.Config
Normal file
40
Web.Config
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
注意: 除了手动编辑此文件以外,您还可以使用
|
||||
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
|
||||
“网站”->“Asp.Net 配置”选项。
|
||||
设置和注释的完整列表在
|
||||
machine.config.comments 中,该文件通常位于
|
||||
\Windows\Microsoft.Net\Framework\v2.x\Config 中
|
||||
-->
|
||||
<configuration>
|
||||
<appSettings/>
|
||||
<connectionStrings/>
|
||||
<system.web>
|
||||
<!--
|
||||
设置 compilation debug="true" 将调试符号插入
|
||||
已编译的页面中。但由于这会
|
||||
影响性能,因此只在开发过程中将此值
|
||||
设置为 true。
|
||||
-->
|
||||
<compilation debug="true"/>
|
||||
<!--
|
||||
通过 <authentication> 节可以配置 ASP.NET 使用的
|
||||
安全身份验证模式,
|
||||
以标识传入的用户。
|
||||
-->
|
||||
<authentication mode="Windows"/>
|
||||
<!--
|
||||
如果在执行请求的过程中出现未处理的错误,
|
||||
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
|
||||
开发人员通过该节可以配置
|
||||
要显示的 html 错误页
|
||||
以代替错误堆栈跟踪。
|
||||
|
||||
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
|
||||
<error statusCode="403" redirect="NoAccess.htm" />
|
||||
<error statusCode="404" redirect="FileNotFound.htm" />
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
47
article.aspx
Normal file
47
article.aspx
Normal file
@@ -0,0 +1,47 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="article.aspx.cs" Inherits="article" Title="10228宿舍论坛" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
<div class="page" id="page">
|
||||
<div id="table" runat=server class="table">
|
||||
<h2 runat=server id="h2"></h2>
|
||||
<asp:GridView ID="articlelist" runat="server" CellPadding="4" ForeColor="#6C7E4A" GridLines="Horizontal" AllowPaging="True" AutoGenerateColumns="False" Width="100%">
|
||||
<FooterStyle BackColor="#BCD988" Font-Bold="True" ForeColor="#ffffff" />
|
||||
<RowStyle BackColor="#F9F9F9" BorderColor="#BCD988" BorderStyle="Solid" BorderWidth="1px" />
|
||||
<PagerStyle BackColor="#BCD988" ForeColor="#ffffff" HorizontalAlign="Left"/>
|
||||
<HeaderStyle BackColor="#4ca8e5" Font-Bold="True" ForeColor="#ffffff" HorizontalAlign="Center" VerticalAlign="Middle" />
|
||||
<AlternatingRowStyle BackColor="White" />
|
||||
<PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
|
||||
NextPageText="下一页" PreviousPageText="上一页" />
|
||||
<Columns>
|
||||
<asp:BoundField DataField="id" HeaderText="文章编号" ReadOnly="True" Visible="False" />
|
||||
<asp:BoundField DataField="replaynum" HeaderText="回复" />
|
||||
<asp:TemplateField HeaderText="头像">
|
||||
<ItemTemplate>
|
||||
<img src='<%# GetAvatarPath(Eval("username").ToString()) %>'
|
||||
width="50" height="50"
|
||||
onerror="this.src='images/tx2.jpg'"/>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField DataField="readnum" HeaderText="阅读" />
|
||||
<asp:BoundField DataField="title" HeaderText="题目" />
|
||||
<asp:BoundField DataField="username" HeaderText="作者" />
|
||||
<asp:BoundField DataField="classname" HeaderText="类别" />
|
||||
<asp:BoundField DataField="time" HeaderText="发表时间" />
|
||||
<asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="article.aspx?id={0}"
|
||||
HeaderText="查看" Text="View" />
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
</div>
|
||||
<div id="showContent" class="showContent" runat=server>
|
||||
</div>
|
||||
<div class="comment" id="comment" runat="server">
|
||||
</div>
|
||||
<div class="replay" runat="server" id="replay">
|
||||
<table>
|
||||
<tr><td>名字<asp:TextBox ID="authorName" runat=server></asp:TextBox><asp:HiddenField ID="idValue" runat="server" /></td></tr>
|
||||
<tr><td align=center><asp:TextBox ID="content" runat=server Height="100px" TextMode="MultiLine" Width="480px"></asp:TextBox></td></tr>
|
||||
<tr><td align=center><asp:Button ID="addMessage" runat=server Text="发表评论" OnClick="addMessage_Click" /></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
159
article.aspx.cs
Normal file
159
article.aspx.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
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;
|
||||
|
||||
public partial class article : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
if (Request.QueryString["my"] != null&&Request.QueryString["my"].ToString()!="")
|
||||
{
|
||||
showContent.Style.Add("display", "none");//不显示内容
|
||||
comment.Style.Add("display", "none"); //不显示内容
|
||||
replay.Style.Add("display", "none"); //不显示内容
|
||||
h2.InnerHtml = "<b>" + Session["username"].ToString() + "</b>发表的帖子";
|
||||
string sql = "select article.id,replaynum,readnum,title,username,classname,time from article,[user] where authorid='" +
|
||||
Request.QueryString["my"].ToString() + "' and userid=authorid order by article.id desc";
|
||||
DataSet ds = DbManager.getDataSet(sql, "myArticle");
|
||||
this.articlelist.DataSource = ds.Tables["myArticle"];
|
||||
this.articlelist.DataBind();
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
if (Request.QueryString["class"] != null && Request.QueryString["class"].ToString() != "")
|
||||
{
|
||||
showContent.Style.Add("display", "none");//不显示内容
|
||||
comment.Style.Add("display", "none"); //不显示内容
|
||||
replay.Style.Add("display", "none"); //不显示内容
|
||||
h2.InnerHtml = "类别:" +Server.UrlDecode(Request.QueryString["class"].ToString());
|
||||
string sql = "select article.id,replaynum,readnum,title,username,classname,time from article,[user] " +
|
||||
"where classname='" + Server.UrlDecode(Request.QueryString["class"].ToString()) + "' and userid=authorid order by article.id desc";
|
||||
DataSet ds = DbManager.getDataSet(sql, "classArticle");
|
||||
this.articlelist.DataSource = ds.Tables["classArticle"];
|
||||
this.articlelist.DataBind();
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString() != "")
|
||||
{
|
||||
int id = Convert.ToInt32(Request.QueryString["id"].ToString());
|
||||
idValue.Value = id.ToString();
|
||||
table.Style.Add("display", "none"); //不显示GridView控件
|
||||
string sql = "select article.id,classname,title,authorid,time,context,userid,username,email from article,[user]"+
|
||||
" where userid=authorid and article.id=" + id;
|
||||
SqlDataReader reader = DbManager.getReader(sql);
|
||||
if (reader.HasRows)
|
||||
{
|
||||
reader.Read();
|
||||
string strContent = "<a href='article.aspx?id=" + id + "'><h2>" + reader["title"].ToString() + "</h2></a>";
|
||||
strContent += "<div class='content'>" + reader["context"].ToString().Replace("\n", "<br>") + "</div>";
|
||||
string author = reader["authorid"].ToString();
|
||||
string classname = reader["classname"].ToString();
|
||||
string userid = reader["userid"].ToString();
|
||||
System.IO.StringWriter urlClass = new System.IO.StringWriter();
|
||||
Server.UrlEncode(classname, urlClass);
|
||||
strContent += "<div class='infor'>" + reader["time"].ToString() + "由 <b>" +
|
||||
reader["username"].ToString() + "</b> 撰写 类别:<a href='article.aspx?class=" +
|
||||
urlClass.ToString() + "'>" + classname + "</a></div>";
|
||||
strContent += "<div class='tool'><a href='#'>评论</a> ";
|
||||
if (Session["userid"] != null && Session["userid"].ToString() == userid)
|
||||
{
|
||||
strContent += "<a href='articleEdit.aspx?id=" + id + "&action=edit'>编辑</a> ";
|
||||
strContent += "<a href='articleEdit.aspx?id=" + id + "&action=delete'>删除</a> ";
|
||||
}
|
||||
strContent += "<a href='mailto:" + reader["email"].ToString() + "'>Email</a></div><hr/>";
|
||||
showContent.InnerHtml = strContent;
|
||||
if (!reader.IsClosed)
|
||||
reader.Close();
|
||||
//更新阅读次数=======================
|
||||
string upsql = "update article set readnum=readnum+1 where id=" + id;
|
||||
DbManager.getNonQuery(upsql);
|
||||
//回复===============================
|
||||
string replaySql = "select * from replay where articleid="+id;
|
||||
reader = DbManager.getReader(replaySql);
|
||||
if (reader.HasRows)
|
||||
{
|
||||
string strGuest = "";
|
||||
int i = 1;
|
||||
while (reader.Read())
|
||||
{
|
||||
strGuest += "<fieldset><legend><img src='images/tx2.jpg' width='30' height='30'/><b>" +
|
||||
reader["guest"].ToString() + "</b> 于 " +
|
||||
reader["time"].ToString() + " 跟帖 <font color=red>" + i + "楼</font></legend>" +
|
||||
reader["message"].ToString().Replace("\n", "<br>") + "</fieldset>";
|
||||
i++;
|
||||
}
|
||||
comment.InnerHtml = strGuest;
|
||||
reader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
comment.InnerHtml = "<b>暂时没有回帖</b>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showContent.InnerHtml = "<div class='content'>文章不存在</div>";
|
||||
}
|
||||
if (!reader.IsClosed)
|
||||
reader.Close();
|
||||
DbManager.closeConnection();
|
||||
|
||||
//如果用户登录将其用户名写入留言文本框
|
||||
if (Session["username"] == null || string.IsNullOrEmpty(Session["username"].ToString()))
|
||||
{
|
||||
// 未登录时隐藏整个评论区域
|
||||
replay.Style["display"] = "none";
|
||||
// 同时隐藏或禁用提交按钮(可选)
|
||||
addMessage.Visible = false; // 假设按钮ID为 addMessage
|
||||
}
|
||||
else
|
||||
{
|
||||
// 已登录时显示评论区域
|
||||
replay.Style["display"] = "block";
|
||||
addMessage.Visible = true;
|
||||
authorName.Text = Session["username"].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void addMessage_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 没有登陆点击回复弹出登录框
|
||||
if (Session["username"] == null)
|
||||
{
|
||||
Response.Redirect("Login.aspx");
|
||||
return;
|
||||
}
|
||||
|
||||
// 原有代码
|
||||
int articleid = Convert.ToInt32(idValue.Value);
|
||||
string replaySql = "insert into replay(articleid,guest,message,time) values(" + articleid + ",'" +
|
||||
Session["username"].ToString() + "','" + content.Text + "','" + DateTime.Now.ToString() + "')";
|
||||
|
||||
int flag = DbManager.getNonQuery(replaySql);
|
||||
if (flag > 0)
|
||||
{
|
||||
string upsql = "update article set replaynum=replaynum+1 where id=" + articleid;
|
||||
if (DbManager.getNonQuery(upsql) > 0)
|
||||
Response.Redirect("replay.aspx?id=" + articleid);
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.Redirect("replay.aspx?action=error");
|
||||
}
|
||||
}
|
||||
protected string GetAvatarPath(string username)
|
||||
{
|
||||
// 统一返回默认头像路径
|
||||
return "images/tx2.jpg";
|
||||
}
|
||||
}
|
||||
16
articleEdit.aspx
Normal file
16
articleEdit.aspx
Normal file
@@ -0,0 +1,16 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="articleEdit.aspx.cs" Inherits="articleEdit" Title="10228宿舍论坛" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
<div class="page" id="page">
|
||||
<div class="addEdit" id="addEdit" runat="server">
|
||||
<table align=center width=520>
|
||||
<tr><td width=30>标题</td><td><asp:TextBox ID="title" runat="server"></asp:TextBox><asp:HiddenField ID="idValue" runat="server" /></td></tr>
|
||||
<tr><td>分类</td><td><asp:DropDownList ID="classname" runat="server"></asp:DropDownList></td></tr>
|
||||
<tr><td valign=top>正文</td><td><asp:TextBox ID="content" runat="server" Height="300px" TextMode="MultiLine" Width="450px"></asp:TextBox></td></tr>
|
||||
<tr><td colspan=2 align=center><asp:Button ID="addEdit_OK" runat="server" Text="" OnClick="addEdit_OK_Click" /></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="message" id="message" runat="server">
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
124
articleEdit.aspx.cs
Normal file
124
articleEdit.aspx.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
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;
|
||||
|
||||
public partial class articleEdit : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
//处理安全性
|
||||
if (Session["login"] == null || Session["login"].ToString() != "true")
|
||||
{
|
||||
message.InnerHtml = function.redirect("Default.aspx", "您没有正常登录!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "add")
|
||||
{
|
||||
addEdit_OK.Text = "发表新帖";
|
||||
idValue.Value = "-1";
|
||||
//绑定类别
|
||||
string classSql = "select * from class";
|
||||
classname.DataSource = DbManager.getReader(classSql);
|
||||
classname.DataTextField = "classname";
|
||||
classname.DataValueField = "id";
|
||||
classname.DataBind();
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "edit")
|
||||
{
|
||||
addEdit_OK.Text = "更新帖子";
|
||||
idValue.Value = Request.QueryString["id"].ToString();
|
||||
//绑定类别及原信息,更新的文章不能够改变其所属类别
|
||||
string sql = "select * from article where id=" + Convert.ToInt32(Request.QueryString["id"].ToString());
|
||||
SqlDataReader reader = DbManager.getReader(sql);
|
||||
if (reader.HasRows)
|
||||
{
|
||||
reader.Read();
|
||||
ListItem item = new ListItem (reader["classname"].ToString(),reader["classid"].ToString());
|
||||
this.classname.Items.Add(item);
|
||||
title.Text = reader["title"].ToString();
|
||||
content.Text = reader["context"].ToString();
|
||||
reader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
addEdit.Style.Add("display", "none");
|
||||
message.InnerHtml = function.redirect("Default.aspx", "更新出错");
|
||||
}
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "delete")
|
||||
{
|
||||
//屏蔽table控件
|
||||
addEdit.Style.Add("display", "none");
|
||||
string delSql = "delete from article where id=" + Convert.ToInt32(Request.QueryString["id"].ToString());
|
||||
if (DbManager.getNonQuery(delSql) > 0)
|
||||
{
|
||||
//更改作者发帖的总数
|
||||
string deleteNum = "update [user] set blognum=blognum-1 where userid='" + Session["userid"].ToString() + "'";
|
||||
DbManager.getNonQuery(deleteNum);
|
||||
message.InnerHtml = function.redirect("Default.aspx", "删除成功!");
|
||||
}
|
||||
else
|
||||
message.InnerHtml = function.redirect("Default.aspx", "删除失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void addEdit_OK_Click(object sender, EventArgs e)
|
||||
{
|
||||
//屏蔽table控件
|
||||
addEdit.Style.Add("display", "none");
|
||||
if (idValue.Value == "-1")
|
||||
{
|
||||
//处理添加新帖任务
|
||||
int classId = Convert.ToInt32(classname.SelectedItem.Value); //类别id
|
||||
string classType = classname.SelectedItem.Text;
|
||||
string authorid=Session["userid"].ToString();
|
||||
string sql = "insert into article(classid,classname,title,authorid,time,context,readnum,replaynum)" +
|
||||
" values(" + classId + ",'" + classType + "','" + title.Text + "','" + authorid + "','" + DateTime.Now.ToString() + "','" +
|
||||
content.Text + "',0,0)";
|
||||
if (DbManager.getNonQuery(sql) > 0)
|
||||
{
|
||||
//添加成功,使得authorid的blognum字段值加1
|
||||
string addSql = "update [user] set blognum=blognum+1 where userid='" + authorid + "'";
|
||||
if (DbManager.getNonQuery(addSql) > 0)
|
||||
{
|
||||
System.IO.StringWriter urlClass = new System.IO.StringWriter();
|
||||
Server.UrlEncode(classType, urlClass);
|
||||
message.InnerHtml = function.redirect("article.aspx?class=" + urlClass.ToString(), "发帖成功!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.InnerHtml = function.redirect("Default.aspx", "发帖失败");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//处理更新
|
||||
int id = Convert.ToInt32(idValue.Value);
|
||||
string upSql = "update article set title='" + title.Text + "',context='" + content.Text + "' where id=" + id;
|
||||
if (DbManager.getNonQuery(upSql) > 0)
|
||||
{
|
||||
System.IO.StringWriter urlClass = new System.IO.StringWriter();
|
||||
Server.UrlEncode(classname.SelectedItem.Text, urlClass);
|
||||
message.InnerHtml = function.redirect("article.aspx?class=" + urlClass.ToString(), "更新成功!");
|
||||
}
|
||||
else
|
||||
message.InnerHtml = function.redirect("Default.aspx", "更新失败 ");
|
||||
}
|
||||
DbManager.closeConnection();
|
||||
}
|
||||
}
|
||||
215
images/StyleSheet.css
Normal file
215
images/StyleSheet.css
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* css style for my bss
|
||||
* use ms visual studio 2005
|
||||
* author:wxy,email:leixiaoli@126.com
|
||||
*/
|
||||
*
|
||||
{
|
||||
font-size:15px;
|
||||
font-family:Verdana;
|
||||
text-decoration:none;
|
||||
|
||||
}
|
||||
img {
|
||||
vertical-align: middle
|
||||
}
|
||||
html{
|
||||
width:100%;
|
||||
height:100%;
|
||||
position:absolute;
|
||||
}
|
||||
body
|
||||
{
|
||||
padding:0;
|
||||
margin:0;
|
||||
text-align:center;
|
||||
background:url(bg.gif) repeat-x;
|
||||
background-color:white
|
||||
}
|
||||
a
|
||||
{
|
||||
font-weight:900;
|
||||
color:#4ca8e5;
|
||||
text-decoration:none;
|
||||
}
|
||||
a:hover
|
||||
{
|
||||
color:#6C7E4A;
|
||||
text-decoration:underline;
|
||||
}
|
||||
form{padding:0; margin:0;}
|
||||
fieldset{border:solid 1px #ccc; padding:5px;}
|
||||
#top{width:760px;height:100px;background:url(logo2.png) no-repeat;}
|
||||
#menu
|
||||
{
|
||||
font-size:13px;
|
||||
color:White;
|
||||
line-height:25px;
|
||||
margin-top:4px;
|
||||
text-align:right;
|
||||
height:25px;
|
||||
font-weight:900;
|
||||
}
|
||||
#menu2 {
|
||||
float: left;
|
||||
margin-left: 500px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
#menu a {
|
||||
color: black;
|
||||
}
|
||||
#menu a:hover{
|
||||
color: skyblue;
|
||||
}
|
||||
#main
|
||||
{
|
||||
text-align:left;
|
||||
height:350px;
|
||||
width:100%;
|
||||
}
|
||||
.main
|
||||
{
|
||||
width:550px;
|
||||
border:solid 1px #ddd;
|
||||
float:left;
|
||||
margin-left:251px;
|
||||
background:url(mainBg.gif) no-repeat;
|
||||
background-position:0 5px;
|
||||
padding-top:25px;
|
||||
margin-top:5px;
|
||||
}
|
||||
.mainFoot
|
||||
{
|
||||
background:url(mainBg2.gif) no-repeat bottom;
|
||||
height:5px;
|
||||
padding-top:5px;
|
||||
padding-bottom:15px;
|
||||
margin-bottom:5px;
|
||||
}
|
||||
#mainContent{padding:2px 8px;}
|
||||
#foot {
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
line-height: 50px;
|
||||
clear: both;
|
||||
background: url(bg.gif) repeat-x;
|
||||
background-position: -30px;
|
||||
}
|
||||
#nav
|
||||
{
|
||||
border:solid 1px #ddd;
|
||||
float:left;
|
||||
width:200px;
|
||||
height:100%;
|
||||
position:relative;
|
||||
background:white;
|
||||
padding:10px 0;
|
||||
}
|
||||
#nav ul
|
||||
{
|
||||
margin:0;
|
||||
padding:0;
|
||||
list-style-type:none;
|
||||
}
|
||||
#nav ul li{margin:2px 12px;display:block;}
|
||||
#nav li a {
|
||||
display: block;
|
||||
color: #4ca8e5;
|
||||
text-decoration: underline;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
#nav li a:hover{
|
||||
text-decoration:none;
|
||||
border-bottom:1px solid #ccc;
|
||||
padding-bottom:1px;
|
||||
}
|
||||
.lable
|
||||
{
|
||||
font-size:12px;
|
||||
color:#8CA464;
|
||||
font-family:Verdana;
|
||||
}
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 900;
|
||||
color: white;
|
||||
line-height: 18px;
|
||||
background: #4ca8e5;
|
||||
text-align: left;
|
||||
margin: 0 10px;
|
||||
padding: 8px 12px;
|
||||
text-indent: 5px;
|
||||
}
|
||||
h2 {
|
||||
text-indent: 10px;
|
||||
border-bottom: 1px dotted #ccc;
|
||||
color: #4ca8e5;
|
||||
font-size: 16px;
|
||||
font-family: Arial;
|
||||
margin: 0 20px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.table{margin:0 10px;padding:2px;}
|
||||
|
||||
.table a {
|
||||
color: #4ca8e5;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.table a:hover{color:#030;}
|
||||
.content {
|
||||
color: #4ca8e5;
|
||||
text-indent: 10px;
|
||||
font-family: Verdana;
|
||||
background: #f9f9f9;
|
||||
margin: 0 20px;
|
||||
padding: 10px;
|
||||
}
|
||||
.tool
|
||||
{
|
||||
margin:0 20px;
|
||||
padding-top:3px;
|
||||
padding-left:5px;
|
||||
}
|
||||
.tool a {
|
||||
color: #4ca8e5;
|
||||
}
|
||||
.tool a:hover{color:#030;}
|
||||
.infor{text-align:right;color:#666;margin:0 20px;}
|
||||
hr{width:520px;text-align:center;color:#ddd;}
|
||||
.comment
|
||||
{
|
||||
background:#f9f9f9;
|
||||
padding:10px;
|
||||
margin:0 20px;
|
||||
}
|
||||
.replay table{text-align:left;padding:10px;}
|
||||
fieldset{
|
||||
border:1px solid #ccc;padding:5px;
|
||||
}
|
||||
/*
|
||||
warning style
|
||||
*/
|
||||
#warning {
|
||||
padding: 5px;
|
||||
width: 50%;
|
||||
margin: 5px auto;
|
||||
border: 1px solid #6C7E4A;
|
||||
background: #4ca8e5
|
||||
}
|
||||
/*hidden for gridview*/
|
||||
.hidden{display:none}
|
||||
|
||||
table{
|
||||
color:#4ca8e5 !important
|
||||
}
|
||||
tr {
|
||||
background-color: #4ca8e5
|
||||
currentColor:white !important
|
||||
}
|
||||
|
||||
textarea{
|
||||
height:40px !important
|
||||
}
|
||||
BIN
images/bg.gif
Normal file
BIN
images/bg.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 833 B |
BIN
images/logo2.png
Normal file
BIN
images/logo2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
BIN
images/mainBg.gif
Normal file
BIN
images/mainBg.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 650 B |
BIN
images/mainBg2.gif
Normal file
BIN
images/mainBg2.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 657 B |
BIN
images/tx.jpg
Normal file
BIN
images/tx.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
images/tx2.jpg
Normal file
BIN
images/tx2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
90
login.aspx
Normal file
90
login.aspx
Normal file
@@ -0,0 +1,90 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
|
||||
<%@ Import Namespace="System.Data" %>
|
||||
<%@ Import Namespace="System.Data.SqlClient" %>
|
||||
<!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 runat="server">
|
||||
<title>10228 宿舍论坛</title>
|
||||
<link href="images/StyleSheet.css" rel="stylesheet" type="text/css" />
|
||||
<style>
|
||||
*{font-size:13px;}
|
||||
body{text-align:center;padding:10px;}
|
||||
table{border-collapse:collapse;width:300px;background:#fff;margin-top:100px;border:1px solid #000;}
|
||||
th{background:#ffffff;border:1px solid #000;height:25px;}
|
||||
td{border:1px solid #999;padding:3px;}
|
||||
input{width:200px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<%
|
||||
if (Request.QueryString["action"] == null)
|
||||
{
|
||||
Response.Write(function.redirect("Default.aspx", ""));
|
||||
Session["login"] = "no";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (Request.QueryString["action"].ToString() == "")
|
||||
Response.Write(function.redirect("Default.aspx", ""));
|
||||
if (Request.QueryString["action"].ToString() == "logout")
|
||||
{
|
||||
Session.RemoveAll();
|
||||
Response.Write(function.redirect("login.aspx", "退出登录"));
|
||||
}
|
||||
if (Request.QueryString["action"].ToString() == "login")
|
||||
{
|
||||
if (Request.Form["account"].ToString() == "" || Request.Form["pass"].ToString() == "")
|
||||
Response.Write(function.redirect("login.aspx", "帐号、密码均不为空"));
|
||||
else
|
||||
{
|
||||
string sql = "select * from [user] where userid='" + Request.Form["account"].ToString() + "' and password='" + Request.Form["pass"].ToString() + "'";
|
||||
SqlConnection conn = new SqlConnection("server=localhost\\SQLEXPRESS;database=bbs;Integrated security=true");
|
||||
SqlCommand comm = new SqlCommand(sql, conn);
|
||||
conn.Open();
|
||||
SqlDataReader reader = comm.ExecuteReader();
|
||||
if (reader.HasRows)
|
||||
{
|
||||
reader.Read();
|
||||
Session["userid"] = reader["userid"].ToString();
|
||||
Session["username"] = reader["username"].ToString();
|
||||
Session["lastlogin"] = reader["lastlogin"].ToString().Substring(0, 10);
|
||||
Session["login"] = "true";
|
||||
Response.Write(function.redirect("Default.aspx", "登录成功"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Session["login"] = "no";
|
||||
Response.Write(function.redirect("login.aspx", "帐号、密码不正确"));
|
||||
}
|
||||
reader.Close();
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%>
|
||||
<form action="login.aspx?action=login" method="post">
|
||||
<table align="center">
|
||||
<tr>
|
||||
<th colspan="2">登陆</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50" align="right">帐号:</td>
|
||||
<td><input type="text" name="account" Maxlength="30" value="wxy"/><font color="red">*</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">密码:</td>
|
||||
<td><input type="password" name="pass" Maxlength="30"/><font color="red">*</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="center">
|
||||
<input type="submit" value="提交" style="width:30%"/>
|
||||
<input type="reset" value="重写" style="width:30%"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
18
login.aspx.cs
Normal file
18
login.aspx.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
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 login : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
83
master.master
Normal file
83
master.master
Normal file
@@ -0,0 +1,83 @@
|
||||
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="master.master.cs" Inherits="master" %>
|
||||
|
||||
<!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 runat="server">
|
||||
<title>10228宿舍论坛</title>
|
||||
<link href="images/StyleSheet.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="top">
|
||||
<div id="menu">
|
||||
<div id="menu2">
|
||||
<a href="Default.aspx">| 主页 |</a>
|
||||
<a href="register.aspx">| 注册 |</a>|
|
||||
<%
|
||||
//消除bug
|
||||
if (Session["login"] == null)
|
||||
Session["login"] = "no";
|
||||
if (Session["login"].ToString() != "true")
|
||||
Response.Write("<a href=\"login.aspx?action=dsd\">| 登录 |</a>");
|
||||
else
|
||||
{
|
||||
Response.Write("<a href=\"articleEdit.aspx?action=add\">| 发帖 |</a>");
|
||||
Response.Write("<a href=\"login.aspx?action=logout\">| 退出 |</a>");
|
||||
}
|
||||
%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="main">
|
||||
<div id="nav">
|
||||
<h3>帐号信息</h3>
|
||||
<%
|
||||
if (Session["login"].ToString() == "true")
|
||||
{
|
||||
%>
|
||||
<div style='margin:5px 15px;width:165px'>欢迎:<asp:Label ID="username" CssClass="label" runat="server" Text=""></asp:Label><br />
|
||||
上次登录:<asp:Label ID="lastlogin" runat="server" CssClass="label" Text=""></asp:Label><br />
|
||||
<asp:Label ID="status" CssClass="label" runat="server" Text=""></asp:Label>
|
||||
<div id="shenfen" runat=server></div>
|
||||
发表文章:<asp:Label ID="blognum" CssClass="label" runat="server" Text=""></asp:Label> 篇<br />
|
||||
<asp:HyperLink ID="myArticle" runat="server">我的文章</asp:HyperLink><br />
|
||||
<asp:HyperLink ID="addArticle" runat="server">添加新文章</asp:HyperLink>
|
||||
</div>
|
||||
<%
|
||||
}
|
||||
else
|
||||
{
|
||||
%>
|
||||
<form method=post action="login.aspx?action=login">
|
||||
<table style='margin:5px 10px;padding:0px;width:175px'>
|
||||
<tr><td>帐号</td><td><input type='text' style='width:120px' name='account'></td></tr>
|
||||
<tr><td>密码</td><td><input type='password' style='width:120px' name='pass'></td></tr>
|
||||
<tr><td colspan=2 align=center><input type='submit' value='登录'></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<h3>社区在线</h3>
|
||||
<div runat=server id="online">
|
||||
</div>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div id="mainContent">
|
||||
<form id="form1" runat="server">
|
||||
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
|
||||
</asp:ContentPlaceHolder>
|
||||
</form>
|
||||
</div>
|
||||
<div class="mainFoot">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<div id="foot">
|
||||
©2025 - 2025 By 10228宿舍论坛
|
||||
</div>
|
||||
|
||||
</html>
|
||||
86
master.master.cs
Normal file
86
master.master.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
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;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public partial class master : System.Web.UI.MasterPage
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
SqlConnection conn = new SqlConnection("Server=localhost\\SQLEXPRESS;database=bbs;Integrated security=true");
|
||||
if (Session["userid"] != null && Session["username"] != null)
|
||||
{
|
||||
username.Text = Session["username"].ToString();
|
||||
lastlogin.Text = Session["lastlogin"].ToString();
|
||||
string strsql = "select * from class,banzhu where class.id = banzhu.classid and userid='" +
|
||||
Session["userid"].ToString() + "'";
|
||||
SqlCommand myComm = new SqlCommand(strsql, conn);
|
||||
conn.Open();
|
||||
SqlDataReader myReader = myComm.ExecuteReader();
|
||||
if (myReader.HasRows)
|
||||
{
|
||||
status.Text = "担任的社区版主";
|
||||
string strStatus = "<ul>\n";
|
||||
int i=1;
|
||||
while (myReader.Read())
|
||||
{
|
||||
string classname = myReader["classname"].ToString();
|
||||
System.IO.StringWriter urlClass = new System.IO.StringWriter();
|
||||
Server.UrlEncode(classname, urlClass);
|
||||
strStatus += "<li><a href='Manager.aspx?class="+urlClass+"'>" + classname + "</a></li>";
|
||||
string banzhu = "banzhu" + i;
|
||||
Session[banzhu] = classname;
|
||||
i++;
|
||||
}
|
||||
strStatus += "</ul>";
|
||||
Session["banzhu"] = i.ToString();
|
||||
shenfen.InnerHtml = strStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
status.Text= "您是普通会员!";
|
||||
}
|
||||
myReader.Close();
|
||||
strsql = "select * from [user] where userid ='" + Session["userid"].ToString() + "'";
|
||||
myComm.CommandText = strsql;
|
||||
myReader = myComm.ExecuteReader();
|
||||
myReader.Read();
|
||||
blognum.Text = myReader["blognum"].ToString();
|
||||
myReader.Close();
|
||||
conn.Close();
|
||||
myArticle.NavigateUrl = "article.aspx?my=" + Session["userid"].ToString();
|
||||
addArticle.NavigateUrl = "articleEdit.aspx?action=add";
|
||||
}
|
||||
string sql = "select * from class";
|
||||
SqlCommand Comm = new SqlCommand(sql, conn);
|
||||
conn.Open();
|
||||
SqlDataReader Reader = Comm.ExecuteReader();
|
||||
if (Reader.HasRows)
|
||||
{
|
||||
string str = "<ul>\n";
|
||||
while (Reader.Read())
|
||||
{
|
||||
string classname = Reader["classname"].ToString();
|
||||
System.IO.StringWriter urlname = new System.IO.StringWriter();
|
||||
Server.UrlEncode(classname, urlname);
|
||||
str += "<li><a href='article.aspx?class=" +urlname.ToString() + "'>" + classname + "</a></li>\n";
|
||||
}
|
||||
str += "</ul>";
|
||||
online.InnerHtml = str;
|
||||
Reader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
online.InnerHtml = "<span style='text-indent:5px'>没有论坛分区</span>";
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
91
register.aspx
Normal file
91
register.aspx
Normal file
@@ -0,0 +1,91 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>
|
||||
|
||||
<!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 runat="server">
|
||||
<title>My BBS</title>
|
||||
<link href="images/StyleSheet.css" rel="stylesheet" type="text/css" />
|
||||
<style>
|
||||
*{font-size:13px;}
|
||||
body{text-align:center;padding:10px;}
|
||||
table{border-collapse:collapse;width:300px;background:#fff;margin-top:100px;border:1px solid #000;}
|
||||
th{background:#ffffff;border:1px solid #000;height:25px;}
|
||||
td{border:1px solid #999;padding:3px;}
|
||||
.total{font-size:8pt;color:red;text-align:left;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server">
|
||||
<div>
|
||||
<table align="center">
|
||||
<tr>
|
||||
<th colspan="2">注册</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50" align="right">帐号:</td>
|
||||
<td align=left><asp:TextBox ID="userid" runat="server" ValidationGroup="add"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="userid"
|
||||
ErrorMessage="帐号不为空" ValidationGroup="add">*</asp:RequiredFieldValidator></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">密码:</td>
|
||||
<td align=left><asp:TextBox ID="pass" runat="server" TextMode="Password" ValidationGroup="add"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="pass"
|
||||
ErrorMessage="密码不为空" ValidationGroup="add">*</asp:RequiredFieldValidator></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">确认:</td>
|
||||
<td align=left><asp:TextBox ID="againPass" runat="server" TextMode="Password" ValidationGroup="add"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="againPass"
|
||||
ErrorMessage="请确认" ValidationGroup="add">*</asp:RequiredFieldValidator>
|
||||
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="pass"
|
||||
ControlToValidate="againPass" ErrorMessage="密码不一致" ValidationGroup="add">*</asp:CompareValidator></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">昵称:</td>
|
||||
<td align=left><asp:TextBox ID="nickname" runat="server" ValidationGroup="add"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="nickname"
|
||||
ErrorMessage="昵称不为空" ValidationGroup="add">*</asp:RequiredFieldValidator></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">电邮:</td>
|
||||
<td align=left><asp:TextBox ID="email" runat="server" ValidationGroup="add"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="email"
|
||||
ErrorMessage="Email不为空" ValidationGroup="add">*</asp:RequiredFieldValidator>
|
||||
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="email"
|
||||
ErrorMessage="Emal格式不正确" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="add">*</asp:RegularExpressionValidator></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">性别:</td>
|
||||
<td align=left><asp:DropDownList ID="sex" runat="server">
|
||||
<asp:ListItem Selected="True">男</asp:ListItem>
|
||||
<asp:ListItem>女</asp:ListItem>
|
||||
</asp:DropDownList></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">生日:</td>
|
||||
<td align=left><asp:TextBox ID="birth" runat="server" Text="2003-07-18"></asp:TextBox></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">主页:</td>
|
||||
<td align=left><asp:TextBox ID="homeurl" runat="server" Text="http://"></asp:TextBox></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="center">
|
||||
<asp:Button ID="checkUserid" runat="server" OnClick="checkUserid_Click" Text="检查帐号"
|
||||
Width="60px" />
|
||||
<asp:Button ID="add_reg" runat="server" Text="注册" ValidationGroup="add" OnClick="add_reg_Click" Width="60px" />
|
||||
<asp:Button ID="reset" runat="server" Text="重置" Width="60px" OnClick="reset_Click" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td colspan=2 height=10>
|
||||
<asp:Label ID="message" runat="server" ForeColor="Red" Visible="False"></asp:Label></td></tr>
|
||||
<tr><td colspan=2 align=center>
|
||||
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="add" CssClass="total" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
71
register.aspx.cs
Normal file
71
register.aspx.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
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;
|
||||
|
||||
public partial class register : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
protected void checkUserid_Click(object sender, EventArgs e)
|
||||
{
|
||||
string sql = "select * from [user] where userid='" + userid.Text + "'";
|
||||
SqlDataReader reader = DbManager.getReader(sql);
|
||||
if (reader.HasRows)
|
||||
{
|
||||
message.Visible = true;
|
||||
message.Text = "该帐号已存在,请更改!";
|
||||
userid.Text = "";
|
||||
userid.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
message.ForeColor = System.Drawing.Color.Green;
|
||||
message.Visible = true;
|
||||
message.Text = "恭喜,该帐号可以使用!";
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
protected void add_reg_Click(object sender, EventArgs e)
|
||||
{
|
||||
string addSql = "insert into [user](userid,username,password,sex,birthday,email,homeadd,lastlogin,blognum)" +
|
||||
"values('" + userid.Text + "','" + nickname.Text + "','" + pass.Text + "','" + sex.SelectedItem.Value + "','" + birth.Text + "','" +
|
||||
email.Text + "','" + homeurl.Text + "','" + DateTime.Now.ToString() + "',0)";
|
||||
if (DbManager.getNonQuery(addSql) > 0)
|
||||
{
|
||||
Session["userid"] = userid.Text;
|
||||
Session["username"] = nickname.Text;
|
||||
Session["lastlogin"] = DateTime.Now.ToString().Substring(0, 10);
|
||||
Session["login"] = "true";
|
||||
DbManager.closeConnection();
|
||||
Response.Write(function.redirect("Default.aspx", "注册成功,将自动转到主页!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Session["login"] = "no";
|
||||
DbManager.closeConnection();
|
||||
Response.Write(function.redirect("Default.aspx", "注册失败!请重试..."));
|
||||
}
|
||||
}
|
||||
protected void reset_Click(object sender, EventArgs e)
|
||||
{
|
||||
userid.Text = "";
|
||||
pass.Text = "";
|
||||
againPass.Text = "";
|
||||
nickname.Text = "";
|
||||
email.Text = "";
|
||||
birth.Text = "2003-12-20";
|
||||
homeurl.Text = "http://";
|
||||
message.Visible = false;
|
||||
userid.Focus();
|
||||
}
|
||||
}
|
||||
12
replay.aspx
Normal file
12
replay.aspx
Normal file
@@ -0,0 +1,12 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="replay.aspx.cs" Inherits="replay" %>
|
||||
|
||||
<!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 runat="server">
|
||||
<title>10228 宿舍论坛</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
23
replay.aspx.cs
Normal file
23
replay.aspx.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
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 replay : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "error")
|
||||
{
|
||||
Response.Write(function.redirect("Default.aspx", "回复出错,请重试!"));
|
||||
}
|
||||
if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString() != "")
|
||||
Response.Write(function.redirect("article.aspx?id=" + Request.QueryString["id"].ToString(), "回复成功!"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user