学校教材订购系统编码设计方案_第1页
学校教材订购系统编码设计方案_第2页
学校教材订购系统编码设计方案_第3页
学校教材订购系统编码设计方案_第4页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、软件工程课程设计题 目学校教材订购系统编码学 院长安学院专 业软件工程班级09421学 号052050060学生姓名范文标罗宇航田翼彪指导教师刘锋编写日期2011-5-271目录:目录:21 登陆界面32 用 datagrid 显示数据43 添加历史书目54 删除记录92主要代码1 登陆界面/当单击确定按钮时 , 连接数据库 , 确定输入的帐号和密码是否匹配 , 跳转到书目的页面,若不匹配 , 则弹出帐号错误或密码错误的提示 /具体代码如下:PrivateSubbutton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)

2、Handles button1.ClickDim str As StringDim passstr As Stringpassstr = Trim(CStr(TextBox2.Text)str = & TextBox1.Text & Dim sql As String = select * from adminlist where帐号 = & Trim(str)在数据库中搜索帐号为textbox1.text的数据Dim connstr As String = server=localhost;uid=sa;pwd=;database=bookDim myconn As New SqlClien

3、t.SqlConnection(connstr)Dim da As New SqlClient.SqlDataAdapter(sql, myconn)Dim ds As New DataSetda.Fill(ds, adminlist)Dim dacomm As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)If ds.Tables(adminlist).Rows.Count = 1 Then判断帐号密码是否和数据库匹配If passstr = Trim(ds.Tables(adminlist).Rows(0)

4、(密码 ) ThenResponse.Redirect(book.aspx)3ElseResponse.Write(密码错误 !)End IfElseResponse.Write(用户名不存在!)End IfEnd SubEnd Class2 用 datagrid 显示数据/ 首先建立 datagrid,通过连接数据库,将数据显示在datagrid中 /具体代码如下:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Loadbinddata()End S

5、ubSub binddata()DimmyconnectionAs New SqlConnection(initialcatalog=book;uid=sa;pwd=)Const strsql As String = select * from book08 order by书号 Dim mycommand As New SqlCommand(strsql, myconnection)Dim myda As New SqlDataAdaptermyda.SelectCommand = mycommandDim myds As New DataSetmyda.Fill(myds)4DataGri

6、d1.DataSource = mydsDataGrid1.DataBind()End Sub3 添加历史书目/history.aspx在登陆系统并选择插入历史书本后,进入添加历史书目的页面,决定选择哪条记录进行添加/ 在单击左侧的选择后,自动跳转到update1.aspx ,根据所选择的书目,进行相应的修改后添加到记录中去/具体代码如下:PrivateSub Page_Load( ByVal sender As System.Object, ByVale As System.EventArgs)Handles MyBase.LoadIf Not Page.IsPostBack Thenbin

7、ddata()End IfEnd Sub连接数据库:Sub binddata()DimmyconnectionAs New SqlConnection(“ initialcatalog=book;uid=sa;pwd=“)Const strsql As String =“ select * from book07 order by书号”Dim mycommand As New SqlCommand(strsql, myconnection)Dim myda As New SqlDataAdapterMyda.SelectCommand = mycommandDim myds As New Da

8、taSetMyda.Fill( myds)DataGrid1.DataSource = myds5DataGrid1.DataBind()End Sub确定所选择的行的数据,并把该行相应的内容分别通过session 变量储存下来。Private Sub DataGrid1_ItemCommand ( ByVal source As Object, ByVal e AsSystem.Web.UI.WebControls.DataGridCommandEventArgs ) HandlesDataGrid1.ItemCommandDim b_no As TableCell = e.Item.Cel

9、ls( 1)Dim b_name As TableCell = e.Item.Cells( 2)Dim b_a As TableCell = e.Item.Cells( 3)Dim b_b As TableCell = e.Item.Cells( 4)Dim b_c As TableCell = e.Item.Cells( 5)Session(“ a”) = b_no.TextSession(“ b”) = b_name.TextSession(“ c”) = b_a.TextSession(“ d”) = b_b.TextSession(“ e”) = b_c.TextResponse.Re

10、direct(“ history1.aspx”)End SubButton_click事件,重定向到book.aspx 页面Private Sub Button1_Click( ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ClickResponse。Redirect (“ book.aspx ”)End SubEnd class6/history1.aspx页面:通过上一个页面的选择后,该页面进行修改并添加的操作/ 当管理员修改完成后,则可单击确定添加操作,将数据添加到11 年的数据库中

11、/具体代码如下:页面登陆代码:PrivateSub Page_Load( ByVal sender As System.Object, ByVale As System.EventArgs)Handles MyBase.LoadIf Not IsPostBack ThenDim str As Stringstr =“ “ & Label6.Text &“ “Dim sql As String= “select* from book11 where 书号=“ & Trim (Session(“ a”)Dim connstr As String =“server=localhost;uid=sa;

12、pwd=;database=book”Dim myconn As New SqlClient.SqlConnection( connstr )Dim da As New SqlClient.SqlDataAdapter( sql , myconn )Dim ds As New DataSetDa.Fill(ds,“book 11”)Dim dacomm As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCommandBuilder( da)Label6.Text = ds.Tables(“ book 11”) .Rows( 0)(“书号”)Lab

13、el7.Text = ds.Tables(“ book 11”) .Rows( 0)(“书名”)Label8.Text = ds.Tables(“ book 11”) .Rows( 0)(“作者”)7TextBox1.Text = ds.Tables(“ book 11”) .Rows( 0)(“征定时间”)TextBox2.Text = ds.Tables(“ book 11”) .Rows( 0)(“数量”)End IfEnd Sub修改后添加到数据库的代码:Private Sub Button1_Click( ByVal sender As System.Object, ByVal e

14、AsSystem.EventArgs) Handles Button1.ClickDim str As StringDim litem As ListItemstr =“ “ & Label6.Text &“ “Dim sql As String =“select * from book08 where书号 =“ & Trim (str )Dim connstr As String =“server=localhost;uid=sa;pwd=;database=book”Dim myconn As New SqlConnection(connstr )Dim da As New SqlData

15、Adapter( sql , myconn )Dim ds As New DataSetda。 Fill(ds, “book08”)Dim myrow As DataRowDim dacomm As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCommandBuilder( da)If ds.Tables(“ book08”) .Rows.Count = 1 ThenResponse.Write(“此书已存在”)End Ifmyrow = ds.Tables(“ book 11”) .NewRowmyrow(“书号”)= Trim(Label6.

16、Text)myrow(“书名”)= Trim(Label7.Text)myrow(“作者”)= Trim(Label8.Text)myrow(“征定时间”) = Trim ( TextBox1.Text)myrow(“数量”)= Trim(TextBox2.Text)8ds.Tables(“ book 11”) .Rows.Add (myrow)da.UpdateCommand = dacomm.GetUpdateCommandda.Update( ds, “book 11”)Response.Redirect(“ book.aspx ”)End Sub单击返回按钮后,重定向到history.

17、aspx的代码:Private Sub Button2_Click( ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.ClickResponse.Redirect(“ history.aspx”)End SubEnd Class4 删除记录/ 在登陆系统后点击修改按钮进入修改页面delete.aspx,通过复选框的选择,删除数据/ 该页面通过复选框的操作删除数据后,重定向回该页面,以便显示删除后数据的更新/具体代码如下:页面登陆代码:PrivateSub Page_Load( ByVal se

18、nder As System.Object, ByVale As System.EventArgs)Handles MyBase.LoadIf Not Page.IsPostBack Then用来确认页面是否第一次登陆binddata()End IfEnd SubSub binddata() 连接到数据库9Dim myconnection As New SqlConnection(“ initialcatalog=book;uid=sa;pwd=“)Const strsql As String =“select * from book08 order by书号”Dim mycommand As

19、 New SqlCommand(strsql, myconnection)Dim myda As New SqlDataAdapterMyda.SelectCommand = mycommandDim myds As New DataSetMyda.Fill( myds)DataGrid1.DataSource = mydsDataGrid1.DataBind()myda.Update( myds, “book11”)End SubButton_click事件:Private Sub Button1_Click( ByVal sender As System.Object, ByVal e A

20、sSystem.EventArgs) Handles Button1.ClickDim i As IntegerDim x As StringDim item As DataGridItemFor i = 0 To DataGrid1.Items.Count 1item = DataGrid1.Items( i )Dim bookcheckbox As CheckBox = item.FindControl(“ checkbox1”)If bookcheckbox.Checked Then确认数据是否被点击进行删除x = item.Cells( 1) .Text x为 datagrid第二列的

21、数据的内容deletedataset( x)End IfNextbinddata()Response.Write(“删除成功! ”)End SubSub deletedataset( ByVal y As String)10Dim con As New SqlConnection(“ initial catalog=book;uid=sa;pwd=“)Dim cmd As SqlCommandDim qry As StringCon.Open()qry =“delete book08 where书号 = “ & y &“ “cmd = New SqlClient.SqlCommand( qry

22、 , con )cmd.ExecuteNonQuery()con.Close()End SubButton_click的重定向事件Private Sub Button2_Click( ByVal sender As System。 Object , ByVal e AsSystem.EventArgs) Handles Button2.ClickResponse.Redirect(“ book.aspx ”)End subEnd class/ 添加新教材和修改记录两大模块共三个页面的代码编写与设计/ 添加新教材。在登陆系统并选择录入新书后,进入添加新教材页面/对 textbox1到 textb

23、ox5添加RequiredFiledValidator控件,并设置相应属性使textbox中的文本不能为空。对 textbox1添加 RegularExpressionValidator控件,设置ValidationExpression属性为” d4”, ErrorMessage 为”书号的格式为0001”。对 textbox1添加 RangeValidator控件,设置 MinimunValue 为” 0001”,MaxmumValue为” 9999”。使书号的取值范围为0001 9999。对 textbox4添加 RegularExpressionValidator控件,设置Validat

24、ionExpression属性为” d4-d1,2 ”,使时间格式为2011-1 。对 textbox5添加 RangeValidator控件,设置MinimunValue为” 1”, MaxmumValue为” 99”,使订阅的教材数量在1-99 本之间。该页面程序代码如下:Page Load 事件代码11Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.LoadEnd SubButton Click事件代码Private Sub Button1_Cl

25、ick(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ClickDim str As StringDim litem As ListItemstr = & TextBox1。 Text & Dim sql As String = select * from book11 where书号 = & Trim(str)Dim connstr As String = server=localhost;uid=sa;pwd=;database=bookDim myconn As New SqlConn

26、ection(connstr)Dim da As New SqlDataAdapter(sql, myconn)Dim ds As New DataSetda。 Fill(ds, book11)Dim myrow As DataRowDim dacomm As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCommandBuilder(da)If ds.Tables(book08).Rows.Count = 1 ThenResponse.Redirect(new.aspx)Response.Write(书号重复,请重新输入)End Ifmyrow

27、= ds.Tables(book08).NewRowmyrow(书号 ) = Trim(TextBox1.Text)myrow(书名 ) = Trim(TextBox2.Text)myrow(作者 ) = Trim(TextBox3.Text)myrow(征定时间 ) = Trim(TextBox4.Text)myrow(数量 ) = Trim(TextBox5.Text)ds.Tables(book08).Rows.Add(myrow)da.UpdateCommand = dacomm.GetUpdateCommand12da.Update(ds, book11)Response.Redir

28、ect(book.aspx)End Sub/ 修改记录。在登陆系统后点击修改按钮进入修改页面update.aspx / 页面中 textbox 的文本来自与 update.aspx 中定义并赋值的 Session 变量。用户通过修改其中的文本值并单击确定完成修改 /修改部分代码如下:update.aspx中的 Page Load 事件Private Sub Page_Load(ByVal sender As System.Object , ByVal e As System.EventArgs) Handles MyBase.LoadIf Not Page.IsPostBack Thenbinddata()End IfEnd Sub用于加载页面及确认是否第一次访问。Update.aspx中的 binddata事件private Sub binddata()DimmyconnectionAs New SqlConnection(initialcatalog=book;uid=sa;pwd=)Const strsql As String = selec

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论