📄 makedatabase.aspx.vb
字号:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Public Class makedatabase
Inherits System.Web.UI.Page
Dim SQLstr As String
Dim person_Condition As String '定义查询条件
Dim person_RangeString As String '定义查询表达式
Dim competence As Boolean '判断用户的权限是否为超级用户
Dim deleteCar As ArrayList
Dim checkBox As checkBox
#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
Protected WithEvents CustomValidator1 As System.Web.UI.WebControls.CustomValidator
Protected WithEvents RangeString As System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Condition As System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents VerdictDeleteButton As System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents info As System.Web.UI.WebControls.Label
Protected WithEvents tempUpdataResult As System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents notSelectAll As System.Web.UI.WebControls.LinkButton
Protected WithEvents selectAll As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnRemoveAll As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents btnRemove As System.Web.UI.HtmlControls.HtmlInputButton
'注意: 以下占位符声明是 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
'在此处放置初始化页的用户代码
Dim person_tag As String = Global.ReturnSingleInfo("SELECT 权限 FROM person WHERE 登陆名='" & Session("login_name") & "'")
If person_tag = "00" Then
Me.competence = True
Else
Me.competence = False
End If
If Not IsPostBack Then
If Session("login_name") = "" Then
Response.Redirect("../login.aspx")
End If
'<-------------------------------判断是否是管理人员(person_tag=0*)---------------------------->'")
If person_tag >= "00" And person_tag <= "09" Then
Else
Response.Redirect("false.aspx")
End If
Session.Remove("deleteBase")
Session.Remove("deleteCar")
Me.Condition.Value = ""
Me.RangeString.Value = "" '这两个控件用来记载已经查询过的状态
Dim conditionString() As String = New String(2) {"按设备名称", "按生产厂家", "按设备编号"}
conditiondropdownlist.DataSource = conditionString
conditiondropdownlist.DataBind()
Me.conditiondropdownlist.SelectedIndex = -1
'<------------------------------按用户单位显示数据表------------------------------>
SQLstr = getQueryString(Me.competence)
mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataKeyField = "card_id"
mydatagrid.DataBind()
ElseIf Me.VerdictDeleteButton.Value = "updata" Then
refresh()
End If
End Sub
Function getQueryString(ByVal competence As Boolean) As String
If (Me.competence) Then
If Me.Condition.Value <> "" Then
Return "Select * From card where " & Me.Condition.Value & " like'%" & Me.RangeString.Value & "%'"
Else
Return "Select * From card"
End If
Else
Dim person_unit As String = Global.ReturnSingleInfo("SELECT 单位 FROM person WHERE 登陆名='" & Session("login_name") & "'")
If Me.Condition.Value <> "" Then
Return "Select * From card where " & Me.Condition.Value & " like'%" & Me.RangeString.Value & "%' and 使用单位='" & person_unit & "' "
Else
Return "Select * From card where 使用单位='" & person_unit & "' "
End If
End If
End Function
'<-------------当用户翻页时处理------------------->
Sub ChangePage(ByVal Sender As Object, ByVal e As DataGridPageChangedEventArgs) Handles mydatagrid.PageIndexChanged
info.Text = ""
mydatagrid.SelectedIndex = -1
mydatagrid.CurrentPageIndex = e.NewPageIndex
SQLstr = getQueryString(Me.competence)
mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataBind()
Me.allSession()
Me.reMark()
End Sub
Public Sub SelectThisPage(ByVal sender As System.Object, ByVal E As System.EventArgs) Handles selectAll.Click
info.Text = ""
Dim oDataGridItem As DataGridItem
Dim check_card As System.Web.UI.WebControls.CheckBox '声明ChecBox控件
For Each oDataGridItem In mydatagrid.Items '遍利数据库中的所有行
check_card = oDataGridItem.FindControl("check_card") '将每列前面的CheckBox值赋予 check_card
If check_card.Checked = False Then
If Not Session("deleteCar") Is Nothing Then
deleteCar = CType(Session("deleteCar"), ArrayList)
Else
deleteCar = New ArrayList
End If
deleteCar.Add(Convert.ToString(check_card.CssClass))
Session("deleteCar") = deleteCar
check_card.Checked = True '将其设置为“真” (打勾)
End If
Next
Me.allSession()
End Sub
Public Sub NotSelectThisPage(ByVal sender As System.Object, ByVal E As System.EventArgs) Handles notSelectAll.Click
info.Text = ""
Dim oDataGridItem As DataGridItem
Dim check_card As System.Web.UI.WebControls.CheckBox ' 同上
For Each oDataGridItem In mydatagrid.Items
check_card = oDataGridItem.FindControl("check_card")
If check_card.Checked = True Then
deleteCar = CType(Session("deleteCar"), ArrayList)
deleteCar.Remove(Convert.ToString(check_card.CssClass))
Session("deleteCar") = deleteCar
check_card.Checked = False
End If
Next
If deleteCar.Count = 0 Then
Session.Remove("deleteCar")
End If
Me.allSession()
End Sub
'<----------------------------点击模糊查询产生的事件----------------------------------->
Sub querybuttton_click(ByVal sender As Object, ByVal e As EventArgs) Handles query_Button.Click
info.Text = ""
Dim ConditionString As String
ConditionString = Trim(conditiondropdownlist.SelectedItem.Text)
person_RangeString = Trim(rangetextbox.Text)
Select Case ConditionString
Case "按设备名称"
person_Condition = "设备名称"
Case "按生产厂家"
person_Condition = "生产厂家"
Case "按设备编号"
person_Condition = "设备编号"
End Select
Me.Condition.Value = Me.person_Condition
Me.RangeString.Value = Me.person_RangeString '用控件记载状态比用Session节省内存
SQLstr = getQueryString(Me.competence)
mydatagrid.SelectedIndex = -1
mydatagrid.CurrentPageIndex = 0
mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataBind()
Me.compareDeleteSession(SQLstr)
Me.reMark()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
info.Text = ""
Me.Condition.Value = ""
Me.RangeString.Value = ""
SQLstr = getQueryString(Me.competence)
mydatagrid.SelectedIndex = -1
mydatagrid.CurrentPageIndex = 0
mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataBind()
Me.allSession()
Me.reMark()
Me.conditiondropdownlist.SelectedIndex = -1
Me.rangetextbox.Text = ""
End Sub
Protected Sub singleDelete(ByVal Sender As Object, ByVal e As CommandEventArgs)
Dim MyConnection As SqlConnection = Global.GetConnection("equipment")
Dim DeleteCmd As String = "DELETE from card where card_id = @Id"
Dim MyCommand As SqlCommand = New SqlCommand(DeleteCmd, MyConnection)
MyCommand.Parameters.Add(New SqlParameter("@Id", SqlDbType.Int, 4))
MyCommand.Parameters("@Id").Value = CInt(e.CommandArgument) '取出点击的记录行
MyCommand.Connection.Open()
Try '删除数据的提示
MyCommand.ExecuteNonQuery()
info.Text = "记录已经成功删除"
info.Style.Add("color", "#5a8ede")
MyConnection.Close()
deleteCar = CType(Session("deleteCar"), ArrayList)
For Each st As String In deleteCar
If e.CommandArgument = st Then
deleteCar.Remove(st)
Exit For
End If
Next
Me.allSession()
Catch Exc As SqlException
info.Text = "ERROR: Could not delete record"
info.Style.Add("color", "red")
Finally
MyCommand.Connection.Close()
End Try
SQLstr = Me.getQueryString(Me.competence)
mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataBind()
Me.reMark()
End Sub
Sub refresh()
SQLstr = Me.getQueryString(Me.competence)
Me.mydatagrid.DataSource = Global.CreateDataView(SQLstr)
mydatagrid.DataBind()
Me.reMark()
Me.info.Text = Me.tempUpdataResult.Value
If info.Text = "修改记录成功!" Then
info.Style.Add("color", "green")
Else
info.Style.Add("color", "red")
End If
Me.VerdictDeleteButton.Value = ""
End Sub
Sub checkedChanged(ByVal sender As Object, ByVal e As EventArgs)
info.Text = ""
If Session("deleteCar") Is Nothing Then
checkBox = CType(sender, CheckBox)
deleteCar = New ArrayList
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -