Imports System.Data
Imports System.Data.SqlClient
Public Class usermanage
Inherits System.Web.UI.Page
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox5 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox6 As System.Web.UI.WebControls.TextBox
Protected WithEvents btSubmit As System.Web.UI.WebControls.Button
Protected WithEvents AddPanel As System.Web.UI.WebControls.Panel
Protected WithEvents DtgUserManage As System.Web.UI.WebControls.DataGrid
#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
'If Session("USER_LOGINNAME") = "" Then
' Response.Redirect("http://zhangxq/zzapp/login.aspx")
'End If
FillDataGrid()
End If
'Dim objDtAdapter As SqlDataAdapter
'Dim objDataset As DataSet
'Dim strsql As String
'strsql = "select * from T_USER"
'Try
' objDtAdapter = New SqlDataAdapter(strsql, objConnDB)
' objDataset = New DataSet()
' objDtAdapter.Fill(objDataset)
' Me.DtgUserManage.DataSource = objDataset
' Me.DtgUserManage.DataBind()
'Catch objex As Exception
' SendMessage(objex.Message, "错误提示", Page)
'Finally
' objConnDB.Close()
' objConnDB.Dispose()
' objDtAdapter.Dispose()
' objDataset.Dispose()
'End Try
End Sub
'Sub SUBMIT(ByVal OBJ As Object, ByVal E As EventArgs)
' Dim I, J As Integer
' Dim PARAMS(6) As String
' Dim STRTEXT As String
' J = 0
' FOR J=0 TO
'End Sub
Private Sub DtgUserManage_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DtgUserManage.PageIndexChanged
Me.DtgUserManage.CurrentPageIndex = e.NewPageIndex
Me.DtgUserManage.DataBind()
End Sub
Sub Submit(ByVal obj As Object, ByVal e As EventArgs)
Dim i, j As Integer
Dim params(6) As String
Dim strText As String
Dim blnGo As Boolean = True
j = 0
For i = 0 To AddPanel.Controls.Count - 1
If AddPanel.Controls(i).GetType Is GetType(TextBox) Then
strText = CType(AddPanel.Controls(i), TextBox).Text
If strText <> "" Then
params(j) = strText
Else
blnGo = False
SendMessage("您忘记输入一个值", "信息提示", Page)
End If
j = j + 1
End If
Next
If Not blnGo Then
Exit Sub
End If
Dim strSql As String
strSql = "insert into T_USER (USER_LOGINNAME,USER_PASSWORD,USER_NAME,USER_EMAIL,USER_QX) VALUES(" & _
" '" & params(0) & "'," & _
" '" & params(1) & "'," & _
" '" & params(2) & "'," & _
" '" & params(3) & "'," & _
" '" & params(4) & "')"
' " '" & params(4) & "'," & _
ExecuteStatement(strSql)
FillDataGrid()
End Sub
Sub DtgUserManage_Edit(ByVal obj As Object, ByVal e As DataGridCommandEventArgs)
FillDataGrid(e.Item.ItemIndex)
'Me.DtgUserManage.EditItemIndex = e.Item.ItemIndex
'Me.DtgUserManage.DataBind()
End Sub
Sub DtgUserManage_Update(ByVal obj As Object, ByVal e As DataGridCommandEventArgs)
If UpdateData(e) Then
FillDataGrid(-1)
End If
'Me.DtgUserManage.DataBind()
End Sub
Sub DtgUserManage_Cancel(ByVal obj As Object, ByVal e As DataGridCommandEventArgs)
FillDataGrid(-1)
End Sub
Sub DtgManage_Delete(ByVal obj As Object, ByVal e As DataGridCommandEventArgs)
Dim strSQL As String = "delete from T_USER where USER_ID=" & CType(e.Item.Cells(0).Controls(1), Label).Text 'e.Item.ItemIndex + 1
ExecuteStatement(strSQL)
FillDataGrid()
End Sub
Function UpdateData(ByVal e As DataGridCommandEventArgs) As Boolean
Dim i, j As Integer
Dim params(6) As String
Dim strText As String
Dim blnGo As Boolean = True
j = 0
For i = 1 To e.Item.Cells.Count - 3
strText = CType(e.Item.Cells(i).Controls(0), TextBox).Text
If strText <> "" Then
params(j) = strText
j = j + 1
Else
blnGo = False
SendMessage("请输入一个值", "信息提示", Page)
End If
Next
If Not blnGo Then
Return False
Exit Function
End If
' "USER_ID='" & params(0) & "'," & _
Dim STR As String
Dim strSql As String = "Update T_USER set USER_LOGINNAME='" & params(0) & "'," & _
"USER_PASSWORD='" & params(1) & "',USER_NAME='" & params(2) & "'," & _
"USER_QX= '" & params(3) & "',USER_EMAIL='" & params(4) & "'" & _
" where USER_ID=" & CType(e.Item.Cells(0).Controls(1), Label).Text
STR = strSql
ExecuteStatement(strSql)
Return blnGo
End Function
Function FillDataGrid(Optional ByVal editindex As Integer = -1)
'Dim objConnDB As SqlClient.SqlConnection
Dim objConnDB As New SqlClient.SqlConnection(Application("ConnDB"))
Dim strSQL As String = "select *from T_USER"
Dim objDtAdapter As SqlClient.SqlDataAdapter
Dim objDataset As DataSet
'objConnDB = New SqlClient.SqlConnection(Application("ConnDB"))
'objConnDB = New SqlClient.SqlConnection(Application("ConnDB"))
objDtAdapter = New SqlDataAdapter(strSQL, objConnDB)
objDataset = New DataSet()
objDtAdapter.Fill(objDataset)
Me.DtgUserManage.DataSource = objDataset
'Dim objCmd As New SqlCommand(strSQL, objConnDB)
'Dim objReader As SqlDataReader
'Try
' objCmd.Connection.Open()
' objReader = objCmd.ExecuteReader
'Catch objex As Exception
' SendMessage("从数据库返回错误,请确保输入的值都是正确的!", "信息提示", Page)
'Finally
'End Try
'Me.DtgUserManage.DataSource = objReader
If Not editindex.Equals(Nothing) Then
Me.DtgUserManage.EditItemIndex = editindex
End If
'Me.DtgUserManage.DataBind()
Me.DtgUserManage.DataBind()
Dim objConnDB As New SqlClient.SqlConnection(Application("ConnDB"))
Dim objCmd As New SqlCommand(strSQL, objConnDB)
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
End Function
Private Sub DtgUserManage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DtgUserManage.SelectedIndexChanged