扫描视图中的所有文档
Scan all the documents in a View
所以,这是我的代码。它只获取第一个文档。但是我想做的是阅读特定文档。该视图是用户名和密码的集合。因此,例如:用户名在第 5 个文档中,然后程序将扫描视图,直到找到正确的文档。抱歉我的解释不当。我希望你能理解我的问题。
On Error Goto e
Dim db As NotesDatabase
Dim view As NotesView
Dim results As Variant
Dim cmd As String
Dim d As NotesDocument, flag As Integer, upw As String, uname As String
Set db = source.Database
uname = Inputbox("Enter Username")
Set view = db.GetView("Registration View")
Set d = view.GetFirstDocument()
'cmd = {@DbLookup("";"48257E00:00089AF5";"RegView";1)}
'results = Evaluate(cmd)
Dim pw As String, un As String
'Forall Username In results
' Msgbox username(1)
'End Forall
If Not d Is Nothing Then
un = d.userfield(0)
pw = d.passfield(0)
If un <> uname Then
Msgbox "Username invalid!"
End If
If un = uname Then
upw = Inputbox("Enter Password")
If pw <> upw Then
Msgbox "Password invalid!"
End If
If pw = upw Then
Msgbox "Log In succesful!"
flag = 1
End If
End If
End If
If flag <> 1 Then Call source.Close()
Exit Sub
e:
Print Error, Erl
您应该使用 view.getDocumentByKey(uname,true) 而不是使用 view.getFirstDocument,其中 return 在视图的第一列中具有键 uname 的文档
确保视图中的第一列设置为已排序
如果使用密钥没有找到文档,则 getDocumentByKey return什么都没有
您可以使用第一列用户字段和第二列密码字段创建视图。第一列必须排序。
在您的代码中构建一个 uname 和 upw 数组
Dim strSearch (0 to 1) as String
Dim viewSearch as NotesView
Dim doc as NotesDocument
viewSearch = db.getView("YourSearchView")
strSearch(0) = uname
strSearch(1) = upw
Set doc = db.getDocumentByKey(strSearch, true)
If(Not doc is nothing)Then
Print "Login successfull"
Else
Print "Wrong username or password"
End if
如果您想对用户名和密码进行两步检查,您可以创建两个搜索视图,第一个用于检查用户名是否存在,第二个用于检查给定的用户名和密码。
当然,您可以循环查看完整视图并比较每个条目,但这会很慢。在您的代码中缺少完整的 "cycling" 。您需要使用 do - while 循环 运行 遍历视图中的所有条目:
Set d = view.GetFirstDocument()
Do
un = d.userfield(0)
pw = d.passfield(0)
'- here comes the rest of your code, if password is right - exit
If flag = 1 then exitLoop = True
Set d = view.GetNextDocument( d )
if d is Nothing then exitLoop = True
Loop until exitLoop
但这效率很低。如果您的视图是按用户名排序的(如果不是,则创建一个),然后按照 Thomas 的建议使用 getDocumentbyKey。
Set d = view.GetDocumentByKey( uname )
If not d is Nothing then
un = d.userfield
问题是为什么人们会做这样的事情:Notes / Domino 有一个很好的安全概念并将所有用户名和密码保存在一个视图中,每个人都可以通过检查文档属性简单地读取密码 - 抱歉说-愚蠢,不会给你更多的安全感......
所以,这是我的代码。它只获取第一个文档。但是我想做的是阅读特定文档。该视图是用户名和密码的集合。因此,例如:用户名在第 5 个文档中,然后程序将扫描视图,直到找到正确的文档。抱歉我的解释不当。我希望你能理解我的问题。
On Error Goto e
Dim db As NotesDatabase
Dim view As NotesView
Dim results As Variant
Dim cmd As String
Dim d As NotesDocument, flag As Integer, upw As String, uname As String
Set db = source.Database
uname = Inputbox("Enter Username")
Set view = db.GetView("Registration View")
Set d = view.GetFirstDocument()
'cmd = {@DbLookup("";"48257E00:00089AF5";"RegView";1)}
'results = Evaluate(cmd)
Dim pw As String, un As String
'Forall Username In results
' Msgbox username(1)
'End Forall
If Not d Is Nothing Then
un = d.userfield(0)
pw = d.passfield(0)
If un <> uname Then
Msgbox "Username invalid!"
End If
If un = uname Then
upw = Inputbox("Enter Password")
If pw <> upw Then
Msgbox "Password invalid!"
End If
If pw = upw Then
Msgbox "Log In succesful!"
flag = 1
End If
End If
End If
If flag <> 1 Then Call source.Close()
Exit Sub
e:
Print Error, Erl
您应该使用 view.getDocumentByKey(uname,true) 而不是使用 view.getFirstDocument,其中 return 在视图的第一列中具有键 uname 的文档
确保视图中的第一列设置为已排序
如果使用密钥没有找到文档,则 getDocumentByKey return什么都没有
您可以使用第一列用户字段和第二列密码字段创建视图。第一列必须排序。
在您的代码中构建一个 uname 和 upw 数组
Dim strSearch (0 to 1) as String
Dim viewSearch as NotesView
Dim doc as NotesDocument
viewSearch = db.getView("YourSearchView")
strSearch(0) = uname
strSearch(1) = upw
Set doc = db.getDocumentByKey(strSearch, true)
If(Not doc is nothing)Then
Print "Login successfull"
Else
Print "Wrong username or password"
End if
如果您想对用户名和密码进行两步检查,您可以创建两个搜索视图,第一个用于检查用户名是否存在,第二个用于检查给定的用户名和密码。
当然,您可以循环查看完整视图并比较每个条目,但这会很慢。在您的代码中缺少完整的 "cycling" 。您需要使用 do - while 循环 运行 遍历视图中的所有条目:
Set d = view.GetFirstDocument()
Do
un = d.userfield(0)
pw = d.passfield(0)
'- here comes the rest of your code, if password is right - exit
If flag = 1 then exitLoop = True
Set d = view.GetNextDocument( d )
if d is Nothing then exitLoop = True
Loop until exitLoop
但这效率很低。如果您的视图是按用户名排序的(如果不是,则创建一个),然后按照 Thomas 的建议使用 getDocumentbyKey。
Set d = view.GetDocumentByKey( uname )
If not d is Nothing then
un = d.userfield
问题是为什么人们会做这样的事情:Notes / Domino 有一个很好的安全概念并将所有用户名和密码保存在一个视图中,每个人都可以通过检查文档属性简单地读取密码 - 抱歉说-愚蠢,不会给你更多的安全感......