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

📄 frmaddstu.frm

📁 是一个 学生管理系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FrmAddStu 
   Caption         =   "Form1"
   ClientHeight    =   5730
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7530
   LinkTopic       =   "Form1"
   ScaleHeight     =   5730
   ScaleWidth      =   7530
   StartUpPosition =   3  '窗口缺省
   Begin VB.ComboBox Combo3 
      Height          =   300
      Left            =   4800
      TabIndex        =   25
      Top             =   1200
      Width           =   975
   End
   Begin VB.CommandButton Command2 
      Caption         =   "取消"
      Height          =   375
      Left            =   5520
      TabIndex        =   24
      Top             =   4920
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "确定"
      Height          =   375
      Left            =   5520
      TabIndex        =   23
      Top             =   4080
      Width           =   1455
   End
   Begin VB.TextBox EditStu 
      Height          =   1695
      Index           =   8
      Left            =   1320
      TabIndex        =   22
      Top             =   3600
      Width           =   3855
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   5
      Left            =   4800
      TabIndex        =   20
      Top             =   2400
      Width           =   1215
   End
   Begin VB.ComboBox Combo2 
      Height          =   300
      Left            =   4800
      TabIndex        =   18
      Top             =   1920
      Width           =   975
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   4800
      TabIndex        =   15
      Top             =   600
      Width           =   975
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   7
      Left            =   4800
      TabIndex        =   13
      Top             =   3000
      Width           =   1335
   End
   Begin VB.TextBox EditStu 
      Height          =   390
      Index           =   6
      Left            =   1320
      TabIndex        =   11
      Top             =   3000
      Width           =   1215
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   4
      Left            =   1320
      TabIndex        =   9
      Top             =   2400
      Width           =   1215
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   3
      Left            =   1320
      TabIndex        =   7
      Top             =   1800
      Width           =   1215
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   2
      Left            =   1320
      TabIndex        =   5
      Top             =   1200
      Width           =   1215
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   1
      Left            =   1320
      TabIndex        =   3
      Top             =   600
      Width           =   1215
   End
   Begin VB.TextBox EditStu 
      Height          =   375
      Index           =   0
      Left            =   1320
      TabIndex        =   1
      Top             =   120
      Width           =   1215
   End
   Begin VB.Label Label12 
      Caption         =   "备注"
      Height          =   255
      Left            =   240
      TabIndex        =   21
      Top             =   3600
      Width           =   735
   End
   Begin VB.Label Label11 
      Caption         =   "邮编"
      Height          =   375
      Left            =   3480
      TabIndex        =   19
      Top             =   2520
      Width           =   855
   End
   Begin VB.Label Label10 
      Caption         =   "政治面貌"
      Height          =   375
      Left            =   3480
      TabIndex        =   17
      Top             =   1920
      Width           =   855
   End
   Begin VB.Label Label9 
      Caption         =   "民族"
      Height          =   255
      Left            =   3480
      TabIndex        =   16
      Top             =   1320
      Width           =   855
   End
   Begin VB.Label Label8 
      Caption         =   "性别"
      Height          =   255
      Left            =   3480
      TabIndex        =   14
      Top             =   720
      Width           =   855
   End
   Begin VB.Label Label7 
      Caption         =   "寝室号码"
      Height          =   375
      Left            =   3480
      TabIndex        =   12
      Top             =   3120
      Width           =   855
   End
   Begin VB.Label Label6 
      Caption         =   "联系电话"
      Height          =   255
      Left            =   240
      TabIndex        =   10
      Top             =   3120
      Width           =   735
   End
   Begin VB.Label Label5 
      Caption         =   "家庭住址"
      Height          =   375
      Left            =   240
      TabIndex        =   8
      Top             =   2400
      Width           =   855
   End
   Begin VB.Label Label4 
      Caption         =   "籍贯"
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   1800
      Width           =   855
   End
   Begin VB.Label Label3 
      Caption         =   "出生年月"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   1200
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "姓名"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   600
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "学号"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   735
   End
End
Attribute VB_Name = "FrmAddStu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim EditNum As String
Dim temp As String

Public Sub LoadStu(temp)
EditNum = temp
Me.Show 1
End Sub


Private Sub Command1_Click()

'On Error Resume Next
'检测输入的数据
If Trim(EditStu(0).Text) = "" Or Val(Trim(EditStu(0).Text)) > 99999999 Or Val(Trim(EditStu(0).Text)) <= 0 Or Len(EditStu(0)) <> 8 Then
     MsgBox "学号输入有错误!请重新输入学号(xxxxxxxx)!", vbInformation
    EditStu(0).SetFocus
    Exit Sub
End If

If Trim(EditStu(1).Text) = "" Then
    MsgBox "必须输入学生的姓名!", vbInformation
    EditStu(1).Text = ""
    EditStu(1).SetFocus
    Exit Sub
End If

If IsDate(EditStu(2).Text) = False Then
   MsgBox "请按照(YYYY-MM-DD)的格式输入出生年月!", vbOKOnly + vbExclamation, "警告"
   EditStu(2).SelLength = Len(EditStu(2).Text)
   EditStu(2).SetFocus
   Exit Sub
End If
 
Dim i As Integer
For i = 0 To 8
    If InStr(1, EditStu(i).Text, "'", 1) Then
        MsgBox "添加的资料有非法字符(不允许输入'号)!", vbInformation
        Exit Sub
        EditStu(i).SetFocus
    End If
Next

If EditStu(0).Enabled Then
    '添加资料
    sqlstr = "select * from StuInfo where SID='" & EditStu(0).Text & "'"
    rs.Open sqlstr, con, 1, 1
    If Not rs.EOF Then
        MsgBox "已经存在学号为" & EditStu(0).Text & "的学生资料,请重新输入!", vbInformation
        EditStu(0).SetFocus
        Exit Sub
    End If
    rs.Close: Set rs = Nothing
    
    sqlstr = "insert into StuInfo(SID,SName,SGender,SPlace,SBirthday,SMinzu,SZhengzhi,SDormitory,SAddress,SCode,STel,SRemark)"
    sqlstr = sqlstr & "values('" & EditStu(0).Text & "','" & EditStu(1).Text & "','" & Combo1.Text & "',"
    sqlstr = sqlstr & "'" & EditStu(3).Text & "','" & EditStu(2).Text & "','" & Combo3.Text & "','" & Combo2.Text & "','" & EditStu(7).Text & "',"
    sqlstr = sqlstr & "'" & EditStu(4).Text & "','" & EditStu(5).Text & "','" & EditStu(6).Text & "','" & EditStu(8).Text & "')"
    
Else
  ' '修改资料
   sqlstr = "update StuInfo set SName='" & EditStu(1).Text & "',SBirthday='" & EditStu(2).Text & "',SGender='" & Combo1.Text & "',"
   sqlstr = sqlstr & "SPlace='" & EditStu(3).Text & "',SMinzu='" & Combo3.Text & "',SZhengzhi='" & Combo2.Text & "',SAddress='" & EditStu(4).Text & "',"
   sqlstr = sqlstr & "SCode='" & EditStu(5).Text & "',STel='" & EditStu(6).Text & "',SDormitory='" & EditStu(7).Text & "',SRemark='" & EditStu(8).Text & "' "
   sqlstr = sqlstr & "where SID='" & EditStu(0).Text & "'"
End If

con.Execute sqlstr

If EditStu(0).Enabled Then
    If MsgBox("添加学号为" & EditStu(0).Text & "的学生资料成功!是否继续?", vbYesNo) = vbYes Then
      For i = 0 To 8
          EditStu(i).Text = ""
      Next
      EditStu(0).SetFocus
    Else
      Call Frmstu.ListviewLoad(classid)
      Unload Me
    End If
Else
           '修改操作提交后退出窗体
         MsgBox "修改学号为" & EditStu(0).Text & "的学生资料成功!", vbInformation
           Call Frmstu.ListviewLoad(classid)
          Unload Me
    End If
End Sub

Private Sub Command2_Click()
   Unload Me
End Sub

Private Sub Form_Load()
  On Error Resume Next
'确定添加或者修改,保存数据
Combo1.Clear
Combo1.AddItem "男"
Combo1.AddItem "女"
Combo1.ListIndex = 0

Combo2.Clear
Combo2.AddItem ""
Combo2.AddItem "团员"
Combo2.AddItem "党员"
Combo2.AddItem "预备党员"
Combo2.ListIndex = 1

Combo3.Clear
Combo3.AddItem "汉族"
Combo3.AddItem "瑶族"
Combo3.AddItem "土家族"
Combo3.AddItem "侗族"
Combo3.AddItem "白族"
Combo3.AddItem "苗族"
Combo3.AddItem "回族"
Combo3.AddItem "壮族"
Combo3.ListIndex = 0

If EditNum = "00000000" Then
    Me.Caption = "添加学生资料(班级:" & classid & ")"
    Command1.Caption = "添加(&A)"
    EditStu(0).Text = classid
    EditStu(0).SelStart = 6
Else
    Me.Caption = "修改学号为" & EditNum & "的学生资料"
    EditStu(0).Enabled = False
    Command1.Caption = "修改(&M)"
    Dim rs As New ADODB.Recordset, sqlstr As String
     
    sqlstr = "select * from StuInfo where SID='" & EditNum & "'"
    rs.Open sqlstr, con
    '把数据代入文本框中
    
    EditStu(0).Text = rs.Fields("SID")
    EditStu(1).Text = rs.Fields("SName")
    EditStu(2).Text = rs.Fields("SBirthday")
    EditStu(3).Text = rs.Fields("SPlace")
    EditStu(4).Text = rs.Fields("SAddress")
    EditStu(5).Text = rs.Fields("SCode")
    EditStu(6).Text = rs.Fields("STel")
    EditStu(7).Text = rs.Fields("SDormitory")
    EditStu(8).Text = rs.Fields("SRemark")
    
          
    If rs.Fields("SGender") = "男" Then
        Combo1.ListIndex = 0
    ElseIf rs.Fields("SGender") = "女" Then
        Combo1.ListIndex = 1
    End If
    
    If rs.Fields("SZhengzhi") = "" Then
        Combo2.ListIndex = 0
    ElseIf rs.Fields("SZhengzhi") = "团员" Then
        Combo2.ListIndex = 1
    ElseIf rs.Fields("SZhengzhi") = "党员" Then
        Combo2.ListIndex = 2
    ElseIf rs.Fields("SZhengzhi") = "预备党员" Then
        Combo2.ListIndex = 3
    End If
    
    Select Case rs.Fields("SMinzu")
    Case "汉族": Combo3.ListIndex = 0
    Case "瑶族": Combo3.ListIndex = 1
    Case "土家族": Combo3.ListIndex = 2
    Case "侗族": Combo3.ListIndex = 3
    Case "白族": Combo3.ListIndex = 4
    Case "苗族": Combo3.ListIndex = 5
    Case "回族": Combo3.ListIndex = 6
    Case "壮族": Combo3.ListIndex = 7
    End Select
    
    rs.Close: Set rs = Nothing
End If
End Sub

⌨️ 快捷键说明

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