201313137028 陈旻实 计科1301
ASP.NET网站开发实验
指导老师:柯鹏 学院:计算机学院
学生姓名:陈旻实
学生学号:201313137028
班级:计科1301班
201313137028 陈旻实 计科1301
实验1 EFlinq操作
实验目的:
1. 熟悉linq code frist技术的相关背景
2. 熟悉linq操作在visual studio上的基本流程
实验过程:
1. 打开visual studio
2. 创建新的控制台应用程序
3. 在web.config文件中添加如下语句
<connectionStrings>
<add name="StudentDBContext"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=C:\vsproject\TestEF\TestEF\App_Data\Students.mdf;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
4. 添加student类
public class Student
{
publicint ID { get; set; }
public string Name { get; set; }
publicint Age { get; set; }
201313137028 陈旻实 计科1301
}
5. 添加数据库上下文类
public class StudentDBContext : DbContext
{
public DbSet<Student> Students { get; set; }
}
6. 主代码中添加如下测试代码:
namespacelinq
{
class Program
{
staticStudentDBContextdb = new StudentDBContext();
static void Main(string[] args)
{
Student stu1 = new Student() { ID = 1, Name = "张飞", Age = 20 };
db.Students.Add(stu1);
db.SaveChanges();
}
}
}
7. 在生成的appdata的文件中查看数据库的生成情况
实验二 MVC架构实战开发
实验目的:
开发一个MVC架构的电影网站,可以实现体现电影名称,上映时间,票价和电影类型. 实验过程:
1. 添加movie类
public class Movie
{
publicint ID { get; set; }
public string Title { get; set; }
publicDateTimeReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
2. 创建数据库上下文类
public class MovieDBContext:DbContext
{
publicDbSet<Movie> Movies { get; set; }
}
3. 创建数据库连接串
<connectionStrings>
<add name="MovieDBContext"
connectionString="Data Source=(LocalDb)\v11.0;
201313137028 陈旻实 计科1301
AttachDbFilename=|DataDirectory|\Movies.mdf;
Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
4. 添加控制器:MoviesController
5. 添加Action:2个Create()、Index()
6. 使用类图模板自动生成cshtml文件 MoviesController代码:
namespaceMvcMovie.Controllers{
publicclassMoviesController : Controller
{
//
// GET: /Movies/
privateMovieDBContextdb=newMovieDBContext();
publicActionResult Index()
{
return View(db.Movies.ToList());
}
[Authorize]
publicActionResult Create()
{
return View();
}
[HttpPost]
[Authorize]
publicActionResult Create(Movie movie)
{
db.Movies.Add(movie);
db.SaveChanges();
returnRedirectToAction("Index");
}
publicActionResultTestJQueryUI()
{
return View(); //视图见后页
}
[Authorize]
publicActionResult Edit(int? id)
{
if (id ==null)
{
returnnewHttpStatusCodeResult(HttpStatusCode.BadRequest);
}
201313137028 陈旻实 计科1301 Moviemovie=db.Movies.Find(id); //查找给定主键的实体
if (movie ==null)
{
returnHttpNotFound();
}
return View(movie);
}
[HttpPost]
[ValidateAntiForgeryToken]
publicActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State =EntityState.Modified;
db.SaveChanges();
returnRedirectToAction("Index");
}
return View(movie);
}
[Authorize]
publicActionResult Delete(int? id)
{
if (id ==null)
{
returnnewHttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Moviemovie=db.Movies.Find(id);
if (movie ==null)
{
returnHttpNotFound();
}
return View(movie);
}
[HttpPost]
[ValidateAntiForgeryToken]
publicActionResult Delete(int id)
{
Moviemovie=db.Movies.Find(id);
db.Movies.Remove(movie);
db.SaveChanges();
returnRedirectToAction("Index");
}
201313137028 陈旻实 计科1301 publicActionResult Details(int? id)
{
if (id ==null)
{
returnnewHttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Moviemovie=db.Movies.Find(id);
if (movie ==null)
{
returnHttpNotFound();
}
return View(movie);
}
} }
运行结果:
201313137028 陈旻实 计科1301
一.实训题目
留言板系统
二.实训内容
留言板系统是一个简单的网络系统,它的开发流程可以简单的归纳为:系统功能概述、数据库设计、公共类编写、母板页设计、首页设计、发表留言模块的设计、留言管理功能的设计、回复留言功能设计等。下面分别简单的介绍留言板系统的开发过程。
一. 各模块具体实现
1. 【系统功能概述】
(1) 实验目的
通过对系统功能的需求分析,完成对系统功能的建模
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1) 目标:主要制作一个图书介绍网站,用户可以查看图书的详细信息,同时能对自己喜爱的书籍进行评价。
2) 主要功能:
1、网站主页以及图书详细信息的查看。
2、前台显示留言信息、包括留言内容,留言者的姓名,性别,联系方式、留言时间以及管理员的回复。
3、访客注册发布留言模块,需要填写详细信息。
4、管理员登陆模块、管理员可以删除留言、回复留言等。
功能设计图:
2. 【数据库设计】
(1) 实验目的
结合对系统的功能需求分析,设计出相应的数据库结构。
(2) 实验环境
硬件:windows xp、PC
软件:sqlsever2005
(3) 实验内容
该数据库共有两个表,管理员表(adminInfo)、访客信息表(guestInfo)
1、概念模型
2、物理模型
Admininfo表
Guestinfo表
3. 【公共类的编写】
(1) 实验目的
公共类的创建可以减少重复代码的编写,并有利于代码的维护。在网站开发项目中以类的形式来组织,封装一些常用的方法和事件,将会在编程过程中起到事半功倍的效果。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005
(3) 实验内容
1) 配置web.config
<configuration>
<appSettings/>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=bookDB;integrated security=true"/>
</connectionStrings>
2) SqlData类
1.SqlData类的命名空间
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;
3
4. 【母版页的设计】
(1) 实验目的
使用ASP.NET母版页可以为应用程序中的页面创建一致的布局。单个母版页可以为应用程序中所有的页面定义统一的外观和标准行为。可以创建包含要显示内容的各个内容页。当用户请求内容页时,这些内容页和母版页合并,然后将母版页的布局与内容页的内容组合在一起。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1) 创建母版页:
新建母版页
背景颜色
页面设计
最初效果
更改为IE6.0
设计其他页面时选中---选择母版页
5. 【首页的设计】
(1) 实验目的
网站分为两个首页---网站主页、留言板首页。网站主页的目的是引导互联网用户浏览网站其他部分的内容。留言板首页是将数据库中检索到的留言信息显示出来。用户可以选择发布留言或系统管理来实现相应功能。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1) 网站主页设计:
该页面主要显示网站的导航信息及部分图书简介。
主页代码:
<HTML>
<HEAD>
<TITLE>216main</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (216main.psd) -->
<TABLE ID="__01" WIDTH=886 HEIGHT=1184 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD COLSPAN=5>
<IMG SRC="images/216index_1.jpg" WIDTH=885 HEIGHT=285 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=285 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=4>
<IMG SRC="images/216index_2.jpg" ALT="" WIDTH=879 HEIGHT=42 border="0" usemap="#Map6"></TD>
<TD>
<IMG SRC="images/216index_3.jpg" WIDTH=6 HEIGHT=42 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=42 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=5>
<IMG SRC="images/216index_4.jpg" WIDTH=885 HEIGHT=34 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=34 ALT=""></TD>
</TR>
<TR>
<TD ROWSPAN=2><IMG SRC="images/216index_5.jpg" ALT="" WIDTH=219 HEIGHT=183 border="0" usemap="#Map"></TD>
<TD ROWSPAN=2>
<IMG SRC="images/216index_6.jpg" WIDTH=1 HEIGHT=183 ALT=""></TD>
<TD COLSPAN=3>
<IMG SRC="images/216index_7.jpg" WIDTH=665 HEIGHT=73 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=73 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=3 ROWSPAN=2>
<IMG SRC="images/216index_8.jpg" ALT="" WIDTH=665 HEIGHT=115 border="0" usemap="#Map4"></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=110 ALT=""></TD>
</TR>
<TR>
<TD ROWSPAN=2>
<IMG SRC="images/216index_9.jpg" ALT="" WIDTH=219 HEIGHT=82 border="0" usemap="#Map2"></TD>
<TD ROWSPAN=3>
<IMG SRC="images/216index_10.jpg" WIDTH=1 HEIGHT=159 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=5 ALT=""></TD>
</TR>
<TR>
<TD ROWSPAN=3>
<IMG SRC="images/216index_11.jpg" ALT="" WIDTH=293 HEIGHT=260 border="0" usemap="#Map5"></TD>
<TD COLSPAN=2 ROWSPAN=3>
<IMG SRC="images/216index_12.jpg" WIDTH=372 HEIGHT=260 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=77 ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/216index_13.jpg" ALT="" WIDTH=219 HEIGHT=77 border="0" usemap="#Map3"></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=77 ALT=""></TD>
</TR>
<TR>
<TD ROWSPAN=3>
<IMG SRC="images/216index_14.jpg" WIDTH=219 HEIGHT=362 ALT=""></TD>
<TD ROWSPAN=3>
<IMG SRC="images/216index_15.jpg" WIDTH=1 HEIGHT=362 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=106 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=3>
<IMG SRC="images/216index_16.jpg" WIDTH=665 HEIGHT=69 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=69 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=3>
<IMG SRC="images/216index_17.jpg" WIDTH=665 HEIGHT=187 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=187 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=5>
<IMG SRC="images/216index_18.jpg" WIDTH=885 HEIGHT=118 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=118 ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=219 HEIGHT=1 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=1 HEIGHT=1 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=293 HEIGHT=1 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=366 HEIGHT=1 ALT=""></TD>
<TD>
<IMG SRC="images/分隔符.gif" WIDTH=6 HEIGHT=1 ALT=""></TD>
<TD></TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
<map name="Map">
<area shape="rect" coords="138,106,199,133" href="CheckLogin.aspx">
</map>
<map name="Map2">
<area shape="rect" coords="18,17,222,80" href="www.baidu.com">
</map>
<map name="Map3">
<area shape="rect" coords="18,3,219,75" href="www.gougou.com">
</map>
<map name="Map4">
<area shape="rect" coords="53,40,256,337" href="index.aspx">
</map>
<map name="Map5">
<area shape="rect" coords="51,-14,261,227" href="index.aspx">
</map>
<map name="Map6">
<area shape="rect" coords="392,5,463,40" href="index.aspx">
</map>
</BODY>
</HTML>
2) 留言板主页设计
留言板首页代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="EeekSoft.Web.PopupWin" Namespace="EeekSoft.Web" TagPrefix="cc1" %>
<%@ Register Src="UserLink.ascx" TagName="UserLink" TagPrefix="uc2" %>
<%@ Register Src="Userhooder.ascx" TagName="Userhooder" TagPrefix="uc3" %>
<%@ Register Src="UserHead.ascx" TagName="UserHead" TagPrefix="uc1" %>
<!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>无标题页</title>
<script language="javascript" type="text/javascript">
<!--
function DIV2_onclick() {
}
function TABLE1_onclick() {
}
// -->
</script>
</head>
<body class="body" align ="center" style="background-image: url(images/images/in_03.jpg) ; background-repeat: repeat-y; background-position-x:7px">
<form id="form1" runat="server">
<div>
<div><img src="images/216main_1.jpg" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="220,261,302,293" href="216index.html" />
<area shape="rect" coords="355,264,427,292" href="index.aspx" />
</map>
</div>
<div>
<img src="images/images/in_02.jpg" /></div>
<div align = "center" style="margin-top: 500px">
<table align = "center" border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 8px; width: 744px; position: absolute; top: 650px; height: 521px; margin-left: 120px; text-align: center;" id="TABLE1" onclick="return TABLE1_onclick()" >
<div align = "center" ><tr>
<td style="width: 92px; height: 1px;">
<uc1:UserHead ID="UserHead1" runat="server" />
<uc2:UserLink ID="UserLink1" runat="server" />
</td>
</tr></div>
<tr>
<div align ="center" ><td rowspan="2" align = "center"style="width: 92px; height: 455px; top:150px; float: inherit; text-align: center;">
<asp:DataList ID="DataList1" runat="server" Style="position: relative; top: 100px; text-align: center; color: #F30;" CellPadding="2" Width="748px" ForeColor="Black" BackColor="" BorderColor="" BorderWidth="1px" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnItemCommand="DataList1_ItemCommand" OnItemDataBound="DataList1_ItemDataBound" f>
<ItemTemplate>
<div align ="left" >
<img src = 'images/<%#DataBinder.Eval(Container.DataItem,"imageAddress") %>' />
留言者:<%#DataBinder.Eval(Container.DataItem,"userName") %>
QQ号:<%#DataBinder.Eval(Container.DataItem,"QQ") %>
留言时间:<%#DataBinder.Eval(Container.DataItem, "postTime")%>
</div>
<div align ="right" style="font-size: x-small">
<asp:LinkButton runat = "server" Text = "回复留言" CommandArgument = '<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="Reply" BorderColor="red" ForeColor="red"></asp:LinkButton>
<asp:LinkButton ID = "lbtdel" runat = "server" Text = "删除留言" CommandArgument = '<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="del" BorderColor="red" ForeColor="red"></asp:LinkButton>
</div>
<hr />
<div align ="center" style="font-size: medium">
留言信息: <%#DataBinder.Eval(Container.DataItem,"Content")%>
</div>
<hr />
<div align ="center" style="font-size: medium">
回复信息: <%# DataBinder.Eval(Container.DataItem,"Reply") %>
</div>
</ItemTemplate>
<FooterStyle BackColor="" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="" Font-Bold="True" />
<AlternatingItemStyle BackColor="" />
</asp:DataList>
<cc1:PopupWin ID="PopupWin1" runat="server" Message="" Style="position: relative; left: 148px; top: 1px;"
Title="系统提示 !" />
</td></div>
</tr>
<tr>
<td rowspan="1" style="width: 92px; height: 31px; top: 430px; text-align: left;">
<div id="DIV1" style="z-index: 102; left: -724px; width: 747px; position: relative;
top: 430px; height: 31px; clear: both;" language="javascript" onclick="return DIV1_onclick()" align="left">
<asp:Label ID="Label3" runat="server" Style="position: relative" Text="当前"></asp:Label>
<asp:Label ID="Label1" runat="server" Style="position: relative" Text="1"></asp:Label>
<asp:Label ID="Label4" runat="server" Style="position: relative" Text="页"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
Text="首页" BackColor="#FF8080" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="position: relative; left: 1px; top: 1px;"
Text="上一页" BackColor="#FF8080" BorderColor="White" />
<asp:Label ID="Label5" runat="server" Style="position: relative" Text="转到第"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
Style="position: relative" BackColor="White" ForeColor="Black">
</asp:DropDownList>
<asp:Label ID="Label6" runat="server" Style="position: relative" Text="页"></asp:Label>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Style="position: relative"
Text="下一页" BackColor="#FF8080" />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Style="position: relative"
Text="尾页" BackColor="#FF8080" />
<asp:Label ID="Label2" runat="server" Style="position: relative"></asp:Label></div>
</td>
</tr>
</table>
<asp:Localize ID="Localize1" runat="server"></asp:Localize>
</div>
</form>
</body>
</html>
6. 【发表留言模块的设计】
(1) 实验目的
发表留言--在留言板首页点发表留言即可进入留言填写页面,通过该页面用户可以发表任何评论,但是需要填写用户名、性别、联系方式等,填写完毕后点击提交即可完成留言发布。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1、设计发表留言模块:
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Post.aspx.cs" Inherits="Post" %>
<%@ Register Src="UserHead.ascx" TagName="UserHead" TagPrefix="uc1" %>
<%@ Register Src="Userhooder.ascx" TagName="Userhooder" TagPrefix="uc2" %>
<%@ Register Src="UserLink.ascx" TagName="UserLink" TagPrefix="uc3" %>
<!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>无标题页</title>
</head>
<body background="images/106.jpg">
<form id="form1" runat="server">
<div><img src="images/216main_1.jpg" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="220,261,302,293" href="216index.html" />
<area shape="rect" coords="355,264,427,292" href="index.aspx" />
</map>
</div>
<table id="TABLE1" border="0" cellpadding="0" cellspacing="0" style="left: 70px;
width: 730px; position: relative; top: -5px; height: 521px" language="javascript" onclick="return TABLE1_onclick()">
<tr>
<td style="width: 100px"> </td>
</tr>
<tr>
<td style="width: 100px"> </td>
</tr>
<tr>
<td style="width: 100px; height: 464px;">
<div align="center" style="z-index: 101; left: 38px; width: 683px; position: relative;
top: 0px; height: 297px; color: purple; font-style: normal; font-family: 新宋体; font-variant: normal;">
<br />
<table style="left: 0px; width: 622px; position: relative; top: -11px; height: 348px; color: #F30;">
<tr>
<td style="width: 77px">
</td>
<td align="left" style="width: 137px">
<asp:Label ID="Label1" runat="server" Style="left: -32px; position: relative; top: 0px"
Text="用户留言"></asp:Label></td>
</tr>
<tr>
<td align="left" style="width: 77px">
<asp:Label ID="Label2" runat="server" Style="position: relative; left: 6px; top: 0px;" Text="留言者:"></asp:Label></td>
<td style="width: 137px" align = "left">
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="留言者名称不能为空!!" Style="position: relative">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="left" style="width: 77px; height: 15px" >
<asp:Label ID="Label3" runat="server" Style="position: relative" Text="性 别:"></asp:Label></td>
<td style="width: 137px; height: 15px" align = "left">
<asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="Group"
Style="position: relative" Text="男" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Group" Style="position: relative"
Text="女" /></td>
</tr>
<tr>
<td align="left" style="width: 77px; height: 30px;">
<asp:Label ID="Label4" runat="server" Style="position: relative" Text="QQ号:"></asp:Label></td>
<td style="width: 137px; height: 30px;" align = "left">
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative; left: 0px; top: 1px;"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox2"
ErrorMessage="用户QQ号不能为空!!" Style="position: relative">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="left" style="width: 77px">
<asp:Label ID="Label5" runat="server" Style="position: relative" Text="Email信箱:" Width="91px"></asp:Label></td>
<td style="width: 137px" align = "left">
<asp:TextBox ID="TextBox3" runat="server" Style="position: relative"></asp:TextBox></td>
</tr>
<tr>
<td align="left" style="width: 77px; height: 104px;">
<asp:Label ID="Label7" runat="server" Style="position: relative; left: -5px; top: -43px;" Text="留言内容:"></asp:Label></td>
<td align="left" valign = "baseline" style="width: 137px; height: 104px;">
<asp:TextBox ID="TextBox4" runat="server" Height="85px" Style="position: relative; left: 4px; top: 6px;"
TextMode="MultiLine" Width="209px"></asp:TextBox>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="left: 201px;
position: relative; top: -66px" Width="209px" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox4"
ErrorMessage=" 发帖内容不能为空!!" Style="left: 116px; position: relative; top: -138px">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="Button1" runat="server" Style="position: relative; left: -31px; top: 0px;" Text=" 提交 " OnClick="Button1_Click" BackColor="#FFC0C0" />
<asp:Button ID="Button2" runat="server" Style="position: relative; left: 0px; top: 0px;" Text=" 重置 " OnClick="Button2_Click" BackColor="#FFC0C0" /></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
</tr>
</table>
<div><img src="images/216index_18.jpg" /></div>
</form>
</body>
</html>
连接控件主要代码:
public partial class Post : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string userName = this.TextBox1.Text;
string Sex = null;
string imageAddress = null;
if (this.RadioButton1.Checked == true)
{
Sex = "男";
imageAddress = "boy.gif";
}
else
{
Sex = "女";
imageAddress = "girl.gif";
}
string QQ = this.TextBox2.Text;
string Email = this.TextBox3.Text;
string Content = this.TextBox4.Text;
SqlConnection conn = DB.getConnection();
SqlCommand cmd = new SqlCommand("insert into guestInfo(userName,Sex,QQ,Email,Content,ImageAddress) values('" + userName + "','" + Sex + "','" + QQ + "','" + Email + "','" + Content + "','" + imageAddress + "')", conn);
conn.Open();
int count = cmd.ExecuteNonQuery();
conn.Close();
if (count > 0)
{
Response.Redirect("ShowInfo.aspx?info=" + Server.UrlDecode("发布成功!!!") + "");
}
else
{
Response.Redirect("ShowInfo.aspx?info=" + Server.UrlDecode("发布失败!!!") + "");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.RadioButton1.Checked = true;
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.TextBox4.Text = "";
this.TextBox1.Focus();
}
}
7. 留言信息查看模块的设计
(1) 实验目的
查看留言(首页可直接查看)
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1) 该页面中使用了数据控件Datalist,主要用来显示从数据库中检索出的符合条件的数据
主要代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="EeekSoft.Web.PopupWin" Namespace="EeekSoft.Web" TagPrefix="cc1" %>
<%@ Register Src="UserLink.ascx" TagName="UserLink" TagPrefix="uc2" %>
<%@ Register Src="Userhooder.ascx" TagName="Userhooder" TagPrefix="uc3" %>
<%@ Register Src="UserHead.ascx" TagName="UserHead" TagPrefix="uc1" %>
<!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>无标题页</title>
<script language="javascript" type="text/javascript">
<!--
function DIV2_onclick() {
}
function TABLE1_onclick() {
}
// -->
</script>
</head>
<body class="body" align ="center" style="background-image: url(images/images/in_03.jpg) ; background-repeat: repeat-y; background-position-x:7px">
<form id="form1" runat="server">
<div>
<div><img src="images/216main_1.jpg" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="220,261,302,293" href="216index.html" />
<area shape="rect" coords="355,264,427,292" href="index.aspx" />
</map>
</div>
<div>
<img src="images/images/in_02.jpg" /></div>
<div align = "center" style="margin-top: 500px">
<table align = "center" border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 8px; width: 744px; position: absolute; top: 650px; height: 521px; margin-left: 120px; text-align: center;" id="TABLE1" onclick="return TABLE1_onclick()" >
<div align = "center" ><tr>
<td style="width: 92px; height: 1px;">
<uc1:UserHead ID="UserHead1" runat="server" />
<uc2:UserLink ID="UserLink1" runat="server" />
</td>
</tr></div>
<tr>
<div align ="center" ><td rowspan="2" align = "center"style="width: 92px; height: 455px; top:150px; float: inherit; text-align: center;">
<asp:DataList ID="DataList1" runat="server" Style="position: relative; top: 100px; text-align: center; color: #F30;" CellPadding="2" Width="748px" ForeColor="Black" BackColor="" BorderColor="" BorderWidth="1px" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnItemCommand="DataList1_ItemCommand" OnItemDataBound="DataList1_ItemDataBound" f>
<ItemTemplate>
<div align ="left" >
<img src = 'images/<%#DataBinder.Eval(Container.DataItem,"imageAddress") %>' />
留言者:<%#DataBinder.Eval(Container.DataItem,"userName") %>
QQ号:<%#DataBinder.Eval(Container.DataItem,"QQ") %>
留言时间:<%#DataBinder.Eval(Container.DataItem, "postTime")%>
</div>
<div align ="right" style="font-size: x-small">
<asp:LinkButton runat = "server" Text = "回复留言" CommandArgument = '<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="Reply" BorderColor="red" ForeColor="red"></asp:LinkButton>
<asp:LinkButton ID = "lbtdel" runat = "server" Text = "删除留言" CommandArgument = '<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="del" BorderColor="red" ForeColor="red"></asp:LinkButton>
</div>
<hr />
<div align ="center" style="font-size: medium">
留言信息: <%#DataBinder.Eval(Container.DataItem,"Content")%>
</div>
<hr />
<div align ="center" style="font-size: medium">
回复信息: <%# DataBinder.Eval(Container.DataItem,"Reply") %>
</div>
</ItemTemplate>
<FooterStyle BackColor="" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="" Font-Bold="True" />
<AlternatingItemStyle BackColor="" />
</asp:DataList>
<cc1:PopupWin ID="PopupWin1" runat="server" Message="" Style="position: relative; left: 148px; top: 1px;"
Title="系统提示 !" />
</td></div>
</tr>
<tr>
<td rowspan="1" style="width: 92px; height: 31px; top: 430px; text-align: left;">
<div id="DIV1" style="z-index: 102; left: -724px; width: 747px; position: relative;
top: 430px; height: 31px; clear: both;" language="javascript" onclick="return DIV1_onclick()" align="left">
<asp:Label ID="Label3" runat="server" Style="position: relative" Text="当前"></asp:Label>
<asp:Label ID="Label1" runat="server" Style="position: relative" Text="1"></asp:Label>
<asp:Label ID="Label4" runat="server" Style="position: relative" Text="页"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
Text="首页" BackColor="#FF8080" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="position: relative; left: 1px; top: 1px;"
Text="上一页" BackColor="#FF8080" BorderColor="White" />
<asp:Label ID="Label5" runat="server" Style="position: relative" Text="转到第"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
Style="position: relative" BackColor="White" ForeColor="Black">
</asp:DropDownList>
<asp:Label ID="Label6" runat="server" Style="position: relative" Text="页"></asp:Label>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Style="position: relative"
Text="下一页" BackColor="#FF8080" />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Style="position: relative"
Text="尾页" BackColor="#FF8080" />
<asp:Label ID="Label2" runat="server" Style="position: relative"></asp:Label></div>
</td>
</tr>
</table>
<asp:Localize ID="Localize1" runat="server"></asp:Localize>
</div>
</form>
</body>
</html>
页面展示:
8. 留言管理模块设计
(1) 实验目的
单击导航栏中的“系统管理”链接,进入管理员登陆页面,输入管理员用户名和密码后,即可进入留言管理页面,管理员可以对留言信息进行回复和删除工作。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
1) 管理员登陆:
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckLogin.aspx.cs" Inherits="CheckLogin" %>
<%@ Register Src="UserHead.ascx" TagName="UserHead" TagPrefix="uc1" %>
<%@ Register Src="UserLink.ascx" TagName="UserLink" TagPrefix="uc2" %>
<%@ Register Src="Userhooder.ascx" TagName="Userhooder" TagPrefix="uc3" %>
<!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>无标题页</title>
<style type="text/css">
<!--
.bj {
background-image: url(images/216main_1.jpg);
}
-->
</style>
</head>
<body background="mages/216main_1.jpg">
<form id="form1" runat="server">
<div></div>
<img src="images/216main_1.jpg" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="220,261,302,293" href="216index.html" />
<area shape="rect" coords="355,264,427,292" href="index.aspx" />
</map>
<table border="0" cellpadding="0" cellspacing="0" style="left: 70px; width: 733px;
position: relative; top: 0px; height: 553px">
<tr>
<td style="width: 100px; height: 112px"> </td>
</tr>
<tr>
<td style="width: 100px; height: 224px">
<div align="center" style="z-index: 101; left: 0px; width: 728px; color: #F30; font-style: normal; font-family: 宋体; position: relative; top: -47px; height: 124px; font-variant: normal">
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="X-Large" Style="position: relative"
Text="欢迎登陆"></asp:Label><br />
<br />
<asp:Label ID="Label1" runat="server" Style="position: relative" Text="用户名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative" Width="136px"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Style="position: relative" Text="密 码:" Width="58px"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative" TextMode="Password"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Style="position: relative" Text=" 登陆 " OnClick="Button1_Click" BackColor="#FFC0C0" />
<asp:Button ID="Button2" runat="server" Style="position: relative" Text=" 重置 " OnClick="Button2_Click" BackColor="#FFC0C0" /></div>
</td>
</tr>
<tr>
<td style="width: 100px; height: 79px">
</td>
</tr>
</table>
<div><img src="images/216index_18.jpg" /></div>
</form>
</body>
</html>
主要代码:public partial class CheckLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string userName = this.TextBox1.Text;
string userPwd = this.TextBox2.Text;
SqlConnection conn = DB.getConnection();
SqlCommand cmd = new SqlCommand("select count(*) from dbo.adminInfo where userName = '" + userName + "' and userPwd = '" + userPwd + "'", conn);
conn.Open();
int count = (int)cmd.ExecuteScalar();
conn.Close();
if (count > 0)
{
Session["Admin"] = userName;
Response.Redirect("ShowInfo.aspx?info=" + Server.HtmlEncode("欢迎进入!!") + "");
}
else
{
Response.Redirect("ShowInfo.aspx?info="+ Server.HtmlEncode("对不起!用户名或者密码错误!!请确认后重新登陆!")+"");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox1.Focus();
}
}
2) 留言删除及回帖
主要代码:
if (e.CommandName == "del")
{
if (Session["Admin"] == null)
{
Response.Redirect("ShowInfo.aspx?info="+Server.HtmlEncode("对不起!只有管理员才有此权限!如果你是管理员请登陆!!")+"");
}
else
{
int ID = Convert.ToInt32(e.CommandArgument);
//Response.Write("<script>alert('"+ID+"')</script>");
SqlConnection conn = DB.getConnection();
SqlCommand cmd = new SqlCommand("delete from guestInfo where ID = " + ID + "", conn);
conn.Open();
int count = cmd.ExecuteNonQuery();
conn.Close();
if (count > 0)
{
Response.Write("<script>alert('删除成功!!')</script>");
this.DandData();
}
}
}
//回帖
if (e.CommandName == "Reply")
{
int ID = Convert.ToInt32(e.CommandArgument);
if (Session["Admin"] == null)
{
Response.Redirect("ShowInfo.aspx?info=" + Server.HtmlEncode("对不起!只有管理员才有此权限!如果你是管理员请登陆!!") + "");
}
else
{
Response.Write("<script>alert('" + ID + "')</script>");
Response.Redirect("Reply.aspx?ID=" + Server.HtmlEncode(ID.ToString()) + "");
}
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
//确认是否删除
LinkButton lbtdel = e.Item.FindControl("lbtdel") as LinkButton;
if (lbtdel != null)
{
lbtdel.Attributes.Add("onclick", "return confirm('你确认删除该条记录!')");
}
}
}
9. 回复留言功能设计
(1) 实验目的
回复留言模块的主要功能是对留言人进行回复,点击回复按钮即可进入回复页面,填写信息点提交即可。
(2) 实验环境
硬件:windows xp、PC
软件:visual studio 2005+sqlsever2005
(3) 实验内容
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reply.aspx.cs" Inherits="Post" %>
<%@ Register Src="UserHead.ascx" TagName="UserHead" TagPrefix="uc1" %>
<%@ Register Src="Userhooder.ascx" TagName="Userhooder" TagPrefix="uc2" %>
<%@ Register Src="UserLink.ascx" TagName="UserLink" TagPrefix="uc3" %>
<!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>无标题页</title>
</head>
<body background="images/106.jpg">
<form id="form1" runat="server">
<div><img src="images/216main_1.jpg" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="220,261,302,293" href="216index.html" />
<area shape="rect" coords="355,264,427,292" href="index.aspx" />
</map>
</div>
<table border="0" cellpadding="0" cellspacing="0" style="left: 70px; width: 732px;
position: relative; top: -1px; height: 519px">
<tr>
<td style="width: 100px; height: 122px"> </td>
</tr>
<tr>
<td style="width: 100px; height: 110px"> </td>
</tr>
<tr>
<td style="width: 100px; height: 120px">
<div align="center" style="z-index: 101; left: 1px; width: 728px; position: relative;
top: -86px; height: 100px">
<asp:Label ID="Label1" runat="server" BackColor="MistyRose" BorderColor="White" Font-Bold="True"
Font-Italic="True" Font-Size="X-Large" ForeColor="Crimson" Style="position: relative; left: -49px; top: -23px;"
Text="管理回帖" BorderStyle="Dashed"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtContent" runat="server" BackColor="Snow" ForeColor="Red"
Height="189px" Style="position: relative" TextMode="MultiLine" Width="369px" BorderColor="#FFC0C0"></asp:TextBox><br />
<br />
<asp:Button ID="btnSumit" runat="server" Style="position: relative; left: -22px; top: 0px;" Text=" 提 交 " OnClick="btnSumit_Click" BackColor="#FFC0C0" />
<asp:Button ID="btnReset" runat="server" Style="position: relative" Text=" 重 置 " BackColor="#FFC0C0" /><br />
</div>
</td>
</tr>
<tr>
<td style="width: 100px; height: 155px">
</td>
</tr>
</table>
<div><img src="images/216index_18.jpg" /></div>
</form>
</body>
</html>
页面展示:
主要代码:
public partial class Post : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void btnSumit_Click(object sender, EventArgs e)
{
string ID = Request.QueryString["ID"];
//Response.Write("<script>alert('" + ID + "')</script>");
SqlConnection conn = DB.getConnection();
SqlCommand cmd = new SqlCommand("update dbo.guestInfo set Reply = '" + this.txtContent.Text + "' where ID = " + int.Parse(ID) + "", conn);
conn.Open();
int count = cmd.ExecuteNonQuery();
conn.Close();
if (count > 0)
{
//Response.Write("<script>alert('回复成功!!')</script>");
//Page.ClientScript.RegisterStartupScript(this.GetType(), "StartUp", "<script>alert('回复成功!!')</script>");
Response.Redirect("ShowInfo.aspx?info=" + Server.HtmlEncode("回复成功!!") + "");
}
else
{
Response.Redirect("ShowInfo.aspx?info=" + Server.HtmlEncode("回复失败!!") + "");
}
}
}
功能展示:
实验报告学院系名称计算机与通信工程学院第1页共9页第2页共9页第3页共9页第4页共9页第5页共9页第6页共9页第7页共9页第8页共…
实验一环境配置与sql操作学号姓名日期20xx年11月251实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环…
NET上机实验报告WEB数据库应用程序设计姓名杨森班级计103学号10101020xx2实验成绩一实验目的通过对aspnet学习完…
燕山大学Net程序设计实验报告学院信息科学与工程学院年级专业08级计算机科学2班指导教师崔永强学生学号080104010108学生…
河南城建学院网站建设技术实验报告实验名称用户名密码登录切图制作网站专业班级软件工程姓名吴春龙学号084413147实验日期20xx…
实验一1实验要求基本的网页制作2目的掌握HTML与ASPX基础联系制作基本的ASPNET网页使用VS20xx提供的导航控件并结合站…
实验一环境配置与sql操作学号姓名日期1实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环境WindowsXP…
燕山大学Net程序设计实验报告学院信息科学与工程学院年级专业09级信息安全1班指导教师崔永强学生学号090104070017学生姓…
源代码1usingSystemusingSystemCollectionsGenericusingSystemComponentM…
丽水职业技术学院机电信息分院课程实训基于ASP.NET旅游导购网站的设计与开发学生学号:学生姓名:实训老师:班级信管1222专业名…