📄 xtglyrk_right_bmry.aspx.vb
字号:
Imports System
Imports System.Object
Imports System.Data
Imports System.Data.SqlClient
Namespace wsbgxt
Partial Class xtglyrk_right_bmry
Inherits System.Web.UI.Page
Public Shared StaticId As Integer
Public Shared Static1Id As Integer
#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
MyDataBind1()
myDatagrid2.Visible = False
tiplabel.Visible = False
MyDataBind3()
editmanname.Text = "修改用户个人信息:"
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")
ddltnewmandqx.DataSource = myDataSet.Tables("dqxdmb")
ddltnewmandqx.DataBind()
ddltedmandqx.DataSource = myDataSet.Tables("dqxdmb")
ddltedmandqx.DataBind()
Catch ex As SqlException
Status1.Text = ex.Message + "绑定失败!"
Finally
myConn.Close()
End Try
End If
End Sub
Sub MyDataBind1()
'重新从数据库中读出所有部门名
'代码说明:以下一句是,隐藏了id列,定义id列但是不显示它的原因是为了删除按钮可以拿到其信息id值
myDataGrid1.Columns(0).Visible = False
Dim myConn As New SqlConnection
myConn.ConnectionString = SQL_CONNECTION_STRING
Try
myConn.Open()
Dim myCmdStr As String
myCmdStr = "SELECT * FROM n_bmdmb_ent ORDER BY id"
'数据源:dataset
Dim myDataAD As SqlDataAdapter = New SqlDataAdapter(myCmdStr, myConn)
Dim myDataset As New DataSet
myDataAD.Fill(myDataset)
'以下是相关的绑定语句
myDataGrid1.DataSource = myDataset
myDataGrid1.DataBind()
Catch ex As SqlException
Status1.Text = ex.Message
Status2.Text = ""
Finally
myConn.Close()
End Try
End Sub
Sub MyDataBind2(ByVal MessageId As Integer)
'参数传过来部门的id值,在datagrid2中宣示其全部人员及去权限,并隐藏其id值
myDatagrid2.Columns(0).Visible = False
myDatagrid2.Columns(1).Visible = False
Dim myConn As New SqlConnection
myConn.ConnectionString = SQL_CONNECTION_STRING
Try
myConn.Open()
Dim myCmdStr As String
myCmdStr = "SELECT n_yhjbxx_ent.id,n_yhjbxx_ent.bmhdwid,n_bmdmb_ent.bmhdwmc,n_yhjbxx_ent.xm,n_yhjbxx_ent.dlm,n_yhjbxx_ent.fbqxbz,n_yhjbxx_ent.jybz,n_dqxdmb_ent.dqxmc FROM n_yhjbxx_ent,n_dqxdmb_ent,n_bmdmb_ent where n_yhjbxx_ent.bmhdwid = n_bmdmb_ent.id and n_yhjbxx_ent.dqxid = n_dqxdmb_ent.id and n_yhjbxx_ent.bmhdwid= '" + Trim(CStr(MessageId)) + "' ORDER BY n_yhjbxx_ent.id"
'数据源:dataset
Dim myDataAD As SqlDataAdapter = New SqlDataAdapter(myCmdStr, myConn)
Dim myDataset As New DataSet
myDataAD.Fill(myDataset)
'以下是相关的绑定语句
myDatagrid2.DataSource = myDataset
myDatagrid2.DataBind()
Catch ex As SqlException
Status2.Text = ex.Message
Status1.Text = ""
Finally
myConn.Close()
End Try
End Sub
Sub MyDataBind3()
Dim myConn As New SqlConnection
myConn.ConnectionString = SQL_CONNECTION_STRING
Try
myConn.Open()
Dim MyDataAD As SqlDataAdapter = New SqlDataAdapter("Select * from n_bmdmb_ent", myConn)
Dim myDataSet As DataSet = New DataSet
MyDataAD.Fill(myDataSet, "bmdmb")
ddltnewmanbmhdw.DataSource = myDataSet.Tables("bmdmb")
ddltnewmanbmhdw.DataBind()
ddltedmanbmhdw.DataSource = myDataSet.Tables("bmdmb")
ddltedmanbmhdw.DataBind()
Catch ex As SqlException
Status2.Text = ex.Message + "绑定失败!"
Status1.Text = ""
Finally
myConn.Close()
End Try
End Sub
Sub editbmhdwmc(ByVal objSender As Object, ByVal objArgs As DataGridCommandEventArgs)
myDataGrid1.EditItemIndex = objArgs.Item.ItemIndex
MyDataBind1()
End Sub
Sub updatebmhdwmc(ByVal objSource As Object, ByVal objArgs As DataGridCommandEventArgs)
Dim NotSame As Boolean = True
Dim CurrentTextBox As TextBox
CurrentTextBox = objArgs.Item.Cells(1).Controls(0)
Dim ColValue As String = Trim(CurrentTextBox.Text)
Dim DeptId As Integer = myDataGrid1.DataKeys(objArgs.Item.ItemIndex)
Status1.Text = ""
Status2.Text = ""
If ColValue.Length = 0 Then
Status1.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_bmdmb_ent WHERE n_bmdmb_ent.bmhdwmc='" + ColValue + "' and n_bmdmb_ent.id != '" + Trim(CStr(DeptId)) + "'"
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_bmdmb_ent SET n_bmdmb_ent.bmhdwmc='" + ColValue + "' WHERE n_bmdmb_ent.id='" + Trim(CStr(DeptId)) + "'"
Dim myCmd2 As SqlCommand = New SqlCommand(myCmdStr, myConn)
Dim n As Integer = myCmd2.ExecuteNonQuery()
If n = 1 Then
Status1.Text = "成功修改了部门名称"
myDataGrid1.EditItemIndex = -1
MyDataBind1()
Else
Status1.Text = "试图修改部门名称不成功!"
End If
Else
Status1.Text = "已存在相同的部门或单位名称!"
ColValue = ""
CurrentTextBox.Text = ""
End If
Catch ex As SqlException
Status2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub cancelbmhdwmc(ByVal objSource As Object, ByVal objArgs As DataGridCommandEventArgs)
myDataGrid1.EditItemIndex = -1
MyDataBind1()
End Sub
Sub ClickItem(ByVal objSender As Object, ByVal objArgs As DataGridCommandEventArgs)
'当按下datagrid中的按钮时,触发下面事件:
If myDataGrid1.EditItemIndex <> -1 Then
Status1.Text = "请先退出编辑状态"
Return
End If
'部门的人员管理
If objArgs.CommandSource.CommandName = "MemberOfIt" Then
myDatagrid2.Visible = True
tiplabel.Text = objArgs.Item.Cells(1).Text + "人员管理"
tiplabel.Visible = True
Dim DeptId As Integer = CInt(objArgs.Item.Cells(0).Text)
StaticId = DeptId
myDatagrid2.CurrentPageIndex = 0
MyDataBind2(StaticId)
End If
'部门的删除该部门
If objArgs.CommandSource.CommandName = "DeleteDept" Then
'删除部门,则要删除该部门中的所有人员,以及属于该部门的所有信息。
'是否必要:保留没做。
Dim DeptId As Integer = CInt(objArgs.Item.Cells(0).Text)
Dim DeptName As String = CStr(objArgs.Item.Cells(1).Text)
Status1.Text = ""
Status2.Text = ""
Dim myConn As New SqlConnection
myConn.ConnectionString = SQL_CONNECTION_STRING
Try
myConn.Open()
'以下三个部分应该使用事务对象,待改进!(V3.0 中实现)
'首先是删信息,信息与部门关系
Dim myCmdStr4 As String
myCmdStr4 = "DELETE FROM n_xxybmgx_ent WHERE bmhdwid = '" + Trim(CStr(DeptId)) + "'"
Dim myCmd4 As SqlCommand = New SqlCommand(myCmdStr4, myConn)
Dim j As Integer = myCmd4.ExecuteNonQuery()
Dim myCmdStr3 As String
myCmdStr3 = "DELETE FROM n_xxdjb_ent WHERE bmhdwid = '" + Trim(CStr(DeptId)) + "'"
Dim myCmd3 As SqlCommand = New SqlCommand(myCmdStr3, myConn)
Dim k As Integer = myCmd3.ExecuteNonQuery()
'其次是删人员
Dim myCmdStr2 As String
myCmdStr2 = "DELETE FROM n_yhjbxx_ent WHERE bmhdwid = '" + Trim(CStr(DeptId)) + "'"
Dim myCmd2 As SqlCommand = New SqlCommand(myCmdStr2, myConn)
Dim n As Integer = myCmd2.ExecuteNonQuery()
'最后是删部门
Dim myCmdStr1 As String
myCmdStr1 = "DELETE FROM n_bmdmb_ent WHERE id = '" + Trim(CStr(DeptId)) + "'"
Dim myCmd1 As SqlCommand = New SqlCommand(myCmdStr1, myConn)
Dim m As Integer = myCmd1.ExecuteNonQuery()
If (j = 1 And k = 1 And n = 1 And m = 1) Then
'刷新datagrid
'这个时候,可能myDatagrid2中显示的可能是已经删除的,故将其设为不可视。
'MyDataBind1()
MyDataBind3()
myDatagrid2.Visible = False
tiplabel.Visible = False
Status1.Text = "成功删除了部门" + Trim(DeptName) + "以及属于其的所有人员及信息!"
Else
Status1.Text = "试图删除部门" + Trim(DeptName) + "以及属于其的所有人员及信息,不成功!"
End If
Catch ex As SqlException
Status1.Text = ex.Message
Finally
myConn.Close()
End Try
If (myDatagrid2.CurrentPageIndex = myDatagrid2.PageCount - 1 And myDatagrid2.CurrentPageIndex > 0) Then
myDatagrid2.CurrentPageIndex = myDatagrid2.CurrentPageIndex - 1
MyDataBind2(StaticId)
If (myDatagrid2.CurrentPageIndex = myDatagrid2.PageCount - 2) Then
myDatagrid2.CurrentPageIndex = myDatagrid2.CurrentPageIndex + 1
MyDataBind2(StaticId)
End If
Else
MyDataBind2(StaticId)
End If
If (myDataGrid1.CurrentPageIndex = myDataGrid1.PageCount - 1 And myDataGrid1.CurrentPageIndex > 0) Then
myDataGrid1.CurrentPageIndex = myDataGrid1.CurrentPageIndex - 1
MyDataBind1()
If (myDataGrid1.CurrentPageIndex = myDataGrid1.PageCount - 2) Then
myDataGrid1.CurrentPageIndex = myDataGrid1.CurrentPageIndex + 1
MyDataBind1()
End If
Else
MyDataBind1()
End If
End If
'人员列表中的删除该人员
If objArgs.CommandSource.CommandName = "DeleteMember" Then
Dim PersonId As Integer = CInt(objArgs.Item.Cells(0).Text)
Dim DeptId As Integer = CInt(objArgs.Item.Cells(1).Text)
Dim PersonName As String = CStr(objArgs.Item.Cells(2).Text)
Dim myConn As New SqlConnection
myConn.ConnectionString = SQL_CONNECTION_STRING
Try
myConn.Open()
'以下两个部分应该使用事务对象,待改进!(V3.0 中实现)
'首先是删信息
Dim myCmdStr2 As String
myCmdStr2 = "DELETE FROM n_xxdjb_ent WHERE fbyhid = '" + Trim(CStr(PersonId)) + "'"
Dim myCmd2 As SqlCommand = New SqlCommand(myCmdStr2, myConn)
Dim n As Integer = myCmd2.ExecuteNonQuery()
'最后是删人员
Dim myCmdStr1 As String
myCmdStr1 = "DELETE FROM n_yhjbxx_ent WHERE id = '" + Trim(CStr(PersonId)) + "'"
Dim myCmd1 As SqlCommand = New SqlCommand(myCmdStr1, myConn)
Dim m As Integer = myCmd1.ExecuteNonQuery()
Status1.Text = ""
If m = 1 Then
Status2.Text = "成功删除了用户" + Trim(PersonName) + "以及其发布的所有信息!"
Else
Status2.Text = "试图删除用户" + Trim(PersonName) + "以及其发布的所有信息,不成功!"
End If
Catch ex As SqlException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -