📄 frmcourses.frm
字号:
BackColor = &H00E0E0E0&
FillColor = &H008080FF&
ForeColor = &H80000008&
Height = 375
Left = 150
ScaleHeight = 345
ScaleWidth = 6735
TabIndex = 14
Top = 600
Visible = 0 'False
Width = 6765
Begin VB.PictureBox picStatBox
Appearance = 0 'Flat
BackColor = &H00E0E0E0&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 300
Left = 90
ScaleHeight = 300
ScaleWidth = 7995
TabIndex = 15
Top = 30
Width = 7995
Begin VB.CommandButton cmdLast
BackColor = &H00C0C0C0&
Height = 300
Left = 6195
Style = 1 'Graphical
TabIndex = 19
Top = 0
UseMaskColor = -1 'True
Width = 345
End
Begin VB.CommandButton cmdNext
BackColor = &H00C0C0C0&
Height = 300
Left = 3840
Style = 1 'Graphical
TabIndex = 18
Top = 0
UseMaskColor = -1 'True
Width = 345
End
Begin VB.CommandButton cmdPrevious
BackColor = &H00C0C0C0&
Height = 300
Left = 345
Style = 1 'Graphical
TabIndex = 17
Top = 0
UseMaskColor = -1 'True
Width = 345
End
Begin VB.CommandButton cmdFirst
BackColor = &H00C0C0C0&
Height = 300
Left = 0
Style = 1 'Graphical
TabIndex = 16
Top = 0
UseMaskColor = -1 'True
Width = 345
End
Begin VB.Label lblStatus
Alignment = 2 'Center
BackColor = &H00FFFFFF&
BorderStyle = 1 'Fixed Single
Height = 285
Left = 690
TabIndex = 20
Top = 0
Width = 5115
End
End
End
End
Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grid
Height = 2985
Left = -74880
TabIndex = 11
Top = 570
Width = 6675
_ExtentX = 11774
_ExtentY = 5265
_Version = 393216
Rows = 3
Cols = 6
FixedCols = 0
WordWrap = -1 'True
FocusRect = 2
SelectionMode = 1
AllowUserResizing= 3
BeginProperty FontFixed {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_NumberOfBands = 1
_Band(0).Cols = 6
_Band(0).GridLinesBand= 2
_Band(0).TextStyleBand= 0
_Band(0).TextStyleHeader= 0
End
End
End
Attribute VB_Name = "frmCourses"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim WithEvents Rs As ADODB.Recordset
Attribute Rs.VB_VarHelpID = -1
Dim rsgrid As New ADODB.Recordset
Dim RsCombo As New ADODB.Recordset
Private Sub cmdback_Click()
Rs.MovePrevious
If Rs.BOF Then
MsgBox ("First Record"), vbInformation
Rs.MoveFirst
End If
End Sub
Private Sub cmdnexts_Click()
Rs.MoveNext
If Rs.EOF Then
MsgBox ("Last Record"), vbInformation
Rs.MoveLast
End If
End Sub
Private Sub cmdSave_Click()
On Error GoTo 1
If T(0).Text = "" Then
MsgBox "COURSE NAME CAN'T BE EMPTIED", vbInformation, App.Comments
T(0).SetFocus
Exit Sub
End If
If T(2).Text = "" Or Not IsNumeric(T(2).Text) Then
MsgBox "Sections FIELD CAN'T BE EMPTIED OR CAN'T BE NON-NUMERIC", vbInformation, App.Comments
T(2).SetFocus
Exit Sub
End If
Rs.UpdateBatch adAffectCurrent
DisableButtons
SetGridData
Exit Sub
1:
MsgBox Err.Description, vbInformation, App.Comments
End Sub
Private Sub Form_Load()
Dither Me
Set Rs = New ADODB.Recordset
If Rs.State = 1 Then Rs.Close
Rs.CursorLocation = adUseClient
Rs.Open "course", frmMain.Cn, adOpenKeyset, adLockOptimistic
SetDataSources
SetGridData
For i = 0 To Rs.Fields.Count - 1
Grid.ColWidth(i) = GetSetting(App.EXEName, "Grid3", "grid3" & i, 1200)
Next
LoadInCombo
End Sub
Private Sub cmdDelete_Click()
If Rs.RecordCount = 1 Then MsgBox "CAN'T BE DELETED,BECAUSE IT IS ONLY RECORD IN DATABASE", vbInformation, App.Comments: Exit Sub
N = MsgBox("Are You sure you want to delete the record", vbYesNo + vbInformation, App.Comments)
If N = vbYes Then
Rs.Delete adAffectCurrent
Rs.Requery
End If
SetGridData
End Sub
Private Sub cmdEdit_Click()
EnableButtons
lblStatus.Caption = "Editing Record....."
T(0).SetFocus
End Sub
Private Sub cmdFind_Click()
Rs.Requery
U = InputBox("Enter the ID which you want to search")
Rs.Find "COURSE_id=" & Val(U), 0, adSearchForward, 1
If Rs.EOF Or Rs.BOF Then
Rs.Requery
MsgBox "No match Found...", vbInformation, App.Comments
End If
End Sub
Private Sub cmdAddNew_Click()
If Not Rs.EOF Or Not Rs.BOF Then
Mv = Rs.Bookmark
End If
EnableButtons
If (Rs.EOF And Rs.BOF) Then
AutoNumber = 1
Else
Rs.MoveLast
AutoNumber = Rs!Course_id
End If
Rs.AddNew
lblSub_ID.Caption = AutoNumber + 1
T(0).SetFocus
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
Rs.CancelUpdate
If Mv > 0 Then
Rs.Bookmark = Mv
Else
Rs.Requery
End If
DisableButtons
End Sub
Public Sub SetGridData()
If rsgrid.State = 1 Then rsgrid.Close
rsgrid.CursorLocation = adUseClient
rsgrid.Open "select Course_id as [COURSE CODE], course_name as [COURSE NAME],DESCRIPTION,Sections FROM COURSE", _
frmMain.Cn, adOpenDynamic, adLockOptimistic
Set Grid.DataSource = rsgrid
Grid.Refresh
End Sub
Public Sub SetDataSources()
Dim j As Control
For Each j In frmCourses
If TypeOf j Is TextBox Then
Set j.DataSource = Rs
ElseIf TypeOf j Is DTPicker Then
Set j.DataSource = Rs
End If
Next
Set lblSub_ID.DataSource = Rs
lblSub_ID.DataField = "course_ID"
T(0).DataField = "course_NAME"
T(1).DataField = "DESCRIPTION"
T(2).DataField = "Sections"
End Sub
Public Sub EnableButtons()
cmdAddNew.Enabled = False
cmdEdit.Enabled = False
cmdDelete.Enabled = False
cmdFind.Enabled = False
cmdCancel.Enabled = True
cmdSave.Enabled = True
cmdNext.Enabled = False
cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdPrevious.Enabled = False
' this will enable all text boxes
Dim K As Control
For Each K In frmCourses
If TypeOf K Is TextBox Then
K.Enabled = True
ElseIf TypeOf K Is DataCombo Then
K.Enabled = True
ElseIf TypeOf K Is DTPicker Then
K.Enabled = True
ElseIf TypeOf K Is ComboBox Then
K.Enabled = True
End If
Next
cmbCourseType.Enabled = True
End Sub
Public Sub DisableButtons()
cmdAddNew.Enabled = True
cmdEdit.Enabled = True
cmdDelete.Enabled = True
cmdFind.Enabled = True
cmdCancel.Enabled = False
cmdSave.Enabled = False
cmdNext.Enabled = True
cmdFirst.Enabled = True
cmdLast.Enabled = True
cmdPrevious.Enabled = True
Dim K As Control
For Each K In frmCourses
If TypeOf K Is TextBox Then
K.Enabled = False
ElseIf TypeOf K Is DataCombo Then
K.Enabled = False
ElseIf TypeOf K Is DTPicker Then
K.Enabled = False
ElseIf TypeOf K Is ComboBox Then
K.Enabled = False
End If
Next
cmbCourseType.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
For i = 0 To 3
SaveSetting App.EXEName, "Grid3", "grid3" & i, Grid.ColWidth(i)
Next
If frm2 = 1 Then
frmResult.ShowCourses
End If
If frm1 = 1 Then
frmSubject.ShowCourses
End If
End Sub
Private Sub Grid_DblClick()
Rs.Requery
ST.Tab = 0
H = Grid.TextMatrix(Grid.Row, 0)
Rs.Find "course_id= " & H, 1, adSearchForward, 1
If Rs.EOF Then
Rs.Requery
End If
End Sub
Private Sub Grid_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Grid_DblClick
End If
End Sub
Public Sub LoadInCombo()
With RsCombo
If .State = 1 Then .Close
.CursorLocation = adUseClient
' .Open "COURSEtype", frmMain.Cn, adOpenDynamic, adLockOptimistic
End With
With cmbCourseType
Set .DataSource = Rs
Set .RowSource = RsCombo
' .ListField = RsCombo(1).Name
' .BoundColumn = RsCombo(0).Name
' .DataField = Rs("type_ID").Name
End With
End Sub
Private Sub Label2_Click()
Unload frmCourses
End Sub
Private Sub T_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 32 And T(Index).Text = "" Then
MsgBox "Starting Space Are Not Allow Please Enter Correct Data "
T(Index).SelStart = 0
T(Index).Text = Trim(T(Index).Text)
Else
If Index > 1 And KeyCode = 13 Then
'T(Index + 1).SetFocus
SendKeys "{TAB}"
End If
End If
End Sub
Private Sub T_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
If Index = 2 And KeyAscii <> 13 Then
ChkNumericDigit KeyAscii
End If
If Index = 0 Or Index = 1 Then
If KeyAscii <> 8 And KeyAscii <> 32 And KeyAscii <> 46 And KeyAscii <> 45 Then
If KeyAscii < 65 Or (KeyAscii > 90 And KeyAscii < 97) Then KeyAscii = 0
If KeyAscii > 122 Then KeyAscii = 0
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -