接上一个推文 简易在线留言板(上)
http://blog.youkuaiyun.com/florencezky/article/details/74295704,接下来主要是说明一下留言板客户端的代码:
WebApp:
修改一下Web.config的代码:
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="AppConn" connectionString="server=pc.hstc.cn;database=wpd2014117132;uid=2014117132;pwd=19951104"
providerName="System.Data.SqlClient" />
<add name="MyApp.Properties.Settings.cs2014117132ConnectionString"
connectionString="Data Source=pc.hstc.edu.cn;Initial Catalog=wpd2014117132;Persist Security Info=True;User ID=2014117132;Password=19951104"
providerName="System.Data.SqlClient" />
<add name="wpd2014117132ConnectionString" connectionString="Data Source=pc.hstc.cn;Initial Catalog=wpd2014117132;User ID=2014117132;Password=19951104"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
母版页:Main.Master(母版页中没有设计,主要是因为登录、注册、修改密码界面与主界面大不相同)
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="WebApp.Main" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
主界面:index.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApp.Homepage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>树洞留言板</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#body1 {
width: 900px;
z-index: 1;
height: 100%;
margin: 0px auto;
background: #efffff;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: 450px 880px;
background-image: url(pic/background.jpg);
}
body, td, th {
color: #666;
}
</style>
</head>
<body runat="server" id="body">
<form name="form1" runat="server">
<div id="body1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img src="pic/treeLogo.png" style="width: 75px; height: 32px" /></a>
</div>
<div runat="server" id="home7" style="float: right;">
<ul class="nav navbar-nav">
<li>
<br />
<asp:Label ID="lblUser" runat="server"></asp:Label></li>
<li><a href="#"></a></li>
<li class="dropdown">
<asp:HyperLink ID="HLUser" runat="server" class="dropdown-toggle" data-toggle="dropdown">用户
<img src="pic/user.png"style="width:25px;height:25px"/>
<b class="caret"></b>
</asp:HyperLink>
<ul class="dropdown-menu">
<li>
<asp:HyperLink ID="HLLogin" runat="server" NavigateUrl="~/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLRes" runat="server" NavigateUrl="~/Register.aspx">注册</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLUpdate" runat="server" NavigateUrl="~/UpdatePassword.aspx">修改密码</asp:HyperLink></li>
<li> <asp:Button ID="btnLogout" runat="server" Text="退出系统" OnClick="btnLogout_Click" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="#313131" /></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1 contenteditable="true" align="center">
<img src="pic/标题.png" style="width: 500px; height: 110px" /></h1>
<ul class="nav nav-pills ">
<li class="active"><a href="#">主页 </a></li>
<li><a href="EditBlog.aspx">树洞留言</a></li>
<li><a href="MyBlog.aspx">我的留言</a></li>
</ul>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-4 col-md-push-8" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<center>
<img src="pic/Title.png" style="height:380px;width:140px"/>
</center>
</div>
<div class="col-md-8 col-md-pull-4" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Username" DataSourceID="SqlDataSource1" class="table" contenteditable="false" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="7" Width="620px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Username" HeaderText="用户" ReadOnly="True" SortExpression="Username" HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Mess" HeaderText="留言" SortExpression="Mess" HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Time" HeaderText="留言时间" SortExpression="Time" HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCFF" ForeColor="White" HorizontalAlign="Center" Font-Size="18px" Font-Underline="False" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:wpd2014117132ConnectionString %>" SelectCommand="SELECT * FROM [Mess] ORDER BY [Time] DESC"></asp:SqlDataSource>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<center>此系统由:2014117132号开发。</center>
</div>
</div>
</div>
</div>
</form>
<p></p>
</body>
</html>
Index.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApp
{
public partial class Homepage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else
{
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("index.aspx");
}
}
}
Index.aspx界面效果如下:
**登录界面**Login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebApp.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>树洞留言板-登录</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#login1 {
margin:auto;
width:320px;
height:100%;
z-index:1;
}
#login2 {
margin:auto auto;
width:320px;
height:120px;
z-index:1;
}
#login3 {
margin:auto auto;
width:320px;
height:450px;
z-index:1;
background-color: #EfFFFf;
border-radius: 20px;
-webkit-box-shadow: #666 0px 0px 15px;
-moz-box-shadow: #666 0px 0px 15px;
}
#login4 {
margin:auto auto;
width:160px;
height:150px;
z-index:1;
}
#login5 {
margin:auto auto;
width:280px;
height:40px;
z-index:1;
}
#login6{
margin:auto auto;
width:200px;
height:200px;
z-index:1;
background-color: #EfFFFf;
}
html,body{
height: 100%;
margin: 0px 0px;
padding: 0;
background-size:450px 880px;
background-image:url(pic/background.jpg) ;
}
</style>
</head>
<body>
<div id="login1">
<div id="login2">
</div>
<div id="login3">
<div id="login5">
</div>
<div id="login4">
<img src="pic/treeLogo.png" style="width:150px;" />
<img src="pic/loginlogo.png" style="width:150px;" />
</div>
<div id="login6">
<form method="post" runat="server">
<p><img src="pic/userhead1.png" style="width:35px;height:35px" />
<asp:TextBox ID="txtUsername" runat="server" placeholder="请输入用户名" style="width:150px;height:35px;font-size:15px;border-radius:7px;" ></asp:TextBox><br/>
<asp:Label ID="lblUsername" runat="server" ForeColor="#FF6666"></asp:Label>
<br/></p>
<p><img src="pic/userPassword.png" style="width:35px;height:35px" />
<asp:TextBox ID="txtPassword" runat="server" placeholder="请输入密码" style="width:150px; height:35px;font-size:15px;border-radius:7px;" TextMode="Password"></asp:TextBox> </p>
<p>
<asp:Label ID="lblPassword" runat="server" ForeColor="#FF5050"></asp:Label>
<br/></p>
<p>
<asp:Button ID="btnLogin" runat="server" class="btn" Text="登录" style="font-size:15px;width:95px" OnClick="btnLogin_Click"/>
<asp:Button ID="btnRegister" runat="server" class="btn" Text="注册" style="font-size:15px;width:95px" OnClick="btnRegister_Click" />
</p>
</form>
<p>
<asp:HyperLink ID="HyperLink1" runat="server" style="font-size:15px;" NavigateUrl="~/index.aspx">返回首页</asp:HyperLink></p>
</div>
</div>
</div>
</body>
</html>
Login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApp
{
public partial class Homepage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else
{
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("index.aspx");
}
}
}
登录界面Login.aspx效果图如下:
注册界面Register.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApp.Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>树洞留言板-注册</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#login1 {
margin:auto;
width:320px;
height:100%;
z-index:1;
}
#login2 {
margin:auto auto;
width:320px;
height:120px;
z-index:1;
}
#login3 {
margin:auto auto;
width:320px;
height:450px;
z-index:1;
background-color: #EfFFFf;
border-radius: 20px;
-webkit-box-shadow: #666 0px 0px 15px;
-moz-box-shadow: #666 0px 0px 15px;
}
#login4 {
margin:auto auto;
width:160px;
height:130px;
z-index:1;
}
#login5 {
margin:auto auto;
width:280px;
height:40px;
z-index:1;
}
#login6{
margin:auto auto;
width:260px;
height:200px;
z-index:1;
background-color: #EfFFFf;
}
html,body{
height: 100%;
margin: 0px 0px;
padding: 0;
background-size:450px 880px;
background-image:url(pic/background.jpg) ;
}
</style>
</head>
<body>
<div id="login1">
<div id="login2">
</div>
<div id="login3">
<div id="login5">
</div>
<div id="login4">
<img src="pic/treeLogo.png" style="width:150px;" /> <br />
<asp:Label ID="lblRegister" runat="server" Text="注册" Font-Names="幼圆" Font-Size="30px" ForeColor="#99CCFF" EnableViewState="True"></asp:Label>
</div>
<div id="login6">
<form id="Form1" method="post" runat="server">
<p>用户名:
<asp:TextBox ID="txtUsername" runat="server" placeholder="用户名长度为6~14个字符" style="width:180px;height:35px;font-size:15px;border-radius:7px;" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVusername" runat="server" ControlToValidate="txtUsername" ErrorMessage="用户名不能为空!" ForeColor="#FF5050" OnDataBinding="txtRegister_Click"></asp:RequiredFieldValidator>
</p>
<p>密 码:
<asp:TextBox ID="txtPassword" runat="server" placeholder="密码长度为6~14个字符" style="width:180px; height:35px;font-size:15px;border-radius:7px;" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVPassword" runat="server" ControlToValidate="txtPassword" ErrorMessage="密码不能为空!" ForeColor="#FF5050" OnDataBinding="txtRegister_Click"></asp:RequiredFieldValidator>
<br/></p>
<p> 再次输入:
<asp:TextBox ID="txtPasswordt" runat="server" placeholder="密码长度为6~14个字符" style="width:180px; height:35px;font-size:15px;border-radius:7px;" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CVPasswordt" runat="server" ControlToCompare="txtPasswordt" ControlToValidate="txtPassword" ErrorMessage="密码不一致!" ForeColor="#FF5050" OnDataBinding="txtRegister_Click"></asp:CompareValidator>
<asp:Label ID="Label1" runat="server" ForeColor="#FF5050"></asp:Label>
<br/></p><p>
<asp:Button ID="btnRegister" runat="server" class="btn" Text="注册" style="font-size:15px;width:95px" OnClick="txtRegister_Click"/>
</p>
</form>
<p><asp:HyperLink ID="HyperLink1" runat="server" style="font-size:15px;" NavigateUrl="~/index.aspx">返回首页</asp:HyperLink></p>
</div>
</div>
</div>
</body>
</html>
Register.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Bll;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApp
{
public partial class Register : System.Web.UI.Page
{
string strMsg = "";
bllUsers Buser;
EntUsers Euser;
private static string strCn = ConfigurationManager.ConnectionStrings["AppConn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtRegister_Click(object sender, EventArgs e)
{
Euser = new EntUsers();
Euser.Username = this.txtUsername.Text.Trim();
Euser.Password = this.txtPasswordt.Text.Trim();
Buser = new bllUsers();
if (Buser.Create(Euser, out strMsg))
{
Response.Write("<script>alert('创建成功!跳转到登录页面!')</script>");
Server.Transfer("Login.aspx");
}
else
{
this.Label1.Text = strMsg;
}
}
}
}
用户注册界面Register.aspx效果如下:
修改密码:UpdatePassword.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdatePassword.aspx.cs" Inherits="WebApp.UpdatePassword" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>树洞留言版-修改密码</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#login1 {
margin:auto;
width:320px;
height:100%;
z-index:1;
}
#login2 {
margin:auto auto;
width:320px;
height:120px;
z-index:1;
}
#login3 {
margin:auto auto;
width:320px;
height:450px;
z-index:1;
background-color: #EfFFFf;
border-radius: 20px;
-webkit-box-shadow: #666 0px 0px 15px;
-moz-box-shadow: #666 0px 0px 15px;
}
#login4 {
margin:auto auto;
width:160px;
height:150px;
z-index:1;
}
#login5 {
margin:auto auto;
width:280px;
height:20px;
z-index:1;
}
#login6{
margin:auto auto;
width:200px;
height:200px;
z-index:1;
background-color: #EfFFFf;
}
html,body{
height: 100%;
margin: 0px 0px;
padding: 0;
background-size:450px 880px;
background-image:url(pic/background.jpg) ;
}
</style>
</head>
<body>
<div id="login1">
<div id="login2">
</div>
<div id="login3">
<div id="login5">
</div>
<div id="login4">
<img src="pic/treeLogo.png" style="width:150px;" /> <br />
<asp:Label ID="lblRegister" runat="server" Text="修改密码" Font-Names="幼圆" Font-Size="30px" ForeColor="#99CCFF"></asp:Label>
</div>
<div id="login6">
<form id="Form1" method="post" runat="server">
<p>用户名:
<asp:Label ID="Label1" runat="server" ForeColor="#333333"></asp:Label>
</p>
<p>密 码:
<asp:TextBox ID="txtPassword" runat="server" placeholder="密码长度为6~14个字符" style="width:180px; height:35px;font-size:15px;border-radius:7px;" TextMode="Password"></asp:TextBox>
<br/><asp:RequiredFieldValidator ID="RFVPassword" runat="server" ControlToValidate="txtPassword" ErrorMessage="密码不能为空!" ForeColor="#FF5050" OnDataBinding="txtRegister_Click"></asp:RequiredFieldValidator>
<br/></p>
<p> 再次输入:
<asp:TextBox ID="txtPasswordt" runat="server" placeholder="密码长度为6~14个字符" style="width:180px; height:35px;font-size:15px;border-radius:7px;" TextMode="Password"></asp:TextBox>
<br/><asp:CompareValidator ID="CVPasswordt" runat="server" ControlToCompare="txtPasswordt" ControlToValidate="txtPassword" ErrorMessage="密码不一致!" ForeColor="#FF5050" OnDataBinding="txtRegister_Click"></asp:CompareValidator>
<asp:Label ID="Label2" runat="server" ForeColor="#FF5050"></asp:Label>
<br/></p>
<p>
<asp:Button ID="btnUpdate" runat="server" class="btn" Text="修改密码" style="font-size:15px;width:95px" OnClick="txtRegister_Click"/>
</p>
</form>
<p><asp:HyperLink ID="HyperLink1" runat="server" style="font-size:15px;" NavigateUrl="~/index.aspx">返回首页</asp:HyperLink></p>
</div>
</div>
</div>
</body>
</html>
UpdatePassword.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Bll;
namespace WebApp
{
public partial class UpdatePassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.Label1.Text = str1;
}
else
{
Response.Write("<script>alert('请登录系统后修改密码,点击确定跳转到登录页!')</script>");
Server.Transfer("Login.aspx");
}
}
protected void txtRegister_Click(object sender, EventArgs e)
{
EntUsers user = new EntUsers();
user.Username = this.Label1.Text.Trim();
user.Password = this.txtPassword.Text;
bllUsers bll = new bllUsers();
string strMsg = "";
if (bll.Update(user, out strMsg))
{
Response.Write("<script>alert('修改成功,点击确定跳转到首页!')</script>");
Server.Transfer("index.aspx");
}
else
{
this.Label2.Text = strMsg;
}
}
}
}
用户修改密码UpdatePassword.aspx效果如下:
管理员界面:AdminPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminPage.aspx.cs" Inherits="WebApp.AdminPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>树洞留言板</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#body1 {
width: 900px;
z-index: 1;
height: 100%;
margin: 0px auto;
background: #efffff;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: 450px 880px;
background-image: url(pic/background.jpg);
}
body, td, th {
color: #666;
}
</style>
</head>
<body runat="server" id="body">
<form id="Form1" runat="server">
<div id="body1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img src="pic/treeLogo.png" style="width: 75px; height: 32px" /></a>
</div>
<div runat="server" id="home7" style="float: right;">
<ul class="nav navbar-nav">
<li>
<br />
<asp:Label ID="lblUser" runat="server"></asp:Label></li>
<li class="dropdown">
<asp:HyperLink ID="HLUser" runat="server" class="dropdown-toggle" data-toggle="dropdown">用户
<img src="pic/user.png"style="width:25px;height:25px"/>
<b class="caret"></b>
</asp:HyperLink>
<ul class="dropdown-menu">
<li>
<asp:HyperLink ID="HLLogin" runat="server" NavigateUrl="~/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLRes" runat="server" NavigateUrl="~/Register.aspx">注册</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLUpdate" runat="server" NavigateUrl="~/UpdatePassword.aspx">修改密码</asp:HyperLink></li>
<li> <asp:Button ID="btnLogout" runat="server" Text="退出系统" OnClick="btnLogout_Click" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="#313131" /></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1 contenteditable="true" align="center">
<img src="pic/标题.png" style="width: 500px; height: 110px" /></h1>
<ul class="nav nav-pills ">
<li class="active"><a href="#">留言管理 </a></li>
<li><a href="AdminUserPage.aspx">用户管理 </a></li>
</ul>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-4 col-md-push-8" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff; top: 0px; left: 0px;">
<div style="float: right;">
</div>
</div>
<div class="col-md-8 col-md-pull-4" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Username,Time" DataSourceID="SqlDataSource1" class="table" contenteditable="false" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="7" Width="863px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Username" HeaderText="用户" ReadOnly="True" SortExpression="Username" HeaderStyle-ForeColor="White">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Mess" HeaderText="用户留言" SortExpression="Mess" HeaderStyle-ForeColor="White">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Time" HeaderText="留言时间" SortExpression="Time" HeaderStyle-ForeColor="White" ReadOnly="True">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:CommandField ShowDeleteButton="True">
<ItemStyle Font-Names="微软雅黑" ForeColor="#FF5050" />
</asp:CommandField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCFF" ForeColor="White" HorizontalAlign="Center" Font-Size="18px" Font-Underline="False" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:wpd2014117132ConnectionString %>" SelectCommand="SELECT * FROM [Mess] ORDER BY [Time] DESC" DeleteCommand="DELETE FROM [Mess] WHERE [Username] = @Username AND [Time] = @Time" InsertCommand="INSERT INTO [Mess] ([Username], [Mess], [Time]) VALUES (@Username, @Mess, @Time)" UpdateCommand="UPDATE [Mess] SET [Mess] = @Mess WHERE [Username] = @Username AND [Time] = @Time">
<DeleteParameters>
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Time" Type="DateTime" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Mess" Type="String" />
<asp:Parameter Name="Time" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Mess" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Time" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<center>此系统由:2014117132号开发。</center>
</div>
</div>
</div>
</div>
</form>
<p></p>
</body>
</html>
AdminPage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Bll;
namespace WebApp
{
public partial class AdminPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else {
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("index.aspx");
}
}
}
管理员登录系统后的主界面AdminPage.aspx效果如下:
管理员管理用户界面:AdminUserPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminUserPage.aspx.cs" Inherits="WebApp.AdminUserPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>树洞留言板</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#body1 {
width: 900px;
z-index: 1;
height:100%;
margin: 0px auto;
background: #efffff;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: 450px 880px;
background-image: url(pic/background.jpg);
}
body, td, th {
color: #666;
}
</style>
</head>
<body runat="server" id="body">
<form id="Form1" runat="server">
<div id="body1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img src="pic/treeLogo.png" style="width: 75px; height: 32px" /></a>
</div>
<div runat="server" id="home7" style="float: right;">
<ul class="nav navbar-nav">
<li>
<br />
<asp:Label ID="lblUser" runat="server"></asp:Label></li>
<li><a href="#"></a></li>
<li class="dropdown">
<asp:HyperLink ID="HLUser" runat="server" class="dropdown-toggle" data-toggle="dropdown">用户
<img src="pic/user.png"style="width:25px;height:25px"/>
<b class="caret"></b>
</asp:HyperLink>
<ul class="dropdown-menu">
<li>
<asp:HyperLink ID="HLLogin" runat="server" NavigateUrl="~/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLRes" runat="server" NavigateUrl="~/Register.aspx">注册</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLUpdate" runat="server" NavigateUrl="~/UpdatePassword.aspx">修改密码</asp:HyperLink></li>
<li> <asp:Button ID="btnLogout" runat="server" Text="退出系统" OnClick="btnLogout_Click" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="#313131" /></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1 contenteditable="true" align="center">
<img src="pic/标题.png" style="width: 500px; height: 110px" /></h1>
<ul class="nav nav-pills ">
<li><a href="AdminPage.aspx">留言管理 </a></li>
<li class="active"><a href="#">用户管理 </a></li>
</ul>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-4 col-md-push-8" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff; top: 0px; left: 0px;">
</div>
<div class="col-md-8 col-md-pull-4" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Username" DataSourceID="SqlDataSource1" class="table" contenteditable="false" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="7" Width="558px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="用户ID" ReadOnly="True" SortExpression="id" HeaderStyle-ForeColor="White" InsertVisible="False">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Username" HeaderText="用户名" SortExpression="Username" HeaderStyle-ForeColor="White" ReadOnly="True">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:CommandField HeaderText="操作" ShowDeleteButton="True">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
<ItemStyle ForeColor="#FF5050" />
</asp:CommandField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCFF" ForeColor="White" HorizontalAlign="Center" Font-Size="18px" Font-Underline="False" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:wpd2014117132ConnectionString %>" DeleteCommand="DELETE FROM [Users] WHERE [Username] = @Username" InsertCommand="INSERT INTO [Users] ([Username]) VALUES (@Username)" SelectCommand="SELECT [Username], [id] FROM [Users] ORDER BY [id]" UpdateCommand="UPDATE [Users] SET [id] = @id WHERE [Username] = @Username">
<DeleteParameters>
<asp:Parameter Name="Username" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Username" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="Username" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<center>此系统由:2014117132号开发。</center>
</div>
</div>
</div>
</div>
</form>
<p></p>
</body>
</html>
AdminUserPage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApp
{
public partial class AdminUserPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else
{
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("index.aspx");
}
}
}
管理员管理用户界面AdminUserPage.aspx效果如下:
用户发布留言界面EditBlog.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditBlog.aspx.cs" Inherits="WebApp.EditBlog" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>树洞留言</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#body1 {
width: 900px;
z-index: 1;
height: 690px;
margin: 0px auto;
background: #efffff;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: 450px 880px;
background-image: url(pic/background.jpg);
}
body, td, th {
color: #666;
}
.auto-style1 {
width: 93px;
height: 33px;
}
</style>
</head>
<body runat="server" id="body1">
<form id="Form1" name="form1" runat="server">
<div id="Div1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img src="pic/treeLogo.png" style="width: 75px; height: 32px" /></a>
</div>
<div runat="server" id="home7" style="float: right;">
<ul class="nav navbar-nav">
<li>
<br />
<asp:Label ID="lblUser" runat="server"></asp:Label></li>
<li class="dropdown">
<asp:HyperLink ID="HLUser" runat="server" class="dropdown-toggle" data-toggle="dropdown">用户
<img src="pic/user.png"style="width:25px;height:25px"/>
<b class="caret"></b>
</asp:HyperLink>
<ul class="dropdown-menu">
<li>
<asp:HyperLink ID="HLLogin" runat="server" NavigateUrl="~/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLRes" runat="server" NavigateUrl="~/Register.aspx">注册</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLUpdate" runat="server" NavigateUrl="~/UpdatePassword.aspx">修改密码</asp:HyperLink></li>
<li> <asp:Button ID="btnLogout" runat="server" Text="退出系统" OnClick="btnLogout_Click" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="#313131" /></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1 contenteditable="true" align="center">
<img src="pic/标题.png" style="width: 500px; height: 110px" /></h1>
<ul class="nav nav-pills ">
<li><a href="index.aspx">主页 </a></li>
<li class="active"><a href="EditBlog.aspx">树洞留言</a></li>
<li><a href="MyBlog.aspx">我的留言</a></li>
</ul>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-4 col-md-push-8" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<center>
<img src="pic/Title.png" style="height:380px;width:140px"/>
</center>
</div>
<div class="col-md-8 col-md-pull-4" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<img class="auto-style1" src="pic/liuyanLogo.png" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:TextBox ID="txtBlog" runat="server" Height="206px" Style="margin-bottom: 0px" TextMode="MultiLine" Width="620px" placeholder="写下留言……" Font-Size="16px"></asp:TextBox>
<br />
<asp:Button ID="BtnSendBlog" runat="server" class="btn" OnClick="BtnSendBlog_Click" Text="发布留言" />
</div>
</div>
<div class="row-fluid">
<div class="span12">
<center>此系统由:@2014117132号开发。</center>
</div>
</div>
</div>
</div>
</form>
<p></p>
</body>
</html>
EditBlog.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Bll;
using System.Configuration;
namespace WebApp
{
public partial class EditBlog : System.Web.UI.Page
{
string strMsg = "";
bllBlog BBlog;
EntBlog EBlog;
private static string strCn = ConfigurationManager.ConnectionStrings["AppConn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else {
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("Homepage.aspx");
}
protected void BtnSendBlog_Click(object sender, EventArgs e)
{
if (Session["username"] != null)
{
EBlog = new EntBlog();
EBlog.Username = (string)Session["username"];
EBlog.Message = this.txtBlog.Text.Trim();
EBlog.Time = DateTime.Now.ToLocalTime();
BBlog = new bllBlog();
if (BBlog.Create(EBlog, out strMsg))
{
Response.Write("<script>alert('发布成功!点击确定跳转到首页!')</script>");
Server.Transfer("index.aspx");
}
else
{
Response.Write("<script>alert('" + strMsg + "<br/>点击确定返回原界面!')</script>");
Server.Transfer("EditBlog.aspx");
}
}
else
{
Response.Write("<script>alert('请登录系统后发布留言,点击确定跳转到登录页!')</script>");
Server.Transfer("Login.aspx");
}
}
}
}
用户发布留言界面EditBlog.aspx效果如下:
用户查看个人留言MyBlog.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyBlog.aspx.cs" Inherits="WebApp.MyBlog" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的留言</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="css/jquery.min.js"></script>
<script src="css/bootstrap.min.js"></script>
<style type="text/css">
#body1 {
width: 900px;
z-index: 1;
height:690px;
margin: 0px auto;
background: #efffff;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: 450px 880px;
background-image: url(pic/background.jpg);
}
body, td, th {
color: #666;
}
.auto-style1 {
width: 93px;
height: 33px;
}
</style>
</head>
<body runat="server" id="body1">
<form id="Form1" name="form1" runat="server">
<div id="Div1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img src="pic/treeLogo.png" style="width: 75px; height: 32px" /></a>
</div>
<div runat="server" id="home7" style="float: right;">
<ul class="nav navbar-nav">
<li><br />
<asp:Label ID="lblUser" runat="server"></asp:Label></li>
<li class="dropdown">
<asp:HyperLink ID="HLUser" runat="server" class="dropdown-toggle" data-toggle="dropdown">用户
<img src="pic/user.png"style="width:25px;height:25px"/>
<b class="caret"></b>
</asp:HyperLink>
<ul class="dropdown-menu">
<li>
<asp:HyperLink ID="HLLogin" runat="server" NavigateUrl="~/Login.aspx">登录</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLRes" runat="server" NavigateUrl="~/Register.aspx">注册</asp:HyperLink></li>
<li>
<asp:HyperLink ID="HLUpdate" runat="server" NavigateUrl="~/UpdatePassword.aspx">修改密码</asp:HyperLink></li>
<li> <asp:Button ID="btnLogout" runat="server" Text="退出系统" OnClick="btnLogout_Click" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" ForeColor="#313131" /></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<h1 contenteditable="true" align="center">
<img src="pic/标题.png" style="width: 500px; height: 110px" /></h1>
<ul class="nav nav-pills ">
<li><a href="index.aspx">主页 </a></li>
<li><a href="EditBlog.aspx">树洞留言</a></li>
<li class="active"><a href="#">我的留言</a></li>
</ul>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-4 col-md-push-8" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<center>
<img src="pic/Title.png" style="height:380px;width:140px"/>
</center>
</div>
<div class="col-md-8 col-md-pull-4" style="box-shadow: inset 1px -1px 1px #fff, inset -1px 1px 1px #fff;">
<p><img class="auto-style1" src="pic/liuyanLogo.png" /></p>
<asp:Label ID="Label1" runat="server" Text="Label" Font-Size="24px" ForeColor="#FF5050" Font-Names="微软雅黑" Font-Bold="True"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Class="table" AllowPaging="True" PageSize="7" Width="615px" DataKeyNames="Username,Time">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Username" HeaderText="我" SortExpression="Username" ReadOnly="True">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Mess" HeaderText="留言" SortExpression="Mess">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Time" HeaderText="留言时间" ReadOnly="True" SortExpression="Time">
<HeaderStyle Font-Names="微软雅黑" Font-Size="16px" ForeColor="White" />
</asp:BoundField>
<asp:CommandField HeaderText="操作" ShowDeleteButton="True">
<HeaderStyle Font-Names="微软雅黑" Font-Size="12px" ForeColor="White" />
<ItemStyle ForeColor="#FF5050" />
</asp:CommandField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:wpd2014117132ConnectionString %>" DeleteCommand="DELETE FROM [Mess] WHERE [Username] = @original_Username AND [Time] = @original_Time AND [Mess] = @original_Mess" InsertCommand="INSERT INTO [Mess] ([Username], [Mess], [Time]) VALUES (@Username, @Mess, @Time)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Mess] WHERE ([Username] = @Username) ORDER BY [Time] DESC" UpdateCommand="UPDATE [Mess] SET [Mess] = @Mess WHERE [Username] = @original_Username AND [Time] = @original_Time AND [Mess] = @original_Mess">
<DeleteParameters>
<asp:Parameter Name="original_Username" Type="String" />
<asp:Parameter Name="original_Time" Type="DateTime" />
<asp:Parameter Name="original_Mess" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Mess" Type="String" />
<asp:Parameter Name="Time" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="Username" SessionField="Username" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Mess" Type="String" />
<asp:Parameter Name="original_Username" Type="String" />
<asp:Parameter Name="original_Time" Type="DateTime" />
<asp:Parameter Name="original_Mess" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
</div>
</div>
<div class="row-fluid">
<div class="span12">
<center>此系统由:@2014117132号开发。</center>
</div>
</div>
</div>
</div>
</form>
<p></p>
</body>
</html>
MyBlog.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApp
{
public partial class MyBlog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
string str1;
str1 = (string)Session["username"];
this.HLLogin.Visible = false;
this.HLRes.Visible = false;
this.Label1.Text = "";
this.lblUser.Text = " 欢迎用户:“" + str1 + "”进入树洞留言系统! 登录时间为" + Session["time"].ToString();
}
else {
this.btnLogout.Visible = false;
this.HLUpdate.Visible = false;
this.Label1.Text = "<center><p>请登录后查看!</p></center>";
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session["username"] = null;
Response.Write("<script>alert('退出成功!返回首页。')</script>");
this.lblUser.Text = "";
Server.Transfer("index.aspx");
}
}
}
用户查看个人留言界面MyBlog.aspx效果如下:
以上是所有的主要代码,Css文件以及其他说明我将在下一篇文章中说明,接下来可请看我的 简易在线留言板(下)——树洞留言板。