0

我有两个数据库:一个保存员工摘要信息,另一个保存员工的序列号。在 database1 上,我有这个代理,它可以让您导入包含员工更新记录的文本文件。但是,为了使该代理成功导入文本文件记录,要导入的文本文件必须具有与数据库中相同的序列号记录2。顺便说一句,它正在工作,但我需要在导入时创建一个日志,仍然不知道如何解决这个问题。必须在字段上查看日志(导入的日期、导入的成功和失败文件)。你能帮我吗?这是我的代码:

加载APMSAWDdoc

Sub LoadAPMSAWDdoc(Rname As Variant, directory As Variant, Datef As Variant)
Dim session As New NotesSession
Dim Tdoc As NotesDocumentCollection
Dim dateTime As New NotesDateTime ("01/01/2000")
'12/20/2005
Dim LocView As notesview
Dim LocDoc As NotesDocument
Dim subsidiary As String
Print "Loading APMSAWD - Award Information"

Set cdb = Session.CurrentDatabase
'12/20/2005
'StaffServerName = cdb.Server 
Set LocView = cdb.GetView("LsvLocationProfile")
'02/07/2006
'Set LocDoc = LocView.getdocumentbykey(cdb.Server)
Set LocDoc = LocView.getfirstdocument
StaffServerName = LocDoc.z_ExtServer(0)

 'SearchFormula$ = "Select Form = ""dfAward""  & @Date(s_Created) != @Date(@Today) "


If (ibmmy = True) And (ibmgdc = True) Then
SearchFormula$ = "Select Form = ""dfAward""  "
ElseIf  (ibmmy = True) Then 
SearchFormula$ = "Select Form = ""dfAward"" & I_GDCEmployee = ""IBM MY""" 
Else 
SearchFormula$ = "Select Form = ""dfAward"" & I_GDCEmployee = ""IBM GDC""" 
End If

Set Tdoc = cdb.Search( SearchFormula$, DateTime, 0 )  

If Tdoc.Count <> 0 Then
    Call Tdoc.RemoveAll(True)          
End If

 'Get an unused file number
file_no% = Freefile()
Open (Trim(directory + "apmsawd.txt")) For Input As file_no%      

Set db = Session.CurrentDatabase

Select Case Datef
Case "DMY" : Cdatf = "dd/mm/yyyy"
Case "MDY" : Cdatf = "mm/dd/yyyy"
Case "YMD" : Cdatf = "yyyy/mm/dd"
Case Else : 
    Print "LoadAPMSAWDdoc - Unknown system date format"          
    Exit Sub
End Select

Do While Not Eof(file_no%)
    Line Input #file_no%, tmp

    SerialNo = Trim$(Mid$(tmp,1,6))

    AB = 0
    For i = 29 To 0 Step -1               
        x1 = 8 + (i * 50)
        x2 = 11 + (i * 50)
        x3 = 41 + (i * 50)
        x4 = 49 + (i * 50)

        temp = Strconv(Trim$(Mid$(tmp,x2,30)),3)
        If temp <> "" Then
            Redim Preserve ACode(AB)
            Redim Preserve ADes(AB)
            Redim Preserve ADate(AB)
            Redim Preserve AAmt(AB)
            Acode(AB) = Trim$(Mid$(tmp,x1,3))
            ADes(AB) = temp
            If Trim$(Mid$(tmp,x3,8)) <> "" Then
                AD1 = Setdate(Trim$(Mid$(tmp,x3,8)), "mm/dd/yy", Datef)               
                ADate(AB) = Cdat(Format(AD1, Cdatf))
                     'Datenumber ( Val(Trim$(Mid$(tmp,x3+6,2))) , Val(Trim$(Mid$(tmp,x3+3,2))) , Val(Trim$(Mid$(tmp,x3,2))) )
            Else
                ADate(AB) = Null
            End If
            AAmt(AB) = Val(Trim$(Mid$(tmp,x4,9)))
            AB = AB + 1
        Else 
            Exit For
        End If
    Next

    subsidiary = Filter(CStr(SerialNo))
    If (subsidiary = "AMY" And ammmy = True) Or (subsidiary  = "ADC" And aaadc = True) Then

    Set doc = New NotesDocument(db)
    doc.Form = "dfAward"
    doc.E_StaffSerialNo = SerialNo
    doc.I_GDCEmployee = subsidiary
    If AB = 0 And Trim$(Mid$(tmp,1461,30))  = "" Then
        Redim Preserve ACode(AB)
        Redim Preserve ADes(AB)
        Redim Preserve ADate(AB)
        Redim Preserve AAmt(AB)
        ACode(0) = ""
        ADes(0) = ""
        ADate(0) = Null
        AAmt(0) = Null
    End If
    doc.E_AwardType = ADes
    doc.E_AwardDate = ADate
    doc.E_AwardAmt = AAmt
    doc.G_AuthorDisp = Rname
    doc.s_created = Now
    Call doc.Save (True, True)

    End If
Loop

Close file_no% 
Print "Award information imported"

End Sub

如果我只发布了一些函数,我很抱歉,因为我的代码太长,不适合这里。

4

1 回答 1

2

首先:这是非常糟糕的做法,永久删除所有符合搜索条件的文档,然后直接将它们添加回来。

删除存根会爆炸,这个数据库会变得越来越慢,在某些时候将不再可用。

更好地构建一个密钥来识别文档,使用密钥获取文档,然后在必要时更新......

我通常会建立一个包含所有键/unid(或文档,如果它们不多的话)的列表,并在处理后从该列表中删除在“源”(您的情况下为文本文档)中找到的任何文档。

导入文件运行后留在列表中的任何文档都可以删除...

Dim lstrUnids List as String

Set doc = Tdoc.GetFirstDocument()
While not doc is Nothing
    lstrUnids( doc.E_StaffSerialNo(0) ) = doc.UniversalID
    set doc = TDoc.GetNextDocument(doc)
Wend

但现在回到你的问题:

要编写一个简单的日志,您可以使用 NotesLogClass。您可以记录到数据库(模板:代理日志)、记录到邮件或记录到代理日志(阅读起来很复杂)甚至是文件。

这样做:

Dim agLog as New NotesLog( "MyImportLog" )
Call agLog.OpenNotesLog( Server , logdbPath )
...
Call agLog.LogMessage( "Award information imported" )
...
Call agLog.Close() 'IMPORTANT !!!!
于 2013-09-10T10:21:36.103 回答