📄 教室窗体.frm
字号:
BackColor = &H00FFC0C0&
Height = 1575
Left = 0
TabIndex = 19
Top = 9480
Width = 13575
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "添加"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 480
Style = 1 'Graphical
TabIndex = 9
Top = 600
Width = 1215
End
Begin VB.CommandButton Cmddelete
BackColor = &H00FFC0C0&
Caption = "删除"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 7080
Style = 1 'Graphical
TabIndex = 12
Top = 600
Width = 1215
End
Begin VB.CommandButton Cmdedit
BackColor = &H00FFC0C0&
Caption = "编辑"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4800
Style = 1 'Graphical
TabIndex = 11
Top = 600
Width = 1215
End
Begin VB.CommandButton Cmdadd
BackColor = &H00FFC0C0&
Caption = "保存"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2640
Style = 1 'Graphical
TabIndex = 10
Top = 600
Width = 1215
End
Begin VB.CommandButton Cmdexit
BackColor = &H00FFC0C0&
Cancel = -1 'True
Caption = "退出"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 11520
Style = 1 'Graphical
TabIndex = 14
Top = 600
Width = 1215
End
Begin VB.CommandButton Cmdfind
BackColor = &H00FFC0C0&
Caption = "查找"
BeginProperty Font
Name = "楷体_GB2312"
Size = 15.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 9360
Style = 1 'Graphical
TabIndex = 13
Top = 600
Width = 1215
End
End
End
Attribute VB_Name = "Frmclassroom"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim db As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim temp As New ADODB.Recordset
Dim strSQL1 As String
Option Explicit
'连接到数据库
Private Function ConenctToDatabase() As Boolean
On Error GoTo ErrorHandler
Dim DBName As String, ServerAdd As String, UserName As String, UserPwd As String
'设置连接信息字符串的参数
ServerAdd = "IMAGE"
DBName = "Paike"
UserName = ""
UserPwd = ""
'连接数据库
Set db = New ADODB.Connection
db.ConnectionTimeout = 10
db.CursorLocation = adUseServer
db.ConnectionString = "uid=" & UserName & ";pwd=" & UserPwd & _
";driver={SQL Server};server=" & ServerAdd & _
";database=" & DBName & ";dsn=''"
db.Open
'返回值
ConenctToDatabase = True
Exit Function
ErrorHandler:
MsgBox "连接到数据库出错", vbCritical, "出现错误"
Exit Function
End Function
Private Sub Cmdadd_Click()
strSQL1 = "SELECT classroomID FROM bclassroom"
If rst.RecordCount() <> 0 Then
rst.MoveLast
End If
temp.Open strSQL1, db, adOpenStatic, adLockOptimistic
temp.Filter = "classroomID='" & txtid.Text & "'"
temp.Requery
If temp.RecordCount <> 0 Then
MsgBox ("这个教室编号已存在,编辑操作失败!")
temp.Close
Exit Sub
End If
temp.Close
If txtid.Text = "" Then
MsgBox "请输入教室编号!"
txtid.SetFocus
Exit Sub
End If
If txtname.Text = "" Then
MsgBox "请输入教室名称!"
txtname.SetFocus
Exit Sub
End If
If Combo1.Text = "0" Then
MsgBox "请输入教室类型!"
Combo1.SetFocus
Exit Sub
End If
If TxtRoomStuNum.Text = "" Then
MsgBox "请输入容纳人数!"
TxtRoomStuNum.SetFocus
Exit Sub
End If
rst.AddNew
fillrecord
rst.Update
rst.Requery
txtid.SetFocus
Adodc1.Refresh
End Sub
Private Sub Cmddelete_Click()
rst.Delete
rst.Requery
Adodc1.Refresh
If rst.RecordCount() = 0 Then
cleartext
txtid.SetFocus
hidebutton
MsgBox "系统中已经没有记录了!"
Exit Sub
End If
rst.MoveNext
If rst.EOF = True Then
rst.MoveLast
End If
Adodc1.Refresh
End Sub
Private Sub Cmdedit_Click()
strSQL1 = "select classroomID from bclassroom"
If txtid.Text = "" Then
MsgBox "请输入教室编号!"
txtid.SetFocus
Exit Sub
End If
temp.Open strSQL1, db, adOpenKeyset, adLockOptimistic
temp.Filter = "classroomid='" & txtid.Text & "'"
temp.Requery
If temp.RecordCount() = 0 Then
MsgBox "这个教室编号不存在,您的修改无效!"
temp.Close
Exit Sub
End If
temp.Close
If txtname.Text = "" Then
MsgBox "请输入教室名称!"
txtname.SetFocus
Exit Sub
End If
If Combo1.Text = "" Then
MsgBox "请输入教室类型!"
Combo1.SetFocus
Exit Sub
End If
If TxtRoomStuNum.Text = "" Then
MsgBox "请输入容纳人数!"
TxtRoomStuNum.SetFocus
Exit Sub
End If
fillrecord
rst.Update
Adodc1.Refresh
txtid.SetFocus
End Sub
Private Sub Cmdexit_Click()
db.Close
Unload Me
frmmain.Show vbModal
End Sub
Private Sub cmdfind_Click()
Dim findstr As String
findstr = InputBox("请输入要查找的教室名称:", "查找提示窗口")
rst.find "classroomName='" & findstr & "'"
If rst.EOF = True Then
MsgBox "没有要查询的数据!"
Exit Sub
End If
filltext
End Sub
Private Sub cmdfirst_Click()
rst.MoveFirst
filltext
End Sub
Private Sub Cmdlast_Click()
rst.MoveLast
filltext
End Sub
Private Sub Cmdnext_Click()
rst.MoveNext
If rst.EOF Then
MsgBox "这是最后一条记录了!"
rst.MoveLast
End If
filltext
End Sub
Private Sub Cmdprevious_Click()
rst.MovePrevious
If rst.BOF Then
MsgBox "这是第一条记录!"
rst.MoveFirst
End If
filltext
End Sub
Private Sub Command1_Click()
cleartext
txtid.SetFocus
End Sub
Private Sub DataGrid1_Click()
txtid.Text = DataGrid1.Text
txtname.Text = DataGrid1.Columns(1).Text
TxtRoomStuNum.Text = DataGrid1.Columns(4).Text
Combo1.Text = DataGrid1.Columns(2).Text
End Sub
Private Sub Form_Load()
Dim strSQL As String
strSQL = "SELECT * FROM bClassroom"
ConenctToDatabase
rst.Open strSQL, db, adOpenKeyset, adLockOptimistic
If rst.RecordCount() = 0 Then
hidebutton
cleartext
Else
showbutton
rst.MoveFirst
filltext
End If
Combo1.AddItem "0"
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
End Sub
Public Sub filltext()
txtid.Text = rst.Fields("classroomid")
txtname.Text = rst.Fields("classroomname")
Combo1.Text = rst.Fields("classroomtypeid")
TxtRoomStuNum.Text = rst.Fields("ClassRoomStuNum")
End Sub
Public Sub cleartext()
txtid.Text = ""
txtname.Text = ""
Combo1.Text = ""
TxtRoomStuNum.Text = ""
End Sub
Public Sub hidebutton()
cmdfirst.Enabled = False
Cmdnext.Enabled = False
Cmdlast.Enabled = False
Cmdprevious.Enabled = False
Cmddelete.Enabled = False
cmdfind.Enabled = False
Cmdedit.Enabled = False
End Sub
Public Sub showbutton()
cmdfirst.Enabled = True
Cmdnext.Enabled = True
Cmdlast.Enabled = True
Cmdlast.Enabled = True
Cmddelete.Enabled = True
cmdfind.Enabled = True
Cmdedit.Enabled = True
Cmdprevious.Enabled = True
End Sub
Public Sub fillrecord()
rst.Fields("classroomid") = txtid.Text
rst.Fields("classroomname") = txtname.Text
rst.Fields("Classtypeid") = Combo1.Text
rst.Fields("ClassRoomStuNum") = TxtRoomStuNum
End Sub
Private Sub txtid_Click()
Adodc1.Refresh
End Sub
Private Sub txtid_GotFocus()
rst.Requery
If rst.RecordCount() = 0 Then
hidebutton
Else
showbutton
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -