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

📄 person_query.aspx.vb

📁 用VB.NET在VS.NET 2003下开发的完整的设备管理系统,后台数据库为SQL SERVER 2000,解压缩后请先阅读"说明"文件来部署此系统.
💻 VB
字号:
Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class person_query
    Inherits System.Web.UI.Page

    Dim myDataView As DataView
    Dim SQLstr As String
    Dim person_Condition As String   '定义查询条件
    Dim person_RangeString As String '定义查询表达式



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

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

    End Sub
    Protected WithEvents mydatagrid As System.Web.UI.WebControls.DataGrid
    Protected WithEvents conditiondropdownlist As System.Web.UI.WebControls.DropDownList
    Protected WithEvents rangetextbox As System.Web.UI.WebControls.TextBox
    Protected WithEvents query_Button As System.Web.UI.WebControls.Button

    '注意: 以下占位符声明是 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 Not IsPostBack Then

            If Session("login_name") = "" Then
                Response.Redirect("../login.aspx")
            End If

            Dim conditionString(2) As String
            conditionString(0) = "按用户名"
            conditionString(1) = "按单位"
            conditionString(2) = "按登陆名"
            conditiondropdownlist.DataSource = conditionString
            conditiondropdownlist.DataBind()

            '<------------------------------按用户单位显示数据表------------------------------>
            Dim person_tag As String = Global.ReturnSingleInfo("SELECT 权限 FROM person WHERE 登陆名='" & Session("login_name") & "'")
            If person_tag = "00" Then '如果是超级用户就可以查看所有的库
                SQLstr = "Select * From person "
                myDataView = Global.CreateDataView(SQLstr)
            Else  '不是超级用户就按单位情况查询
                Dim person_unit As String = Global.ReturnSingleInfo("SELECT 单位 FROM person WHERE 登陆名='" & Session("login_name") & "'")
                SQLstr = "Select * From person where 单位='" & person_unit & "' "
                myDataView = Global.CreateDataView(SQLstr)
            End If
            mydatagrid.DataSource = myDataView
            mydatagrid.DataBind()
        End If
    End Sub


    '<-------------当用户翻页时处理------------------->
    Sub ChangePage(ByVal Sender As Object, ByVal e As DataGridPageChangedEventArgs) Handles mydatagrid.PageIndexChanged
        mydatagrid.CurrentPageIndex = e.NewPageIndex
        '<------------在对当前页在进行一次查询然后再次与DataView控件绑定------------------->
        SQLstr = "Select * From person"
        myDataView = Global.CreateDataView(SQLstr)
        mydatagrid.DataSource = myDataView
        mydatagrid.DataBind()
    End Sub

    '<----------------------------点击查询产生的事件----------------------------------->
    Sub querybuttton_click(ByVal sender As Object, ByVal e As EventArgs) Handles query_Button.Click
        Dim person_ConditionString As String
        person_ConditionString = Trim(conditiondropdownlist.SelectedItem.Text) '查询条件下拉列表框值取出
        person_RangeString = Trim(rangetextbox.Text) '查询范围文本框值取出
        Select Case person_ConditionString '判断的查询条件下拉列表框的值
            Case "按用户名"
                person_Condition = "用户名"
            Case "按单位"
                person_Condition = "单位"
            Case "按登陆名"
                person_Condition = "登陆名"
        End Select

        Dim person_tag As String = Global.ReturnSingleInfo("SELECT 权限 FROM person WHERE 登陆名='" & Session("login_name") & "'")
        If person_tag = "00" Then
            SQLstr = "Select * From person where " & person_Condition & " like '%" & person_RangeString & "%'" '是超级用户则查看所有表
        Else
            Dim person_unit As String = Global.ReturnSingleInfo("SELECT 单位 FROM person WHERE 登陆名='" & Session("login_name") & "'")
            SQLstr = "Select * From person where " & person_Condition & " like '%" & person_RangeString & "%' and 单位='" & person_unit & "' " '不是超级用户按单位查
        End If
        mydatagrid.CurrentPageIndex = 0
        myDataView = Global.CreateDataView(SQLstr)
        mydatagrid.DataSource = myDataView
        mydatagrid.DataBind()
    End Sub

End Class

⌨️ 快捷键说明

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