WEB实训报告例子

江苏建筑职业技术学院

《WEB程序设计》

课程实习报告

(留言板系统)

设计名称: WEB程序设计

班 级: 软件09-2

学 号: 31 号

姓 名: 花 童

2011-05-31

1

1.0、实习时间:

2011-5-22—2011-5-28共计一周

2.0、实习地点:

实训楼209

3.0、实习目的:

“WEB程序设计”是实践性教学环节之一,是综合性、理论联系实际的教学课程。通过课程设计,使学生掌握B/S结构的管理系统的基本概念、原理和技术,结合实际的操作和设计,巩固课堂教学内容,将理论与实际相结合,应用现有的B/S结构的开发工具(ASP.NET)和数据库技术,规范、科学地完成一个小型的基于B/S结构的中小企业的管理信息系统的设计与实现,把理论课与实验课所学内容做一综合,并在此基础上强化学生的实践意识、提高其实际动手能力和创新能力。

4.0、实验环境:

安装Windows xp,含有Micarosoft Visual Studio 2005并配有IIS服务,含有Micarosoft SQL Server 2005的数据库的电脑一台.

5.0、实验内容:

5.1、设计准备工作

1、熟悉WEB程序设计任务,明确设计内容

根据WEB程序设计任务书给定的或收集的原始数据和资料,结合设计要求,理清设计思路,明确设计内容。

2、设计准备工作

根据WEB技术设计任务,做好设计手册、参考资料、设计期间的工具等的准备工作。

5.2、实验主要步骤:

1、开发背景

2、需求分析

3、系统设计

(1)、系统目标

(2)、系统预览

(3)、功能模块设计

(4)、数据库分析

(5)、数据库设计

(6)、文件夹组织结构

4、建立项目PersonManage

2

(1)、三层架构概述即建立

B/S系统常常采用多层体系结构,这种多层结构在层与层之间相互独立,任何一层的改变不会影响其他层得功能。在多层体系结构中,具有基本的三层结构。

数据访问层:实现对数据的访问功能,如增加、删除、修改、查询数据。

业务逻辑层:实现业务的具体逻辑功能,如学生入学、退学、成绩管理等。

页面显示层:将业务功能在浏览器上显示,如分页显示学生信息等。

除此之外,还可以具有其他的层次。特别是在业务逻辑层,常常需要根据实际情况增加层次,但总的原则是:每一层都完成相对独立的系统功能。

另外,在这三层基础之下,还有更为基础的工作,即数据库的设计模型。数据库的设计模型是整个系统的基础,一旦确定了数据库的结构,在开发过程中不就轻易改变,否则会对后面的工作造成巨大的负担。

5.3、实验的主要代码:

(1)首页的主要代码:

<HTML>

<HEAD> <title>WebForm1</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="/intellisense/ie5"

name="vs_targetSchema">

<LINK href="Styles/Style.css" type="text/css" rel="stylesheet"> </HEAD> <body> <form id="Form1" method="post" runat="server"> <FONT face="宋体"> <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 48px; WIDTH: 328px; POSITION: absolute; TOP: 32px; HEIGHT: 158px"

cellSpacing="0" cellPadding="0" width="328" border="0"> <TR> <TD style="WIDTH: 45px"></TD> <TD style="WIDTH: 164px" align="center"><FONT face="宋体"><IMG alt="" src="Images/1.GIF" width="130"></FONT></TD>

</TR> <TR> <TD style="WIDTH: 45px"><asp:label id="Label1" runat="server">登录名*</asp:label></TD>

<TD style="WIDTH: 164px"><asp:textbox id="TextBoxLoginName" 3

runat="server" Width="160px"></asp:textbox></TD>

</TR> <TR> <TD style="WIDTH: 45px"><asp:label id="Label2" runat="server">密码*</asp:label></TD>

<TD style="WIDTH: 164px"><asp:textbox id="TextBoxPassword" runat="server" Width="160px" TextMode="Password"></asp:textbox></TD>

</TR> <TR> <TD align="center" colSpan="3" style="height: 24px"><asp:button id="ButtonLogin" runat="server" Width="56px" Text="登录"

onclick="ButtonLogin_Click"></asp:button>&nbsp;&nbsp;&nbsp;

&nbsp; <asp:button id="ButtonGuest" runat="server" Width="50px" Text="游客" onclick="ButtonGuest_Click"></asp:button>&nbsp;

<asp:hyperlink id="HyperLinkRegister" runat="server" NavigateUrl="Register.aspx">注册</asp:hyperlink></TD>

</TR> </TABLE> </FONT> </form> </body>

</HTML>

(2)留言列表

<HEAD> <title>TopicList</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="/intellisense/ie5"

name="vs_targetSchema">

<LINK href="Styles/Style.css" type="text/css" rel="stylesheet"> </HEAD> <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" style="WIDTH: 480px; HEIGHT: 272px" cellSpacing="1" cellPadding="1"

width="480" border="1"> <TR> <TD align="center"><FONT face="宋体">留言列表</FONT></TD> </TR> <TR> <TD vAlign="top" align="center"> 4

&nbsp;<asp:GridView ID="GV" runat="server"

AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GV_PageIndexChanging" OnRowDeleting="GV_RowDeleting" OnRowUpdating="GV_RowUpdating" PageSize="5"

OnRowCommand="GV_RowCommand" CellPadding="4" ForeColor="#333333" GridLines="None"

AllowSorting="True">

<Columns>

<asp:BoundField DataField="TopicId" HeaderText="编号" />

<asp:BoundField DataField="UserLoginName" HeaderText="用户"/> <asp:BoundField DataField="Title" HeaderText="标题"/>

<asp:BoundField DataField="CreateTime" HeaderText="发表时间"/>

<asp:ButtonField Text="修改" HeaderText="修改"

CommandName="Update"/>

<asp:HyperLinkField HeaderText="详细信息"

dataTextFormatString="详细信息" DataNavigateUrlFormatString="TopicDetail.aspx?topic_id={0}" Text="详细信息" DataNavigateUrlFields="TopicId" />

<asp:ButtonField Text="删除" HeaderText="删除"

CommandName="Delete"/>

</Columns>

<FooterStyle BackColor="#5D7B9D" Font-Bold="True"

ForeColor="White" />

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<EditRowStyle BackColor="#999999" />

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"

ForeColor="#333333" />

<PagerStyle BackColor="#284775" ForeColor="White"

HorizontalAlign="Center" />

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"

ForeColor="White" />

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

<asp:label id="LabelPages" runat="server"

Width="150px"></asp:label><asp:hyperlink id="HyperLinkAddTopic" runat="server"

NavigateUrl="TopicAdd.aspx">发表新帖>></asp:hyperlink>

</TD>

</TR> </TABLE> </form> </body>

(3)留言列表代码

using MyBBS.BusinessLogicLayer;

namespace MyBBS.Web

5

{

/// <summary>

/// TopicList 的摘要说明。

/// </summary>

public partial class TopicList : System.Web.UI.Page

{

/// <summary>

/// 页面加载事件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Page_Load(object sender, System.EventArgs e)

{

if (!CheckUser())

Response.Redirect("Login.aspx");

InitData();

}

#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 该调用是ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// 设计器支持所需的方法- 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

}

#endregion

/// <summary>

/// 验证用户身份

/// </summary>

/// <returns></returns>

private bool CheckUser()

{

if (Session["login_name"] == null)

{

Response.Write("<Script Language=JavaScript>alert('请登录!');</Script>"); return false;

6

}

return true;

}

/// <summary>

/// 按时间降序,读取帖子数据

/// </summary>

private void InitData()

{

DataSet ds = Topic.QueryTopics();

GV.DataSource = ds;

GV.DataBind();

LabelPages.Text = "查询结果(第" + (GV.PageIndex + 1).ToString() + "页共" + GV.PageCount.ToString() + "页)";

}

/// <summary>

/// 按钮列单击事件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void GV_RowCommand(object sender, GridViewCommandEventArgs e) {

int index = Convert.ToInt32(e.CommandArgument); //待处理的行下标

int topicId = -1;

switch (e.CommandName)

{

//修改

case "Update":

topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text);

Response.Redirect("TopicUpdate.aspx?topic_id=" + topicId); break;

//删除

case "Delete":

topicId = Convert.ToInt32(GV.Rows[index].Cells[0].Text);

Topic topic = new Topic();

topic.LoadData(topicId);

topic.Delete();

break;

default:

break;

}

}

/// <summary>

/// 翻页事件

/// </summary>

7

/// <param name="sender"></param>

/// <param name="e"></param>

protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e) {

GV.PageIndex = e.NewPageIndex;

InitData();

}

/// <summary>

/// 删除前事件,检测用户是否有删除该数据的权限

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e) {

string userLoginNameOfTopic = GV.Rows[e.RowIndex].Cells[1].Text.ToString(); //UserLoginName

if (userLoginNameOfTopic == "guest" || userLoginNameOfTopic !=

Session["login_name"].ToString())

{

Response.Write("<Script Language=JavaScript>alert('您无权删除!');</Script>");

e.Cancel = true;

}

}

/// <summary>

/// 修改前事件,检测用户是否有修改该数据的权限

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e) {

string userLoginNameOfTopic = GV.Rows[e.RowIndex].Cells[1].Text.ToString(); if (userLoginNameOfTopic == "guest" || userLoginNameOfTopic !=

Session["login_name"].ToString())

{

Response.Write("<Script Language=JavaScript>alert('您无权修改!');</Script>");

e.Cancel = true;

}

}

}

}

8

(4)回复留言

using MyBBS.BusinessLogicLayer; using MyBBS.DataAccessHelper; namespace MyBBS.Web

{

/// <summary> /// TopicReply 的摘要说明。 /// </summary> public partial class TopicReply : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { } // // CODEGEN: 该调用是ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); if(!CheckUser()) Response.Redirect("Login.aspx"); /// <summary> /// 设计器支持所需的方法- 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { } #endregion /// <summary> /// 验证当前操作的用户是否合法 /// </summary> /// <returns></returns> private bool CheckUser() { if(Session["login_name"]==null) { } 9 Response.Write("<Script Language=JavaScript>alert('请登录!');</Script>"); return false;

));

} return true; /// <summary> /// 回复主题确定按钮单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonOK_Click(object sender, System.EventArgs e) { int topicId=Convert.ToInt32(Request.QueryString["topic_id"]); Hashtable ht=new Hashtable(); ht.Add("UserLoginName",SqlStringFormat.GetQuotedString(Session["login_name"].ToString() ht.Add("TopicID",topicId); ht.Add("Title",SqlStringFormat.GetQuotedString(TextBoxTitle.Text)); ht.Add("Content",SqlStringFormat.GetQuotedString(TextBoxContent.Text)); ht.Add("CreateTime",SqlStringFormat.GetQuotedString(System.DateTime.Now.ToString())); ht.Add("IP",SqlStringFormat.GetQuotedString(Request.UserHostAddress.ToString())); //用户IP

} } /// <summary> /// 返回按钮单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonBack_Click(object sender, System.EventArgs e) { } int topicId=Convert.ToInt32(Request.QueryString["topic_id"]); Response.Redirect("TopicDetail.aspx?topic_id="+topicId.ToString()); Reply reply =new Reply(); reply.Add(ht); Response.Redirect("TopicDetail.aspx?topic_id="+topicId.ToString());

(5)修改留言

using MyBBS.BusinessLogicLayer;

using MyBBS.DataAccessHelper;

namespace MyBBS.Web

{

/// <summary> /// TopicUpdate 的摘要说明。 /// </summary> public partial class TopicUpdate : System.Web.UI.Page 10

{ /// <summary> /// 页面加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param>

protected void Page_Load(object sender, System.EventArgs e) {

if (!CheckUser())

Response.Redirect("Login.aspx");

if(!IsPostBack)

InitData();

}

#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { } /// <summary> /// 设计器支持所需的方法- 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { } #endregion private bool CheckUser() { } /// <summary> /// 初始化页面数据 /// </summary> private void InitData() { int topicId=Convert.ToInt32(Request.QueryString["topic_id"]); 11 if(Session["login_name"]==null) { } return true; Response.Write("<Script Language=JavaScript>alert('请登录!');</Script>"); return false; // // CODEGEN: 该调用是ASP.NET Web 窗体设计器所必需的。 InitializeComponent(); base.OnInit(e); //

Topic topic=new Topic(); topic.LoadData(topicId); } TextBoxTitle.Text=topic.Title; TextBoxContent.Text=topic.Content; LabelCreateTime.Text=topic.CreateTime.ToString(); LabelIP.Text=topic.IP; LabelUserLoginName.Text=Session["login_name"].ToString(); protected void ButtonBack_Click(object sender, System.EventArgs e) { } /// <summary> /// 修改主题按钮单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ButtonUpdate_Click(object sender, System.EventArgs e) { Topic topic=new Topic(); topic.TopicID=Convert.ToInt32(Request.QueryString["topic_id"]); Hashtable ht=new Hashtable(); ht.Add("Title",SqlStringFormat.GetQuotedString(TextBoxTitle.Text)); ht.Add("Content",SqlStringFormat.GetQuotedString(TextBoxContent.Text)); Page.Response.Redirect("TopicList.aspx"); } } topic.Update(ht); Page.Response.Redirect("TopicList.aspx");

其他页面与此类似。

6.0、总结

本课程设计的目的是建立一个小型的B/S结构的企业管理系统。在进行设计之前,应掌握以下技术:1、Asp.net.2、Sql Server 2000.3、Access.4、ADO.NET 为了能够快速高效地完成课程设计,掌握一些编程工具是必要的,这些工具包括:

1、Asp.net.2、ADO.NET.3、Sql Server 2000.4、Access

经过一周的奋战我的库存管理系统终于完成了!在没有实训以前觉得

是对这之前所学知识的单纯总结,但是通过这次实训发现自己的看法有点太片面了。实训不仅是对前面所学知识的一种检验,而且也是对自己能力的一种提高.通过这次实训使我明白了自己原来知识还比较欠缺。我想在今后的实训中不仅是Web实训还是VC++实训我都能养成独立思考的良好习惯。

2011-5-31

12

相关推荐