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

📄 xtglyrk_right_qx.aspx.vb

📁 vb2005电子书籍——vb.net项目开发宝典源码
💻 VB
字号:
Imports System
Imports System.Object
Imports System.Data
Imports System.Data.SqlClient


Namespace wsbgxt


Partial Class xtglyrk_right_qx
    Inherits System.Web.UI.Page
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

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

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

    End Sub

    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
            'ddlt权限列绑定
            MyDataBind1()
            MyDataBind2()
        End If
    End Sub

    Sub editdqxmc(ByVal objSender As Object, ByVal objArgs As DataGridCommandEventArgs)
        myDataGrid1.EditItemIndex = objArgs.Item.ItemIndex
        MyDataBind1()
    End Sub

    Sub updatedqxmc(ByVal objSource As Object, ByVal objArgs As DataGridCommandEventArgs)
        Dim NotSame As Boolean = True
        Dim CurrentTextBox As TextBox
        CurrentTextBox = objArgs.Item.Cells(2).Controls(0)
        Dim ColValue As String = Trim(CurrentTextBox.Text)
        Dim dqxId As Integer = myDataGrid1.DataKeys(objArgs.Item.ItemIndex)
        Status.Text = ""
        If ColValue.Length = 0 Then
            Status.Text = "请先输入阅读权限名称!"
            Return
        End If
        Dim myConn As New SqlConnection()
            myConn.ConnectionString = SQL_CONNECTION_STRING
        Try
            myConn.Open()
            Dim myCmdStr As String
            myCmdStr = "SELECT * FROM n_dqxdmb_ent WHERE n_dqxdmb_ent.dqxmc='" + ColValue + "' and n_dqxdmb_ent.id != '" + Trim(CStr(dqxId)) + "'"
            Dim myCmd1 As SqlCommand = New SqlCommand(myCmdStr, myConn)
            Dim reader As SqlDataReader = myCmd1.ExecuteReader()

            Do While reader.Read()
                NotSame = False
            Loop
            reader.Close()
            If NotSame Then
                myCmdStr = " UPDATE n_dqxdmb_ent SET n_dqxdmb_ent.dqxmc='" + ColValue + "' WHERE n_dqxdmb_ent.id='" + Trim(CStr(dqxId)) + "'"
                Dim myCmd2 As SqlCommand = New SqlCommand(myCmdStr, myConn)
                Dim n As Integer = myCmd2.ExecuteNonQuery()
                If n = 1 Then
                    Status.Text = "成功修改了部门名称"
                    myDataGrid1.EditItemIndex = -1
                    MyDataBind1()
                    MyDataBind2()
                Else
                    Status.Text = "试图修改部门名称不成功!"
                End If
            Else
                Status.Text = "已存在相同的部门或单位名称!"
                ColValue = ""
                CurrentTextBox.Text = ""
                'Return
            End If
        Catch ex As SqlException
            Status.Text = ex.Message
        Finally
            myConn.Close()
        End Try

    End Sub

    Sub canceldqxmc(ByVal objSource As Object, ByVal objArgs As DataGridCommandEventArgs)
        myDataGrid1.EditItemIndex = -1
        MyDataBind1()
    End Sub

    Sub btdqx_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btdqx.Click
        Dim input As String = Trim(tbdqx.Text)
        If input.Length = 0 Then
            Status.Text = "请先输入新增阅读权限名称!"
            Return
        Else
            Dim max As Integer
            Dim min As Integer
            Dim myConn As New SqlConnection
                myConn.ConnectionString = SQL_CONNECTION_STRING
            Try
                myConn.Open()

                Dim myCmdStr As String = "SELECT dqxmc FROM n_dqxdmb_ent"
                Dim myCmd As SqlCommand = New SqlCommand(myCmdStr, myConn)
                Dim reader As SqlDataReader = myCmd.ExecuteReader()

                Do While reader.Read()
                    If Trim(reader.Item("dqxmc")) = input Then
                        Status.Text = "已存在相同阅读权限名称" + input + ",不能增添新阅读权限!"
                        tbdqx.Text = ""
                        input = ""
                        Return
                    End If
                Loop
                reader.Close()
                '假如没有相同的,则判断是否还有空间插入新的读权限
                Dim myCmdStr1 As String = "SELECT dqxbh FROM n_dqxdmb_ent"
                myCmdStr1 = myCmdStr1 + " WHERE id= '" + CStr(ddltdqx.SelectedItem.Value) + "'"
                Dim myCmd1 As SqlCommand = New SqlCommand(myCmdStr1, myConn)
                Dim reader1 As SqlDataReader = myCmd1.ExecuteReader()
                Do While reader1.Read()
                    max = reader1.Item("dqxbh")
                Loop
                reader1.Close()
                Dim myCmdStr2 As String = "SELECT * FROM n_dqxdmb_ent"
                myCmdStr2 = myCmdStr2 + " WHERE dqxbh ='" + CStr(max - 1) + "'"
                Dim myCmd2 As SqlCommand = New SqlCommand(myCmdStr2, myConn)
                Dim reader2 As SqlDataReader = myCmd2.ExecuteReader()
                If reader2.Read Then
                    Status.Text = "此阅读权限之前不能再负荷增添新阅读权限!"
                    Return
                End If
                reader2.Close()
                Dim myCmdStr3 As String = "SELECT dqxbh FROM n_dqxdmb_ent"
                myCmdStr3 = myCmdStr3 + " WHERE dqxbh < '" + CStr(max) + "' ORDER by dqxbh DESC"
                Dim myCmd3 As SqlCommand = New SqlCommand(myCmdStr3, myConn)
                Dim reader3 As SqlDataReader = myCmd3.ExecuteReader()
                If reader3.Read Then
                    min = reader3.Item("dqxbh")
                Else
                    Status.Text = "此阅读权限之前不能增添阅读权限!"
                    Return
                End If
                reader3.Close()
                min = (max + min) \ 2
                Dim myCmdStr4 As String
                myCmdStr4 = "Insert into n_dqxdmb_ent(dqxmc,dqxbh) values("
                myCmdStr4 = myCmdStr4 + "'" + input + "','" + CStr(min) + "')"
                Dim myCmd4 As SqlCommand = New SqlCommand(myCmdStr4, myConn)
                Dim n As Integer = myCmd4.ExecuteNonQuery()
                If n = 1 Then
                    Status.Text = "插入成功新的阅读权限" + input + ",请继续!"
                    tbdqx.Text = ""
                    input = ""
                    myConn.Close()
                    MyDataBind1()
                    MyDataBind2()
                Else
                    Status.Text = "新增阅读权限失败"
                End If
            Catch ex As SqlException
                Status.Text = ex.Message
            Finally
                myConn.Close()
            End Try
        End If
    End Sub

    Sub MyDataBind1()
        myDataGrid1.Columns(0).Visible = False
        myDataGrid1.Columns(1).Visible = False
        Dim myConn As New SqlConnection
            myConn.ConnectionString = SQL_CONNECTION_STRING
        Try
            myConn.Open()
            Dim MyDataAD As SqlDataAdapter = New SqlDataAdapter("Select * from n_dqxdmb_ent ORDER by dqxbh", myConn)
            Dim myDataSet As DataSet = New DataSet
            MyDataAD.Fill(myDataSet, "dqxdmb")
            myDataGrid1.DataSource = myDataSet.Tables("dqxdmb")
            myDataGrid1.DataBind()
        Catch ex As SqlException
            Status.Text = ex.Message
        Finally
            myConn.Close()
        End Try
    End Sub

    Sub MyDataBind2()
        Dim myConn As New SqlConnection
            myConn.ConnectionString = SQL_CONNECTION_STRING
        Try
            myConn.Open()
            Dim MyDataAD As SqlDataAdapter = New SqlDataAdapter("Select * from n_dqxdmb_ent ORDER by dqxbh", myConn)
            Dim myDataSet As DataSet = New DataSet
            MyDataAD.Fill(myDataSet, "dqxdmb")
            ddltdqx.DataSource = myDataSet.Tables("dqxdmb")
            ddltdqx.DataBind()
        Catch ex As SqlException
            Status.Text = ex.Message
        Finally
            myConn.Close()
        End Try
    End Sub

    Sub ChangeGridPage1(ByVal objSender As Object, ByVal objArgs As DataGridPageChangedEventArgs)
        myDataGrid1.EditItemIndex = -1
        myDataGrid1.CurrentPageIndex = objArgs.NewPageIndex
        MyDataBind1()
    End Sub
End Class

End Namespace

⌨️ 快捷键说明

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