add_person.aspx.vb
来自「用VB.NET在VS.NET 2003下开发的完整的设备管理系统,后台数据库为S」· VB 代码 · 共 130 行
VB
130 行
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class add_person
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents usenametxt As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents regularexpressionvalidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents useunitdownlist As System.Web.UI.WebControls.DropDownList
Protected WithEvents loginnametxt As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents RegValtxt1 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents loginpwtxt As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents RegValtxt2 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents sexdownlist As System.Web.UI.WebControls.RadioButtonList
Protected WithEvents tagdownlist As System.Web.UI.WebControls.DropDownList
Protected WithEvents mybutton As System.Web.UI.WebControls.Button
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Protected WithEvents CompareValidator1 As System.Web.UI.WebControls.CompareValidator
Protected WithEvents cloneloginpwtxt As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected MyBody As System.Web.UI.HtmlControls.HtmlControl
Protected WithEvents returnInfoTemp As System.Web.UI.HtmlControls.HtmlInputHidden
'注意: 以下占位符声明是 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
'在此处放置初始化页的用户代码
End Sub
'<----------------------------------------增加的处理------------------------------------------------->
Sub addbuttton_click(ByVal sender As Object, ByVal e As EventArgs)
If Page.IsValid Then
Dim ConnectionString As String
Dim MyConnection As SqlConnection
Dim InsertCmd As String
Dim MyCommand As SqlCommand
Dim person_tagdownlist, person_useunitdownlist As String '声明用户权限和用户单位
'<-------------------------------------判断用户权限--------------------------------------------->
' person_tagdownlist=trim(tagdownlist.SelectedItem.text) '从用户权限下拉列表框中取值
' person_useunitdownlist=trim(useunitdownlist.SelectedItem.text) '取用户单位
'<--------------------将用户权限“普通”转换为“11,12,13...”等 “管理人员为”01,02,03.."--------------->
If tagdownlist.SelectedItem.text = "超级用户" Then '判断是超级用户的情况
person_tagdownlist = "00"
'---------------------当位普通用户的情况-------------------------------
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "计算机" Then
person_tagdownlist = "11"
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "工商管理" Then
person_tagdownlist = "12"
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "外语" Then
person_tagdownlist = "13"
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "国土资源" Then
person_tagdownlist = "14"
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "教务处" Then
person_tagdownlist = "15"
ElseIf tagdownlist.SelectedItem.text = "普通用户" And useunitdownlist.SelectedItem.text = "财务处" Then
person_tagdownlist = "16"
Else '如果选择的不是“超级用户”也不是“普通用户”的情况
Select Case tagdownlist.SelectedItem.text = "单位管理员" '判断选择的是否单位管理员
Case useunitdownlist.SelectedItem.text = "计算机" '如果是单位管理人员,并且单位是计算机的
person_tagdownlist = "01" '那么他的权限就是01
Case useunitdownlist.SelectedItem.text = "工商管理"
person_tagdownlist = "02"
Case useunitdownlist.SelectedItem.text = "外语"
person_tagdownlist = "03"
Case useunitdownlist.SelectedItem.text = "国土资源"
person_tagdownlist = "04"
Case useunitdownlist.SelectedItem.text = "教务处"
person_tagdownlist = "05"
Case useunitdownlist.SelectedItem.text = "财务处"
person_tagdownlist = "06"
End Select
End If
'<----------------------------------添加数据入库------------------------------------------------>
MyConnection = Global.GetConnection("equipment")
InsertCmd = "Insert into person(用户名,单位,登陆名,登陆密码,性别,权限) Values(@用户名,@单位,@登陆名,@登陆密码,@性别,@权限)"
MyCommand = New SqlCommand(InsertCmd, MyConnection)
'向MyCommand加入各参数对象
MyCommand.Parameters.Add(New SqlParameter("@用户名", SQLDbType.Char, 8))
MyCommand.Parameters("@用户名").Value = usenametxt.Value
MyCommand.Parameters.Add(New SqlParameter("@单位", SQLDbType.Char, 16))
MyCommand.Parameters("@单位").Value = useunitdownlist.SelectedItem.text
MyCommand.Parameters.Add(New SqlParameter("@登陆名", SQLDbType.Char, 10))
MyCommand.Parameters("@登陆名").Value = loginnametxt.Value
MyCommand.Parameters.Add(New SqlParameter("@登陆密码", SQLDbType.Char, 6))
MyCommand.Parameters("@登陆密码").Value = loginpwtxt.Value
MyCommand.Parameters.Add(New SqlParameter("@性别", SQLDbType.Char, 2))
MyCommand.Parameters("@性别").Value = sexdownlist.SelectedItem.text
MyCommand.Parameters.Add(New SqlParameter("@权限", SQLDbType.Char, 4))
MyCommand.Parameters("@权限").Value = person_tagdownlist
MyCommand.Connection.Open() '打开连接
'--------------------------------判断数据库中是否有相同的的记录关键字是唯一的----------------------------
Try
myCommand.ExecuteNonQuery() '执行不代查询功能的的命令
MyConnection.Close()
Me.MyBody.Attributes.Add("onload", "exit()")
Me.returnInfoTemp.Value = "添加记录成功!"
Catch Exp As SqlException '定义在数据库中值重复的异常
If Exp.Number = 2627 Then '调用错误磊型编号
lblMessage.Text = "错误:编号值不能与已有值重复。"
Else
lblMessage.Text = "错误: 增加记录失败,请检查输入信息是否正确。"
End If
lblMessage.ForeColor = Color.red
End Try
MyCommand.Connection.Close() '关闭连接
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?