?? frmclass.frm
字號:
EndProperty
BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628}
Enabled = 0 'False
Caption = "保存"
Key = "btnSave"
ImageIndex = 8
EndProperty
BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628}
Enabled = 0 'False
Caption = "取消"
Key = "btnCancel"
ImageIndex = 9
EndProperty
BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628}
Caption = "退出"
Key = "btnExit"
ImageIndex = 10
EndProperty
EndProperty
Begin MSComctlLib.ImageList ImageList1
Left = 7440
Top = 0
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 16
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 10
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0457
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0569
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":067B
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":078D
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":089F
Key = ""
EndProperty
BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":09B1
Key = ""
EndProperty
BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0AC3
Key = ""
EndProperty
BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0BD5
Key = ""
EndProperty
BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0CE7
Key = ""
EndProperty
BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmClass.frx":0DF9
Key = ""
EndProperty
EndProperty
End
End
Begin VB.Label Label20
Caption = "班級簡稱"
Height = 255
Left = 7680
TabIndex = 21
Top = 4440
Width = 855
End
Begin VB.Label Label15
Caption = "班級名稱"
Height = 255
Left = 6120
TabIndex = 20
Top = 4440
Width = 975
End
Begin VB.Label Label14
Caption = "班主任"
Height = 255
Left = 4800
TabIndex = 19
Top = 4440
Width = 855
End
Begin VB.Label Label13
Caption = "人數"
Height = 255
Left = 3360
TabIndex = 18
Top = 4440
Width = 855
End
Begin VB.Label Label7
Caption = "年級"
Height = 255
Left = 1920
TabIndex = 17
Top = 4440
Width = 855
End
Begin VB.Label Label9
Caption = "班級編號"
Height = 255
Left = 120
TabIndex = 16
Top = 4440
Width = 975
End
End
Attribute VB_Name = "frmClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private bAdd As Boolean
Private Sub LoadData()
Dim strFilter As String
Dim db As New DataBases
Dim rs As Recordset
If Len(Trim(txbOne.Text)) = 0 Then
If Len(Trim(txbTwo.Text)) = 0 Then
If Len(Trim(txbThree.Text)) = 0 Then
strFilter = ""
Else
strFilter = "where 班級名稱 like '"
strFilter = strFilter + Trim(txbThree.Text) + "%'"
End If
Else
strFilter = "where 年級 like '"
strFilter = strFilter + Trim(txbTwo.Text) + "%'"
If Len(Trim(txbThree.Text)) <> 0 Then
strFilter = strFilter + " and 班級名稱 like '"
strFilter = strFilter + Trim(txbThree.Text) + "%'"
End If
End If
Else
strFilter = "where 班級編號 like '"
strFilter = strFilter + Trim(txbOne.Text) + "%'"
If Len(Trim(txbTwo.Text)) <> 0 Then
strFilter = strFilter + " and 年級 like '"
strFilter = strFilter + Trim(txbTwo.Text) + "%'"
If Len(Trim(txbThree.Text)) <> 0 Then
strFilter = strFilter + " and 班級名稱 like '"
strFilter = strFilter + Trim(txbThree.Text) + "%'"
End If
Else
If Len(Trim(txbThree.Text)) <> 0 Then
strFilter = strFilter + " and 班級名稱 like '"
strFilter = strFilter + Trim(txbThree.Text) + "%'"
End If
End If
End If
Set rs = db.RunSelectSQLUpdatable("select * from 班級信息 " + strFilter)
'根據查詢條件重新填充DataGrid
Set Adodc1.Recordset = rs
End Sub
Private Sub btnSearch_Click()
LoadData
End Sub
Private Sub Form_Load()
Dim db As New DataBases
Adodc1.ConnectionString = db.sConn
LoadData
SetTextBoxState (False)
End Sub
Private Sub SetToolBarState(ByVal bState As Boolean)
'設置Button的是否能夠單擊
Toolbar1.Buttons("btnFirst").Enabled = bState
Toolbar1.Buttons("btnBefore").Enabled = bState
Toolbar1.Buttons("btnNext").Enabled = bState
Toolbar1.Buttons("btnLast").Enabled = bState
Toolbar1.Buttons("btnNew").Enabled = bState
Toolbar1.Buttons("btnModify").Enabled = bState
Toolbar1.Buttons("btnDelete").Enabled = bState
Toolbar1.Buttons("btnSave").Enabled = Not bState
Toolbar1.Buttons("btnCancel").Enabled = Not bState
grdDataGrid.Enabled = bState
End Sub
Private Sub SetTextBoxState(ByVal bState As Boolean)
Me.txbClassId.Enabled = bState
Me.txbGrade.Enabled = bState
Me.txbNumber.Enabled = bState
Me.txbTeacher.Enabled = bState
Me.txbName.Enabled = bState
Me.txbShortName.Enabled = bState
End Sub
Private Sub Clear()
Me.txbClassId.Text = ""
Me.txbGrade.Text = ""
Me.txbNumber.Text = ""
Me.txbTeacher.Text = ""
Me.txbName.Text = ""
Me.txbShortName.Text = ""
End Sub
Private Sub SaveForUpdate()
Adodc1.Recordset.UpdateBatch adAffectAll
End Sub
Private Sub DeleteData()
Dim db As New DataBases
Dim strSQL As String
Dim rs As ADODB.Recordset
strSQL = "select 學號 from 學生信息 where 班級編號=" + txbClassId.Text
Set rs = db.RunSelectSQL(strSQL)
If rs.RecordCount = 0 Then
Adodc1.Recordset.Delete adAffectCurrent
Adodc1.Recordset.UpdateBatch adAffectAll
Else
Call MsgBox("有學生屬于這個班級,無法刪除", vbOKOnly)
End If
End Sub
Private Sub SaveForAdd()
Dim db As New DataBases
Dim strSQL As String
strSQL = "insert into 班級信息(班級編號, 年級, 班級名稱, 班級簡稱, 人數, 班主任) values ('"
strSQL = strSQL + Trim(txbClassId.Text) + "','"
strSQL = strSQL + Trim(txbGrade.Text) + "','"
strSQL = strSQL + Trim(txbName.Text) + "','"
strSQL = strSQL + Trim(txbShortName.Text) + "','"
strSQL = strSQL + Trim(txbNumber.Text) + "','"
strSQL = strSQL + Trim(txbTeacher.Text) + "')"
db.RunSelectSQL (strSQL)
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If StrComp(Button.Key, "btnFirst") = 0 Then
Adodc1.Recordset.MoveFirst
ElseIf StrComp(Button.Key, "btnBefore") = 0 Then
Adodc1.Recordset.MovePrevious
ElseIf StrComp(Button.Key, "btnNext") = 0 Then
Adodc1.Recordset.MoveNext
ElseIf StrComp(Button.Key, "btnLast") = 0 Then
Adodc1.Recordset.MoveLast
ElseIf StrComp(Button.Key, "btnNew") = 0 Then
bAdd = True
Adodc1.Recordset.AddNew
SetTextBoxState (True)
SetToolBarState (False)
Clear
ElseIf StrComp(Button.Key, "btnModify") = 0 Then
bAdd = False
SetTextBoxState (True)
SetToolBarState (False)
ElseIf StrComp(Button.Key, "btnDelete") = 0 Then
If MsgBox("確定要刪除嗎?", vbYesNo) = vbYes Then
DeleteData
End If
ElseIf StrComp(Button.Key, "btnSave") = 0 Then
SetTextBoxState (False)
SetToolBarState (True)
If bAdd = True Then
'為新增數據保存
SaveForAdd
Adodc1.Recordset.CancelUpdate
LoadData
Else
'為更新數據保存
SaveForUpdate
End If
ElseIf StrComp(Button.Key, "btnCancel") = 0 Then
SetTextBoxState (False)
SetToolBarState (True)
ElseIf StrComp(Button.Key, "btnExit") = 0 Then
Hide
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -