⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform4.aspx.vb

📁 这是用ASP.NET和SQLserver编写的购物网站的程序
💻 VB
字号:
Imports System.Data.SqlClient
Public Class WebForm4
    Inherits System.Web.UI.Page
    Dim connString As String = "data source=(local);initial catalog=ECDB;user id=sa;pwd=200343"
    Dim conn As SqlConnection = New SqlConnection(connString)
    Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
    Protected WithEvents HyperLink6 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink5 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink4 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink3 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink2 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents Hyperlink7 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
    Protected WithEvents Label8 As System.Web.UI.WebControls.Label
    Protected WithEvents Button3 As System.Web.UI.WebControls.Button
    Protected WithEvents lblRecordCount As System.Web.UI.WebControls.Label
    Protected WithEvents Label5 As System.Web.UI.WebControls.Label
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents LinkButton5 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents lbnPrevPage As System.Web.UI.WebControls.LinkButton
    Protected WithEvents lbnNextPage As System.Web.UI.WebControls.LinkButton

    Dim connSQL As String
    Dim Pagesize, Pagecount, RecordNum, CurrentPage As Integer
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Session("userpower") = 1 Then
            Label8.Text = "欢迎" & Session("username")
            Label8.Visible = True
            Button3.Visible = True
        Else
            Label8.Visible = False
            Button3.Visible = False
        End If
        Dim itemID As String = Session("itemID")
        Dim itemName As String = Session("itemName")
        Dim lowPrice As String = Session("lowPrice")
        Dim highPrice As String = Session("highPrice")
        If itemID = "产品编号" Then
            itemID = "%"
        Else
            itemID = "%" & itemID & "%"
        End If

        If itemName = "产品名称" Then
            itemName = "%"
        Else
            itemName = "%" & itemName & "%"
        End If

        If lowPrice = "最低价格" Then
            lowPrice = 0
        End If

        If highPrice = "最高价格" Then
            highPrice = 99999999

        End If

        Dim querySQL As String = "Select * from item where itemid like " + "'" + itemID + "'" + " and itemname like " + "'" + itemName + "'" + " and listprice between " + lowPrice + " and " + highPrice
        conn.Open()
        Dim DS As New DataSet
        Dim adapter As New SqlDataAdapter(querySQL, conn)
        adapter.Fill(DS)
        DataList1.DataSource = DS.Tables(0).DefaultView
        DataList1.DataBind()


        '每页显示的个数
        Pagesize = 3
        querySQL = "Select count(*) ID from item where itemid like " + "'" + itemID + "'" + " and itemname like " + "'" + itemName + "'" + " and listprice between " + lowPrice + " and " + highPrice
        Dim cmd As New SqlCommand
        cmd.CommandText = querySQL
        cmd.Connection = conn

        '计算总共有多少记录   
        Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
        Dim intCount As Integer
        If dr.Read() Then
            intCount = dr("ID")
        Else
            intCount = 0
        End If
        dr.Close()
        RecordNum = intCount

        '计算总共有多少页    
        If RecordNum Mod Pagesize = 0 Then
            Pagecount = RecordNum \ Pagesize
        Else
            Pagecount = RecordNum \ Pagesize + 1
        End If
        ViewState("PageCount") = Pagecount
        lblRecordCount.Text = Pagecount
        If Not IsPostBack Then
            CurrentPage = 0
            ViewState("PageIndex") = 0
            listbind()
        End If
        Label5.Text = CurrentPage + 1
        conn.Close()


    End Sub

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Response.Redirect("WebForm1.aspx")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Session("userpower") = -1
        Session("username") = ""
        Label8.Visible = False
        Button3.Visible = False

    End Sub

    Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Response.Redirect("WebForm1.aspx")
    End Sub

    Private Sub DataList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged

    End Sub
    Sub listbind()
        Dim StartIndex As Integer
        Dim itemID As String = Session("itemID")
        Dim itemName As String = Session("itemName")
        Dim lowPrice As String = Session("lowPrice")
        Dim highPrice As String = Session("highPrice")
        If itemID = "产品编号" Then
            itemID = "%"
        Else
            itemID = "%" & itemID & "%"
        End If

        If itemName = "产品名称" Then
            itemName = "%"
        Else
            itemName = "%" & itemName & "%"
        End If

        If lowPrice = "最低价格" Then
            lowPrice = 0
        End If

        If highPrice = "最高价格" Then
            highPrice = 99999999

        End If
        StartIndex = CurrentPage * Pagesize
        Dim strSel As String = "Select * from item where itemid like " + "'%" + itemID + "%'" + " and itemname like " + "'%" + itemName + "%'" + " and listprice between " + lowPrice + " and " + highPrice
        Dim ds As DataSet = New DataSet
        Dim MyAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strSel, conn)
        MyAdapter.Fill(ds, StartIndex, Pagesize, "Result")

        DataList1.DataSource = ds.Tables("result").DefaultView
        DataList1.RepeatDirection = RepeatDirection.Horizontal
        DataList1.DataBind()

        lbnNextPage.Enabled = True
        lbnPrevPage.Enabled = True
        If (CurrentPage = (Pagecount - 1)) Then lbnNextPage.Enabled = False
        If (CurrentPage = 0) Then lbnPrevPage.Enabled = False

    End Sub
    Sub Page_OnClick(ByVal sender As Object, ByVal e As CommandEventArgs)

        CurrentPage = ViewState("PageIndex")
        Pagecount = ViewState("PageCount")

        Dim cmd As String = e.CommandName
        Select Case cmd
            Case "next"
                If CurrentPage < (Pagecount - 1) Then CurrentPage += 1
            Case "prev"
                If CurrentPage > 0 Then CurrentPage -= 1
        End Select
        ViewState("PageIndex") = CurrentPage
        Label5.Text = CurrentPage + 1
        listbind()

    End Sub

    Private Sub LinkButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton5.Click
        CurrentPage = TextBox1.Text - 1
        ViewState("PageIndex") = CurrentPage
        Label5.Text = CurrentPage + 1
        listbind()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -