?? form_course.frm
字號:
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Begin VB.Form Form_course
Caption = "課程表"
ClientHeight = 6255
ClientLeft = 60
ClientTop = 450
ClientWidth = 8295
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6255
ScaleWidth = 8295
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame_sou_botton
Height = 855
Left = 120
TabIndex = 8
Top = 5280
Width = 8055
Begin VB.CommandButton return
Caption = "返 回"
Height = 375
Left = 6600
TabIndex = 14
Top = 240
Width = 1215
End
Begin VB.CommandButton del
Caption = "刪 除"
Height = 375
Left = 5040
TabIndex = 13
Top = 240
Width = 975
End
Begin VB.CommandButton cancel
Caption = "取 消"
Height = 375
Left = 3840
TabIndex = 12
Top = 240
Width = 975
End
Begin VB.CommandButton save
Caption = "保 存"
Height = 375
Left = 2640
TabIndex = 11
Top = 240
Width = 975
End
Begin VB.CommandButton updata
Caption = "修 改"
Height = 375
Left = 1440
TabIndex = 10
Top = 240
Width = 975
End
Begin VB.CommandButton add
Caption = "添 加"
Height = 375
Left = 240
TabIndex = 9
Top = 240
Width = 975
End
End
Begin VB.Frame Frame_sou
Height = 5055
Left = 120
TabIndex = 0
Top = 120
Width = 8055
Begin VB.TextBox Text10
DataField = "課程號"
DataSource = "Data_sour"
Height = 375
Left = 1320
TabIndex = 3
Top = 240
Width = 855
End
Begin VB.TextBox Text11
DataField = "課程名稱"
DataSource = "Data_sour"
Height = 375
Left = 3360
TabIndex = 2
Top = 240
Width = 1815
End
Begin VB.TextBox Text12
DataField = "任課老師"
DataSource = "Data_sour"
Height = 375
Left = 6360
TabIndex = 1
Top = 240
Width = 1335
End
Begin VB.Data Data_sour
Caption = "課程表"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 '缺省游標
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 375
Left = 2400
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "課程表"
Top = 2040
Visible = 0 'False
Width = 2655
End
Begin MSDBGrid.DBGrid DBGrid1
Bindings = "Form_course.frx":0000
Height = 3975
Left = 240
OleObjectBlob = "Form_course.frx":0018
TabIndex = 4
Top = 840
Width = 7575
End
Begin VB.Label Label10
Caption = "課程代號:"
Height = 255
Left = 360
TabIndex = 7
Top = 360
Width = 975
End
Begin VB.Label Label11
Caption = "課程名稱:"
Height = 255
Left = 2400
TabIndex = 6
Top = 360
Width = 975
End
Begin VB.Label Label12
Caption = "任課老師:"
Height = 255
Left = 5400
TabIndex = 5
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "Form_course"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'======================= 初始化 =================================
Private Sub Form_Load()
saveoff
openbook App.Path & "\MDB\成績管理.mdb" '鏈接數據庫:必須把數據庫放在同級文件夾MDB中
End Sub
Public Sub openbook(filename As String)
Data_sour.DatabaseName = filename
Data_sour.RecordSource = "課程表"
Data_sour.Refresh
End Sub
'===============================================================
'===================== 對數據的基本操作 ========================
Private Sub add_Click() '添加記錄
saveok
Data_sour.Recordset.AddNew
End Sub
Private Sub cancel_Click() '取消更新
On Error Resume Next
saveoff
Data_sour.Recordset.CancelUpdate
End Sub
Private Sub del_Click() '刪除記錄
On Error Resume Next
Dim sel As String
sel = MsgBox("確定要刪除這條信息嗎?", vbInformation + vbOKCancel, "詢問")
If sel = 1 Then
BeginTrans
Data_sour.Recordset.Delete
CommitTrans
Data_sour.Refresh
If Data_sour.Recordset.Fields(0) = "" Then
sel = MsgBox("對不起學生表中已經沒有信息了!!", vbInformation + vbOKOnly, "數據庫信息") '如果表為空的話,彈出窗口來提示
End If
End If
End Sub
Private Sub save_Click() '保存記錄
saveoff
On Error Resume Next
BeginTrans
Data_sour.Recordset.update
CommitTrans
Data_sour.Refresh
End Sub
Private Sub updata_Click() '修改記錄
saveok
Data_sour.Recordset.edit
End Sub
'================================================================
'======================= 返回主界面 =================================
Private Sub return_Click()
main.Visible = True
Form_course.Visible = False
End Sub
'===============================================================
' ======================= 公共子程序 =======================
Public Sub saveoff() '讓各個顯示記錄的控件處于不可編輯的鎖定狀態
Text10.Locked = True
Text10.BackColor = &H8000000F
Text11.Locked = True
Text11.BackColor = &H8000000F '控件的背景色為灰色
Text12.Locked = True
Text12.BackColor = &H8000000F
DBGrid1.AllowAddNew = False
DBGrid1.AllowArrows = False '各個Dbgrid控件處于不可修改狀態
DBGrid1.AllowDelete = False
DBGrid1.AllowUpdate = False
End Sub
Public Sub saveok() '讓各個顯示記錄的控件處于可編輯的非鎖定狀態
Text10.Locked = False
Text10.BackColor = &H80000005
Text11.Locked = False
Text11.BackColor = &H80000005 '控件的背景色為白色
Text12Locked = False
Text12.BackColor = &H80000005
DBGrid1.AllowAddNew = True '各個Dbgrid控件處于可修改狀態
DBGrid1.AllowArrows = True
DBGrid1.AllowDelete = True
DBGrid1.AllowUpdate = True
End Sub
'================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -