'--------------------------------------------------------------------------
' 您可以在这里添加自己的插件函数,插件的制作和使用方法如下:
' 第一步:在下面添加插件函数,一个插件可以添加多个函数。
' 第二步:请修改下面的Get_Plugin_Description函数,加入插件和插件函数的说明信息,帮助信息会显示在按键精灵里方便使用
' 第三步:请修改Class Module(类模块)的名字,尽量用一些独特的名字避免和别人的插件名字冲突(默认是MyPluginName)
' 第四步:生成插件DLL!将DLL文件放到按键精灵的PLUGIN目录下,然后启动按键精灵测试您制作的插件功能是否正常
'--------------------------------------------------------------------------
//user_login.cls -->user_login.dll
//Plugin.user_login.F_user
//Plugin.user_login.F_login
//Plugin.user_login.F_select
//Plugin.user_login.F_insert
//Plugin.user_login.F_update 为自定义数据库操作自定义插件
//sqloledb_string = "Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=sa;Initial Catalog=Mydbase;Data Source=WIN-2008"
Public Function F_login(sqloledb_string As Variant, select_from As Variant, select_user As Variant, select_password As Variant, String1 As Variant, String2 As Variant) As String
If String1 = "" Or String2 = "" Then
F_login = 0
Else
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open sqloledb_string
Set rs = New Recordset
select_string = "select " & select_user & "," & select_password & " from " & select_from & " where " & select_user & " ='" & String1 & "'"
rs.Open select_string, db, adOpenStatic, adLockOptimistic
Dim i As String
For t = 0 To Val(rs.RecordCount) - 1
password = Trim(rs.Fields(select_password).Value)
rs.MoveNext
Next t
If password = String2 Then
F_login = 1
Else
F_login = 0
End If
rs.Close
End If
End Function
'查询数据
Public Function F_select(sqloledb_string As Variant, select_from As Variant, select_id As Variant, select_field As Variant, String_id As Variant) As String
F_select = ""
If select_id <> "" And select_field <> "" Then
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open sqloledb_string
Set rs = New Recordset
select_string = "select " & select_field & " from " & select_from & " where " & select_id & " ='" & String_id & "'"
rs.Open select_string, db, adOpenStatic, adLockOptimistic
mm = Val(rs.RecordCount)
If mm <> "" Then
String2 = ""
For t = 0 To Val(rs.RecordCount) - 1
String2 = Trim(rs.Fields(select_field).Value) & "|" & String2
rs.MoveNext
Next t
If Val(rs.RecordCount) > 0 Then
F_select = String2
Else
F_select = "0"
End If
End If
rs.Close
End If
End Function
'写入数据
Public Function F_update(sqloledb_string As Variant, select_from As Variant, select_id As Variant, update_field As Variant, String_id As Variant, String2 As Variant) As String
F_update = ""
If String_id <> "" And String2 <> "" Then
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open sqloledb_string
Set rs = New Recordset
select_string = "select " & select_id & " from " & select_from & " where " & select_id & " ='" & String_id & "'"
rs.Open select_string, db, adOpenStatic, adLockOptimistic
Dim mm
mm = Val(rs.RecordCount)
If mm <> "" Then
If mm > 0 Then
update_string = "update " & select_from & " set " & update_field & "= '" & String2 & "' where " & select_id & "='" & String_id & "' "
' MsgBox (update_string)
db.Execute update_string
F_update = "1"
Else
F_update = "0"
End If
End If
rs.Close
End If
End Function
'加入数据
Public Function F_insert(sqloledb_string As Variant, select_from As Variant, insert_field As Variant, String1 As Variant) As String
F_insert = ""
If insert_field <> "" And String1 <> "" Then
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open sqloledb_string
Set rs = New Recordset
select_string = "select * from " & select_from & " where " & insert_field & " ='" & String1 & "'"
rs.Open select_string, db, adOpenStatic, adLockOptimistic
Dim mm
mm = Val(rs.RecordCount)
' MsgBox mm
If mm <> "" Then
If mm = 0 Then
insert_string = "insert " & select_from & " ( " & insert_field & " ) select '" & String1 & "'"
' MsgBox (insert_string)
db.Execute insert_string
F_insert = "1"
Else
F_insert = "0"
End If
End If
rs.Close
End If
End Function
来源:oschina
链接:https://my.oschina.net/u/4368132/blog/4547180