?? form1.frm
字號(hào):
Next
Grid2.Visible = False
Call c1_Click(0)
Exit Sub
finish:
MsgBox Err.Description
End Sub
Private Sub Grid2_CellChange(ByVal Row As Long, ByVal Col As Long) '使用智能輸入
If Grid2.Cell(Row, 1).Text <> "" And Row <> 0 Then
Dim length1, length2 As Integer
length1 = Len(Grid2.Cell(Row, 1).Text)
Do While length2 < length1
length2 = length2 + 1
If Right(Left(Grid2.Cell(Row, 1).Text, length2), 1) = "-" Then
Grid2.Cell(Row, 2).Text = Mid(Grid2.Cell(Row, 1).Text, length2 + 1, length1)
Grid2.Cell(Row, 1).Text = Mid(Grid2.Cell(Row, 1).Text, 1, length2 - 1)
Exit Do
End If
Loop
End If
If Grid2.Cell(Row, 3).Text <> "" And Row <> 0 Then
Dim length3, length4 As Integer
length3 = Len(Grid2.Cell(Row, 3).Text)
Do While length4 < length3
length4 = length4 + 1
If Right(Left(Grid2.Cell(Row, 3).Text, length4), 1) = "-" Then
Grid2.Cell(Row, 4).Text = Mid(Grid2.Cell(Row, 3).Text, length4 + 1, length4)
Grid2.Cell(Row, 3).Text = Mid(Grid2.Cell(Row, 3).Text, 1, length4 - 1)
Exit Do
End If
Loop
End If
End Sub
Private Sub Grid2_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 2 Then
If admin = False Then
cgedit.Enabled = False
cgdel.Enabled = False
addcg.Enabled = False
End If
PopupMenu cg
End If
End Sub
Private Sub Grid2_RowColChange(ByVal Row As Long, ByVal Col As Long)
hang = Row
End Sub
Private Sub datagrid()
griddelete = True '允許刪除
gridedit = True
If tkbase = "學(xué)生信息" Then
If qy1.State = adStateOpen Then '表狀態(tài)
qy1.Close
End If
qy1.Open sql, cnn, adOpenStatic, adLockReadOnly, adCmdText
For i = 1 To fnumber
Grid1.Cell(0, i).Text = qy1.Fields(i - 1).Name
Next
qy1.PageSize = 20
nnum = qy1.PageCount
If qy1.PageCount = 0 Then
nnum = 1
End If
numpage = 1
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Grid1.Rows = 1
Grid1.Rows = 21
If qy1.RecordCount = 0 Then
Exit Sub
End If
qy1.AbsolutePage = numpage
For i = 1 To qy1.PageSize '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.EOF = True Then
Exit Sub
End If
If Not qy1.Fields(j - 1) Is Nothing Then '空值的處理
Grid1.Cell(i, j).Text = qy1.Fields(j - 1)
Else
Grid1.Cell(i, j).Text = ""
End If
Next
If qy1.EOF = False Then
qy1.MoveNext '讀取下一記錄
Else
Exit Sub
End If
Next
ElseIf tkbase = "學(xué)生與課程" Then
If qy1.State = adStateOpen Then '表狀態(tài)
qy1.Close
End If
qy1.Open sql, cnn, adOpenStatic, adLockReadOnly, adCmdText
For i = 1 To fnumber
Grid2.Cell(0, i).Text = qy1.Fields(i - 1).Name
Next
qy1.PageSize = 20
nnum = qy1.PageCount
If qy1.PageCount = 0 Then
nnum = 1
End If
numpage = 1
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Grid2.Rows = 1
Grid2.Rows = 21
If qy1.RecordCount = 0 Then
Exit Sub
End If
qy1.AbsolutePage = numpage
For i = 1 To qy1.PageSize '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.EOF = True Then
Exit Sub
End If
If Not qy1.Fields(j - 1) Is Nothing Then '空值的處理
Grid2.Cell(i, j).Text = qy1.Fields(j - 1)
Else
Grid2.Cell(i, j).Text = ""
End If
Next
If qy1.EOF = False Then
qy1.MoveNext '讀取下一記錄
Else
Exit Sub
End If
Next
End If
End Sub
Private Sub Grid2_Validate(Cancel As Boolean)
Dim nActiveRow As Long, nActiveCol As Long
Const VK_TAB = 9
If GetKeyState(VK_TAB) < 0 Then
nActiveRow = Grid1.ActiveCell.Row
nActiveCol = Grid1.ActiveCell.Col
If nActiveCol < Grid1.Cols - 1 Then
Grid1.Range(nActiveRow, nActiveCol + 1, _
nActiveRow, nActiveCol + 1).Selected
End If
Cancel = True
End If
End Sub
Private Sub Label7_Click()
If tkbase = "學(xué)生信息" Then
If numpage > 1 Then
numpage = numpage - 1
qy1.AbsolutePage = numpage
Grid1.Rows = 1
Grid1.Rows = 21
For i = 1 To 20 '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.Fields(j - 1) = Null Then '空值的處理
Grid1.Cell(i, j).Text = ""
Else
Grid1.Cell(i, j).Text = qy1.Fields(j - 1)
End If
Next
qy1.MoveNext '讀取上一記錄
Next
End If
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
ElseIf tkbase = "學(xué)生與課程" Then
If numpage > 1 Then
numpage = numpage - 1
qy1.AbsolutePage = numpage
Grid2.Rows = 1
Grid2.Rows = 21
For i = 1 To 20 '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.Fields(j - 1) = Null Then '空值的處理
Grid2.Cell(i, j).Text = ""
Else
Grid2.Cell(i, j).Text = qy1.Fields(j - 1)
End If
Next
qy1.MoveNext '讀取上一記錄
Next
End If
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
End If
End Sub
Private Sub Label8_Click()
If tkbase = "學(xué)生信息" Then
If numpage < nnum Then
numpage = numpage + 1
qy1.AbsolutePage = numpage
Grid1.Rows = 1
Grid1.Rows = 21
For i = 1 To 20 '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.EOF = True Then
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Exit Sub
End If
If qy1.Fields(j - 1) = Null Then '空值的處理
Grid1.Cell(i, j).Text = ""
Else
Grid1.Cell(i, j).Text = qy1.Fields(j - 1)
End If
Next
If qy1.EOF = False Then
qy1.MoveNext '讀取下一記錄
Else
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Exit Sub
End If
Next
End If
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
ElseIf tkbase = "學(xué)生與課程" Then
If numpage < nnum Then
numpage = numpage + 1
qy1.AbsolutePage = numpage
Grid2.Rows = 1
Grid2.Rows = 21
For i = 1 To 20 '設(shè)定讀取行
For j = 1 To fnumber '設(shè)定讀取列
If qy1.EOF = True Then
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Exit Sub
End If
If qy1.Fields(j - 1) = Null Then '空值的處理
Grid2.Cell(i, j).Text = ""
Else
Grid2.Cell(i, j).Text = qy1.Fields(j - 1)
End If
Next
If qy1.EOF = False Then
qy1.MoveNext '讀取下一記錄
Else
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
Exit Sub
End If
Next
End If
Label1.Caption = "共" & nnum & "頁 第" & numpage & "頁"
End If
End Sub
Private Sub pcg_Click()
If hang <> 0 Then
If Grid2.Cell(hang, 2).Text <> "" Then
sql = "select sum(成績(jī))/count(成績(jī)) from 學(xué)生與課程 where 學(xué)號(hào)='" & Grid2.Cell(hang, 3).Text & "'"
Set qy2 = cnn.Execute(sql)
MsgBox "學(xué)號(hào)為" & Grid2.Cell(hang, 3).Text & "的成績(jī)平均為" & qy2.Fields(0) & "分"
End If
End If
End Sub
Private Sub renovate_Click()
Call asPopup1_Click(False)
End Sub
Private Sub returncg_Click()
Grid1.Visible = True
Grid2.Visible = False
End Sub
Private Sub savestudent_Click()
Call XPButton5_Click
End Sub
Private Sub sclass_Click()
If hang <> 0 Then
Set qy2 = cnn.Execute("select 班級(jí) from 學(xué)生信息 where 學(xué)號(hào)='" & Grid2.Cell(hang, 3).Text & "'")
If qy2.EOF = False Then
MsgBox "學(xué)生" & Grid2.Cell(hang, 4).Text & "所屬班級(jí)是" & qy2.Fields(0)
End If
End If
End Sub
Private Sub XPButton13_Click()
Call XPButton3_Click
Select Case tkbase
Case "學(xué)生信息"
Grid1.Visible = True
Grid2.Visible = False
fnumber = 13
grid1pz '執(zhí)行g(shù)rid1的分配空間任務(wù)
datagrid '按要求讀取數(shù)據(jù)空間
Case "學(xué)生與課程"
Grid1.Visible = False
Grid2.Visible = True
fnumber = 6
gridpz2
datagrid
gridsave = False
gridedit = True
griddel = True
Grid2.Column(1).Locked = True
Grid2.Column(2).Locked = True
Grid2.Column(3).Locked = True
End Select
Frame2.Visible = False
End Sub
Private Sub XPButton14_Click()
Frame2.Visible = False
End Sub
Private Sub XPButton3_Click()
tkbase = Combo1.Text
If Combo1.Text = "" Then
MsgBox "未選擇對(duì)象!", vbInformation, "提示"
Exit Sub
ElseIf Text1.Text = "" Then
sql = "select * from " & Combo1.Text
ElseIf Text1.Text <> "" Then
sql = "select * from " & Combo1.Text & " where " & Text1.Text
End If
Label5.Caption = sql
End Sub
Private Sub XPButton4_Click()
On Error GoTo tkFinish
If gridedit = False Then
MsgBox "當(dāng)前修改操作不被允許!", vbInformation, "非使用對(duì)象"
Exit Sub
End If
Dim delok As String
Select Case tkbase
Case "學(xué)生信息"
delok = MsgBox("確認(rèn)修改剛才修改的所有數(shù)據(jù)嗎??", vbQuestion + vbOKCancel, "提示")
If delok = vbOK Then
hang = 1
Do While hang < Grid1.Rows - 1
If Grid1.Cell(hang, 1).Text = "" Then
MsgBox "己完成修改操作!", , "提示"
Exit Sub
End If
sql = "update " & tkbase & " set "
For j = 2 To fnumber - 1
sql = sql & qy1.Fields(j - 1).Name & "='" & Grid1.Cell(hang, j).Text & "',"
Next
sql = sql & qy1.Fields(j - 1).Name & "='" & Grid1.Cell(hang, j).Text & "' where " & qy1.Fields(0).Name & "='" & Grid1.Cell(hang, 1).Text & "'"
Set qy2 = cnn.Execute(sql) '用qy2更新數(shù)據(jù)集,這樣可實(shí)現(xiàn)批量更新
hang = hang + 1
Loop
MsgBox "己完成修改操作!", , "提示"
End If
Case "學(xué)生與課程"
delok = MsgBox("確認(rèn)提交當(dāng)前成績(jī)的修改嗎??", vbQuestion + vbOKCancel, "提示")
If delok = vbOK Then
hang = 1
Do While hang < Grid2.Rows - 1
If Grid2.Cell(hang, 1).Text = "" Then
MsgBox "己完成修改操作!", , "提示"
Exit Sub
End If
sql = "update " & tkbase & " set "
For j = 2 To fnumber - 1
sql = sql & qy1.Fields(j - 1).Name & "='" & Grid2.Cell(hang, j).Text & "',"
Next
sql = sql & qy1.Fields(j - 1).Name & "='" & Grid2.Cell(hang, j).Text & "' where " & qy1.Fields(0).Name & "='" & Grid2.Cell(hang, 1).Text & "' and " & qy1.Fields(1).Name & "='" & Grid2.Cell(hang, 2).Text & "'"
Set qy2 = cnn.Execute(sql)
hang = hang + 1
Loop
MsgBox "己完成修改操作!", , "提示"
End If
End Select
Exit Sub
tkFinish:
MsgBox Err.Description
End Sub
Private Sub XPButton5_Click()
On Error GoTo tkFinish
If tkbase = "" Then
MsgBox "表指向不明,請(qǐng)確認(rèn)", vbInformation, "提示"
Exit Sub
End If
If gridsave = False Then
MsgBox "當(dāng)前不允許保存!", vbInformation, "提示"
Exit Sub
End If
Select Case tkbase
Case "學(xué)生信息"
For i = 1 To 20 '處理重名數(shù)據(jù)
If Grid1.Cell(i, 1).Text <> "" Then
Set qy1 = cnn.Execute("select 學(xué)號(hào) from 學(xué)生信息 where 學(xué)號(hào)='" & Grid1.Cell(i, 1).Text & "'")
If qy1.EOF = False Then
MsgBox "第" & i & "行的學(xué)號(hào)在數(shù)據(jù)庫里出現(xiàn)重復(fù),請(qǐng)檢查", vbInformation, "錯(cuò)誤"
Grid1.Cell(i, 1).SetFocus
Exit Sub
End If
End If
Next
For i = 1 To 20
For n = 1 To fnumber
Select Case n
Case 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 '檢查數(shù)據(jù)是否為空
If Grid1.Cell(i, 1).Text <> "" Then
If Grid1.Cell(i, n).Text = "" Then
MsgBox "第" & i & "行的--[" & Grid1.Cell(0, n).Text & "]--字段不允許為空!", vbInformation, "提示"
Grid1.Cell(i, n).SetFocus
Exit Sub
End If
End If
End Select
Next
If Grid1.Cell(i, 1).Text <> "" Then '執(zhí)行插入語句
sql = "insert into " & tkbase & " values('"
For j = 1 To fnumber - 1
sql = sql & Grid1.Cell(i, j).Text & "','"
Next
sql = sql & Grid1.Cell(i, fnumber).Text & "')"
Set qy1 = cnn.Execute(sql)
End If
Next
MsgBox "命令執(zhí)行完畢!", vbInformation, "完成"
Grid1.Rows = 1
Grid1.Rows = 21
Case "學(xué)生與課程"
MsgBox "未授權(quán)版本,學(xué)生與課程的保存代碼未執(zhí)行,聯(lián)系:QQ342483870!"
End Select
gridsave = False
griddelete = False '拒絕刪除
gridedit = False
Exit Sub
tkFinish:
MsgBox Err.Description
End Sub
Private Sub XPButton6_Click()
On Error GoTo tkFinish
MsgBox "未授權(quán)版本,不支持目標(biāo)刪除操作!", , "提示"
Exit Sub
tkFinish:
MsgBox Err.Description
End Sub
Private Sub XPButton8_Click(Index As Integer)
Call findcg_Click
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -