Domino 9 und frühere Versionen > ND6: Entwicklung
Typisch Notes
MadMetzger:
Dann habe ich das eben ein bißchen falsch aufgefasst und wir sind eigentlich der gleichen Meinung.
Aber diese Feldübernahme ist ja eine Sache die durchaus öfter vorkommen kann und man diese eben in einen "Werkzeugkasten" übernehmen könnte und dann bei Bedarf aus der Tasche ziehen kann... Daher kam mir die Aussage komisch vor. Das Verhältnis hier zwischen Code für Iteration und Code für Aufbau der Zuordnung war mir klar, aber ich sehe hier durchaus Nutzen, das so anzugehen.
flaite:
Als Klasse mit zugegebenermassen zu wenig errorhandling
--- Code: ---Public Class DocCopyFactory
Private db As NotesDatabase
Private fieldNames As Variant
Sub New (fieldNamesIn As String)
' first get the names of the fields which should be copied.
' if (fieldNamesIn == null) throw new ilegalArgumentException (no idea how to code that in LS)
' extracted as tokens separated by ~ (by convention)
fieldNames = Split(fieldNamesIn, "~")
Dim s As New NotesSession
Set db = s.CurrentDatabase
End Sub
Public Function copyDocument(docToCopy As NotesDocument, formCopyDocument As String) As NotesDocument
' document to return
Set copyDocument = db.createDocument ' return value
copyDocument.form=formCopyDocument
' copy the items
Dim itemDocToCopy As NotesItem
Forall fieldName In fieldNames
Set itemDocToCopy = docToCopy.GetFirstItem(fieldName)
If Not itemDocToCopy Is Nothing Then
Call itemDocToCopy.CopyItemToDocument(copyDocument, fieldName)
Else
' do some better errorhandling or logging than this.
Print "NO GOOD. The item " + fieldName + " does not exist in the document to be copied."
End If
End Forall
End Function
End Class
--- Ende Code ---
wird so angesprochen:
(Client code für Klasse)
--- Code: ---Dim s As New NotesSession
Dim docOriginal As NotesDocument
Dim docNochneKopie As NotesDocument
Dim aDocCopyFactory As New DocCopyFactory("item1~item2~item3")
Set docOriginal = s.DocumentContext
Set docKopie = aDocCopyFactory.copyDocument(docOriginal, "Kopie von original")
docKopie.save True, False
Set docNochneKopie = aDocCopyFactory.copyDocument(docOriginal, "Kopie von original")
docNochneKopie.save True, False
--- Ende Code ---
In der Beispiel DB in Agenten DocCopyFactory.
In BeispielDB sich in der Ansicht "Alle" auf das einzige Dokument stellen und dann den einzigen button mit der Beschriftung "push the button" drücken. Der startet den Client code für die Klasse (im Agenten DocCopyFactory).
Axel:
--- Zitat von: Axel Janssen am 01.03.07 - 01:43:53 ---
' if (fieldNamesIn == null) throw new ilegalArgumentException (no idea how to code that in LS)
--- Ende Zitat ---
Kein Wunder, dass Notes dich hier anmeckert. Diese Art von Codierung erinnert mich an C(++ oder #).
In Notes kann das so ausehen:
Sub New (fieldNamesIn As String)
' first get the names of the fields which should be copied.
if fieldNamesIn = "" Then Exit Sub
' extracted as tokens separated by ~ (by convention)
fieldNames = Split(fieldNamesIn, "~")
Dim s As New NotesSession
Set db = s.CurrentDatabase
End Sub
Das wäre die einfachste Form und ist mit Sicherheit ausbaufähig.
Axel
flaite:
Hallo Axel,
ich wusste, dass das kein LS ist. Hab das nur zur Markierung dagelassen, weil mir um 1:45 Uhr nachts das nicht einfiehl.
Gruß Axel
koehlerbv:
Der Code kopiert aber nicht den Inhalt von Feld A (in Doc X) nach Feld B (in Doc Y), sondern schaufelt "nur" die Items einfach so rüber.
Bernhard
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln