📄 borrow.frm
字号:
datPrimaryRS.Open sSQL, tsdata.db, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datPrimaryRS
With MSHFlexGrid1
.Redraw = False
' 设置网格列宽度
.ColWidth(0) = -1
.ColWidth(1) = -1
.ColWidth(2) = -1
.ColWidth(3) = -1
.ColWidth(4) = -1
.ColWidth(5) = -1
' 设置网格样式
.AllowBigSelection = True
.FillStyle = flexFillRepeat
' 将标头作成粗体
.Row = 0
.Col = 0
.RowSel = .FixedRows - 1
.ColSel = .Cols - 1
.CellFontBold = True
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
' .FormatString = "图书编号|图书名称|图书类别|借阅人|借出时间|备注"
End With
End Sub
Private Sub CmdExit_Click()
Unload Me
End Sub
Private Sub CmdLook_Click()
If Text1.Text = "" Then
MsgBox "请输入你的查询条件!", vbOKOnly, "提醒"
Exit Sub
End If
If Option1(0).Value = True Then
Condi_Conn 1
ElseIf Option1(1).Value = True Then
Condi_Conn 2
ElseIf Option1(2).Value = True Then
Condi_Conn 3
ElseIf Option1(3).Value = True Then
Condi_Conn 4
End If
End Sub
Private Sub Command2_Click()
BorrowAll_Conn 3
End Sub
Private Sub Command3_Click()
BorrowAll_Conn 1
End Sub
Private Sub Command4_Click()
BorrowAll_Conn 2
End Sub
Private Sub Form_Load()
Data_Conn
End Sub
Private Sub MSHFlexGrid1_DragDrop(Source As Control, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
'-------------------------------------------------------------------------------------------
If m_iDragCol = -1 Then Exit Sub ' 现在不能拖拽
If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
With MSHFlexGrid1
.Redraw = False
.ColPosition(m_iDragCol) = .MouseCol
.Redraw = True
End With
End Sub
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
'-------------------------------------------------------------------------------------------
If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
xdn = X
ydn = Y
m_iDragCol = -1 ' 清除拖拽标志
m_bDragOK = True
End Sub
Private Sub MSHFlexGrid1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
'-------------------------------------------------------------------------------------------
' 测试是否能够开始拖拽
If Not m_bDragOK Then Exit Sub
If Button <> 1 Then Exit Sub ' 错误按钮
If m_iDragCol <> -1 Then Exit Sub ' 已经开始拖拽
If Abs(xdn - X) + Abs(ydn - Y) < 50 Then Exit Sub ' 移得不够
If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub ' 必须拖拽标头
' 如果到达这则开始拖拽
m_iDragCol = MSHFlexGrid1.MouseCol
MSHFlexGrid1.Drag vbBeginDrag
End Sub
Private Sub MSHFlexGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'-------------------------------------------------------------------------------------------
' 网格中 DragDrop, MouseDown, MouseMove, 和 MouseUp 事件代码能进行列拖拽
'-------------------------------------------------------------------------------------------
m_bDragOK = False
End Sub
Private Sub MSHFlexGrid1_DblClick()
'-------------------------------------------------------------------------------------------
' 网格的 DblClick 事件代码能进行列排序
'-------------------------------------------------------------------------------------------
Dim i As Integer
' 仅在单击固定行时进行排序
If MSHFlexGrid1.MouseRow >= MSHFlexGrid1.FixedRows Then Exit Sub
i = m_iSortCol ' 保存旧列
m_iSortCol = MSHFlexGrid1.Col ' 设置新列
' 递增排序类型
If i <> m_iSortCol Then
' 如果在新的列上单击鼠标,开始升序排序
m_iSortType = 1
Else
' 如果在相同列单击鼠标,则进行升序和降序排序的转换。
m_iSortType = m_iSortType + 1
If m_iSortType = 3 Then m_iSortType = 1
End If
DoColumnSort
End Sub
Sub DoColumnSort()
'-------------------------------------------------------------------------------------------
' 作 Exchange-type 排序在列 m_iSortCol
'-------------------------------------------------------------------------------------------
With MSHFlexGrid1
.Redraw = False
.Row = 1
.RowSel = .Rows - 1
.Col = m_iSortCol
.Sort = m_iSortType
.Redraw = True
End With
End Sub
Private Sub Condi_Conn(i As Integer) '条件查询
'1-按图书编号 2-按图书类别 3-按图书名称 4-按借阅人
Dim sSQL As String
Dim sSQL1 As String, sSQL2 As String, sSQL3 As String, sSQL4 As String
On Error GoTo CondiErr
' 设置字符串
sSQL1 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 图书编号=" & Text1 & " Order by 图书编号"
sSQL2 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 图书名称='" & Text1 & "' Order by 图书编号"
sSQL3 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 图书类别='" & Text1 & "' Order by 图书编号"
sSQL4 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 读者姓名='" & Text1 & "' Order by 图书编号"
' 打开连接
Select Case i
Case 1
sSQL = sSQL1
Case 2
sSQL = sSQL2
Case 3
sSQL = sSQL3
Case 4
sSQL = sSQL4
End Select
' 使用提供的集合创建 recordset
Set datP = New Recordset
datP.CursorLocation = adUseClient
datP.Open sSQL, tsdata.db, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datP
Sbar.Panels(2).Text = 0
Sbar.Panels(2).Text = datP.RecordCount
Text1 = ""
Set datP = Nothing
Exit Sub
CondiErr:
MsgBox Err.Description
End Sub
Private Sub BorrowAll_Conn(i As Integer) '图书查询
'1-全部借出图书 2-今日借出图书 3-本月借出图书
Dim sSQL As String
Dim sSQL1 As String, sSQL2 As String, sSQL3 As String, sSQL4 As String
On Error GoTo BorrowErr
' 设置字符串
sSQL1 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books Order by 图书编号"
sSQL2 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 借出时间=" & Date & " Order by 图书编号"
' sSQL3 = "select 图书编号,图书名称,图书类别,读者姓名,借出时间,备注 from books where 借出时间=" & Month & " Order by 图书编号"
' 打开连接
Select Case i
Case 1
sSQL = sSQL1
Case 2
sSQL = sSQL2
Case 3
sSQL = sSQL3
End Select
' 使用提供的集合创建 recordset
Set datP = New Recordset
datP.CursorLocation = adUseClient
datP.Open sSQL, tsdata.db, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datP
Sbar.Panels(2).Text = 0
Sbar.Panels(2).Text = datP.RecordCount
Text1 = ""
Set datP = Nothing
Exit Sub
BorrowErr:
MsgBox Err.Description
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -