📄 adminmanageeduform.vb
字号:
Public Class AdminManageEduForm
Private Sub UpdateInfo(ByVal table As DataTable, ByVal index As Integer)
TextUser.Text = table.Rows(index)("euser")
TextKey.Text = table.Rows(index)("ekey")
TextName.Text = table.Rows(index)("ename")
TextEmail.Text = table.Rows(index)("eemail")
Dim strDuty As String = table.Rows(index)("eduty")
If strDuty.Substring(0, 1) = "1" Then
CheckBoxL.Checked = True
Else
CheckBoxL.Checked = False
End If
If strDuty.Substring(1, 1) = "1" Then
CheckBoxM.Checked = True
Else
CheckBoxA.Checked = False
End If
If strDuty.Substring(2, 1) = "1" Then
CheckBoxA.Checked = True
Else
CheckBoxA.Checked = False
End If
End Sub
Private Sub AdminManageEduForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListEduName.Items.Clear()
ListEduName.Items.Add("添加新教员...")
Dim strSQL As String = "select ename from edu"
Dim UserTable As DataTable = DBOperation.Search(strSQL)
Dim UserRow As DataRow
For Each UserRow In UserTable.Rows
ListEduName.Items.Add(UserRow("ename"))
Next
ListEduName.SelectedIndex = 0
End Sub
Private Sub ListEduName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListEduName.SelectedIndexChanged
If ListEduName.SelectedIndex = 0 Then
ButtonInsert.Enabled = True
ButtonUpdate.Enabled = False
ButtonDelete.Enabled = False
TextKey.Enabled = True
TextUser.Text = ""
TextKey.Text = "123456"
TextName.Text = ""
TextEmail.Text = ""
CheckBoxL.Checked = False
CheckBoxM.Checked = False
CheckBoxA.Checked = False
Else
ButtonInsert.Enabled = False
ButtonUpdate.Enabled = True
ButtonDelete.Enabled = True
TextKey.Enabled = False
Dim strListName As String = ListEduName.SelectedItem().ToString
Dim strSQL As String = "select * from edu where ename='" + strListName + "'"
Dim UserTable As DataTable = DBOperation.Search(strSQL)
UpdateInfo(UserTable, 0)
End If
End Sub
Private Sub ButtonInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonInsert.Click
If TextUser.Text.Trim() = "" Then
MsgBox("请输入用户名!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
If TextKey.Text.Trim() = "" Then
MsgBox("请输入密码!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
If TextName.Text.Trim() = "" Then
MsgBox("请输入姓名!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
If TextEmail.Text.Trim() = "" Then
MsgBox("请输入邮箱名!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
Dim strSQL As String = "select eid from edu"
Dim UserTable As DataTable = DBOperation.Search(strSQL)
Dim strId As String
Dim nid As Integer
If UserTable.Rows.Count = 0 Then
strId = "e001"
Else
strId = UserTable.Rows(UserTable.Rows.Count - 1)("eid")
nid = Val(strId.Substring(1)) + 1
If nid < 10 Then
strId = "e00" + nid.ToString
ElseIf nid < 100 Then
strId = "e0" + nid.ToString
Else
strId = "e" + nid.ToString
End If
End If
Dim strDuty As String = ""
If CheckBoxL.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
If CheckBoxM.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
If CheckBoxA.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
strSQL = "insert into edu values('" + strId + "', '" + TextUser.Text.Trim() + "', '" + TextKey.Text.Trim() + "', '" + TextName.Text.Trim() + "', '" + TextEmail.Text.Trim() + "', '" + strDuty + "')"
If DBOperation.Insert(strSQL) Then
MsgBox("添加成功!", MsgBoxStyle.OkOnly, "添加新教员")
Else
MsgBox("添加失败!", MsgBoxStyle.Exclamation, "添加新教员")
End If
'更新ListBox
ListEduName.Items.Clear()
ListEduName.Items.Add("添加新教员...")
strSQL = "select * from edu"
UserTable = DBOperation.Search(strSQL)
Dim UserRow As DataRow
For Each UserRow In UserTable.Rows
ListEduName.Items.Add(UserRow("ename"))
Next
ListEduName.SelectedIndex = 0
End Sub
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
If TextUser.Text.Trim() = "" Then
MsgBox("请输入用户名!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
If TextName.Text.Trim() = "" Then
MsgBox("请输入姓名!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
If TextEmail.Text.Trim() = "" Then
MsgBox("请输入邮箱!", MsgBoxStyle.Exclamation, "错误")
Exit Sub
End If
Dim strListName As String = ListEduName.SelectedItem().ToString
Dim strDuty As String = ""
If CheckBoxL.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
If CheckBoxM.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
If CheckBoxA.Checked Then
strDuty = strDuty + "1"
Else
strDuty = strDuty + "0"
End If
Dim strSQL As String = "update edu set euser='" + TextUser.Text.Trim() + "', ename='" + TextName.Text.Trim() + "', eemail='" + TextEmail.Text.Trim() + "', eduty='" + strDuty + "' where ename='" + strListName + "'"
If DBOperation.Update(strSQL) Then
MsgBox("更新成功!", MsgBoxStyle.OkOnly, "更新资料")
Else
MsgBox("更新失败!", MsgBoxStyle.Exclamation, "更新资料")
End If
'更新ListBox
ListEduName.Items.Clear()
ListEduName.Items.Add("添加新教员...")
strSQL = "select * from edu"
Dim UserTable As DataTable = DBOperation.Search(strSQL)
Dim UserRow As DataRow
For Each UserRow In UserTable.Rows
ListEduName.Items.Add(UserRow("ename"))
Next
ListEduName.SelectedIndex = 0
End Sub
Private Sub ButtonDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDelete.Click
Dim response As Integer = MsgBox("确定删除该教员?", vbOKCancel + vbQuestion, "确认")
If response = 2 Then
Exit Sub
End If
Dim strListName As String = ListEduName.SelectedItem().ToString
Dim strSQL = "delete edu where ename='" + strListName + "'"
If DBOperation.Delete(strSQL) Then
MsgBox("删除成功!", MsgBoxStyle.OkOnly, "删除用户")
Else
MsgBox("删除失败!", MsgBoxStyle.Exclamation, "删除用户")
End If
'更新ListBox
ListEduName.Items.Clear()
ListEduName.Items.Add("添加新教员...")
strSQL = "select * from edu"
Dim UserTable As DataTable = DBOperation.Search(strSQL)
Dim UserRow As DataRow
For Each UserRow In UserTable.Rows
ListEduName.Items.Add(UserRow("ename"))
Next
ListEduName.SelectedIndex = 0
End Sub
Private Sub ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -