防灾科技学院
实习报告书
实习题目: | ||||
学号: | 姓名: | |||
专业: | 计算机科学与技术 | 系别: | ||
实习时间: | 8.14-9.2 | 实习地点: | ||
指导教师: | 史磊 | |||
考勤成绩: | 实习态度: | |||
任务完成: | 实习报告: | |||
实习日志: | 实习总成绩 | |||
指导 教师 评语 | 指导教师(签名): 2016年 月 日 | |||
2015年制
实习目的: 该课程是学生学习完Web应用设计、信息系统分析与设计等专业课程后,进一步学习后继专业课程前必须完成的一项实践教学环节,是信息管理与信息系统专业实习的延续,也是信息管理与信息系统毕业实习课程的先修课程,该课程是信息管理与信息系统专业的一门专业必修实践课程。 本课程主要按照软件工程的相关理论,讲解一个Web网站项目完整的开发流程,包括需求分析、面向对象的分析与设计、数据库设计、界面设计、系统编码、软件测试及系统部署等内容。 通过本课程的学习,使学生掌握开发Web网站所需的各项软件技术;提高学生综合运用专业理论知识分析问题、解决问题的能力;增强动手能力,为学生就业打下坚实的基础。 实习任务概述: 任务:选课系统的设计与实现 其中主要完成以下任务: 1. 对选课系统的需求分析 学生选课系统主要满足来自两方面的需求,这三个方面分别是学生用户和管理员用户,也即是两类用户角。 本系统将管理员用户、学生用户的身份及权限进行严格的划分,让管理员拥有最高权限,可以查看、维护系统中的所有信息,如添加学生,添加课程,修改课程信息,审批学生退课等;让学生拥有选课和退选的权限;而修改密码模块的权限每个用户都可拥有,用以修改自己的密码信息。通过进行严格的权限划分,可以更好地进行管理,也可更好地保护用户信息安全。 2. 选课系统的总体设计 学生选课系统是实现学生选课退课以及学校教务管理员维护信息的一个平台,整个学生选课系统有前台和后台两部分,共分为4个模块:管理员模块,学生模块和公有模块,分别用于完成各自的功能。总体设计包括计算机配置设计、系统模块结构设计、数据库和文件设计、代码设计以及系统可靠性与内部控制设计。 3. 选课系统的详细设计 学生选课系统是实现学生网上选课以及学校教务管理员维护信息的一个平台,整个学生选课系统共分为3个大模块:管理员模块,学生模块和公有模块。 4. 选课系统的实现 学生选课系统主要包含学生部分和管理员部分。管理员首先发布课程,学生根据发布的课程,选择课程,提交课程。如果时间上有冲突,会有提示。如果不想选择课程,可以选择课程后退课处理。管理员可以查看学生的选课情况,管理学生退课,导入学生学校等信息,导出选课情况、退课情况和其他信息。管理员还可以修改学生和自己的登录密码。另外还有一些选课新闻,选课指南,回密码等功能。 5. 选课系统的测试 系统测试是软件开发过程中的关键环节,测试分为白盒测试和黑盒测试,主要是黑盒测试,由于系统模块并不十分复杂,在测试的过程中出现的问题并不多,相对而言比较顺利。 实习所用软件简介: 系统的搭建平台选用的操作系统是Windows XP:Microsoft Windows XP是微软公司推出供个人电脑使用的操作系统,包括商用及家用的台式电脑等。2011年9月底前,Windows XP是世界上使用人数最多的操作系统,它的全球市场占有率达42%。2012年8月份,统治操作系统市场长达11年之久的Windows XP最终被Windows 7超越。 基于数据库的选课系统的数据管理所选得软件是SQL Server2008:SQL Server 2008 在Microsoft的数据平台上发布,可以组织管理任何数据。可以将结构化、半结构化和非结构化文档的数据直接存储到数据库中。可以对数据进行查询、搜索、同步、报告和分析之类的操作。SQL Server 2008 允许使用 Microsoft .NET 和Visual Studio开发的自定义应用程序中使用数据,在面向服务的架构(SOA)和通过 Microsoft BizTalk Server 进行的业务流程中使用数据。信息工作人员可以通过日常使用的工具直接访问数据。 基于ASP.NET的选课系统开发所选的开发工具 Visual Studio 2010:Microsoft Visual Studio 2010 是微软的一个综合性的应用程序生命周期管理工具套件,可供团队用于确保从设计到部署的整个过程都能取得较高质量的结果。无论是创建新的解决方案,还是改进现有的应用程序,都能针对不断增加的平台和技术(包括云和并行计算)将梦想变成现实。 基于系统的建模选择的画图软件viso:Office Visio 2007 是一款便于IT和商务专业人员就复杂信息、系统和流程进行可视化处理、分析和交流的软件。使用具有专业外观的 Office Visio 2007 图表,可以促进对系统和流程的了解,深入了解复杂信息并利用这些知识做出更好的业务决策。Visio帮助创建具有专业外观的图表,以便理解、记录和分析信息、数据、系统和过程。使用 Visio 时,以可视方式传递重要信息就像打开模板、将形状拖放到绘图中以及对即将完成的工作应用主题一样轻松。 实习内容及步骤: 任务:选课系统的设计与实现 1 系统需求分析 学生选课系统主要满足来自两方面的需求,这三个方面分别是学生用户和管理员用户,也即是两类用户角。 (1)学生用户是主要的需求者,主要需求功能是查询可选课程、查看自己选课情况及进行选课、退课操作等; (2)管理员用户的功能需求较为复杂,包括对院系信息、专业信息、学生信息、教师信息、课程信息进行管理。在学生信息管理子模块中,实现对学生信息的添加、修改、删除操作,还可以输入查询条件进行查询操作。在教师管理子模块中,实现对教师信息的添加、修改、删除、查询等操作。在课程管理子模块中,实现对课程信息的添加,添加时为其分配任课教师、上课时间和地点,实现对课程的修改、删除、查看某个课程的详细信息等。在选课管理子模块中,实现课程的发布,和学生退课的审批:查看选课结果和是否同意退课。 本系统将管理员用户、学生用户的身份及权限进行严格的划分,让管理员拥有最高权限,可以查看、维护系统中的所有信息,如添加学生,添加课程,修改课程信息,审批学生退课等;让学生拥有选课和退选的权限;而修改密码模块的权限每个用户都可拥有,用以修改自己的密码信息。通过进行严格的权限划分,可以更好地进行管理,也可更好地保护用户信息安全。 1.1用例图 图1.1选课系统用例图 用例图说明: (1)系统的外部角有:学生用户和管理员。 (2)系统主要用例的文档描述: ①学生管理用例:学生用户可见的功能,包含了选课、退课和查看选课三个用例功能。 ②基础信息管理用例:管理员可见的功能,这个用例进一步分为六个用例:学生信息管理用例、教师信息管理用例和课程信息管理用例,校系信息管理用例,专业信息管理用例,新闻管理用力例。 ③选课管理用例:发布选课与审批选课,审批选课又包括查看选课结果和审批选课。 ④修改密码用例:所有用户都可见的功能,用于修改用户的密码信息。 2 系统的总体设计 学生选课系统是实现学生选课退课以及学校教务管理员维护信息的一个平台,整个学生选课系统有前台和后台两部分,共分为4个模块:管理员模块,学生模块和公有模块,分别用于完成各自的功能。 2.1系统环境要求 操作系统是Windows XP 数据管理所选得软件是:SQL Server2008 开发工具: Visual Studio 2010 画图软件:viso 浏览器:IE6.0 2.2系统功能及模块图 2.2.1总体设计图 图2.2.1总体设计图 2.2.2各功能模块 学生选课系统功能模块表
2.2.3数据库
(4)数据库表结构 ①学生表Student的详细数据字段: Student学生用户表
②教师表Teacher的详细数据字段: Teacher教师用户表
③课程表Course的详细数据字段: Cource课程信息表
④发布选课表Elect的详细数据字段: Elect选课信息表
⑤选课信息表Press的详细数据字段: Press选课信息表
⑥系统管理员表admin的详细数据字段: admin管理员表
⑦系院表Depart的详细数据字段: Depart系院表
⑦系院表Major的详细数据字段: Major专业表
⑧新闻表news的详细数据字段: news新闻表
⑨退课处理表tijiao的详细数据字段: news新闻表
3 系统详细设计 学生选课系统是实现学生网上选课以及学校教务管理员维护信息的一个平台,整个学生选课系统共分为3个大模块:管理员模块,学生模块和公有模块,其中复杂的方法和模块的详细设计流程图如下。 3.1 系统中所设计的主要类及UML图 Sqlhelper类,负责数据库连接和读取的类,包括ExecuteQuery,ExecuteNonQuery,ExecuteScalar,ReadTable等函数负责对数据库增删查改和读取数据成表格或者dataset类型。 3.2 系统主要流程图 3.2.1主系统界面 图3.2.1选课系统主界面 3.2.2选课系统登录流程图 3.2.3管理员添加课程流程图 3.2.4学生选修课程流程图 4 系统实现 4.1 管理员界面的实现 Html <%@ Page Title="" Language="C#" MasterPageFile="~/SMasterPage2.master" AutoEventWireup="true" CodeFile="admin3.aspx.cs" Inherits="admin3" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <script src="js/sdmenu.js" type="text/javascript"></script> <link href="css/dhcss.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var myMenu; load = function () { myMenu = new SDMenu("my_menu"); myMenu.init(); var firstSubmenu = myMenu.submenus[0]; pandMenu(firstSubmenu); }; </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="center" runat="Server"> <div style="text-align: right; font-size: 14px"> <asp:Label ID="lbname" runat="server" Text="Label"></asp:Label> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/login.aspx">退ª?出?系¦Ì统ª3</asp:HyperLink> </div> <table class="style1" style="border: 1px solid #95C9E1; height: 800px"> <tr> <td style="vertical-align: top; padding: inherit; margin: auto; border: thin solid #C7EDCC; width: 150px;"> <div id="my_menu" class="sdmenu" style="margin-top: 0px; background-color: #C7EDCC; border-right: 1px solid #C7EDCC;"> <div> <span style="text-align: left">+个?人¨?信?息¡é</span> <a href="adself.aspx" target="iframe">基¨´本À?信?息¡é</a> </div> <div> <span style="text-align: left">+修T改?密¨¹码?</span> <a href="admima.aspx" target="iframe">修T改?密¨¹码?</a> </div> <div> <span style="text-align: left">+选?课?管¨¹理¤¨ª</span> <a href="adxuanke.aspx" target="iframe"> 发¤¡é布?选?课?</a> <a href="adtuike.aspx" target="iframe">学¡ì生¦¨²退ª?课?</a> </div> <div> <span style="text-align: left">+基¨´础ä?信?息¡é管¨¹理¤¨ª</span> <a href="adstuwh.aspx" target="iframe"> 学¡ì生¦¨²管¨¹理¤¨ª</a> <a href="adkcwh.aspx" target="iframe">课?程¨¬管¨¹理¤¨ª</a> <a href="adteawh.aspx" target="iframe"> 教¨¬师º|管¨¹理¤¨ª</a> <a href="admajorwh.aspx" target="iframe">专Á¡§业°¦Ì管¨¹理¤¨ª</a> <a href="addepartwh.aspx" target="iframe">院o系¦Ì管¨¹理¤¨ª</a> </div> <div> <span style="text-align: left">+数ºy据Y库a管¨¹理¤¨ª</span> <a href="adback.aspx" target="iframe">备À?份¤Y数ºy据Y库a</a> <a href="adrestore.aspx" target="iframe">还1原-数ºy据Y库a</a> </div> <div> <span style="text-align: left">+新?闻?管¨¹理¤¨ª</span> <a href="adback.aspx" target="iframe">添¬¨ª加¨®新?闻?</a> <a href="adrestore.aspx" target="iframe">还1原-数ºy据Y库a</a> </div> </div> </td> <td> <div style="width: 100%;"> <iframe name="iframe" frameborder="0" scrolling="no" style="height: 750px; width: 100%; margin-top: 0px;"></iframe> </div> </td> </tr> </table> </asp:Content> 截图 后台 protected void Page_Load(object sender, EventArgs e) { lbname.Text = "欢?迎®-" + Session["ID"].ToString() + ",今?天¬¨¬是º?" + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek); } 4.2 选课界面的实现 4.2.1发布选课 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adxuanke.aspx.cs" Inherits="adxuanke" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css" /> <style type="text/css"> .style1 { width: 100%; text-align: center; } td { border: 1px solid; } table { border: 1px solid; border-width: 1px 0px 0px 1px; } </style> </head> <body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td colspan="4" align="right"> <asp:Button ID="Button2" runat="server" Text="导Ì?出?" OnClick="Button2_Click" BorderStyle="None" CssClass="button" /> </td> </tr> <tr> <td> <asp:Label ID="Label1" runat="server" Text="发¤¡é布?课?程¨¬"></asp:Label> </td> </tr> <tr> <td> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>全¨?部?课?程¨¬</asp:ListItem> <asp:ListItem>课?程¨¬号?</asp:ListItem> <asp:ListItem>课?程¨¬名?称?</asp:ListItem> <asp:ListItem>教¨¬师º|姓?名?</asp:ListItem> </asp:DropDownList> <asp:TextBox ID="tbsearch" runat="server"></asp:TextBox> <asp:Button ID="btsearch" runat="server" Text="搜?索¡Â" OnClick="btsearch_Click" CssClass="button" /> </td> </tr> <tr> <td> <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" AutoGenerateColumns="False" Width="100%" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowEditing="GridView1_RowEditing"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="课?程¨¬号?" DataField="courseID" /> <asp:BoundField HeaderText="课?程¨¬名?称?" DataField="courseName" /> <asp:BoundField HeaderText="授º¨²课?教¨¬师º|" DataField="teaName" /> <asp:BoundField HeaderText="学¡ì分¤?" DataField="score" /> <asp:BoundField HeaderText="考?试º?类¤¨¤型¨ª" DataField="class" /> <asp:BoundField HeaderText="教¨¬室º¨°" DataField="courseAddress" /> <asp:BoundField HeaderText="上¦?课?时º¡À间?" DataField="courseTime" /> <asp:BoundField HeaderText="课?堂¬?容¨Y量¢?(ꡧ人¨?)ê?" DataField="coursenumber" /> <asp:BoundField DataField="coursestate" HeaderText="发¤¡é布?状Á¡ä态¬?" /> <asp:BoundField HeaderText="备À?注Á¡é" DataField="courseInfo" /> <asp:CommandField HeaderText="课?程¨¬详¨º情¨¦" ShowSelectButton="True" SelectText="课?程¨¬详¨º情¨¦" EditText="发¤¡é布?" /> </Columns> <PagerSettings FirstPageText="第̨²一°?页°3" LastPageText="最Á?后¨®一°?页°3" Mode="NextPreviousFirstLast" /> </asp:GridView> </td> </tr> <tr> <td align="left"> <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox2_CheckedChanged" Text="全¨?选?" /> <asp:Button ID="btup" runat="server" Text="发¤¡é布?课?程¨¬" OnClick="btup_Click" CssClass="button" /> </td> </tr> </table> </div> </form> </body> </html> 截图 后台代码: protected void Page_Load(object sender, EventArgs e) { Session["ID"] = "xxxx"; if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { //从䨮数ºy据Y库a获?取¨?其?他?信?息¡é string sql = "select courseID,courseName,score,class,courseTime,courseAddress,coursePhoto,coursenumber,courseInfo,aName from course,teacher aID "; DataSet ds = SqlHelper.ExecutDataSet(sql); GridView1.DataSource = ds; GridView1.DataBind(); } /// <summary> /// 详¨º情¨¦ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["cID"] = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text; e.NewSelectedIndex = -1; Response.Write("<script>window.open('./adkecheng.aspx','_blank','height=400,width=600,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>"); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { string courseID= GridView1.Rows[e.NewEditIndex].Cells[1].Text; string number= GridView1.Rows[e.NewEditIndex].Cells[8].Text; string sqlt="select teaID from course where courseID='"+courseID+"'"; DataTable dt=SqlHelper.ExecuteQuery(sqlt); string teaID=dt.Rows[0]["teaID"].ToString(); string sql = "update course set coursestate='已°?发¤¡é布?' where courseID='"+courseID+"'"; try { int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?成¨¦功|');", true); string sqlp = "insert into press(courseID,teaID,number) values('{0}','{1}','{2}')"; sqlp = string.Format(sqlp, courseID, teaID, number); int ret2= SqlHelper.ExecuteNonQuery(sqlp); if (ret2 != 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } databind(); } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } e.NewEditIndex = -1; } protected void btsearch_Click(object sender, EventArgs e) { string sql =""; if (DropDownList1.SelectedValue == "全¨?部?课?程¨¬") { databind(); } else { sql = "select courseID,courseName,score,class,courseTime,courseAddress,coursePhoto,coursenumber,courseInfo,aName" + " from course,teacher where courseID like '%{0}%' or courseName like '%{0}%' aName like '%{0}%' and aID "; sql = string.Format(sql,tbsearch.Text); DataSet ds = SqlHelper.ExecutDataSet(sql); try { if (ds.Tables[0].Rows.Count == 0) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?课?程¨¬信?息¡é');", true); return; } GridView1.DataSource = ds; GridView1.DataBind(); } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?课?程¨¬信?息¡é');", true); return; } } } protected void CheckBox2_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); cbox.Checked = CheckBox2.Checked; } } protected void Button1_Click(object sender, EventArgs e) { CheckBox2.Checked = false; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); cbox.Checked = false; } } protected void btup_Click(object sender, EventArgs e) { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cbox.Checked == true) { string courseID = GridView1.Rows[i].Cells[1].Text.ToString(); string number = GridView1.Rows[i].Cells[8].Text.ToString(); string sqlt = "select teaID from course where courseID='" + courseID + "'"; DataTable dt = SqlHelper.ExecuteQuery(sqlt); string teaID = dt.Rows[0]["teaID"].ToString(); string sql = "update course set coursestate='已°?发¤¡é布?' where courseID='" + courseID + "'"; try { int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?成¨¦功|');", true); string sqlp = "insert into press(courseID,teaID,number) values('{0}','{1}','{2}')"; sqlp = string.Format(sqlp, courseID, teaID, number); int ret2 = SqlHelper.ExecuteNonQuery(sqlp); if (ret2 != 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('发¤¡é布?失º¡ì败㨹,ê?请?重?新?发¤¡é布?');", true); return; } } } databind(); } protected void Button2_Click(object sender, EventArgs e) { Export("application/ms-excel"); } private void Export(string FileType) { string FileName = HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddHHmmss"), System.Text.Encoding.UTF8);//解a决?导Ì?出?时º¡À文?件t名?汉o字Á?显?示º?乱¨°码?的Ì?问¨º题¬a HttpResponse resp; resp = Page.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls"); int i_colnum = GridView1.Rows.Count; //定¡§义°?表À¨ª对?象¨®与®?行D对?像?,ê?同ª?时º¡À用®?DataSet对?其?值¦Ì进?行D初?始º?化¡¥ string str_colHeaders = "退ª?课?信?息¡é\n"; str_colHeaders += "序¨°号?\t学¡ì生¦¨²学¡ì号?\t课?程¨¬号?\t课?程¨¬名?称?\t授º¨²课?教¨¬师º|\t学¡ì分¤?\t考?试º?类¤¨¤型¨ª\t上¦?课?时º¡À间?\t上¦?课?地Ì?点Ì?\t课?堂¬?容¨Y量¢?(ꡧ人¨?)ê?\t发¤¡é布?状Á¡ä态¬?\t备À?注Á¡é\n"; for (int i = 0; i < GridView1.Rows.Count; i++) { str_colHeaders += Convert.ToString(i + 1) + "\t"; str_colHeaders += GridView1.Rows[i].Cells[0].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[1].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[2].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[3].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[4].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[5].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[6].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[7].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[8].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[9].Text + "\t"; str_colHeaders += GridView1.Rows[i].Cells[10].Text + "\n"; //str_colHeaders += Convert.ToString(i + 1) + "\t"; } resp.Write(str_colHeaders); //写¡ä缓o冲?区?中D的Ì?数ºy据Y到Ì?HTTP头ª¡¤文?件t中D resp.End(); } 4.2.2学生退课 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adtuike.aspx.cs" Inherits="adtuike" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css" /> <style type="text/css"> .style1 { width: 100%; text-align:center; } td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" AutoGenerateColumns="False" AllowPaging="True" Width="100%" onpageindexchanging="GridView1_PageIndexChanging" onselectedindexchanging="GridView1_SelectedIndexChanging"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="stuID" HeaderText="学¡ì生¦¨²学¡ì号?" /> <asp:BoundField HeaderText="课?程¨¬号?" DataField="courseID" /> <asp:BoundField HeaderText="课?程¨¬名?称?" DataField="courseName" /> <asp:BoundField HeaderText="授º¨²课?教¨¬师º|" DataField="teaName" /> <asp:BoundField DataField="score" HeaderText="学¡ì分¤?" /> <asp:BoundField DataField="class" HeaderText="考?试º?类¤¨¤型¨ª" /> <asp:BoundField HeaderText="教¨¬室º¨°" DataField="courseAddress" /> <asp:BoundField HeaderText="上¦?课?时º¡À间?" DataField="courseTime" /> <asp:BoundField HeaderText="备À?注Á¡é" DataField="courseInfo" /> <asp:CommandField HeaderText="操¨´作Á¡Â" SelectText="课?程¨¬详¨º情¨¦" ShowSelectButton="True" EditText="退ª?课?" /> </Columns> </div> </form> </body> </html> 截图 后台代码: protected void Page_Load(object sender, EventArgs e) { Session["ID"] = "admin"; if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { //从䨮数ºy据Y库a获?取¨?其?他?信?息¡é string sql = "select elect.stuID, urseID,number,aName,score,class,courseTime,courseAddress,courseName" + " from elect,course,teacher" + " aID aID urseID "; DataSet ds = SqlHelper.ExecutDataSet(sql); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["cID"] = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text; e.NewSelectedIndex = -1; Response.Write("<script>window.open('./adkecheng.aspx','详¨º情¨¦','height=400,width=600,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>"); } protected void btup_Click(object sender, EventArgs e) { string setstatic = "已°?处ä|理¤¨ª"; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cbox.Checked == true) { string courseID = GridView1.Rows[i].Cells[2].Text.ToString(); string stuID = GridView1.Rows[i].Cells[1].Text.ToString(); string sqlt = "select teaID from course where courseID='" + courseID + "'"; DataTable dt = SqlHelper.ExecuteQuery(sqlt); string teaID = dt.Rows[0]["teaID"].ToString(); string sql = "update press set number=number+1 where courseID='" + courseID + "' and teaID='" + teaID + "'"; try { int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { sql = "select count(*) from tijiao where stuID='{0}' and courseName='{1}'"; sql = string.Format(sql, GridView1.Rows[i].Cells[1].Text.ToString(), GridView1.Rows[i].Cells[3].Text.ToString()); object obj= SqlHelper.ExecuteScalar(sql); ret = Convert.ToInt32(obj.ToString()); if (ret != 1) { sql = "insert into tijiao(stuID,courseName,setTime,men,setstatic) values('{0}','{1}','{2}','{3}','{4}')"; sql = string.Format(sql, stuID, GridView1.Rows[i].Cells[2].Text.ToString(), DateTime.Now.ToString(), Session["ID"].ToString(), setstatic); } else { sql = "update tijiao set setTime='{0}',men='{1}',setstatic='{2}' where stuID='{3}' and courseName='{4}'"; sql = string.Format(DateTime.Now.ToString(), Session["ID"].ToString(), setstatic, stuID, GridView1.Rows[i].Cells[2].Text.ToString()); } ret = SqlHelper.ExecuteNonQuery(sql); if (ret != 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('退ª?课?失º¡ì败㨹,ê?请?重?新?选?择?或¨°联¢a系¦Ì管¨¹理¤¨ª员¡À');", true); return; } string sqlp = "delete from elect where courseID='{0}'and teaID='{1}'and stuID='{2}'"; sqlp = string.Format(sqlp, courseID, teaID, stuID); int ret2 = SqlHelper.ExecuteNonQuery(sqlp); if (ret2 != 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('退ª?课?失º¡ì败㨹,ê?请?重?新?退ª?课?');", true); return; } ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('退ª?课?成¨¦功|');", true); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('退ª?课?失º¡ì败㨹,ê?请?重?新?选?择?');", true); return; } } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('退ª?课?失º¡ì败㨹,ê?请?重?新?退ª?课?');", true); return; } } } databind(); } protected void btsearch_Click(object sender, EventArgs e) { string sql = ""; if (DropDownList1.SelectedValue == "全¨?部?课?程¨¬") { databind(); } else { sql = "select elect.stuID, urseID,number,aName,score,class,courseTime,courseAddress,courseName" + " from elect,course,teacher " + " urseID like '%{0}%' urseName like '%{0}%' aName like '%{0}%' and " + " aID aID urseID aID and (stuID like '%{0}%' or 1=1)"; sql = string.Format(sql, tbsearch.Text); DataSet ds = SqlHelper.ExecutDataSet(sql); try { if (ds.Tables[0].Rows.Count == 0) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?选?课?信?息¡é');", true); databind(); return; } GridView1.DataSource = ds; GridView1.DataBind(); } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?选?课?信?息¡é');", true); databind(); return; } } } protected void Button2_Click(object sender, EventArgs e) { Export("application/ms-excel"); } 4.3 管理员界面的实现 4.3.1学生管理 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adstuwh.aspx.cs" Inherits="adstuwh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css"/> <style type="text/css"> .style1 { width: 100%; text-align:center; } td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td colspan="4" align="right"> <asp:FileUpload ID="FileUpload2" runat="server" /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="导Ì?入¨?" BorderStyle="None" CssClass="button" Width="55px"/> <asp:Button ID="Button2" runat="server" Text="导Ì?出?" onclick="Button2_Click" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> </td> </tr> <tr> <td align="center"> 学¡ì生¦¨²信?息¡é</td> </tr> <tr> <td> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>全¨?部?学¡ì生¦¨²</asp:ListItem> <asp:ListItem>学¡ì生¦¨²学¡ì号?</asp:ListItem> <asp:ListItem>学¡ì生¦¨²姓?名?</asp:ListItem> <asp:ListItem>院o系¦Ì名?称?</asp:ListItem> <asp:ListItem>专Á¡§业°¦Ì名?称?</asp:ListItem> </td> </tr> </table> </div> <div> <asp:Button ID="btadd" runat="server" Text="添¬¨ª加¨®新?学¡ì生¦¨²" onclick="btadd_Click" CssClass="button" Width="110px" /> </div> <div > <asp:Panel ID="Panel1" runat="server"> <table style="width:100%; "> <tr> <td> <table> <tr> <td colspan="4" align="center"> 个?人¨?信?息¡é </td> </tr> <tr> <td> <asp:TextBox ID="tbstuName" runat="server" MaxLength="4"></asp:TextBox> </td> <td> 性?别Àe:êo </td> <td> <asp:DropDownList ID="ddstuSex" runat="server" Width="150px"> <asp:ListItem>男D</asp:ListItem> <asp:ListItem>女?</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td> 院o系¦Ì:êo </td> <td> <asp:DropDownList ID="dddepartName" runat="server" style="margin-left: 0px" Width="155px" AutoPostBack="True" onselectedindexchanged="dddepartName_SelectedIndexChanged"> <asp:ListItem>请?选?择?</史磊asp:ListItem> </td> </tr> </table> </td> </tr> </table> </asp:Panel> </div> </form> </body> </html> 截图: 后台: protected void Page_Load(object sender, EventArgs e) { if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { //从䨮数ºy据Y库a里¤?调Ì¡Â取¨?院o系¦Ì和¨ª专Á¡§业°¦Ì加¨®入¨?到Ì?下?拉¤-框¨° string sqlddstu = "select * from depart"; DataTable dtstu = SqlHelper.ExecuteQuery(sqlddstu); for (int i = 0; i < dtstu.Rows.Count; i++) { dddepartName.Items.Add(dtstu.Rows[i]["departName"].ToString()); } string sqlmajor = "select * from major"; DataTable dtmajor = SqlHelper.ExecuteQuery(sqlmajor); for (int j = 0; j < dtmajor.Rows.Count; j++) { ddmajorName.Items.Add(dtmajor.Rows[j]["majorName"].ToString()); } //从䨮数ºy据Y库a获?取¨?其?他?信?息¡é string sql = "select * from student"; DataSet ds = SqlHelper.ExecutDataSet(sql); GridView1.DataSource = ds; GridView1.DataBind(); Panel1.Visible = false; } protected void btadd_Click(object sender, EventArgs e) { Panel1.Visible = true; btset.Visible = false; } protected void btsearch_Click(object sender, EventArgs e) { string sql = ""; if (DropDownList1.SelectedValue == "全¨?部?学¡ì生¦¨²") { databind(); } else { sql = "select * from student where stuID like '%{0}%' or stuName like '%{0}%' or stustu like '%{0}%' or stuMajor like '%{0}%'"; sql = string.Format(sql, tbsearch.Text); DataSet ds = SqlHelper.ExecutDataSet(sql); try { if (ds.Tables[0].Rows.Count == 0) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?学¡ì生¦¨²信?息¡é');", true); databind(); return; } GridView1.DataSource = ds; GridView1.DataBind(); } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('暂Y无T此ä?学¡ì生¦¨²信?息¡é');", true); databind(); return; } } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { } protected void btcancel_Click(object sender, EventArgs e) { Panel1.Visible = false; btset.Visible = true; GridView1.EditIndex = -1; } protected void dddepartName_SelectedIndexChanged(object sender, EventArgs e) { ddmajorName.Items.Clear(); string sqlld = "select * from major where majorDepart='" + dddepartName.SelectedValue + "'"; DataTable dtmajor = SqlHelper.ExecuteQuery(sqlld); for (int j = 0; j < dtmajor.Rows.Count; j++) { ddmajorName.Items.Add(dtmajor.Rows[j]["majorName"].ToString()); } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["sID"] = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text; e.NewSelectedIndex = -1; Response.Write("<script>window.open('./adstu.aspx','_blank','height=400,width=600,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>"); } protected void Button2_Click(object sender, EventArgs e) { Export("application/ms-excel"); } protected void Button1_Click(object sender, EventArgs e) { UploadFile(FileUpload2); databind(); } #region 导Ì?入¨? public string UploadFile(FileUpload Fupload) { //文?件t上¦?传ä? string str_ParentFolder = ""; string filename; str_ParentFolder = Server.MapPath("./"); //str_ParentFolder = Server.MapPath(@"..\fliter\"); /*判D断?是º?否¤?更¨¹名?*/ filename = "student.xls"; try { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { str_sql = "select count(*) from student where stuID='" + ds.Tables[0].Rows[i][0].ToString() + "'"; return "上¦?传ä?成¨¦功|"; } catch (IOException e) { return e.Message; } catch (Exception e) { return e.Message; } } #endregion 4.3.2课程管理 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adkcwh.aspx.cs" Inherits="adkcwh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css" /> <style type="text/css"> td { border: 1px solid; } table { border: 1px solid; border-width: 1px 0px 0px 1px; } </style> </head> <body> <form id="form1" runat="server"> <div> <table style="width: 100%"> <tr> <td colspan="4" align="right"> <asp:FileUpload ID="FileUpload2" runat="server" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="导Ì?入¨?" BorderStyle="None" CssClass="button" /> <asp:Button ID="Button2" runat="server" Text="导Ì?出?" OnClick="Button2_Click" BorderStyle="None" CssClass="button" /> </td> </tr> <tr> <td colspan="4" align="center"> 课?程¨¬信?息¡é <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowEditing="GridView1_RowEditing" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"> <PagerSettings FirstPageText="第̨²一°?页°3" LastPageText="最Á?后¨®一°?页°3" Mode="NextPreviousFirstLast" /> </asp:GridView> </td> </tr> </table> <div> <asp:Button ID="btadd" runat="server" Text="添¬¨ª加¨®课?程¨¬" OnClick="btadd_Click" CssClass="button" Width="120px" /> </div> <div> <asp:Panel ID="plsourse" runat="server"> <table> <tr> <td colspan="4" align="center"> 课?程¨¬信?息¡é </td> </tr> <tr> <td style="width: 80px"> 课?程¨¬编À¨¤号?:êo </td> <td style="width: 200px"> <asp:TextBox ID="tbcourseID" runat="server" Enabled="False" MaxLength="7"></asp:TextBox> <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="tbcourseID" ErrorMessage="*" ForeColor="Red" MaximumValue="9999999" MinimumValue="0000000"></asp:RangeValidator> </td> <td style="width: 80px"> 课?程¨¬图ª?片?:êo </td> <td> <asp:Image ID="couphoto" runat="server" Height="108px" Width="108px" ImageUrl="~/images/kecheng.jpg" /> </td> </tr> <tr> <td> 课?程¨¬名?称?:êo </td> <td> <asp:TextBox ID="tbcourseName" runat="server"></asp:TextBox> </td> </td> </tr> <tr> <td> 上¦?课?时º¡À间?:êo </td> <td> <asp:DropDownList ID="ddtbcourseTime" runat="server"> <asp:ListItem>周¨¹一°?7点Ì?~9点Ì?,ê?周¨¹四?7点Ì?~9点Ì?</asp:ListItem> <asp:ListItem>周¨¹二t7点Ì?~9点Ì?,ê?周¨¹四?7点Ì?~9点Ì?</asp:ListItem> <asp:ListItem>周¨¹日¨?7点Ì?~9点Ì?</asp:ListItem> </asp:DropDownList> </td> <td> 上¦?课?地Ì?点Ì?:êo </td> <td> <asp:TextBox ID="tbcourseAddress" runat="server"></asp:TextBox> </td> </tr> <tr> <td> 容¨Y量¢?:êo </td> <td colspan="3"> <asp:TextBox ID="tbcoursenumber" runat="server"></asp:TextBox>人¨? </td> </tr> <tr> <td class="style2"> 课?程¨¬简¨°介¨¦:êo </td> <td class="style2" colspan="3"> <asp:TextBox ID="tbcourseInfo" runat="server" Height="124px" Width="287px" TextMode="MultiLine"></asp:TextBox> </td> </tr> </td> </tr> </table> </asp:Panel> </div> </div> </form> </body> </html> 截图 后台: protected void Page_Load(object sender, EventArgs e) { if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { string sqltea = "select * from teacher"; DataTable dttea = SqlHelper.ExecuteQuery(sqltea); for (int j = 0; j < dttea.Rows.Count; j++) { ddteaName.Items.Add(dttea.Rows[j]["teaName"].ToString()); } //从䨮数ºy据Y库a获?取¨?其?他?信?息¡é string sql = "select courseID,courseName,score,class,courseTime,courseAddress,coursenumber,coursePhoto,aName from course,teacher aID "; DataSet ds = SqlHelper.ExecutDataSet(sql); GridView1.DataSource = ds; GridView1.DataBind(); //图ª?片?和¨ª提¬¨¢交?取¨?消?按ã¡ä钮£¤不?显?示º? plsourse.Visible = false; } protected void btadd_Click(object sender, EventArgs e) { plsourse.Visible = true; btset.Visible = false; tbcourseID.Enabled = true; } protected void btcancel_Click(object sender, EventArgs e) { plsourse.Visible = false; tbcourseID.Enabled = false; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { tbcourseID.Text = GridView1.Rows[e.NewEditIndex].Cells[0].Text; string sqltea = "select teaName from teacher where teaID=(select teaID from course where courseID='{0}')"; sqltea = string.Format(sqltea, tbcourseID.Text); DataTable dttea = SqlHelper.ExecuteQuery(sqltea); ddteaName.SelectedValue = dttea.Rows[0]["teaName"].ToString(); string sql = "select * from course where courseID='" + tbcourseID.Text + "'"; DataTable dt = SqlHelper.ExecuteQuery(sql); ddClass.SelectedValue = dt.Rows[0]["class"].ToString(); tbcourseID.Enabled = false; } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text); string sql = "delete from course where courseID='" + id + "'"; int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('删¦?除y成¨¦功|');", true); databind(); } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["cID"] = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text; e.NewSelectedIndex = -1; //图ª?片?和¨ª提¬¨¢交?取¨?消?按ã¡ä钮£¤不?显?示º? plsourse.Visible = false; } 4.3.3教师信息 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="adstuwh.aspx.cs" Inherits="adstuwh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css"/> <style type="text/css"> .style1 { width: 100%; text-align:center; } td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td colspan="4" align="right"> <asp:FileUpload ID="FileUpload2" runat="server" /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="导Ì?入¨?" BorderStyle="None" CssClass="button" Width="55px"/> <asp:Button ID="Button2" runat="server" Text="导Ì?出?" onclick="Button2_Click" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> </td> </tr> </table> </div> <div> <asp:Button ID="btadd" runat="server" Text="添¬¨ª加¨®新?学¡ì生¦¨²" onclick="btadd_Click" CssClass="button" Width="110px" /> </div> <div > <asp:Panel ID="Panel1" runat="server"> <table style="width:100%; "> <tr> <td> <table> <tr> <td colspan="4" align="center"> 个?人¨?信?息¡é </td> </tr> <tr> <td style="width: 80px"> 学¡ì号?:êo </td> <td style="width: 200px"> <asp:TextBox ID="tbstuID" runat="server"></asp:TextBox> </td> <td style="width: 80px"> 照? 片?:êo </td> <td> <asp:ImageButton ID="stuphoto" runat="server" Height="108px" Width="108px" ImageUrl="~/images/xsm.jpg" ToolTip="点Ì?击¡Â图ª?片?查¨¦看¡ä原-图ª?" /> </td> </tr> <tr> <td > 简¨°介¨¦:êo </td> </tr> </table> </td> </tr> </table> </asp:Panel> </div> </form> </body> </html> 截图 后台: protected void Page_Load(object sender, EventArgs e) { if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { //从䨮数ºy据Y库a里¤?调Ì¡Â取¨?院o系¦Ì和¨ª专Á¡§业°¦Ì加¨®入¨?到Ì?下?拉¤-框¨° string sqlddstu = "select * from depart"; DataTable dtstu = SqlHelper.ExecuteQuery(sqlddstu); GridView1.DataBind(); Panel1.Visible = false; } protected void btadd_Click(object sender, EventArgs e) { Panel1.Visible = true; btset.Visible = false; } protected void btsearch_Click(object sender, EventArgs e) { string sql = ""; if (DropDownList1.SelectedValue == "全¨?部?学¡ì生¦¨²") { databind(); } } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { // ddmajorName.Items.Clear(); tbstuID.Text = GridView1.Rows[e.NewEditIndex].Cells[0].Text; string sql = "select * from student where stuID='" + tbstuID.Text + "'"; DataTable dt = SqlHelper.ExecuteQuery(sql); e.NewEditIndex = -1; btset.Visible = true; } protected void btcancel_Click(object sender, EventArgs e) { Panel1.Visible = false; btset.Visible = true; GridView1.EditIndex = -1; } protected void btup_Click(object sender, EventArgs e) { string filename = stuphoto.ImageUrl; string filepath = filename; } protected void dddepartName_SelectedIndexChanged(object sender, EventArgs e) { ddmajorName.Items.Clear(); string sqlld = "select * from major where majorDepart='" + dddepartName.SelectedValue + "'"; DataTable dtmajor = SqlHelper.ExecuteQuery(sqlld); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text); string sql = "delete from student where stuID='" + id + "'"; int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('删¦?除y成¨¦功|');", true); databind(); } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["sID"] = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text; e.NewSelectedIndex = -1; Response.Write("<script>window.open('./adstu.aspx','_blank','height=400,width=600,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>"); } protected void Button2_Click(object sender, EventArgs e) { Export("application/ms-excel"); } private void Export(string FileType) { string FileName = HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddHHmmss"), System.Text.Encoding.UTF8);//解a决?导Ì?出?时º¡À文?件t名?汉o字Á?显?示º?乱¨°码?的Ì?问¨º题¬a HttpResponse resp; resp = Page.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls"); int i_colnum = GridView1.Rows.Count; //定¡§义°?表À¨ª对?象¨®与®?行D对?像?,ê?同ª?时º¡À用®?DataSet对?其?值¦Ì进?行D初?始º?化¡¥ string str_colHeaders = "学¡ì生¦¨²信?息¡é\n"; str_colHeaders += "序¨°号?\t学¡ì号?\t姓?名?\t性?别Àe\t班㨤级?\t院o系¦Ì\t专Á¡§业°¦Ì\t联¢a系¦Ì方¤?式º?\n"; } resp.Write(str_colHeaders); //写¡ä缓o冲?区?中D的Ì?数ºy据Y到Ì?HTTP头ª¡¤文?件t中D resp.End(); } protected void Button1_Click(object sender, EventArgs e) { UploadFile(FileUpload2); databind(); } #region 导Ì?入¨? public string UploadFile(FileUpload Fupload) { //文?件t上¦?传ä? string str_ParentFolder = ""; string filename; str_ParentFolder = Server.MapPath("./"); //str_ParentFolder = Server.MapPath(@"..\fliter\"); /*判D断?是º?否¤?更¨¹名?*/ filename = "student.xls"; try { //上¦?传ä?新?的Ì?对?应®|关?系¦Ì文?件t if (Fupload.PostedFile.FileName == "") return "请?选?择?要°a上¦?传ä?的Ì?数ºy据Y!ê?"; / if (SqlHelper.ExecuteNonQuery(str_sql) == 0) { return "系¦Ì统ª3错䨪误¨®"; } } str_sql = "select count(*) from student "; string lbl_result = "数ºy据Y库a中D共2有®D记?录? " + SqlHelper.ExecuteScalar(str_sql).ToString() + " 条¬?,ê?本À?次ä?新?增?了¢? " + j.ToString() + " 条¬?记?录?,ê?更¨¹新?了¢? " + k.ToString() + " 条¬?记?录?"; Response.Write("<script>alert(' " + lbl_result + " ');</script>"); Fupload.Dispose(); return "上¦?传ä?成¨¦功|"; } catch (IOException e) { return e.Message; } catch (Exception e) { return e.Message; } } #endregion 4.3.4专业管理 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="admajorwh.aspx.cs" Inherits="admajorwh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <link rel="Stylesheet" type="text/css" href="css/button.css"/> <style type="text/css"> td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <table style="width:100%"> <tr> <td colspan="4" align="right"> <asp:FileUpload ID="FileUpload2" runat="server" /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click1" Text="导Ì?入¨?" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> <asp:Button ID="Button3" runat="server" Text="导Ì?出?" onclick="Button2_Click" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> </td> </tr> <tr> <td colspan="4" align="center"> 专Á¡§业°¦Ì信?息¡é</td> </tr> <tr> <td colspan="4" align="center"> </td> </tr> </table> <div> <asp:Button ID="Button1" runat="server" Text="添¬¨ª加¨®新?专Á¡§业°¦Ì" onclick="Button1_Click" CssClass="button" Height="30px" Width="120px"/> </div> <div> <asp:Panel ID="plmajor" runat="server"> <table > <tr> <td colspan="4" align="center"> 专Á¡§业°¦Ì信?息¡é</td> </tr> <tr> <td style="width:80px"> 专Á¡§业°¦Ì编À¨¤号?:êo</td> <td style="width:200px"> <asp:TextBox ID="tbmajorID" runat="server" Enabled="False"></asp:TextBox> </td> <td style="width:80px"> 照?片?:êo</td> <td> <asp:Image ID="majorPhoto" runat="server" Height="108px" Width="108px" ImageUrl="~/images/xsm.jpg" /> /td> </asp:Panel> </div> </div> </form> </body> </html> 截图: 后台: protected void Page_Load(object sender, EventArgs e) { if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); } } public void databind() { //从䨮数ºy据Y库a里¤?调Ì¡Â取¨?院o系¦Ì和¨ª专Á¡§业°¦Ì加¨®入¨?到Ì?下?拉¤-框¨° string sqldddepart = "select * from depart"; DataTable dtdepart = SqlHelper.ExecuteQuery(sqldddepart); plmajor.Visible = false; GridView1.EditIndex = -1; } protected void btup_Click(object sender, EventArgs e) { //默?认¨?图ª?片?为a页°3面?的Ì?图ª?片? string filename = majorPhoto.ImageUrl; string filepath = filename; } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } /// <summary> /// 添¬¨ª加¨®新?专Á¡§业°¦Ì /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { plmajor.Visible = true; btset.Visible = false; btup.Visible = true; string sqlid = "select majorID from major order by majorID desc"; object obj = SqlHelper.ExecuteScalar(sqlid); int ret = Convert.ToInt32(obj.ToString()); ret = ret + 1; tbmajorID.Text = ret.ToString(); } protected void btcannel_Click(object sender, EventArgs e) { plmajor.Visible = false; tbmajorID.Text = ""; tbmajorInfo.Text = ""; tbmajorName.Text = ""; majorPhoto.ImageUrl = "~/images/xsm.jpg"; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { tbmajorID.Text = GridView1.Rows[e.NewEditIndex].Cells[0].Text; string sql = "select * from major where majorID='" + tbmajorID.Text + "'"; DataTable dt = SqlHelper.ExecuteQuery(sql); btset.Visible = true; } protected void btset_Click(object sender, EventArgs e) { //默?认¨?图ª?片?为a页°3面?的Ì?图ª?片? string filename = majorPhoto.ImageUrl; string filepath = filename; ry { int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?成¨¦功|');", true); databind(); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?失º¡ì败㨹,ê?重?新?输º?入¨?信?息¡é');", true); return; } } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?失º¡ì败㨹,ê?重?新?输º?入¨?信?息¡é');", true); return; } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text); string sql = "delete from major where majorID='" + id + "'"; int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('删¦?除y成¨¦功|');", true); databind(); } } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["mID"] = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text; e.NewSelectedIndex = -1; } 4.3.5院系管理 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="addepartwh.aspx.cs" Inherits="addepartwh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <link rel="Stylesheet" type="text/css" href="css/button.css"/> <title></title> <style type="text/css"> td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <table style="width:100%"> <tr> <td colspan="4" align="right"> <asp:FileUpload ID="FileUpload2" runat="server" /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="导Ì?入¨?" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> <asp:Button ID="Button2" runat="server" Text="导Ì?出?" onclick="Button2_Click" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> </td> </tr> <tr> <td colspan="4" align="center"> 院o系¦Ì信?息¡é</td> </tr> <tr> <td colspan="4" align="center"> </td> </tr> </table> <div> <asp:Button ID="btadd" runat="server" Text="添¬¨ª加¨®新?院o系¦Ì" onclick="btadd_Click" CssClass="button" Height="30px" Width="120px" /> <asp:Panel ID="pldepart" runat="server"> <table > <tr> <td colspan="4" align="center"> 院o系¦Ì信?息¡é</td> </tr> <tr> <td style="width:80px"> 院o系¦Ì编À¨¤号?:êo</td> <td style="width:200px"> <asp:TextBox ID="tbdepartID" runat="server" Enabled="False"></asp:TextBox> </td> <td style="width:80px"> 照?片?:êo</td> <td> <asp:Image ID="departPhoto" runat="server" Height="108px" Width="108px" ImageUrl="~/images/xsm.jpg" /> </td> </tr> <tr> <td> 院o系¦Ì名?称?:êo</td> <td> <asp:TextBox ID="tbdepartName" runat="server"></asp:TextBox> </td> <td colspan="2"> </td> </tr> <tr> <td class="style2"> 院o系¦Ì简¨°介¨¦:êo</td> <td class="style2" colspan="3"> <asp:TextBox ID="tbdepartInfo" runat="server" Height="124px" TextMode="MultiLine" Width="287px"></asp:TextBox> <td colspan="4" align="center"> <asp:Button ID="btset" runat="server" Text="修T改?信?息¡é" onclick="btset_Click" BorderStyle="None" CssClass="button" Height="30px" Width="110px" /> <asp:Button ID="btup" runat="server" onclick="btup_Click" Text="提¬¨¢交?" BorderStyle="None" CssClass="button" Height="30px" Width="55px"/> <asp:Button ID="btcancel" runat="server" onclick="btcancel_Click" Text="取¨?消?" BorderStyle="None" CssClass="button" Height="30px" Width="55px" /> </td> </tr> </table> </asp:Panel> </div> </div> </form> </body> </html> 截图: 后台: protected void Page_Load(object sender, EventArgs e) { if (Session["ID"] == null) Response.Redirect("login.aspx"); if (!IsPostBack) { databind(); tbdepartID.Text = Request.QueryString["id"]; } } public void databind() { string sql = "select * from depart "; DataSet ds = SqlHelper.ExecutDataSet(sql); GridView1.DataSource = ds; GridView1.DataBind(); //图ª?片?和¨ª提¬¨¢交?取¨?消?按ã¡ä钮£¤不?显?示º? pldepart.Visible = false; GridView1.EditIndex = -1; } /// <summary> /// 提¬¨¢交? /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btup_Click(object sender, EventArgs e) { string filename = departPhoto.ImageUrl; string filepath = filename; if (!String.IsNullOrEmpty(this.FileUpload1.PostedFile.FileName.ToString())) { filename = this.FileUpload1.PostedFile.FileName.Substring(this.FileUpload1.PostedFile.FileName.LastIndexOf("\\") + 1); filename = System.IO.Path.GetFileName(filename); } protected void btadd_Click(object sender, EventArgs e) { pldepart.Visible = true; btset.Visible = false; string sql = "select * from depart order by departID desc"; object obj = SqlHelper.ExecuteScalar(sql); int ret = Convert.ToInt32(obj.ToString()); ret = ret + 1; tbdepartID.Text = ret.ToString(); } protected void btcancel_Click(object sender, EventArgs e) { pldepart.Visible = false; btset.Visible = true; GridView1.EditIndex = -1; } protected void btset_Click(object sender, EventArgs e) { //默?认¨?图ª?片?为a页°3面?的Ì?图ª?片? string filename = departPhoto.ImageUrl; string filepath = filename; } #region 编À¨¤辑- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { string sql = "select * from depart where departID='" + tbdepartID.Text + "'"; DataTable dt = SqlHelper.ExecuteQuery(sql); tbdepartID.Text = dt.Rows[0]["departID"].ToString(); tbdepartName.Text = dt.Rows[0]["departName"].ToString(); tbdepartInfo.Text = dt.Rows[0]["departInfo"].ToString(); departPhoto.ImageUrl = "./"+dt.Rows[0]["departPhoto"].ToString(); pldepart.Visible = true; btup.Visible = false; GridView1.EditIndex = -1; e.NewEditIndex = -1; btset.Visible = true; } #endregion protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Session["dID"] = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text; e.NewSelectedIndex = -1; Response.Write("<script>window.open('./addepart.aspx','_blank','height=400,width=600,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>"); } protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e) { } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text); string sql = "delete from depart where departID='" + id + "'"; int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('删¦?除y成¨¦功|');", true); databind(); } } protected void Button1_Click(object sender, EventArgs e) { UploadFile(FileUpload2); databind(); } 4.4 修改密码界面的实现 Html <%@ Page Language="C#" AutoEventWireup="true" CodeFile="admima.aspx.cs" Inherits="admima" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> td{border:1px solid ;} table{border:1px solid ; border-width:1px 0px 0px 1px;} </style> </head> <body> <form id="form1" runat="server"> <div> <table > <tr> <td style="width:50px"> </td> <td> </td> </tr> <tr> <td align="right"> 用®?户¡ì名?:êo</td> <td> <asp:TextBox ID="tbadID" runat="server"></asp:TextBox> </td> </tr> <tr> <td align="right"> 用®?户¡ì类¤¨¤型¨ª:êo</td> <td> <asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="1" Text="学¡ì生¦¨²" /> <asp:RadioButton ID="RadioButton2" runat="server" GroupName="1" Text="管¨¹理¤¨ª员¡À" /> </td> </tr> <tr> <td align="right"> 新?密¨¹码?:êo</td> <td> <asp:TextBox ID="tbnewPwd" runat="server"></asp:TextBox> </td> <td> <asp:Button ID="btup" runat="server" Text="修T改?" onclick="btup_Click" /> </td> </tr> </table> </div> </form> </body> </html> 截图: 后台: protected void Page_Load(object sender, EventArgs e) { // tbadID.Text= Session[ID].ToString(); Session["ID"] = "xxx"; if (Session["ID"] == null) Response.Redirect("login.aspx"); tbadID.Text = "admin"; } protected void btup_Click(object sender, EventArgs e) { string sql = ""; if (RadioButton1.Checked) { sql = "update student set stuPwd='{0}' where stuID='{1}'or stuName like '{1}'"; } else { sql = "update admin set adminPwd='{0}' where adminID='{1}'or adminName like '{1}'"; } sql = string.Format(sql,tbnewPwd.Text,tbadID.Text); try { int ret = SqlHelper.ExecuteNonQuery(sql); if (ret == 1) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?成¨¦功|');", true); tbnewPwd.Text = " "; tbnewPwd2.Text = " "; } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?失º¡ì败㨹,ê?重?新?输º?入¨?');", true); tbnewPwd.Text = " "; tbnewPwd2.Text = " "; } } catch { ScriptManager.RegisterClientScriptBlock(this, GetType(), "aaa", "alert('修T改?成¨¦功|,ê?重?新?输º?入¨?');", true); tbnewPwd.Text = " "; tbnewPwd2.Text = " "; } } 5系统测试 系统测试是软件开发过程中的关键环节,测试分为白盒测试和黑盒测试,主要是黑盒测试,由于系统模块并不十分复杂,在测试的过程中出现的问题并不多,相对而言比较顺利。 本系统设计基本实现了系统分析里的要求,各个界面和函数的使用基本遵循课本上的知识, 还添加了导入和导出功能,在导入中经过调试,固定下导入的excel内容格式,各个字段的排列方式,还加入判断上传文件夹是否存在,判断上传文件的格式,判断加入了几条记录。在导出功能里,设置那些字段来导出到excel里。在信息维护的页面里,上传图片函数做了一部分修改,如果没有上传或者没有修改图片,还保留原格式加入到数据库里。 在此设计中最大的问题在于还原数据库。这部分操作基于后台操作命令。还原数据库之前必须将源数据库删除后,才可以还原。其它页面和函数基本实现了其功能。可以通过系统测试。 实习日程安排:
实习体会: 本次实习取得的成绩 本次实习收获颇丰。通过这一次的实习,我认识到书上和老师教的内容是有限的,要想掌握更多的知识我们必须多动脑,多思考,不断地靠自己去学习,同时我们还应向他人请教,从百度知道,网络论坛等途径学会了导出和gridview与cheackbox混合使用,同时学会了一些调试一个较长程序的基本方法,提高了书写程序设计开发文档的能力。 系统存在的问题 通过这周的编程我发现了自己的一些不足,在编写时经常犯一些低级错误,由于自己的马虎而浪费了不少时间。部分代码重用率高,封装函数较少,导致程序的冗余。设计程序的过程中,想法不成熟,编程方法还是简单的面向对象编程,对于使用和设计程序的区分不是很了解, 总结 这一次的实践让我受益匪浅,学会需求分析,分析这个项目需要什么功能才能更好的表现。培养了结构化程序、模块化程序设计的方法和能力,这样就能更有针对性的编写程序。最重要的就是编写程序了。书上或网上的函数很全,但是一些基本的知识是必须的。比如结构体的定义,函数调用,双主键数据库表的使用等等。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
发布评论