學(xué)校教材訂購系統(tǒng)編碼設(shè)計(jì)方案_第1頁
學(xué)校教材訂購系統(tǒng)編碼設(shè)計(jì)方案_第2頁
學(xué)校教材訂購系統(tǒng)編碼設(shè)計(jì)方案_第3頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、軟件工程課程設(shè)計(jì)題目 學(xué)校教材訂購系統(tǒng)編碼學(xué)院 長安學(xué)院專業(yè) 軟件工程班級(jí)09421學(xué)號(hào) 052050060學(xué)生姓名范文標(biāo)羅宇航田翼彪指導(dǎo)教師劉鋒編寫日期2011-5-27目錄:目錄: 21 登陸界面 32 用 datagrid 顯示數(shù)據(jù) 43 添加歷史書目 54 刪除記錄 9主要代碼1 登陸界面/當(dāng)單擊確定按鈕時(shí) , 連接數(shù)據(jù)庫 , 確定輸入的帳號(hào)和密碼是否匹配, 跳轉(zhuǎn)到書目的頁面,若不匹配 , 則彈出帳號(hào)錯(cuò)誤或密碼錯(cuò)誤的提示 /具體代碼如下:Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.

2、EventArgs) Handles button1.ClickDim str As StringDim passstr As Stringpassstr = Trim(CStr(TextBox2.Text)str = "'" & TextBox1.Text & "'"Dim sql As String = "select * from adminlist where帳號(hào) =" & Trim(str)在數(shù)據(jù)庫中搜索帳號(hào)為 textbox1.text 的數(shù)據(jù)'Dim connstr As

3、String = "server=localhost;uid=sa;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, "adminlist")Dim dacomm As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)If

4、 ds.Tables("adminlist").Rows.Count = 1 Then'判斷帳號(hào)密碼是否和數(shù)據(jù)庫匹配'If passstr = Trim(ds.Tables("adminlist").Rows(0)(" 密碼 ") ThenResponse.Redirect("book.aspx")ElseResponse.Write(" 密碼錯(cuò)誤 !")End IfElseResponse.Write(" 用戶名不存在 !")End IfEnd SubEnd

5、 Class2 用 datagrid 顯示數(shù)據(jù)/ 首先建立 datagrid, 通過連接數(shù)據(jù)庫,將數(shù)據(jù)顯示在 datagrid 中 /具體代碼如下:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Loadbinddata()End SubSub binddata()Dim myconnection As NewSqlConnection("initial catalog=book;uid=sa;pwd=")Const strsql

6、As String = "select * from book08 order by書號(hào) "Dim mycommand As New SqlCommand(strsql, myconnection)Dim myda As New SqlDataAdaptermyda.SelectCommand = mycommandDim myds As New DataSetmyda.Fill(myds)DataGrid1.DataSource = mydsDataGrid1.DataBind()End Sub3 添加歷史書目/history.aspx 在登陸系統(tǒng)并選擇插入歷史書本后,進(jìn)

7、入添加歷史書目的頁面,決定選擇 哪條記錄進(jìn)行添加 / 在單擊左側(cè)的選擇后,自動(dòng)跳轉(zhuǎn)到 update1.aspx ,根據(jù)所選擇的書目,進(jìn)行相應(yīng)的修改 后添加到記錄中去 /具體代碼如下:Private Sub Page_Load( ByVal sender As System.Object , ByVal e As System.EventArgs )Handles MyBase.LoadIf Not Page.IsPostBack Thenbinddata ()End IfEnd Sub連接數(shù)據(jù)庫:Sub binddata ()Dim myconnection As NewSqlConnecti

8、on (“ initial catalog=book;uid=sa;pwd=“)Const strsql As String =“ select * from book07 order by書號(hào)”Dim mycommand As New SqlCommand ( strsql , myconnection )Dim myda As New SqlDataAdapterMyda.SelectCommand = mycommandDim myds As New DataSetMyda.Fill ( myds)DataGrid1.DataSource = mydsDataGrid1.DataBind

9、End Sub確定所選擇的行的數(shù)據(jù),并把該行相應(yīng)的內(nèi)容分別通過 session 變量儲(chǔ)存下來。Private Sub DataGrid1_ItemCommand ( ByVal source As Object , ByVal e AsSystem.Web.UI.WebControls.DataGridCommandEventArgs ) HandlesDataGrid1.ItemCommandDim b_no As TableCell = 1)2)Dim b_a As TableCell =Dim b_b As TableCell =Dim b_c As TableCell =Session

10、SessionSessionSessionSessionResponse.Redirect(3)(4)(5)= b_no.Text= b_name.Text= b_a.Text= b_b.Text= b_c.Text(“ history1.aspx”)« ?e”« ?a”« ?c”« I ?d”« I ?b”End SubButton_click 事件,重定向到book.aspx 頁面Private Sub Button1_ClickByVal sender As System.Object, ByVal e AsDim b_name As T

11、ableCell = System.EventArgs ) Handles Button1.ClickResponse。 Redirect (“ book.aspx ”)End SubEnd class/history1.aspx 頁面:通過上一個(gè)頁面的選擇后,該頁面進(jìn)行修改并添加的操作 / 當(dāng)管理員修改完成后,則可單擊確定添加操作,將數(shù)據(jù)添加到 11 年的數(shù)據(jù)庫中 /具體代碼如下: 頁面登陸代碼:Private Sub Page_Load( ByVal sender As System.Object , ByVal e As System.EventArgs )Handles MyBase.

12、LoadIf Not IsPostBack ThenDim str As Stringstr = “' “ & Label6.Text & “' “Dim sql As String = “select * from book11 where 書號(hào) =“ &Trim(Session/ “ ” (“a”)Dim connstr As String =“server=localhost;uid=sa;pwd=;database=book”Dim myconn As New SqlClient.SqlConnection ( connstr )Dim da A

13、s 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)(“書號(hào)”)Label7.Text =ds.Tables(“ book 11”).Rows(0)(“書名”)Label8.Text =ds.Tables(“ book 11”).Ro

14、ws(0)(“作者”)TextBox1.Text = ds.TablesTextBox2.Text = ds.Tables“ book 11”) .Rows( 0)(“征定時(shí)間”)“ book 11”) .Rows( 0)(“數(shù)量”)End IfEnd Sub修改后添加到數(shù)據(jù)庫的代碼:Private Sub Button1_Click( ByVal sender As System.Object, ByVal e AsSystem.EventArgs ) Handles Button1.ClickDim str As StringDim litem As ListItemstr )str =

15、“' “ & Label6.Text & “' “Dim sql As String =“select * from book08 where書號(hào) =“ & Trim (Dim connstr As String =“ server=localhost;uid=sa;pwd=;database=bookDim myconn As New SqlConnection( connstr )Dim da As New SqlDataAdapter( sql , myconn )Dim ds As New DataSetda 。 Fill (ds, “book0

16、8”)Dim myrow As DataRowDim dacomm As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCommandBuilder ( da)If ds.Tables“ book08”) .Rows.Count >= 1 ThenResponse.Write“此書已存在”)myrow(“書號(hào)”)= Trim(Label6.Text)myrow(“書名”)= Trim(Label7.Text)myrow(“作者”)= Trim(Label8.Text)myrow(“征定時(shí)間”) =Trim ( TextBox1.Textmyr

17、ow(“數(shù)量”)= Trim( TextBox2.Text )“ book 11 ”) .NewRowEnd Ifmyrow = ds.Tablesds.Tables(“ book 11”) .Rows.Add (myrow)da.UpdateCommand = dacomm.GetUpdateCommandda.Update( ds ,“book 11”)Response.Redirect(“ book.aspx ”)End Sub單擊返回按鈕后,重定向到history.aspx 的代碼:Private Sub Button2_Click( ByVal sender As System.Ob

18、ject, ByVal e AsSystem.EventArgs ) Handles Button2.ClickResponse.Redirect(“ history.aspx ”)End SubEnd Class4 刪除記錄/ 在登陸系統(tǒng)后點(diǎn)擊修改按鈕進(jìn)入修改頁面 delete.aspx ,通過復(fù)選框的選擇,刪除數(shù)據(jù)/ 該頁面通過復(fù)選框的操作刪除數(shù)據(jù)后, 重定向回該頁面, 以便顯示刪除后數(shù)據(jù)的更新 / 具體代碼如下:頁面登陸代碼:Private Sub Page_Load( ByVal sender As System.Object , ByVal e As System.EventArgs

19、 )Handles MyBase.LoadIf Not Page.IsPostBack Then 用來確認(rèn)頁面是否第一次登陸'binddata ()End IfEnd SubSub binddata () 連接到數(shù)據(jù)庫'“ initialDim myconnection As New SqlConnection catalog=book;uid=sa;pwd= “)Const strsql As String =“ select * from book08 order by 書號(hào)”Dim mycommand As New SqlCommand( strsql , myconne

20、ction )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 AsSystem.EventArgs ) Han

21、dles Button1.ClickDim i As IntegerDim x As StringDim item As DataGridItemFor i = 0 To DataGrid1.ltems.Cou nt- 1item = DataGrid1.Items(i )Dim bookcheckbox As CheckBox = item.FindControl(“checkbox1”)lf bookcheckbox.Checked Then 確認(rèn)數(shù)據(jù)是否被點(diǎn)擊進(jìn)行刪除'x = item.Cells(1) .Text x為datagrid 第二列的數(shù)據(jù)的內(nèi)容deletedatase

22、t( x)End lfNextbinddata()Response.Write(“刪除成功 ! ”)Sub deletedatasetByVal y As String )End SubDim con As New SqlConnection“ initial catalog=book;uid=sa;pwd=Dim cmd As SqlCommandDim qry As StringCon.Open ()qry = “delete book08 where 書號(hào) =' “ & y & “' “cmd = New SqlClient.SqlCommand( qry

23、 , 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/ 添加新教材和修改記錄兩大模塊共三個(gè)頁面的代碼編寫與設(shè)計(jì)/ 添加新教材。在登陸系統(tǒng)并選擇錄入新書后,進(jìn)入添加新教材頁面 /對(duì) textbox1

24、 到 textbox5 添加 RequiredFiledValidator控件,并設(shè)置相應(yīng)屬性使textbox 中的文本不能為空。對(duì) textbox1 添加 RegularExpressionValidator 控件,設(shè)置 ValidationExpression 屬 性為” d4 ”, ErrorMessage 為”書號(hào)的格式為 0001”。對(duì) textbox1 添加 RangeValidator 控件, 設(shè)置 MinimunValue 為” 0001”, MaxmumValue 為” 9999”。使書號(hào)的取值范圍為 0001 9999。對(duì) textbox4 添加 RegularExpres

25、sionValidator 控件,設(shè)置 ValidationExpression 屬 性為” d4-d1 ,2 ”,使時(shí)間格式為 2011-1 。對(duì) textbox5 添加 RangeValidator 控件,設(shè)置 MinimunValue 為” 1”, MaxmumValue 為” 99”,使訂閱的教材數(shù)量在 1-99 本之間。該頁面程序代碼如下:Page Load 事件代碼Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.LoadEnd SubBut

26、ton Click 事件代碼Private Sub Button1_Click(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 書號(hào) =" & Tri

27、m(str)Dim connstr As String = "server=localhost;uid=sa;pwd=;database=book"Dim myconn As New SqlConnection(connstr)Dim da As New SqlDataAdapter(sql, myconn)Dim ds As New DataSetda 。Fill(ds, "bookll")Dim myrow As DataRowDim dacomm As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCo

28、mmandBuilder(da)If ds.Tables("book08").Rows.Count >= 1 ThenResponse.Redirect("new.aspx")Response.Write("書號(hào)重復(fù),請(qǐng)重新輸入 ")End Ifmyrow = ds.Tables("book08").NewRowmyrow("書號(hào)") = Trim(TextBox1.Text)myrow("書名") = Trim(TextBox2.Text)myrow("作者

29、") = Trim(TextBox3.Text)myrow(" 征定時(shí)間 ") = Trim(TextBox4.Text)myrow("數(shù)量") = Trim(TextBox5.Text)ds.Tables("book08").Rows.Add(myrow)da.UpdateCommand = dacomm.GetUpdateCommandda.Update(ds, "book11")Response.Redirect("book.aspx")End Sub/ 修改記錄。在登陸系統(tǒng)后點(diǎn)

30、擊修改按鈕進(jìn)入修改頁面 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 用于加載頁面及確認(rèn)是否第一次訪問。Update.aspx 中的 binddata 事件private Sub binddata()Dim myconnection As NewSqlConnection("initial catalog=book;uid=sa;pwd=")Const strsql As String = "select * from book08 order by書號(hào) "Dim

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論