如何将教师分配到存储在不同表中的房间? vb将教师分配到考场的申请

时间:2013-02-10 15:21:27

标签: vb.net

我正在创建一个vb应用程序,在考试期间将教师分配到考试大厅。我想根据可用性将教师分配到房间。到目前为止,我已经能够将数据输入作为csv文件,将其存储在访问表中并计算教师和房间的数量。但我不知道如何将教师分配到我存储在数据库中不同表中的房间。我该如何解决这个问题?请帮助我被困住。

 Private Sub btnTeachersUpload_Click(sender As System.Object, e As System.EventArgs) Handles btnTeachersUpload.Click

    ODTeachers.ShowDialog()
    fileNameTeachers = ODTeachers.FileName
    lblTeacherPath.Text = fileNameTeachers

    teacher_Name = readFromCsv(teacher_Name, 0, fileNameTeachers)
    department = readFromCsv(department, 1, fileNameTeachers)
    phoneno = readFromCsv(phoneno, 2, fileNameTeachers)
    email_id = readFromCsv(email_id, 3, fileNameTeachers)
    teachers_availability = readFromCsv(teachers_availability, 4, fileNameTeachers)

    addToDb("teachers", "teacher_name", teacher_Name)
    addToDb("teachers", "department", department)
    addToDb("teachers", "email_id", email_id)
    addToDb("teachers", "phone_number", phoneno)
    addToDb("teachers", "availability", teachers_availability)
End Sub

Private Sub btnTeachersCompute_Click(sender As System.Object, e As System.EventArgs) Handles btnTeachersCompute.Click
    connect()
    Dim rs As New ADODB.Recordset
    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
    rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
    rs.Open("select * from teachers where `availability` = 'yes'", cn)
    rs.ActiveConnection = Nothing

    no_of_avail_teachers = rs.RecordCount
    txtTeachers.Text = no_of_avail_teachers
    cn.Close()
End Sub

Public Function readFromCsv(arr() As String, ByVal index As Integer, ByVal filename As String)
    Using ioReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filename)

        ioReader.TextFieldType = FileIO.FieldType.Delimited
        ioReader.SetDelimiters(",")

        While Not ioReader.EndOfData

            Dim arrCurrentRow As String() = ioReader.ReadFields()

            If arr Is Nothing Then

                ReDim Preserve arr(0)

                arr(0) = arrCurrentRow(index)

            Else

                ReDim Preserve arr(arr.Length)

                arr(arr.Length - 1) = arrCurrentRow(index)
            End If
        End While
    End Using
    Return arr
End Function

Public Sub addToDb(ByVal tablename As String, ByVal fieldname As String, ByVal arr() As String)
    Dim strSql As String
    connect()

    Dim rs As New ADODB.Recordset
    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
    rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
    rs.Open("select * from " & tablename & "", cn)
    rs.ActiveConnection = Nothing

    For i = 0 To arr.Length - 1 Step 1
        strSql = "INSERT INTO " & tablename & " (" & fieldname & ") VALUES ('" & arr(i) & "')"
        cn.Execute(strSql)
    Next
    cn.Close()
End Sub

这是我到目前为止所做的。我发布了一部分内容。我接受excel表作为输入并将其存储在数据库中。

我需要帮助将教师分配到房间。代码类似于房间的一部分。需要将可用的教师分配到可用的房间。

我的老师数据库看起来像这样

teachers_name    availability
 vagarth             yes
 gaurav              no
 nymisha             yes

我的房间数据库看起来像这样

rooms            availability
S203                 yes
H405                 no
S304                 yes

0 个答案:

没有答案