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

📄 frmteacher.frm

📁 VB做的排课
💻 FRM
📖 第 1 页 / 共 2 页
字号:
            Name            =   "楷体_GB2312"
            Size            =   15.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   525
         Left            =   3720
         MaskColor       =   &H00FFFF80&
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   5160
         Width           =   1575
      End
      Begin VB.CommandButton cmdfirst 
         BackColor       =   &H00FFC0C0&
         Caption         =   "第一个"
         BeginProperty Font 
            Name            =   "楷体_GB2312"
            Size            =   15.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   525
         Left            =   720
         MaskColor       =   &H00FF8080&
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   5160
         UseMaskColor    =   -1  'True
         Width           =   1575
      End
      Begin MSAdodcLib.Adodc Adodc1 
         Height          =   330
         Left            =   1440
         Top             =   240
         Visible         =   0   'False
         Width           =   1200
         _ExtentX        =   2117
         _ExtentY        =   582
         ConnectMode     =   0
         CursorLocation  =   3
         IsolationLevel  =   -1
         ConnectionTimeout=   15
         CommandTimeout  =   30
         CursorType      =   3
         LockType        =   3
         CommandType     =   1
         CursorOptions   =   0
         CacheSize       =   50
         MaxRecords      =   0
         BOFAction       =   0
         EOFAction       =   0
         ConnectStringType=   1
         Appearance      =   1
         BackColor       =   -2147483643
         ForeColor       =   -2147483640
         Orientation     =   0
         Enabled         =   -1
         Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Paike.mdb;Persist Security Info=False"
         OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Paike.mdb;Persist Security Info=False"
         OLEDBFile       =   ""
         DataSourceName  =   ""
         OtherAttributes =   ""
         UserName        =   ""
         Password        =   ""
         RecordSource    =   "select * from bTeacher order by teacherid"
         Caption         =   "Adodc1"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "宋体"
            Size            =   15.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _Version        =   393216
      End
      Begin VB.Label Label3 
         BackColor       =   &H00FFC0C0&
         Caption         =   "学院编号:"
         BeginProperty Font 
            Name            =   "楷体_GB2312"
            Size            =   21.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   495
         Left            =   600
         TabIndex        =   19
         Top             =   3240
         Width           =   3015
      End
      Begin VB.Label Label2 
         BackStyle       =   0  'Transparent
         Caption         =   "教师姓名:"
         BeginProperty Font 
            Name            =   "楷体_GB2312"
            Size            =   21.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   615
         Left            =   600
         TabIndex        =   14
         Top             =   2160
         Width           =   2775
      End
      Begin VB.Label Label1 
         BackStyle       =   0  'Transparent
         Caption         =   "教师编号:"
         BeginProperty Font 
            Name            =   "楷体_GB2312"
            Size            =   21.75
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   615
         Left            =   600
         TabIndex        =   13
         Top             =   1080
         Width           =   2775
      End
   End
End
Attribute VB_Name = "frmteacher"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim temp As New ADODB.Recordset
Dim db As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim strSQL1 As String


 '连接到数据库
Private Function ConenctToDatabase() As Boolean
  On Error GoTo ErrorHandler
  Dim DBName As String, ServerAdd As String, UserName As String, UserPwd As String
  '设置连接信息字符串的参数
  ServerAdd = "IMAGE"
  DBName = "Paike.mdb"
  UserName = ""
  UserPwd = ""
  '连接数据库
  Set db = New ADODB.Connection
  db.ConnectionTimeout = 10
  db.CursorLocation = adUseServer
 ' db.ConnectionString = "uid=" & UserName & ";pwd=" & UserPwd & _
                            ";driver={SQL Server};server=" & ServerAdd & _
                            ";database=" & DBName & ";dsn=''"
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & DBName
  db.Open
  '返回值
  ConenctToDatabase = True
  Exit Function
ErrorHandler:
  MsgBox "连接到数据库出错", vbCritical, "出现错误"
End Function

Private Sub Cmddelete_Click()
    rst.Delete
    rst.Requery

    If rst.RecordCount() = 0 Then
        clearfield
        hidebutton
        MsgBox "数据库中已经没有记录了!"
        Exit Sub
        
    End If
    rst.MoveNext
    If rst.EOF = True Then
        rst.MoveLast
    End If

       filltext
    
    Txteachid.SetFocus
    Adodc1.Refresh
End Sub

Private Sub Cmdexit_Click()
    db.Close
    Unload Me
    
    frmteacher.Hide
    frmmain.Show vbModal
    
End Sub

Private Sub cmdfind_Click()
    Dim findstr As String
    
    findstr = InputBox("请输入要查找的教师姓名:", "查找提示窗口")
    rst.find "teacherName='" & findstr & "'"
    If rst.EOF = True Then
        
        MsgBox "没有要查询的数据!"
        Exit Sub
        
    End If

    filltext
End Sub

Private Sub cmdfirst_Click()
    rst.MoveFirst
    filltext
End Sub

Private Sub Cmdlast_Click()
    rst.MoveLast
    filltext
End Sub

Private Sub Cmdmodify_Click()
    strSQL1 = "select teacherid from bteacher"
    If Txteachid.Text = "" Then
        MsgBox "请输入教师编号!"
        Txteachid.SetFocus
    Exit Sub
    End If

    
    If Txteachname.Text = "" Then
        MsgBox "请输入教师姓名!"
        Txteachname.SetFocus
        Exit Sub
    End If
    
    If Combo1.Text = "" Then
        MsgBox "请输入容纳人数!"
        Combo1.SetFocus
        Exit Sub
    End If

   rst.Fields("teacherid") = Txteachid.Text
   rst.Fields("teachername") = Txteachname.Text
   rst.Fields("DepID") = TxtDepid.Text
   rst.Update
   
   Adodc1.Refresh
    End Sub

Private Sub Cmdnext_Click()
    rst.MoveNext
    If rst.EOF Then
      MsgBox "这是最后一个记录了!"
      rst.MoveLast
    End If
    filltext
End Sub

Private Sub Cmdprevious_Click()
    rst.MovePrevious
    If rst.BOF Then
        MsgBox "这是第一个记录了!"
        rst.MoveFirst
    End If
    filltext
End Sub






Private Sub Cmdadd_Click()
    Dim strSQL1 As String
    strSQL1 = "select * from bteacher"
    
    If Txteachid.Text = "" Then
        MsgBox "请输入教师编号!"
        Txteachid.SetFocus
        Exit Sub
        
    End If
    
    temp.Open strSQL1, db, adOpenKeyset, adLockOptimistic
   
   temp.Filter = "teacherid='" & Txteachid.Text & "'"
   temp.Requery
   If temp.RecordCount <> 0 Then
      MsgBox ("这个教师编号已存在,您输入的信息不能被保存!")
      temp.Close
      Exit Sub
   End If
   temp.Close
   If rst.RecordCount() <> 0 Then
      rst.MoveLast
   End If
   rst.AddNew
    

    
    If Txteachname.Text = "" Then
        MsgBox "请输入教师姓名!"
        Txteachname.SetFocus
        Exit Sub
    End If
    
    If Combo1.Text = "" Then
        MsgBox "请输入容纳人数!"
        Combo1.SetFocus
        Exit Sub
    End If
    
    
   rst.Fields("teacherid") = Txteachid.Text
   rst.Fields("teachername") = Txteachname.Text
   rst.Fields("depID") = TxtDepid.Text
  
   rst.Update
   rst.Requery
   Adodc1.Refresh
   
    Txteachid.SetFocus
 End Sub



Private Sub Command1_Click()
clearfield
Txteachid.SetFocus
End Sub

Private Sub DataGrid1_Click()

Txteachid.Text = DataGrid1.Columns(0).Text
Txteachname.Text = DataGrid1.Columns(1).Text
TxtDepid.Text = DataGrid1.Columns(2).Text
End Sub

Private Sub Form_Activate()
    rst.Requery
    If rst.RecordCount() = 0 Then
        clearfield
        hidebutton
    Else
        showbutton
        rst.MoveFirst
        filltext
    End If
    
    Txteachid.SetFocus

End Sub

Public Sub filltext()
    Txteachid.Text = rst.Fields("teacherid")
    Txteachname.Text = rst.Fields("teachername")
    TxtDepid.Text = rst.Fields("depID")

End Sub

Public Sub clearfield()
    Txteachid.Text = ""
    Txteachname.Text = ""
  
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Paike.mdb;Persist Security Info=False"
    
    strSQL = "SELECT * FROM bTeacher"
    ConenctToDatabase
    rst.Open strSQL, db, adOpenKeyset, adLockOptimistic
    
    If rst.RecordCount() = 0 Then
        clearfield
        hidebutton
    Else
        showbutton
        rst.MoveFirst
        filltext
    End If
   
    
End Sub





Private Sub Txteachid_GotFocus()
    
    rst.Requery
    Adodc1.Refresh
    
    If rst.RecordCount <> 0 Then
        showbutton
    Else
        hidebutton
    End If
End Sub

Public Sub hidebutton()
     Cmddelete.Enabled = False
     Cmdnext.Enabled = False
     cmdfind.Enabled = False
     cmdfirst.Enabled = False
     Cmdlast.Enabled = False
     Cmdmodify.Enabled = False
     Cmdprevious.Enabled = False
End Sub

Public Sub showbutton()
    Cmddelete.Enabled = True
     Cmdnext.Enabled = True
     cmdfind.Enabled = True
     cmdfirst.Enabled = True
     Cmdlast.Enabled = True
     Cmdmodify.Enabled = True
     Cmdprevious.Enabled = True
End Sub

⌨️ 快捷键说明

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