Option Explicit
'定义查询字段的窗体级变量
'定义查询的字段窗体变量
Dim sfield As String '查询的关键词
Dim seachtext As String
'查询函数定义
'1、桉书号查询则采用具体查询办法
'2、按书名查询则采用模糊查询办法
Function open_seach(table_name As String, sfield As String, seachtext As String) As Integer
Dim sqlstr As String
Dim str As String
'建立数据库连接
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.CursorLocation = adUseClient
sqlstr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + App.Path + "\data\ComputerBookmanage.mdb" + ";Persist Security Info=False"
con.Open sqlstr
' 查询办法选择
If Option1.Value = True Then
str = "select * from " & table_name & " where " & sfield & "='" & seachtext & "'"
Else
str = "select * from " & table_name & " where " & sfield & " like '" & Trim(" %" & Text1.Text & "%") & "'"
End If
If Option3.Value = True Then
str = "select * from " & table_name & " where " & sfield & "='" & seachtext & "'"
Else
str = "select * from " & table_name & " where " & sfield & " like '" & Trim(" %" & Text1.Text & "%") & "'"
End If
rst.Open str, con, adOpenDynamic, adLockOptimistic
rst.Requery
If rst.RecordCount > 0 Then
open_seach = 1 '返回一个值1,代表有查询结果
Else
open_seach = 0 '返回一个值0,代表没有查询结果
End If
End Function
Private Sub Check4_Click()
'选择查询的字段
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
sfield = "[出版社]"
End Select
End Sub
Private Sub Command1_Click()
If rst.BOF = True Then
frmMsg.Show
frmMsg.info.Visible = True
frmMsg.Text1.Text = "已经到达第一条记录了!"
Exit Sub
Else
rst.MovePrevious
End If
End Sub
Private Sub Command2_Click() '后一记录
If rst.EOF = True Then
frmMsg.Show
frmMsg.info.Visible = True
frmMsg.Text1.Text = "已经到达最后一条记录了!"
Exit Sub
Else
rst.MoveNext
End If
End Sub
Private Sub DataGrid2_Click()
Call connect_db
open_connection ("book") '连接book表
tablename = "book"
If privilege = 1 Then '如果只是普通用户,无法查询员工信息
frmMsg.Show
frmMsg.error.Visible = True
frmMsg.Text1.Text = "对不起,您没有查阅的权限!"
Exit Sub
End If
open_connection ("worker") '连接worker表
tablename = "worker"
open_connection ("record") '连接record表
tablename = "record"
Set DataGrid1.DataSource = rst
End Sub
Private Sub Command4_Click()
Dim ret As Integer
If Command4.Caption = "查 询" Then
Command4.Caption = "确 定"
Else
If Option1.Value = False And Option2.Value = False And Option3.Value = False And Option4.Value = False Then
frmMsg.Show
frmMsg.notice.Visible = True
frmMsg.Text1.Text = "请选择查询项!"
Exit Sub
End If
If Text1.Text = "" Then
frmMsg.Show
frmMsg.notice.Visible = True
frmMsg.Text1.Text = "请输入查询内容!"
Text1.SetFocus
Exit Sub
End If
seachtext = Trim(Text1.Text)
ret = open_seach(tablename, sfield, seachtext)
If ret = 0 Then
frmMsg.Show
frmMsg.error.Visible = True
frmMsg.Text1.Text = "对不起,没有你要的记录!"
Option1.Value = False
Option2.Value = False
Text1.Text = ""
rst.Close
Set rst = Nothing
Set DataGrid1.DataSource = rst
Command1.Enabled = False '上一条,下一条按钮为灰
Command2.Enabled = False
Command4.Caption = "查 询"
Exit Sub
End If
Command1.Enabled = True
Command2.Enabled = True
Set DataGrid1.DataSource = rst
Text1.Text = ""
Option1.Value = False
Option2.Value = False
Command4.Caption = "查 询"
End If
End Sub
Private Sub DataGrid1_Click()
Call connect_db
open_connection ("book") '连接book表
tablename = "book"
If privilege = 1 Then '如果只是普通用户,无法查询员工信息
frmMsg.Show
frmMsg.error.Visible = True
frmMsg.Text1.Text = "对不起,您没有查阅的权限!"
Exit Sub
End If
open_connection ("worker") '连接worker表
tablename = "worker"
open_connection ("record") '连接record表
tablename = "record"
Set DataGrid1.DataSource = rst
End Sub
Private Sub Form_Load()
Option1.Caption = "书号"
Option2.Caption = "书名"
Option3.Caption = "出版社"
Option4.Caption = "作者"
Label2.Caption = frmLogin.Text1.Text
Timer1.Interval = 1000
tablename = "book"
Call connect_db
open_connection ("book")
Set DataGrid1.DataSource = rst
TabStrip1.Tabs.Item(1) = "图书信息浏览"
TabStrip1.Tabs.Item(2) = "员工信息浏览"
TabStrip1.Tabs.Item(3) = "图书借阅情况浏览"
Text1.Text = ""
open_connection ("book")
Set DataGrid1.DataSource = rst
frmLogin.Show
End Sub
Private Sub Image1_Click()
End Sub
Private Sub Option1_Click()
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
sfield = "[图书编码]"
Case "员工信息浏览":
sfield = "[工号]"
Case "图书借阅情况浏览":
sfield = "[图书编码]"
End Select
End Sub
Private Sub Option2_Click()
'选择查询的字段
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
sfield = "[图书名称]"
Case "员工信息浏览":
sfield = "[姓名]"
Case "图书借阅情况浏览":
sfield = "[工号]"
End Select
End Sub
Private Sub Option3_Click()
'选择查询的字段
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
sfield = "[出版社]"
End Select
End Sub
Private Sub Option4_Click()
'选择查询的字段
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
sfield = "[作者]"
End Select
End Sub
Private Sub Text2_Change()
Text1.Text = Time
End Sub
Private Sub TabStrip1_Click()
Call connect_db
Select Case TabStrip1.SelectedItem
Case "图书信息浏览":
open_connection ("book") '连接book表
tablename = "book"
Option1.Caption = "书号"
Option2.Caption = "书名"
Set DataGrid1.DataSource = rst
Case "员工信息浏览":
If privilege = 1 Then '如果只是普通用户,无法查询员工信息
frmMsg.Show
frmMsg.error.Visible = True
frmMsg.Text1.Text = "对不起,您没有查阅的权限!"
Exit Sub
End If
open_connection ("worker") '连接worker表
Option1.Caption = "工号"
Option2.Caption = "姓名"
tablename = "worker"
Set DataGrid1.DataSource = rst
Case "图书借阅情况浏览":
open_connection ("record") '连接record表
Option1.Caption = "书号"
Option2.Caption = "工号"
tablename = "record"
Set DataGrid1.DataSource = rst
End Select
End Sub
Private Sub Timer1_Timer()
Label3.Caption = Now
End Sub
Private Sub xpcmdbutton1_Click()
Form4.Show
End Sub
Private Sub xpcmdbutton12_Click()
Form6.Show
End Sub
Private Sub xpcmdbutton13_Click()
frmAbout.Show
End Sub
Private Sub xpcmdbutton14_Click()
Unload Me
frmLogin.Show
End Sub
Private Sub xpcmdbutton15_Click()
open_connection "reader"
tablename = "reader"
Set DataGrid1.DataSource = rst
End Sub
Private Sub xpcmdbutton2_Click()
Form5.Show
End Sub
Private Sub xpcmdbutton3_Click()
Form2.Show
End Sub
Private Sub xpcmdbutton4_Click()
Form3.Show
End Sub
Private Sub xpcmdbutton5_Click()
open_connection ("book")
tablename = "record"
Set DataGrid1.DataSource = rst
End Sub
Private Sub xpcmdbutton6_Click()
open_connection ("record")
tablename = "record"
Set DataGrid1.DataSource = rst
End Sub
Private Sub xpcmdbutton7_Click()
open_connection ("worker")
tablename = "worker"
Set DataGrid1.DataSource = rst
End Sub
Private Sub xpcmdbutton8_Click()
Frm_sys_set.Show
End Sub
Private Sub xpmin_Click()
Me.WindowState = 1
End Sub
Private Sub xpclose_Click()
Unload Me
frmLogin.Show
End Sub
Private Sub xptopbuttons1_Click()
Unload Me
End S