1、天津理工大学 数据库实验三数据库网页展示实验报告学院(系)名称:计算机与通信工程学院姓名Touchkiss学号20125577专业计算机科学与技术班级2班实验项目实验三:数据库编程课程名称数据库系统课程代码0668026实验时间2014/11/28实验地点计算机软件实验室7-215批改意见成绩教师签字: 1.实验目的1) 了解常用数据库访问技术2) 掌握ODBC、ADO.NET、JDBC等数据库访问技术3) 掌握通过编程的方式对数据库进行操作,为进行数据库课程设计作准备2.实验工具MS SQL server2008、面向对象高级程序设计语言(C#或Java)3.实验内容 完成小型管理信息系统的
2、开发,题目可自选,要求选择一面向对象高级语言,连接后台数据库,以图形界面的方式实现对数据库的增、删、改、查操作。4.实验要求:1)认真完成并按时提交实验报告,在实验报告中附核心源码并给出执行结果截图;所有学生界面:输入查找内容:查找结果:人员编辑新增界面:判断信息输入是否合法: 2)整理上机步骤,总结经验和体会。人员添加页面主要代码:(ashx)context.Response.ContentType = text/html; string sno = context.RequestSno; string dept = context.RequestDept; DataTable dt; if
3、 (string.IsNullOrEmpty(sno)&string.IsNullOrEmpty(dept) dt = SqlHelper.ExecuteDataTable(select * from Student); else if (!string.IsNullOrEmpty(sno) dt = SqlHelper.ExecuteDataTable(select * from Student where Sno=Sno, new SqlParameter(Sno, sno); else dt = SqlHelper.ExecuteDataTable(select * from Stude
4、nt where Sdept=Sdept, new SqlParameter(Sdept, dept); string html = CommonHelper.RenderHtml(PersonList.htm, dt.Rows); context.Response.Write(html);HTML代码: 人员列表 请输入学号查找 或输入系别查找 编辑 删除 学号 姓名 年龄 性别 所在系 #foreach($person in $Data) 编辑 删除 $person.Sno $person.Sname $person.Sage $person.Ssex $person.Sdept #end
5、 人员编辑页面主要代码:(ashx)context.Response.ContentType = text/html; string action = context.RequestAction; if (action = AddNew) /判断是否含有Save并且等于true,如果是的话就说明是点击【保存】按钮请求来的 bool save = Convert.ToBoolean(context.RequestSave); if (save)/是保存 Guid id = new Guid(context.Requestid); int sno = Convert.ToInt32(context
6、.RequestSno); string name = context.RequestName; int age = Convert.ToInt32(context.RequestAge); string sex = context.RequestSex; string dept = context.RequestDept; SqlHelper.ExecuteNonQuery(Insert into Student values(id,Sno,Sname,Sage,Ssex,Sdept), new SqlParameter(id, id),new SqlParameter(Sno,sno),
7、new SqlParameter(Sname, name), new SqlParameter(Sage,age), new SqlParameter(Ssex,sex) , new SqlParameter(Sdept, dept); context.Response.Redirect(PersonList.ashx);/保存成功返回列表页面 else var data =new Action = AddNew, id=System.Guid.NewGuid(), Sno = , Sname = , Sage = , Ssex = , Sdept = , text=添加 ; string h
8、tml = CommonHelper.RenderHtml(PersonEdit.htm, data); context.Response.Write(html); else if (action = Edit) bool save = Convert.ToBoolean(context.RequestSave); if (save) Guid id = new Guid(context.Requestid); int sno = Convert.ToInt32(context.RequestSno); string name = context.RequestName; int age =
9、Convert.ToInt32(context.RequestAge); string sex = context.RequestSex; string dept = context.RequestDept; SqlHelper.ExecuteNonQuery(update dbo.Student 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, na
10、me), new SqlParameter(Sage, age), new SqlParameter(Ssex, sex) , new SqlParameter(Sdept, dept); context.Response.Redirect(PersonList.ashx);/保存成功返回列表页面 else Guid id=new Guid(context.Requestid); DataTable dt=SqlHelper.ExecuteDataTable(select * from dbo.Student where id = id, new SqlParameter(id, id); i
11、f (dt.Rows.Count 1) context.Response.Write(参数错误!); return; else DataRow row = dt.Rows0; var data = new Action = Edit, id=rowid, Sno = rowSno, Sname = rowSname, Sage = rowSage, Ssex = rowSsex, Sdept = rowSdept, text=保存 ; string html = CommonHelper.RenderHtml(PersonEdit.htm, data); context.Response.Wr
12、ite(html); else if (action = Delete) Guid id = new Guid(context.Requestid); SqlHelper.ExecuteNonQuery(delete from dbo.Student where id=id,new SqlParameter(id,id); context.Response.Redirect(PersonList.ashx);/删除成功返回列表页面 else context.Response.Write(Action参数错误!); HTML代码: 编辑学生信息 学号: 姓名: 年龄: 性别: 所在系: 项目中用
13、到的css文件(list.css)#adds font-family: Microsoft YaHei UI; color:White; table.hovertable font-family: Microsoft YaHei UI; font-size:15px; color:#ffffff; border-width: 1px; border-color: #999999; border-collapse: collapse;table.hovertable th border-width: 1px; padding: 8px; border-style: solid; border-c
14、olor: #a9c6c9;table.hovertable tr table.hovertable td border-width: 1px; padding: 8px; border-style: solid; border-color: #a9c6c9;Edit.css: body background-image:url(bg.jpg); background-size:cover; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; /* */ #top_bit width:760px; margin: 0 auto;
15、 span font-family: Microsoft YaHei UI; color: white; 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-c
16、olor:#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; tran
17、sition: all 0.5s ease-in-out; textarea min-height:200px; input:focus, textarea:focus -webkit-box-shadow:0 0 25px #ccc; -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(:fo
18、cus), textarea:not(:focus) opacity:0.5; input:required, textarea:required background:url(asterisk_orange.png) no-repeat 280px 7px; input:valid, textarea:valid background:url(tick.png) no-repeat 280px 5px; input:focus:invalid, textarea:focus:invalid background:url(cancel.png) no-repeat 280px 7px; inp
19、uttype=submit padding:10px; background:none; opacity:1.0; inputtype=button padding:10px; background:none; opacity:1.0; 项目中的类:Velocity VelocityEngine vltEngine = new VelocityEngine(); vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, file); vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_L
20、OADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath(/templates);/模板文件所在的文件夹 vltEngine.Init(); VelocityContext vltContext = new VelocityContext(); vltContext.Put(Data, data);/设置参数,在模板中可以通过$data来引用 Template vltTemplate = vltEngine.GetTemplate(templateName); System.IO.StringWriter vltWriter = new System.IO.StringWriter(); vltTemplate.Merge(vltContext, vltWriter); string html = vltWriter.GetStringBuilder().ToString(); return html;【实验过程记录(源程序、测试用例、测试结果及心得体会等)】实验心得:不会写老师教的aspx下外链css和
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1