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

📄 addwin.vb

📁 强大的教务考勤系统数据库
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '
        Me.Label10.Location = New System.Drawing.Point(24, 120)
        Me.Label10.Name = "Label10"
        Me.Label10.TabIndex = 7
        Me.Label10.Text = "学生姓名"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(24, 32)
        Me.Label9.Name = "Label9"
        Me.Label9.TabIndex = 6
        Me.Label9.Text = "学生ID"
        '
        'tbStuName
        '
        Me.tbStuName.Location = New System.Drawing.Point(72, 144)
        Me.tbStuName.Name = "tbStuName"
        Me.tbStuName.Size = New System.Drawing.Size(152, 21)
        Me.tbStuName.TabIndex = 1
        Me.tbStuName.Text = ""
        '
        'tbStuID
        '
        Me.tbStuID.Location = New System.Drawing.Point(72, 56)
        Me.tbStuID.Name = "tbStuID"
        Me.tbStuID.Size = New System.Drawing.Size(152, 21)
        Me.tbStuID.TabIndex = 0
        Me.tbStuID.Text = ""
        '
        'AddWin
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(264, 273)
        Me.Controls.Add(Me.gbStu)
        Me.Controls.Add(Me.buttonAdd)
        Me.Controls.Add(Me.gbLes)
        Me.Controls.Add(Me.gbTea)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "AddWin"
        Me.Text = "AddWin"
        Me.gbLes.ResumeLayout(False)
        Me.gbTea.ResumeLayout(False)
        Me.gbStu.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub buttonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAdd.Click
        Select Case Me.Text
            Case "添加课程"
                AddLes()
            Case "添加教师"
                AddTea()
            Case "添加学生"
                AddStu()
        End Select

    End Sub

    Private Sub AddLes()
        If buttonAdd.Text = "重新添加" Then
            gbLes.Enabled = True
            tbLesID.Text = ""
            tbLesName.Text = ""
            tbLesCr.Text = ""
            tbLesTea.Text = ""
            tbLesStuNum.Text = ""
            cbWeek.Text = ""
            cbTime.Text = ""
            buttonAdd.Text = "添加"
            Exit Sub
        End If

        If tbLesID.Text = "" Then
            MsgBox("课程ID不能为空!", , "")
            Exit Sub
        End If
        If Main.ISValidUid(tbLesID.Text) = False Then
            MsgBox("课程ID必须为数字!", , "")
            Exit Sub
        End If
        If tbLesName.Text = "" Then
            MsgBox("课程名不能为空!", , "")
            Exit Sub
        End If
        If tbLesCr.Text = "" Then
            MsgBox("教室不能为空!", , "")
            Exit Sub
        End If
        If tbLesTea.Text = "" Then
            MsgBox("教师ID不能为空!", , "")
            Exit Sub
        End If
        If Main.ISValidUid(tbLesStuNum.Text) = False Then
            MsgBox("学生人数无效!", , "")
            Exit Sub
        End If
        If cbTime.Text = "" Or cbWeek.Text = "" Then
            MsgBox("请选择时间!", , "")
            Exit Sub
        End If

        If mycon.State = ConnectionState.Closed Then mycon.Open()
        Dim str As String
        Dim mycom As SqlCommand
        str = "select cTime from time where bTime='" & cbTime.Text & "' and weekday='" & cbWeek.Text & "'"
        mycom = New SqlCommand(str, mycon)
        Dim ctime As Long
        If mycom.ExecuteScalar() = 0 Then
            MsgBox("该时段不存在!", , "")
            Exit Sub
        End If
        ctime = mycom.ExecuteScalar()

        str = "select count(*) from course where cRoom='" & tbLesCr.Text & "' and cTime=" & ctime
        mycom = New SqlCommand(str, mycon)
        If mycom.ExecuteScalar() Then
            MsgBox("该教室在此时段已被占用!", , "")
            tbLesCr.Text = ""
            cbWeek.Text = ""
            cbTime.Text = ""
            Exit Sub
        End If

        str = "select count(*) from teacher where tID='" & tbLesTea.Text & "'"
        mycom = New SqlCommand(str, mycon)
        If mycom.ExecuteScalar() = 0 Then
            MsgBox("该教师ID不存在!", , "")
            tbLesTea.Text = ""
            Exit Sub
        End If

        str = "select count(*) from course where tID='" & tbLesTea.Text & "' and cTime=" & ctime
        mycom = New SqlCommand(str, mycon)
        If mycom.ExecuteScalar() Then
            MsgBox("该教师在此时段已有课!", , "")
            tbLesTea.Text = ""
            cbWeek.Text = ""
            cbTime.Text = ""
            Exit Sub
        End If

        Dim StuNum As String = tbLesStuNum.Text
        If StuNum = "" Then
            StuNum = "0"
        End If

        Dim cNum As Integer = 1
        While True
            str = "select count(*) from course where cNum='" & cNum & "'"
            mycom = New SqlCommand(str, mycon)
            If mycom.ExecuteScalar() = 0 Then
                Exit While
            End If
            cNum = cNum + 1
        End While

        str = "insert into course(cNum,cID,cName,cRoom,tID,sNum,cTime) values('" & cNum & "','" & tbLesID.Text & "','" & tbLesName.Text & "','" & tbLesCr.Text & "','" & tbLesTea.Text & "'," & StuNum & "," & ctime & ")"
        mycom = New SqlCommand(str, mycon)
        mycom.ExecuteNonQuery()
        MsgBox("课程添加成功!", , "")

        buttonAdd.Text = "重新添加"
        gbLes.Enabled = False
    End Sub

    Private Sub AddTea()
        If buttonAdd.Text = "重新添加" Then
            gbTea.Enabled = True
            tbTeaID.Text = ""
            tbTeaName.Text = ""
            buttonAdd.Text = "添加"
            Exit Sub
        End If

        If tbTeaID.Text = "" Then
            MsgBox("教师ID不能为空!", , "")
            Exit Sub
        End If

        If Main.ISValidUid(tbTeaID.Text) = False Then
            MsgBox("教师ID必须为数字!", , "")
            Exit Sub
        End If

        If tbTeaName.Text = "" Then
            MsgBox("教师姓名不能为空!", , "")
            Exit Sub
        End If

        If mycon.State = ConnectionState.Closed Then mycon.Open()
        Dim str As String
        Dim mycom As SqlCommand
        str = "select count(*) from teacher where tID='" & tbTeaID.Text & "'"
        mycom = New SqlCommand(str, mycon)
        If mycom.ExecuteScalar() Then
            MsgBox("教师ID已存在!", , "")
            tbTeaID.Text = ""
            Exit Sub
        End If

        str = "insert into teacher(tID,tName) values('" & tbTeaID.Text & "','" & tbTeaName.Text & "')"
        mycom = New SqlCommand(str, mycon)
        mycom.ExecuteNonQuery()
        str = "insert into password(ID,iden,password) values('" & tbTeaID.Text & "','teacher','" & tbTeaID.Text & "')"
        mycom = New SqlCommand(str, mycon)
        mycom.ExecuteNonQuery()
        MsgBox("教师添加成功!", , "")

        buttonAdd.Text = "重新添加"
        gbTea.Enabled = False
    End Sub

    Private Sub AddStu()
        If buttonAdd.Text = "重新添加" Then
            gbStu.Enabled = True
            tbStuID.Text = ""
            tbStuName.Text = ""
            buttonAdd.Text = "添加"
            Exit Sub
        End If

        If tbStuID.Text = "" Then
            MsgBox("学生ID不能为空!", , "")
            Exit Sub
        End If

        If Main.ISValidUid(tbStuID.Text) = False Then
            MsgBox("学生ID必须为数字!", , "")
            Exit Sub
        End If

        If tbStuName.Text = "" Then
            MsgBox("学生姓名不能为空!", , "")
            Exit Sub
        End If

        If mycon.State = ConnectionState.Closed Then mycon.Open()
        Dim str As String
        Dim mycom As SqlCommand
        str = "select count(*) from student where sID='" & tbStuID.Text & "'"
        mycom = New SqlCommand(str, mycon)
        If mycom.ExecuteScalar() Then
            MsgBox("学生ID已存在!", , "")
            tbStuID.Text = ""
            Exit Sub
        End If

        str = "insert into student(sID,sName) values('" & tbStuID.Text & "','" & tbStuName.Text & "')"
        mycom = New SqlCommand(str, mycon)
        mycom.ExecuteNonQuery()
        str = "insert into password(ID,iden,password) values('" & tbStuID.Text & "','student','" & tbStuID.Text & "')"
        mycom = New SqlCommand(str, mycon)
        mycom.ExecuteNonQuery()
        MsgBox("学生添加成功!", , "")

        buttonAdd.Text = "重新添加"
        gbStu.Enabled = False
    End Sub

    Private Sub cbTime_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If mycon.State = ConnectionState.Closed Then mycon.Open()
        Dim str As String = "select distinct bTime from time"
        Dim mycom As New SqlCommand(str, mycon)
        Dim myread As SqlDataReader
        myread = mycom.ExecuteReader
        While myread.Read()
            cbTime.Items.Add(myread(0))
        End While
        myread.Close()
    End Sub

    Private Sub cbWeek_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If mycon.State = ConnectionState.Closed Then mycon.Open()
        Dim str As String = "select distinct weekday from time"
        Dim mycom As New SqlCommand(str, mycon)
        Dim myread As SqlDataReader
        myread = mycom.ExecuteReader
        While myread.Read()
            cbWeek.Items.Add(myread(0))
        End While
        myread.Close()
    End Sub
End Class

⌨️ 快捷键说明

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