Attribute VB_Name = "Global"
Public cn As ADODB.Connection '全局的数据库连接对象
Public czry_flag As String '保存用户权限字符串
Public isxg As Boolean '是添加用户还是修改用户
Public nodename As String '保存某个用户的帐户名
Public rspsw As ADODB.Recordset '用于用户帐号密码设置的结果集合
Public database_data As String '保存导出数据表信息时的access数据库名称
Public user_name As String '保存登陆的用户名


Public Sub condatabase()           '创建连接到feiyong数据库的记录源                                     '连接本地数据库JIMMY
    Set cn = New ADODB.Connection
      '  cn.Provider = "sqloledb"
      '  cn.Properties("Data Source").Value = "JIMMY"       '建立与本地数据库的连接
      '  cn.Properties("Initial Catalog").Value = "YAOFEI"   '数据库的名称
      '  cn.Properties("Integrated Security").Value = "SSPI"
      'cn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "/data/mis.mdb" '我转换的access数据库路径
      cn.ConnectionString = "Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;DATABASE=MIS;UID=sa;pwd=123456"
        cn.Open
End Sub

Public Sub check_condatabase()
'cn.State的值为1表示数据库处于连接状态
If cn Is Nothing Then
 Call condatabase
 Exit Sub
End If
If cn.State <> 1 Then
   Call condatabase
End If
End Sub

Public Sub close_condatabase()   '关闭数据源
If cn.State = 1 Then
   cn.Close
End If
End Sub

'***************************************************************
'作为检查操作员使用权限的函数，该函数通过截取load表中的ql_flag字段来
'判断该操作员所具有的权限和使用范围

Public Function check_qx(qx_flag As String, i As Integer) As Boolean
Dim temp As Integer
If qx_flag <> "" Then
    temp = Mid(qx_flag, i, 1)
    If temp = 0 Then
       MsgBox "您无权限使用该功能！", vbOKOnly + vbExclamation, "注意了:)"
       check_qx = False
    Else
       check_qx = True
    End If
Else
    MsgBox "未经管理员授权，您无权限使用所有功能！", vbOKOnly + vbExclamation, "注意了:)"
    check_qx = False
End If
End Function

 


'两个记录集之间的数据拷贝
Public Function RescordSet_Copy(rs_source As ADODB.Recordset, rs_destinate As ADODB.Recordset)
'检查源记录表中是否有数据,如果没有,跳出该函数
If rs_source.EOF <> True Then
    If rs_destinate.EOF <> True And rs_destinate.BOF <> True Then  '如果目的表的记录不为空
            Do Until rs_destinate.EOF
               rs_destinate.delete
               rs_destinate.MoveNext
            Loop
            Dim id As String
            id = rs_destinate.Fields(0)  '记录编号的变化
            Do Until rs_source.EOF
               rs_destinate.AddNew
               For i = 1 To 7
                   rs_destinate.Fields(i).Value = rs_source.Fields(i).Value
               Next
               id = id + 1
               rs_destinate.Fields(0).Value = id
               rs_destinate.Update
               rs_destinate.MoveNext
               rs_source.MoveNext
            Loop
    
    Else              '**************如果目的表的记录为空
            Do Until rs_source.EOF
           rs_destinate.AddNew
           For i = 0 To 7
               rs_destinate.Fields(i).Value = rs_source.Fields(i).Value
           Next
           rs_destinate.Update
           rs_destinate.MoveNext
           rs_source.MoveNext
        Loop

    End If
End If
End Function


'通过图书类别名称得到图书类别编号
Public Function getBookTypeIdByBookTypeName(bookTypeName As String) As Integer
  Dim bookTypeRs As ADODB.Recordset
  Call check_condatabase
  Set bookTypeRs = cn.Execute("select * from classInfo")
  While Not bookTypeRs.EOF
    If bookTypeRs("bookTypeName") = bookTypeName Then '找到了该图书类别
      getBookTypeIdByBookTypeName = bookTypeRs("bookTypeId") '取得该类别的编号返回
      Exit Function
    End If
    bookTypeRs.MoveNext
  Wend
  getBookTypeIdByBookTypeName = 0
End Function

 

