⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmadd_student.frm

📁 用VB开发的一个学生管理系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Frmadd_student 
   Caption         =   "添加学生信息"
   ClientHeight    =   5250
   ClientLeft      =   60
   ClientTop       =   420
   ClientWidth     =   9135
   LinkTopic       =   "Form1"
   ScaleHeight     =   5250
   ScaleWidth      =   9135
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmd_cancel 
      Caption         =   "返回"
      Height          =   495
      Left            =   4560
      TabIndex        =   18
      Top             =   4560
      Width           =   1335
   End
   Begin VB.CommandButton cmd_add 
      Caption         =   "添加"
      Height          =   495
      Left            =   1560
      TabIndex        =   17
      Top             =   4560
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "学生基本信息"
      Height          =   3975
      Left            =   360
      TabIndex        =   0
      Top             =   120
      Width           =   8295
      Begin VB.ComboBox Stu_class 
         Height          =   300
         Left            =   5640
         TabIndex        =   7
         Top             =   840
         Width           =   1695
      End
      Begin VB.ComboBox Stu_sex 
         Height          =   300
         Left            =   1800
         TabIndex        =   8
         Top             =   1680
         Width           =   735
      End
      Begin VB.TextBox Stu_memo 
         Height          =   615
         Left            =   1800
         TabIndex        =   11
         Top             =   3000
         Width           =   6015
      End
      Begin VB.TextBox Stu_address 
         Height          =   375
         Left            =   1800
         TabIndex        =   10
         Top             =   2160
         Width           =   3735
      End
      Begin VB.TextBox Stu_tel 
         Height          =   270
         Left            =   5640
         TabIndex        =   9
         Top             =   1440
         Width           =   1815
      End
      Begin VB.TextBox Stu_no 
         Height          =   390
         Left            =   5640
         TabIndex        =   5
         Top             =   240
         Width           =   1575
      End
      Begin VB.TextBox Stu_birth 
         Height          =   375
         Left            =   1800
         TabIndex        =   6
         Top             =   960
         Width           =   1335
      End
      Begin VB.TextBox Stu_name 
         Height          =   375
         Left            =   1800
         TabIndex        =   4
         Top             =   240
         Width           =   1335
      End
      Begin VB.Label Label16 
         Caption         =   "备注:"
         Height          =   375
         Left            =   720
         TabIndex        =   16
         Top             =   3120
         Width           =   615
      End
      Begin VB.Label Label10 
         Caption         =   "地址:"
         Height          =   255
         Left            =   720
         TabIndex        =   15
         Top             =   2280
         Width           =   735
      End
      Begin VB.Label Label7 
         Caption         =   "学号:"
         Height          =   255
         Left            =   4320
         TabIndex        =   14
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "电话:"
         Height          =   255
         Left            =   4320
         TabIndex        =   13
         Top             =   1440
         Width           =   615
      End
      Begin VB.Label Label5 
         Caption         =   "班级:"
         Height          =   255
         Left            =   4320
         TabIndex        =   12
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label4 
         Caption         =   "生日:"
         Height          =   255
         Left            =   720
         TabIndex        =   3
         Top             =   1080
         Width           =   615
      End
      Begin VB.Label Label3 
         Caption         =   "性别:"
         Height          =   255
         Left            =   720
         TabIndex        =   2
         Top             =   1680
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "姓名:"
         Height          =   255
         Left            =   720
         TabIndex        =   1
         Top             =   360
         Width           =   615
      End
   End
End
Attribute VB_Name = "Frmadd_student"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_add_Click()
Dim rs As ADODB.Recordset
Dim rststudent As ADODB.Recordset

If Trim(stu_no.Text) = "" Or Trim(Stu_name.Text) = "" Then
MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"
stu_no.SetFocus
Exit Sub
End If
sqlStr = "select * from students where stu_no='" & stu_no.Text & "'"
Set rs = executesql(sqlStr, msgText)
If rs.RecordCount = 0 Then
 sqlStr = "select * from students"
 Set rststudent = executesql(sqlStr, msgText)
 rststudent.AddNew
 rststudent.Fields("stu_no") = Trim(stu_no.Text)
 rststudent.Fields("Name") = Trim(Stu_name.Text)
 rststudent.Fields("class_no") = Trim(stu_class.Text)
 rststudent.Fields("Birthdate") = Stu_birth.Text
 rststudent.Fields("Sex") = Trim(Stu_sex.Text)
 rststudent.Fields("Address") = Trim(Stu_address.Text)
 rststudent.Fields("TelNo") = Trim(Stu_tel.Text)
 rststudent.Fields("Memo") = Trim(Stu_memo.Text)
 rststudent.Update
 rststudent.Close
 MsgBox "添加学生信息成功", 48, "提示"
 initform
 Else
  MsgBox "您输入的学生学号已存在,请重新输入", 48, "警告"
  stu_no = ""
  stu_no.SetFocus
  Exit Sub
 End If
 
End Sub

Private Sub cmd_cancel_Click()
Unload Me
End Sub

Sub initClass()
Dim rstclass As ADODB.Recordset
sqlStr = "select className from Classes"
Set rstclass = executesql(sqlStr, msgText)
stu_class.Clear
If Not rstclass.EOF Then
Do While Not rstclass.EOF
    stu_class.AddItem Trim(rstclass.Fields(0))
    rstclass.MoveNext
Loop
stu_class.ListIndex = 0
Else
MsgBox "请添加班级", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstclass.Close

End Sub
Sub initform()
 stu_no = ""
 Stu_name = ""
 stu_class = ""
 Stu_sex = ""
 Stu_tel = ""
 Stu_birth = ""
 Stu_address = ""
 Stu_memo = ""

End Sub
Private Sub Form_Load()
'Dim n As Integer
'For n = 1 To n
 ' Stu_sex.AddItem n
 ' Next n
  'connStr = "provider=microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\student_MG.mdb;"
  initClass
  initform
  Stu_sex.AddItem "男"
  Stu_sex.AddItem "女"
 
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -