天津理工大学 数据库实验三数据库网页展示.docx

上传人:b****6 文档编号:8261324 上传时间:2023-01-30 格式:DOCX 页数:18 大小:314.14KB
下载 相关 举报
天津理工大学 数据库实验三数据库网页展示.docx_第1页
第1页 / 共18页
天津理工大学 数据库实验三数据库网页展示.docx_第2页
第2页 / 共18页
天津理工大学 数据库实验三数据库网页展示.docx_第3页
第3页 / 共18页
天津理工大学 数据库实验三数据库网页展示.docx_第4页
第4页 / 共18页
天津理工大学 数据库实验三数据库网页展示.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

天津理工大学 数据库实验三数据库网页展示.docx

《天津理工大学 数据库实验三数据库网页展示.docx》由会员分享,可在线阅读,更多相关《天津理工大学 数据库实验三数据库网页展示.docx(18页珍藏版)》请在冰豆网上搜索。

天津理工大学 数据库实验三数据库网页展示.docx

天津理工大学数据库实验三数据库网页展示

实验报告

学院(系)名称:

计算机与通信工程学院

姓名

Touchkiss

学号

20125577

专业

计算机科学与技术

班级

2班

实验项目

实验三:

数据库编程

课程名称

数据库系统

课程代码

0668026

实验时间

2014/11/28

实验地点

计算机软件实验室7-215

批改意见

成绩

 

教师签字:

1.实验目的

1)了解常用数据库访问技术

2)掌握ODBC、ADO.NET、JDBC等数据库访问技术

3)掌握通过编程的方式对数据库进行操作,为进行数据库课程设计作准备

2.实验工具

MSSQLserver2008、面向对象高级程序设计语言(C#或Java)

3.实验内容

完成小型管理信息系统的开发,题目可自选,要求选择一面向对象高级语言,连接后台数据库,以图形界面的方式实现对数据库的增、删、改、查操作。

4.实验要求:

1)认真完成并按时提交实验报告,在实验报告中附核心源码并给出执行结果截图;

所有学生界面:

输入查找内容:

查找结果:

人员编辑新增界面:

判断信息输入是否合法:

2)整理上机步骤,总结经验和体会。

人员添加页面主要代码:

(ashx)

context.Response.ContentType="text/html";

stringsno=context.Request["Sno"];

stringdept=context.Request["Dept"];

DataTabledt;

if(string.IsNullOrEmpty(sno)&&string.IsNullOrEmpty(dept))

{

dt=

SqlHelper.ExecuteDataTable("select*fromStudent");

}

elseif(!

string.IsNullOrEmpty(sno))

{

dt=

SqlHelper.ExecuteDataTable("select*fromStudentwhereSno=@Sno",newSqlParameter("@Sno",sno));

}

else

{

dt=

SqlHelper.ExecuteDataTable("select*fromStudentwhereSdept=@Sdept",newSqlParameter("@Sdept",dept));

}

stringhtml=CommonHelper.RenderHtml("PersonList.htm",dt.Rows);

context.Response.Write(html);

HTML代码:

//www.w3.org/1999/xhtml">

人员列表

请输入学号查找

id="SnoMsg">

或输入系别查找

Action=AddNew'"

value="新增"/>

编辑

删除

学号

姓名

年龄

性别

所在系

#foreach($personin$Data)

Action=Edit&id=$person.id">编辑

Action=Delete&id=$person.id">删除

$person.Sno

$person.Sname

$person.Sage

$person.Ssex

$person.Sdept

#end

人员编辑页面主要代码:

(ashx)

context.Response.ContentType="text/html";

stringaction=context.Request["Action"];

if(action=="AddNew")

{

//判断是否含有Save并且等于true,如果是的话就说明是点击【保存】按钮请求来的

boolsave=Convert.ToBoolean(context.Request["Save"]);

if(save)//是保存

{

Guidid=newGuid(context.Request["id"]);

intsno=Convert.ToInt32(context.Request["Sno"]);

stringname=context.Request["Name"];

intage=Convert.ToInt32(context.Request["Age"]);

stringsex=context.Request["Sex"];

stringdept=context.Request["Dept"];

SqlHelper.ExecuteNonQuery("InsertintoStudentvalues(@id,@Sno,@Sname,@Sage,@Ssex,@Sdept)",newSqlParameter("@id",id),newSqlParameter("@Sno",sno),

newSqlParameter("@Sname",name),

newSqlParameter("@Sage",age),

newSqlParameter("@Ssex",sex)

newSqlParameter("@Sdept",dept));

context.Response.Redirect("PersonList.ashx");//保存成功返回列表页面

}

else

{

vardata=new

{

Action="AddNew",

id=System.Guid.NewGuid(),

Sno="",

Sname="",

Sage="",

Ssex="",

Sdept="",

text="添加"

};

stringhtml=CommonHelper.RenderHtml("PersonEdit.htm",data);

context.Response.Write(html);

}

}

elseif(action=="Edit")

{

boolsave=Convert.ToBoolean(context.Request["Save"]);

if(save)

{

Guidid=newGuid(context.Request["id"]);

intsno=Convert.ToInt32(context.Request["Sno"]);

stringname=context.Request["Name"];

intage=Convert.ToInt32(context.Request["Age"]);

stringsex=context.Request["Sex"];

stringdept=context.Request["Dept"];

SqlHelper.ExecuteNonQuery("updatedbo.StudentsetSno=@Sno,Sname=@Sname,Sage=@Sage,Ssex=@Ssex,Sdept=@Sdeptwhereid=@id",newSqlParameter("@id",id),newSqlParameter("@Sno",sno),

newSqlParameter("@Sname",name),

newSqlParameter("@Sage",age),

newSqlParameter("@Ssex",sex)

newSqlParameter("@Sdept",dept));

context.Response.Redirect("PersonList.ashx");//保存成功返回列表页面

}

else

{

Guidid=newGuid(context.Request["id"]);

DataTabledt=SqlHelper.ExecuteDataTable("select*fromdbo.Studentwhereid=@id",

newSqlParameter("@id",id));

if(dt.Rows.Count<=0)

{

context.Response.Write("没有找到此学生!

");

return;

}

elseif(dt.Rows.Count>1)

{

context.Response.Write("参数错误!

");

return;

}

else

{

DataRowrow=dt.Rows[0];

vardata=

new

{

Action="Edit",

id=row["id"],

Sno=row["Sno"],

Sname=row["Sname"],

Sage=row["Sage"],

Ssex=row["Ssex"],

Sdept=row["Sdept"],

text="保存"

};

stringhtml=CommonHelper.RenderHtml("PersonEdit.htm",data);

context.Response.Write(html);

}

}

}

elseif(action=="Delete")

{

Guidid=newGuid(context.Request["id"]);

SqlHelper.ExecuteNonQuery("deletefromdbo.Studentwhereid=@id",newSqlParameter("@id",id));

context.Response.Redirect("PersonList.ashx");//删除成功返回列表页面

}

else

{

context.Response.Write("Action参数错误!

");

}

HTML代码:

//www.w3.org/1999/xhtml">

编辑学生信息

学号:

onblur="checkSno()"/>

姓名:

id="SnameMsg">

年龄:

step="1"id="Age"value="$Data.Sage"onblur="checkAge()"/>

性别:

所在系:

项目中用到的css文件(list.css)

#adds{

font-family:

MicrosoftYaHeiUI;

color:

White;

}

table.hovertable{

font-family:

MicrosoftYaHeiUI;

font-size:

15px;

color:

#ffffff;

border-width:

1px;

border-color:

#999999;

border-collapse:

collapse;

}

table.hovertableth{

border-width:

1px;

padding:

8px;

border-style:

solid;

border-color:

#a9c6c9;

}

table.hovertabletr{

}

table.hovertabletd{

border-width:

1px;

padding:

8px;

border-style:

solid;

border-color:

#a9c6c9;

}

Edit.css:

body

{

background-image:

url(bg.jpg);

background-size:

cover;

font-family:

"HelveticaNeue",Helvetica,Arial,sans-serif;/**/

}

#top_bit{

width:

760px;

margin:

0auto;

}

span{

font-family:

MicrosoftYaHeiUI;

color:

white;

}

label{

font-family:

MicrosoftYaHeiUI;

color:

White;

}

#sub{

font-family:

MicrosoftYaHeiUI;

color:

White;

}

form{

width:

400px;

margin:

20pxauto;

}

p{

line-height:

1.6;

}

input,textarea{

font-family:

"HelveticaNeue",Helvetica,Arial,sans-serif;

background-color:

#fff;

border:

1pxsolid#ccc;

font-size:

20px;

width:

300px;

min-height:

30px;

display:

block;

margin-bottom:

16px;

margin-top:

8px;

color:

White;

-webkit-border-radius:

5px;

-moz-border-radius:

5px;

border-radius:

5px;

-webkit-transition:

all0.5sease-in-out;

-moz-transition:

all0.5sease-in-out;

transition:

all0.5sease-in-out;

}

textarea{

min-height:

200px;

}

input:

focus,textarea:

focus{

-webkit-box-shadow:

0025px#ccc;

-moz-box-shadow:

0025px#ccc;

box-shadow:

0025px#ccc;

-webkit-transform:

scale(1.05);

-moz-transform:

scale(1.05);

transform:

scale(1.05);

}

/*Theinterestingbit*/

input:

not(:

focus),textarea:

not(:

focus){

opacity:

0.5;

}

input:

required,textarea:

required{

background:

url("asterisk_orange.png")no-repeat280px7px;

}

input:

valid,textarea:

valid{

background:

url("tick.png")no-repeat280px5px;

}

input:

focus:

invalid,textarea:

focus:

invalid{

background:

url("cancel.png")no-repeat280px7px;

}

input[type=submit]{

padding:

10px;

background:

none;

opacity:

1.0;

}

input[type=button]{

padding:

10px;

background:

none;

opacity:

1.0;

}

项目中的类:

Velocity

VelocityEnginevltEngine=newVelocityEngine();

vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER,"file");

vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹

vltEngine.Init();

VelocityContextvltContext=newVelocityContext();

vltContext.Put("Data",data);//设置参数,在模板中可以通过$data来引用

TemplatevltTemplate=vltEngine.GetTemplate(templateName);

System.IO.StringWritervltWriter=newSystem.IO.StringWriter();

vltTemplate.Merge(vltContext,vltWriter);

stringhtml=vltWriter.GetStringBuilder().ToString();

returnhtml;

【实验过程记录(源程序、测试用例、测试结果及心得体会等)】

实验心得:

不会写老师教的aspx下外链css和

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1