2023年6月21日发(作者:)
天津理工大学数据库实验三:数据库网页展示
实验报告
学院(系)名称:计算机与通信工程学院
姓名
班级
Touchkiss
2班
课程名称
学号
实验项目
专业 计算机科学与技术
实验三:数据库编程
课程代码 0668026 数据库系统
实验时间 2014/11/28 实验地点 计算机软件实验室7-215
批改意见
成绩
教师签字:
1.实验目的
1) 了解常用数据库访问技术
2) 掌握ODBC、、JDBC等数据库访问技术
3) 掌握通过编程的方式对数据库进行操作,为进行数据库课程设计作准备
2.实验工具
MS SQL server2008、面向对象高级程序设计语言(C#或Java)
3.实验内容
完成小型管理信息系统的开发,题目可自选,要求选择一面向对象高级语言,连接后台数据库,以图形界面的方式实现对数据库的增、删、改、查操作。
4.实验要求:
1)认真完成并按时提交实验报告,在实验报告中附核心源码并给出执行结果截图;
所有学生界面:
1 / 14 天津理工大学数据库实验三:数据库网页展示
输入查找内容:
2 / 14 天津理工大学数据库实验三:数据库网页展示
查找结果:3 / 14 天津理工大学数据库实验三:数据库网页展示
人员编辑新增界面:
判断信息输入是否合法:4 / 14 天津理工大学数据库实验三:数据库网页展示
2)整理上机步骤,总结经验和体会。
人员添加页面主要代码:(ashx)
tType = "text/html";
string sno = t["Sno"];
string dept = t["Dept"];
DataTable dt;
if (OrEmpty(sno)&&OrEmpty(dept))
{
dt =
eDataTable("select * from Student");
}
else if (!OrEmpty(sno))
{
dt =
eDataTable("select * from Student where Sno=@Sno", new
SqlParameter("@Sno", sno));
}
else
{
dt =
eDataTable("select * from Student where Sdept=@Sdept", new
SqlParameter("@Sdept", dept));
}
string html = Html("", );
5 / 14 天津理工大学数据库实验三:数据库网页展示
(html);
HTML代码:
人员编辑页面主要代码:(ashx)
tType = "text/html";
string action = t["Action"];
if (action == "AddNew")
{
//判断是否含有Save并且等于true,如果是的话就说明是点击【保存】按钮请求来的
bool save = ean(t["Save"]);
7 / 14 天津理工大学数据库实验三:数据库网页展示
if (save)//是保存
{
Guid id = new Guid(t["id"]);
int sno = 32(t["Sno"]);
string name = t["Name"];
int age = 32(t["Age"]);
string sex = t["Sex"];
string dept = t["Dept"];
eNonQuery("Insert into Student
values(@id,@Sno,@Sname,@Sage,@Ssex,@Sdept)", new SqlParameter("@id", id),new
SqlParameter("@Sno",sno),
new SqlParameter("@Sname", name),
new SqlParameter("@Sage",age),
new SqlParameter("@Ssex",sex)
, new SqlParameter("@Sdept", dept));
ct("");//保存成功返回列表页面
}
else
{
var data =new
{
Action = "AddNew",
id=d(),
Sno = "",
Sname = "",
Sage = "",
Ssex = "",
Sdept = "",
text="添加"
};
string html = Html("", data);
(html);
}
}
else if (action == "Edit")
{
bool save = ean(t["Save"]);
if (save)
{
Guid id = new Guid(t["id"]);
int sno = 32(t["Sno"]);
string name = t["Name"];
int age = 32(t["Age"]);
string sex = t["Sex"];
string dept = t["Dept"];
8 / 14 天津理工大学数据库实验三:数据库网页展示
eNonQuery("update t set
Sno=@Sno,Sname=@Sname,Sage=@Sage,Ssex=@Ssex,Sdept=@Sdept where id =@id", new
SqlParameter("@id", id), new SqlParameter("@Sno", sno),
new SqlParameter("@Sname", name),
new SqlParameter("@Sage", age),
new SqlParameter("@Ssex", sex)
, new SqlParameter("@Sdept", dept));
ct("");//保存成功返回列表页面
}
else
{
Guid id=new Guid(t["id"]);
DataTable dt=eDataTable("select * from t where id =
@id",
new SqlParameter("@id", id));
if ( <= 0)
{
("没有找到此学生!");
return;
}
else if ( > 1)
{
("参数错误!");
return;
}
else
{
DataRow row = [0];
var data =
new
{
Action = "Edit",
id=row["id"],
Sno = row["Sno"],
Sname = row["Sname"],
Sage = row["Sage"],
Ssex = row["Ssex"],
Sdept = row["Sdept"],
text="保存"
};
string html = Html("", data);
(html);
}
}
9 / 14 天津理工大学数据库实验三:数据库网页展示
}
else if (action == "Delete")
{
Guid id = new Guid(t["id"]);
eNonQuery("delete from t where id=@id",new
SqlParameter("@id",id));
ct("");//删除成功返回列表页面
}
else
{
("Action参数错误!");
}
HTML代码:
10 / 14 天津理工大学数据库实验三:数据库网页展示
项目中用到的css文件()
#adds {
font-family: Microsoft YaHei UI;
color:White;
}
able {
font-family: Microsoft YaHei UI;
font-size:15px;
color:#ffffff;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
able th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
able tr {
}
able td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
:
body
{
background-image:url();
background-size:cover;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; /* */
}
#top_bit {
width:760px;
margin: 0 auto;
}
span {
font-family: Microsoft YaHei UI;
color: white;
11 / 14 天津理工大学数据库实验三:数据库网页展示
}
label {
font-family: Microsoft YaHei UI;
color:White;
}
#sub {
font-family: Microsoft YaHei UI;
color:White;
}
form {
width:400px;
margin: 20px auto;
}
p {
line-height: 1.6;
}
input, textarea {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color:#fff;
border:1px solid #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: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
textarea {
min-height:200px;
}
input:focus, textarea:focus {
-webkit-box-shadow:0 0 25px #ccc;
12 / 14 天津理工大学数据库实验三:数据库网页展示
-moz-box-shadow:0 0 25px #ccc;
box-shadow:0 0 25px #ccc;
-webkit-transform: scale(1.05);
-moz-transform: scale(1.05);
transform: scale(1.05);
}
/* The interesting bit */
input:not(:focus), textarea:not(:focus) {
opacity:0.5;
}
input:required, textarea:required {
background:url("asterisk_") no-repeat 280px 7px;
}
input:valid, textarea:valid {
background:url("") no-repeat 280px 5px;
}
input:focus:invalid, textarea:focus:invalid {
background:url("") no-repeat 280px 7px;
}
input[type=submit] {
padding:10px;
background:none;
opacity:1.0;
}
input[type=button] {
padding:10px;
background:none;
opacity:1.0;
}
项目中的类:Velocity
VelocityEngine vltEngine = new VelocityEngine();
perty(CE_LOADER, "file");
perty(RuntimeConstants.,
h("~/templates"));//模板文件所在的文件夹
();
13 / 14 天津理工大学数据库实验三:数据库网页展示
VelocityContext vltContext = new VelocityContext();
("Data", data);//设置参数,在模板中可以通过$data来引用
Template vltTemplate = plate(templateName);
Writer vltWriter = new Writer();
(vltContext, vltWriter);
string html = ingBuilder().ToString();
return html;
【实验过程记录(源程序、测试用例、测试结果及心得体会等)】
实验心得:不会写老师教的aspx下外链css和js,再加上老师鼓励把界面做的漂亮一点,就用了ashx,和html分开,觉得比aspx容易一些。
14 / 14
2023年6月21日发(作者:)
天津理工大学数据库实验三:数据库网页展示
实验报告
学院(系)名称:计算机与通信工程学院
姓名
班级
Touchkiss
2班
课程名称
学号
实验项目
专业 计算机科学与技术
实验三:数据库编程
课程代码 0668026 数据库系统
实验时间 2014/11/28 实验地点 计算机软件实验室7-215
批改意见
成绩
教师签字:
1.实验目的
1) 了解常用数据库访问技术
2) 掌握ODBC、、JDBC等数据库访问技术
3) 掌握通过编程的方式对数据库进行操作,为进行数据库课程设计作准备
2.实验工具
MS SQL server2008、面向对象高级程序设计语言(C#或Java)
3.实验内容
完成小型管理信息系统的开发,题目可自选,要求选择一面向对象高级语言,连接后台数据库,以图形界面的方式实现对数据库的增、删、改、查操作。
4.实验要求:
1)认真完成并按时提交实验报告,在实验报告中附核心源码并给出执行结果截图;
所有学生界面:
1 / 14 天津理工大学数据库实验三:数据库网页展示
输入查找内容:
2 / 14 天津理工大学数据库实验三:数据库网页展示
查找结果:3 / 14 天津理工大学数据库实验三:数据库网页展示
人员编辑新增界面:
判断信息输入是否合法:4 / 14 天津理工大学数据库实验三:数据库网页展示
2)整理上机步骤,总结经验和体会。
人员添加页面主要代码:(ashx)
tType = "text/html";
string sno = t["Sno"];
string dept = t["Dept"];
DataTable dt;
if (OrEmpty(sno)&&OrEmpty(dept))
{
dt =
eDataTable("select * from Student");
}
else if (!OrEmpty(sno))
{
dt =
eDataTable("select * from Student where Sno=@Sno", new
SqlParameter("@Sno", sno));
}
else
{
dt =
eDataTable("select * from Student where Sdept=@Sdept", new
SqlParameter("@Sdept", dept));
}
string html = Html("", );
5 / 14 天津理工大学数据库实验三:数据库网页展示
(html);
HTML代码:
人员编辑页面主要代码:(ashx)
tType = "text/html";
string action = t["Action"];
if (action == "AddNew")
{
//判断是否含有Save并且等于true,如果是的话就说明是点击【保存】按钮请求来的
bool save = ean(t["Save"]);
7 / 14 天津理工大学数据库实验三:数据库网页展示
if (save)//是保存
{
Guid id = new Guid(t["id"]);
int sno = 32(t["Sno"]);
string name = t["Name"];
int age = 32(t["Age"]);
string sex = t["Sex"];
string dept = t["Dept"];
eNonQuery("Insert into Student
values(@id,@Sno,@Sname,@Sage,@Ssex,@Sdept)", new SqlParameter("@id", id),new
SqlParameter("@Sno",sno),
new SqlParameter("@Sname", name),
new SqlParameter("@Sage",age),
new SqlParameter("@Ssex",sex)
, new SqlParameter("@Sdept", dept));
ct("");//保存成功返回列表页面
}
else
{
var data =new
{
Action = "AddNew",
id=d(),
Sno = "",
Sname = "",
Sage = "",
Ssex = "",
Sdept = "",
text="添加"
};
string html = Html("", data);
(html);
}
}
else if (action == "Edit")
{
bool save = ean(t["Save"]);
if (save)
{
Guid id = new Guid(t["id"]);
int sno = 32(t["Sno"]);
string name = t["Name"];
int age = 32(t["Age"]);
string sex = t["Sex"];
string dept = t["Dept"];
8 / 14 天津理工大学数据库实验三:数据库网页展示
eNonQuery("update t set
Sno=@Sno,Sname=@Sname,Sage=@Sage,Ssex=@Ssex,Sdept=@Sdept where id =@id", new
SqlParameter("@id", id), new SqlParameter("@Sno", sno),
new SqlParameter("@Sname", name),
new SqlParameter("@Sage", age),
new SqlParameter("@Ssex", sex)
, new SqlParameter("@Sdept", dept));
ct("");//保存成功返回列表页面
}
else
{
Guid id=new Guid(t["id"]);
DataTable dt=eDataTable("select * from t where id =
@id",
new SqlParameter("@id", id));
if ( <= 0)
{
("没有找到此学生!");
return;
}
else if ( > 1)
{
("参数错误!");
return;
}
else
{
DataRow row = [0];
var data =
new
{
Action = "Edit",
id=row["id"],
Sno = row["Sno"],
Sname = row["Sname"],
Sage = row["Sage"],
Ssex = row["Ssex"],
Sdept = row["Sdept"],
text="保存"
};
string html = Html("", data);
(html);
}
}
9 / 14 天津理工大学数据库实验三:数据库网页展示
}
else if (action == "Delete")
{
Guid id = new Guid(t["id"]);
eNonQuery("delete from t where id=@id",new
SqlParameter("@id",id));
ct("");//删除成功返回列表页面
}
else
{
("Action参数错误!");
}
HTML代码:
10 / 14 天津理工大学数据库实验三:数据库网页展示
项目中用到的css文件()
#adds {
font-family: Microsoft YaHei UI;
color:White;
}
able {
font-family: Microsoft YaHei UI;
font-size:15px;
color:#ffffff;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
able th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
able tr {
}
able td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
:
body
{
background-image:url();
background-size:cover;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; /* */
}
#top_bit {
width:760px;
margin: 0 auto;
}
span {
font-family: Microsoft YaHei UI;
color: white;
11 / 14 天津理工大学数据库实验三:数据库网页展示
}
label {
font-family: Microsoft YaHei UI;
color:White;
}
#sub {
font-family: Microsoft YaHei UI;
color:White;
}
form {
width:400px;
margin: 20px auto;
}
p {
line-height: 1.6;
}
input, textarea {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color:#fff;
border:1px solid #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: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
textarea {
min-height:200px;
}
input:focus, textarea:focus {
-webkit-box-shadow:0 0 25px #ccc;
12 / 14 天津理工大学数据库实验三:数据库网页展示
-moz-box-shadow:0 0 25px #ccc;
box-shadow:0 0 25px #ccc;
-webkit-transform: scale(1.05);
-moz-transform: scale(1.05);
transform: scale(1.05);
}
/* The interesting bit */
input:not(:focus), textarea:not(:focus) {
opacity:0.5;
}
input:required, textarea:required {
background:url("asterisk_") no-repeat 280px 7px;
}
input:valid, textarea:valid {
background:url("") no-repeat 280px 5px;
}
input:focus:invalid, textarea:focus:invalid {
background:url("") no-repeat 280px 7px;
}
input[type=submit] {
padding:10px;
background:none;
opacity:1.0;
}
input[type=button] {
padding:10px;
background:none;
opacity:1.0;
}
项目中的类:Velocity
VelocityEngine vltEngine = new VelocityEngine();
perty(CE_LOADER, "file");
perty(RuntimeConstants.,
h("~/templates"));//模板文件所在的文件夹
();
13 / 14 天津理工大学数据库实验三:数据库网页展示
VelocityContext vltContext = new VelocityContext();
("Data", data);//设置参数,在模板中可以通过$data来引用
Template vltTemplate = plate(templateName);
Writer vltWriter = new Writer();
(vltContext, vltWriter);
string html = ingBuilder().ToString();
return html;
【实验过程记录(源程序、测试用例、测试结果及心得体会等)】
实验心得:不会写老师教的aspx下外链css和js,再加上老师鼓励把界面做的漂亮一点,就用了ashx,和html分开,觉得比aspx容易一些。
14 / 14
发布评论