Web程序设计实验报告

Web程序设计实验报告

姓名:冯刚

学号:200905030324

班级:计科3班

Html代码:

1.首页代码

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

body {

            background-color: #00FFCC;

}

#Layer1 {

            position:absolute;

            width:579px;

            height:89px;

            z-index:1;

            left: 276px;

            top: 17px;

}

.STYLE1 {

            font-size: 5pc;

            color: #660000;

}

#Layer2 {

            position:absolute;

            width:109px;

            height:31px;

            z-index:2;

            left: 426px;

            top: 146px;

}

#Layer3 {

            position:absolute;

            width:91px;

            height:34px;

            z-index:1;

            left: 455px;

            top: -4px;

}

#Layer4 {

            position:absolute;

            width:85px;

            height:33px;

            z-index:3;

            left: 649px;

            top: 142px;

}

.STYLE2 {font-size: 24px}

#Layer5 {

            position:absolute;

            width:611px;

            height:156px;

            z-index:4;

            left: 267px;

            top: 247px;

}

.STYLE3 {

            font-size: 36px;

            color: #CC00CC;

}

.STYLE5 {font-size: 36px; color:  #CC00CC; }

-->

</style></head>

<body>

<div class="STYLE1" id="Layer1">冯刚的个人主页</div>

<div id="Layer2">

  <div class="STYLE2" id="Layer3"><a href="Untitled-2.html">通讯录</a></div>

  <span class="STYLE2"><a href="Untitled-3.html">个人介绍</a></span></div>

<div class="STYLE2" id="Layer4"><a href="Untitled-4.html">留言板</a></div>

<div id="Layer5">

  <p align="center" class="STYLE5">姓名: 冯刚</p>

  <p align="center" class="STYLE3">班级:计科三班</p>

  <p align="center" class="STYLE3">学号:200905030324</p>

  <p>&nbsp;</p>

</div>

</body>

</html>

2.通讯录代码

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

body {

            background-color: #330099;

}

.STYLE2 {font-size: 9pc}

-->

</style></head>

<body>

<div align="center"><span class="STYLE2">通讯录</span>

</div>

<table width="392" height="129" border="1" align="center" bgcolor="#FF9933">

  <tr>

    <td>张三</td>

    <td>1288**********</td>

  </tr>

  <tr>

    <td>李四</td>

    <td>1434********</td>

  </tr>

  <tr>

    <td>王五</td>

    <td>12432********</td>

  </tr>

</table>

</body>

</html>

3.自我介绍代码

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

#Layer1 {

            position:absolute;

            width:199px;

            height:517px;

            z-index:1;

            left: 104px;

            top: 20px;

}

.STYLE1 {font-size: 9pc}

#Layer2 {

            position:absolute;

            width:517px;

            height:378px;

            z-index:2;

            left: 438px;

            top: 74px;

}

.STYLE3 {font-size: 16px}

-->

</style>

</head>

<body>

<img src="1.jpg" width="1335" height="721" />

<div class="STYLE3" id="Layer2">

  <p>我的名字叫做冯刚,出生于1990年1月1日。</p>

  <p>秋意悄悄的随着霏霏细雨潜入我的梦里了<br />

    <br />

    秋夜凉凉的手指划过熟睡的面颊<br />

    <br />

    轻轻的呢喃在嘴角流露来世的期盼<br />

    <br />

    沉醉在梦乡里<br />

    <br />

    沉沉的不愿醒来<br />

    <br />

    <br />

    静谧的月光将浪漫笼罩了满屋<br />

    <br />

    朦胧的挥舞绕指的温柔<br />

    <br />

    孤寂在昏睡中将相思唤回<br />

    <br />

    牵手的岁月如此短暂<br />

    <br />

    回首望不断天涯路漫漫<br />

    <br />

  </p>

</div>

<div class="STYLE1" id="Layer1">自我介绍</div>

</body>

</html>

4.留言板代码

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

body {

            background-color: #CC9966;

}

#Layer1 {

            position:absolute;

            width:712px;

            height:131px;

            z-index:1;

            left: 276px;

            top: 14px;

}

.STYLE1 {font-size: 9pc}

#Layer2 {

            position:absolute;

            width:95px;

            height:40px;

            z-index:2;

            left: 650px;

            top: 504px;

}

#Layer3 {

            position:absolute;

            width:205px;

            height:41px;

            z-index:1;

            left: 30px;

            top: -236px;

}

#Layer4 {

            position:absolute;

            width:72px;

            height:32px;

            z-index:1;

            left: -146px;

            top: 1px;

}

.STYLE2 {font-size: 24px}

-->

</style></head>

<body>

<div class="STYLE1" id="Layer1">

  <div align="right">留言板</div>

</div>

<div id="Layer2">

  <div id="Layer3">

    <div class="STYLE2" id="Layer4">YS</div>

    <span class="STYLE2">dsgsdgdsfgsdfg</span></div>

  <div align="center"><span class="STYLE2">提交</span></div>

</div>

</body>

</html>

 

第二篇:web程序设计 实验七实验报告

实验七 数据访问

一、实验目的

(1)   掌握Visual Studio 2008中管理数据库的方法。

(2)   掌握数据源控件的使用。

(3)   掌握LINQ表达式的使用。

(4)   掌握利用LINQ to SQL和LINQ to XML进行数据访问管理的方法。

二、实验内容及要求

1.  利用SqlDataSource和LINQ to SQL进行SQL Server Express 2005的数据管理

三、实验步骤

(1)   新建网站。

新建一个网站,添加Web窗体DataManage.aspx、Web窗体SqlDSFuzzyQuery.aspx、Web窗体SqlDSInsert.aspx、Web窗体SqlDSEdit.aspx、Web窗体LinqEdit.aspx。

(2)   设计DataManage.aspx。

(3)   编写DataManage.aspx事件代码。

按钮btnQueryAll被单击时执行的事件代码如下:

protected void btnQueryAll_Click(object sender,EvenArgs e)

{

      gvCategory.DataSourceID=”sdsCategory”;

      gvCategory.DataBind();

}

按钮btnFuzzy被单击时执行的事件代码如下:

protected void btnFuzzy_Click(object sender, EventArgs e)

{

 Response.Redirect("sqldsfuzzyquery.aspx");

}

按钮btnInsert被单击时执行的事件代码如下:

protected void btnInsert_Click(object sender, EventArgs e)

{

   Response.Redirect("sqldsinsert.aspx");

}

按钮btnEdit被单击时执行的事件代码如下:

protected void btnEdit_Click(object sender, EventArgs e)
    {
         Response.Redirect("sqldsedit.aspx?CategoryId=" + txtCategoryId.Text);
    }

按钮btnEditLinq被单击时执行的事件代码如下:

protected void btnEditLinq_Click(object sender, EventArgs e)
    {
       Response.Redirect("linqedit.aspx?CategoryId=" + txtCategoryId.Text);
    }

按钮btnDelete被单击时执行的事件代码如下:

protected void btnDelete_Click(object sender, EventArgs e)

{

   sdsCategory.Delete();

 }

(4)   设计SqlDSFuzzyQuery.aspx。

(5)   编写SqlDSFuzzyQuery.aspx事件代码。

按钮btnSearch被单击后,引起页面往返,此时将执行sdsCategory中设置的Select命令后再触发的Selected事件代码如下:

Protected void sdsCategory_Selected(object sender, SqlDataSourceStatusEventArgs e)

{

  if (e.AffectedRows == 0)

  {

       lb1Msg.Text = "没有满足条件的数据!";

   }

   else

   {

        lb1Msg.Text = " ";

    }

  }

按钮btnReturn被单击时执行的事件代码如下:

protected void btnReturn_Click(object sender, EventArgs e)

{

  Response.Redirect("datamanage.aspx");

}

(6)   设计SqlDSInsert.aspx。

(7)   编写SqlDSInsert.aspx事件代码。

按钮btnInsert被单击时执行的事件代码如下:

protected void btnInsert_Click(object sender, EventArgs e)

{

 sdsCategory.Insert();

}

按钮btnReturn被单击时执行的事件代码如下:

protected void btnReturn_Click(object sender, EventArgs e)

{

  Response.Redirect("datamanage.aspx");

}

(8)   设计SqlDSEdit.aspx。

(9)   编写SqlDSEdit.aspx事件代码。

Web窗体首次载入时执行的代码如下:

protected void Page_Load(object sender, EventArgs e)

{

  if (!IsPostBack)

  {

      DataView dv = (DataView)sdsCategory.Select(new DataSourceSelectArguments());

      DataTable dt = dv.ToTable();

      txtCategoryId.Text = dt.Rows[0]["Category"].ToString();

      txtName.Text = dt.Rows[0]["Name"].ToString();

      txtDescn.Text = dt.Rows[0]["Descn"].ToString();

}

按钮btnUpdate被单击时执行的事件代码如下:

protected void btnUpdate_Click(object sender, EventArgs e)

{

 sdsCategory.Update();

       }

按钮btnReturn被单击时执行的事件代码如下:

protected void btnReturn_Click(object sender, EventArgs e)

{

  Response.Redirect("datamanage.aspx");

}

(10)  设计LinqEdit.aspx。

(11)  添加MyPetShop.dbml。

在APP_Code文件夹中添加一个“LINQ to SQL类”MyPetShop.dbml,再从“服务器资源管理器”窗口将MyPetShop的各个表拖动到“对象关系设计器”窗口,然后,Visual Studio 2008将自动生成相应的数据类。

(12)  编写LinqEdit.aspx事件代码。

在所有事件代码外声明MyPetShopDataContext对象db,使得该对象可在多个事件代码中使用,代码如下:

MyPetShopDataContext db=new MyPetShopDataContext();

Web窗体首次载入时执行的代码如下:

protected void Page_Load(object sender,EventArgs e)

{

  If(!IsPostBack)

{

       Var categories=from c in db.Category

                      Where c.CategoryId==int.Parse(Request.QueryString[“CategoryID”])

       Select c;

if(categories!=null)

{

       Foreach(Category!=null)

{

       Foreach(Category category in categories)

{

       txtCategoryId.Text=category.CategoryId.ToString();

       txtName.Text=category.Name;

       txtDescn.Text=category.Descn;

}

}

}

}

              按钮btnUpdate被单击时执行的事件代码如下:

              Protected void btnUpdate_Click(object sender,EventArgs e)

{

       Var categories=from c in db.Category

                     Where c.CategoryId==int.Parse(txtCategoryId.Text)

                     Select c;

If(categories!=null)

{

       Foreach(Category category in categories)

{

       Category.Name=txtName.Text;

       Category.Descn=txtDescn.Text;

}

Db.SubmitChanges();

}

              }

按钮btnReturn被单击时执行的事件代码如下:

protected void btnReturn_Click(object sender, EventArgs e)

{

  Response.Redirect("datamanage.aspx");

}

(13)  从浏览DataManage.aspx开始对数据管理网站进行测试。

三、实验结果

图 1  SQL数据管理导航页浏览效果

图 2 “模糊查找”效果(1)

图 3 “模糊查找”效果(2 )

图 4 “模糊查找”效果(3)

图 5 SQL“插入”效果

图 6 “修改”效果

相关推荐