Download presentation
Presentation is loading. Please wait.
Published byByron Harrell Modified over 9 years ago
1
ASP.NET---ch17 線上購物、線上考試 M9153325 吳宗憲
2
線上購物
3
Main.aspx #059: If Not Sel Is Nothing Then #060: Response.Redirect( “ Buy.aspx?類別名稱= ” _ #061: & Sel.Text & "&類別編號=" & Sel.Value ) #062: End If
4
Buy.aspx #107: For I = 0 To MyGrid.Items.Count - 1 #108: Dim cb As CheckBox = MyGrid.Items(I).FindControl("BuyIt") #109: Dim lb As Label = MyGrid.Items(I).FindControl("ProductID") #110: Dim tb As TextBox = MyGrid.Items(I).FindControl("Quantity") #111: #112: If cb.Checked And Val(tb.Text) > 0 Then #113: If Not Hash.ContainsKey(lb.Text) Then #114: Hash.Add( lb.Text, CInt(Val(tb.Text)) ) #115: Else #116: Hash(lb.Text) += CInt(Val(tb.Text)) #117: End If #118: End If #119: Next #120: Session("購物袋") = Hash #121: Response.Redirect( "List.aspx" )
5
List.aspx #093: Dim X As String #094: For Each X In Hash.Keys #095: Table1.Rows.Find( X ).Item("數量") = Hash.Item(X) #096: Next #097: Table1.Columns.Add(New DataColumn("總價", GetType(Long), _ #098: "價格*數量")) #099: Dim I As Integer #100: For I = 0 To Table1.Rows.Count - 1 #101: 總價格 += Table1.Rows(I).Item("總價") #102: Next
6
Clear.aspx Hash.Clear()
7
HashTable 的使用 1. 建立: Dim A As New HashTable 2. 加入資料 : A.Add( “ key ”, 值 ) 3. 刪除單筆: A.Remove( “ key ” ) 4. 清除所有: A.Clear 5. 檢查是否存在: A.ContainsKey( “ key ” )
8
線上考試
9
Enter.aspx #042: SQL = "Select * From 成績單 Where 學號= “ & _ #043: Number.Text & ” And 姓名= ‘“ & Name.Text & ”’“ #044: Cmd = New OleDbCommand( SQL, Conn ) #045: Rd = Cmd.ExecuteReader() #046: If Rd.Read() Then #047: If Rd.Item( Lesson.SelectedItem.Text ) <> ” 尚未考試 “ Then #048: Msg.Text = ” 你已經考過本科目了! “ #049: Else #050: Dim URL As String #051: URL = "Test.aspx" & _ #052: "?姓名=" & Name.Text & _ #053: "&學號=" & Number.Text & _ #054: "&科目=" & Lesson.SelectedItem.Text #055: Response.Redirect( URL ) #056: End If #057: Else #058: Msg.Text = "學號或姓名欄位錯誤!" #059: End If
10
Test.aspx #041: ' 列出題目 #042: While Rd.Read() #045: Dim Rlist #046: If Rd.Item("類型") = "單選" Then #047: RList = New RadioButtonList #048: Else #049: RList = New CheckBoxList #050: End If
11
#080: While Rd.Read() #081: Answer = "" #082: I = Rd.Item("題號") #083: Dim List As ListControl = MyPanel.Controls(1 + 3*(I-1)) #084: If Rd.Item("類型") = "單選" Then #085: If Not List.SelectedItem Is Nothing Then #086:Answer = List.SelectedItem.Value #087:End If #088: Else #089: For K = 0 To List.Items.Count - 1 #090: If List.Items(K).Selected Then #091: If Answer = "" Then #092:Answer = List.Items(K).Value #093: Else #094: Answer &= ", " & List.Items(K).Value #095: End If #096: End If #097: Next #098: End If #099: If Answer = Rd.Item("解答") Then Score += Rd.Item("分數") #100: End While Test.aspx( 評分 )
12
Score.aspx #052: Dim SQL = "Select * From 成績單 Where 學號=" & Request("學號") 注意:本程式並非作為評分之用,而只是作分數 的查詢,真正的分數計算及將成績寫入資料庫是 利用 Test.aspx
13
簡報完畢 敬請指教
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.