熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 9.2.3 循環[6]

2013-11-13 10:48:12  來源: .NET編程 

    下面通過介紹Wrox United的工作原理給出了循環和測試的一個示例在接下來的試一試部分您可以浏覽比賽日程從而看到進球數以及贏球輸球或平局的場次

    ()創建一個新的Web Form命名為Decisionsaspx並將其設置為起始頁面記得在創建Web Form時要將代碼放到一個單獨的文件中

    ()添加個標簽和一些文本得到頁面可以直接在頁面上輸入文本並確保由上而下逐個添加標簽因此Label在頂端而Label 在底端

    ()創建Page Load事件過程通過打開代碼文件並從第一個列表中選擇PageEvents從第二個列表中選擇Page Load在Page Load事件中添加以下代碼(記住如果不想手工輸入的話則可以從已經完成的示例中復制這些代碼)

 

 Dim conn As New SqlConnection(ConfigurationManagerConnectionStrings(WroxUnited)ConnectionString)

        Dim cmd As New SqlCommand(select * from Fixtures conn)

        Dim rdr As SqlDataReader

 

        Dim wins As Integer =

        Dim losses As Integer =

        Dim draws As Integer =

        Dim goalsFor As Integer =

        Dim goalsAgainst As Integer =

        Dim winRatio As Integer

 

        connOpen()

        rdr = cmdExecuteReader(CommandBehaviorCloseConnection)

 

        While rdrRead

            goalsFor += ConvertToInt(rdr(GoalsFor))

            goalsAgainst += ConvertToInt(rdr(GoalsAgainst))

 

            If goalsFor > goalsAgainst Then

                wins +=

            ElseIf goalsFor < goalsAgainst Then

                losses +=

            Else

                draws +=

            End If

        End While

 

        LabelText = winsToString()

        LabelText = lossesToString()

        LabelText = drawsToString()

        LabelText = goalsForToString()

        LabelText = goalsAgainstToString()

 

        If losses = Then

            LabelText = No losses a perfect season

            Return

        End If

 

        winRatio = ConvertToInt((wins / losses) * )

 

        Select Case winRatio

            Case

                LabelText = No wins Relegation is a certainty

            Case Is <

                LabelText = Less than % Very poor

            Case Is <

                LabelText = Under half Could do better

            Case Is <

                LabelText = Winning more than losing Excellent

            Case Else

                LabelText = A high ratio near the top of the table

        End Select

 

    End Sub

End Class

[]  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/14540.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.