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

📄 form2.frm

📁 本软件是个人的小制作
💻 FRM
📖 第 1 页 / 共 2 页
字号:
                    "'" + Sno.Text + "'," + _
                    "'" + Sname.Text + "'," + _
                    "'" + Ssex.Text + "'," + _
                    "'" + Ssource.Text + "'," + _
                    "'" + Snation.Text + "'," + _
                    "'" + Sdept.Text + "'," + _
                    "'" + Soccupation.Text + "'," + _
                    "'" + Sroom.Text + "'," + _
                    "'" + Sdormitory.Text + "'" + _
                    "'" + Sbirth.Text + "'" + ")"
                   
    
              
    IDB.INPUTDB (SQL)
    
    Set IDB = Nothing
   '结束数据库操作
   '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   '将新的学号添加到列表框combo1中
   Combo1.AddItem Sno.Text
   
   
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '将将界面输入的学号、课程号、成绩显示在界面上的表scgrid上
    
    '因为表scgrid开始设为6行,先变为1行,再为表scgrid添加1行,以便添加新的记录
  
    row = row + 1
    scgrid.Rows = row
    '设置新行中记录的每个单元的值
    scgrid.TextMatrix(scgrid.Rows - 1, 0) = Sno.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 1) = Sname.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 2) = Ssex.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 3) = Ssource.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 4) = Snation.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 5) = Sdept.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 6) = Soccupation.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 7) = Sroom.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 8) = Sdormitory.Text
    scgrid.TextMatrix(scgrid.Rows - 1, 9) = Sbirth.Text
    '保证表scgrid始终保持6行以上,以保持表界面的美观
    
   
    If scgrid.Rows < 6 Then
               row = scgrid.Rows
               scgrid.Rows = 6
    End If
    
    '清空学号、课程号、成绩单元格,以便用户输入新的值
    Sno.Text = ""
    Sname.Text = ""
    Ssex.Text = ""
    Ssource.Text = ""
    Snation.Text = ""
    Sdept.Text = ""
    Soccupation.Text = ""
    Sroom.Text = ""
    Sdormitory.Text = ""
    Sbirth.Text = ""
    
End Sub

Private Sub Command1_Click()
Form2.Hide
Form1.Show
End Sub

'如果用户输入错误的记录,可以选中这条记录点击“删除”键,则记录同时从数据库和scgrid表删除
Private Sub delete_Click()
    Dim currow As Integer
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '从数据库删除选中的记录
    Dim IDB As INPUTDB
    
    Dim SQL As String
    
    
    Set IDB = New INPUTDB
    
    
    SQL = "delete from Student " + _
              "where  Sno='" + scgrid.TextMatrix(scgrid.row, 0) + "'"
                
              
    IDB.INPUTDB (SQL)
    
    Set IDB = Nothing
    '结束数据库操作
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '从界面上的表scgrid删除选中的记录
    With scgrid
        '获得选中行的行号
        currow = .row
        
        '删除选中的该行
        If .Rows > 2 Then
            .RemoveItem currow
        Else
            If .Rows > 1 Then
                .Rows = .Rows - 1
            End If
        End If
    End With
    row = row - 1
    
    '保证表scgrid始终保持6行以上,以保持表界面的美观
    If scgrid.Rows < 6 Then
               scgrid.Rows = 6
    End If
End Sub


'将从数据库查询到的记录显示在界面上的表findgrid中

Private Sub find_Click()

    '先删除findgrid表中原先的内容
     With findgrid
        'get current row
        currow = .row
        
        'delete current row
        While .Rows > 2
            .RemoveItem currow
        Wend
        If .Rows > 1 Then
                .Rows = .Rows - 1
        End If
        
     End With
    
    If findgrid.Rows < 8 Then
               findgrid.Rows = 8
    End If
    
    '再添加搜索结果到findgrid表中
    Dim DB As ADO_connection
    Dim SQL As String
    Dim rs As ADODB.Recordset

    Set DB = New ADO_connection

    SQL = "select Student.Sno,Student.Sname,Student.Sroom,Student.Sdormitory,R_monitor,D_type,Dormitory.Wno,H_total from Student,Room,Dormitory,Health " + _
          "where Student.Sroom=Room.Sroom and Student.Sdormitory=Dormitory.Sdormitory and Student.Sroom=Health.Sroom and " + _
          "Student.Sno=" + "'" + Combo1.List(Combo1.ListIndex) + "'"
                 
    '查询出符合条件的记录集
    DB.ReadDB rs, SQL
    
    findgrid.Rows = findgrid.Rows - 7
    
    '逐条取记录集中的记录,直到记录取完为止
    While rs.EOF = False
        
        '为表findgrid添加1行
        findgrid.Rows = findgrid.Rows + 1
    
        '将一条记录的值赋给表中当前行的每个单元
        findgrid.TextMatrix(findgrid.Rows - 1, 0) = rs.Fields("Sno")
        findgrid.TextMatrix(findgrid.Rows - 1, 1) = rs.Fields("Sname")
        findgrid.TextMatrix(findgrid.Rows - 1, 2) = rs.Fields("Sroom")
        findgrid.TextMatrix(findgrid.Rows - 1, 3) = rs.Fields("Sdormitory")
        findgrid.TextMatrix(findgrid.Rows - 1, 4) = rs.Fields("R_monitor")
        findgrid.TextMatrix(findgrid.Rows - 1, 5) = rs.Fields("D_type")
        findgrid.TextMatrix(findgrid.Rows - 1, 6) = rs.Fields("Wno")
        findgrid.TextMatrix(findgrid.Rows - 1, 7) = rs.Fields("H_total")
        
        '取下一条记录
        rs.MoveNext
    Wend
    
    '保证表findgrid始终保持8行以上,以保持表界面的美观
    If findgrid.Rows < 8 Then
               findgrid.Rows = 8
    End If
    
    Combo1.Text = "      学号 "
End Sub

'设置界面上的初始值
Private Sub form_load()

    row = 1

'查询出s表中所有的学号值,并设置在combo1的下拉框中
    Dim DB As ADO_connection
    Dim SQL As String
    Dim rs As ADODB.Recordset

    Set DB = New ADO_connection

    SQL = "select Sno from Student"
    DB.ReadDB rs, SQL

    While rs.EOF = False
        '将一个学号值添加到combo1中
        Combo1.AddItem rs.Fields("Sno")
        '取下一个值
        rs.MoveNext
    Wend
       
   
    Set DB = Nothing
 '''''''''''''''''''''''''''''''''''''''''''''''''''''
       
    '设置表scgrid各单元格的宽度
        scgrid.ColWidth(0) = 1000
        scgrid.ColWidth(1) = 600
        scgrid.ColWidth(2) = 600
        scgrid.ColWidth(3) = 600
        scgrid.ColWidth(4) = 600
        scgrid.ColWidth(5) = 600
        scgrid.ColWidth(6) = 600
        scgrid.ColWidth(7) = 600
        scgrid.ColWidth(8) = 600
         scgrid.ColWidth(8) = 600
      
        
        
    '设置表scgrid各单元格的名称
        scgrid.TextMatrix(0, 0) = "学号"
        scgrid.TextMatrix(0, 1) = "姓名"
        scgrid.TextMatrix(0, 2) = "性别"
        scgrid.TextMatrix(0, 3) = "籍贯"
        scgrid.TextMatrix(0, 4) = "民族"
        scgrid.TextMatrix(0, 5) = "学院"
        scgrid.TextMatrix(0, 6) = "专业"
        scgrid.TextMatrix(0, 7) = "寝室号"
        scgrid.TextMatrix(0, 8) = "宿舍号"
        scgrid.TextMatrix(0, 9) = "生日"
      
     '设置表findgrid各单元格的宽度
        Dim i As Integer
        For i = 0 To 6
           findgrid.ColWidth(i) = 1000
        Next
        
                
      '设置表findgrid各单元格的名称
        findgrid.TextMatrix(0, 0) = "学号"
        findgrid.TextMatrix(0, 1) = "姓名"
        findgrid.TextMatrix(0, 2) = "寝室号"
        findgrid.TextMatrix(0, 3) = "宿舍号"
        findgrid.TextMatrix(0, 4) = "寝室长"
        findgrid.TextMatrix(0, 5) = "宿舍类型"
        findgrid.TextMatrix(0, 6) = "宿管工号"
        findgrid.TextMatrix(0, 7) = "卫生总评"
       
End Sub




⌨️ 快捷键说明

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