2001-04-23 04:46:42 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
|
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Correspondence" script:language="StarBasic">Option Explicit
|
|
|
|
|
|
|
|
Public msgNoTextmark$, msgError$
|
|
|
|
Public sAddressbook$
|
|
|
|
Public Table
|
|
|
|
Public sCompany$, sFirstName$, sLastName$, sStreet$, sPostalCode$, sCity$, sState$, sInitials$, sPosition$
|
|
|
|
Public DialogExited
|
|
|
|
Public oDocument, oText, oBookMarks, oBookMark, oBookMarkCursor, oBookText as Object
|
|
|
|
|
|
|
|
Sub Main
|
2001-04-25 04:10:51 -05:00
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
2001-04-23 04:46:42 -05:00
|
|
|
TemplateDialog = LoadDialog("Template", "TemplateDialog")
|
|
|
|
DialogModel = TemplateDialog.Model
|
|
|
|
DialogModel.Step = 2
|
|
|
|
DialogModel.Optmerge.State = True
|
|
|
|
If LoadLanguageCorrespondence() Then
|
|
|
|
TemplateDialog.Execute
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Function LoadLanguageCorrespondence() as Boolean
|
|
|
|
Dim oDBAccess as Object
|
|
|
|
Dim oAddressDialog as Object
|
|
|
|
Dim oFields as Object
|
|
|
|
|
|
|
|
If InitResources("'Template'", "tpl") Then
|
|
|
|
oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/")
|
|
|
|
sAddressbook = oDBAccess.DataSourceName
|
|
|
|
If sAddressbook = "" Then
|
|
|
|
oAddressDialog = CreateUnoService("com.sun.star.ui.AddressBookSourceDialog")
|
|
|
|
oAddressDialog.Execute
|
|
|
|
oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/")
|
|
|
|
sAddressbook = oDBAccess.DataSourceName
|
|
|
|
If sAddressbook = "" Then
|
|
|
|
LoadLanguageCorrespondence() = False
|
|
|
|
Exit Function
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
oFields = oDBAccess.GetByName("Fields")
|
|
|
|
Table = oDBAccess.GetByName("Command")
|
|
|
|
sCompany = GetFieldname(oFields, "Company")
|
|
|
|
sFirstName = GetFieldname(oFields, "FirstName")
|
|
|
|
sLastName = GetFieldname(oFields, "LastName")
|
|
|
|
sStreet = GetFieldname(oFields, "Street")
|
|
|
|
sPostalCode = GetFieldname(oFields, "Zip")
|
|
|
|
sCity = GetFieldname(oFields, "City")
|
|
|
|
sState = GetFieldname(oFields, "State")
|
|
|
|
sInitials = GetFieldname(oFields, "Code")
|
|
|
|
sPosition = GetFieldname(oFields, "Position")
|
|
|
|
msgNoTextmark$ = GetResText(1303) & Chr(13) & Chr(10) & GetResText(1301)
|
|
|
|
msgError$ = GetResText(1302)
|
|
|
|
DialogModel.Title = GetResText(1303)
|
|
|
|
DialogModel.CmdCancel.Label = GetResText(1102)
|
2001-04-25 04:10:51 -05:00
|
|
|
DialogModel.CmdCorrGoOn.Label = GetResText(1103)
|
2001-04-23 04:46:42 -05:00
|
|
|
DialogModel.OptSingle.Label = GetResText(1303 + 1)
|
|
|
|
DialogModel.Optmerge.Label = GetResText(1303 + 2)
|
|
|
|
LoadLanguageCorrespondence() = True
|
|
|
|
Else
|
2001-04-25 04:10:51 -05:00
|
|
|
' Todo: Meldung, was Passiert wenn Datenbank nicht angelegt werden konnte
|
|
|
|
LoadLanguageCorrespondence() = False
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
Function GetFieldName(oFieldKnot as Object, GeneralFieldName as String)
|
|
|
|
If oFieldKnot.HasbyName(GeneralFieldName) Then
|
|
|
|
GetFieldName = oFieldKnot.GetbyName(GeneralFieldName).FieldName
|
|
|
|
Else
|
|
|
|
GetFieldName = ""
|
|
|
|
End If
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
Sub OK
|
|
|
|
Dim ParaBreak
|
|
|
|
Dim sDocLang as String
|
|
|
|
Dim bMerge as Boolean
|
|
|
|
bMerge = DialogModel.Optmerge.State
|
|
|
|
' Todo: das muss wieder rein!
|
|
|
|
DialogTemplate.EndExecute()
|
|
|
|
DialogExited = TRUE
|
|
|
|
If bMerge Then
|
|
|
|
ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
|
|
|
|
oDocument = StarDesktop.ActiveFrame.Controller.Model
|
|
|
|
oBookmarks = oDocument.Bookmarks
|
|
|
|
oText = oDocument.Text
|
|
|
|
If oBookmarks.HasbyName("Recipient")Then
|
|
|
|
oBookMark = oDocument.BookMarks.GetbyName("Recipient")
|
|
|
|
Else
|
|
|
|
MsgBox msgNoTextmark, 16, msgError
|
|
|
|
Exit Sub
|
|
|
|
End If
|
|
|
|
oBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
|
|
|
|
OBookText = oBookMarkCursor.Text
|
|
|
|
sDocLang = oDocument.CharLocale.Language
|
|
|
|
Select Case sDocLang
|
|
|
|
Case "nl"
|
|
|
|
InsertDBField(sAddressbook, Table, sCompany)
|
|
|
|
oBookMarkCursor.Text.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertBookMarkString("T.a.v. ")
|
|
|
|
InsertDBField(sAddressbook, Table, sFirstName)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sLastName)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sStreet)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sPostalCode)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sCity)
|
|
|
|
|
|
|
|
Case "en"
|
|
|
|
InsertDBField(sAddressbook, Table, sCompany)
|
|
|
|
oBookMarkCursor.Text.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sFirstName)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sLastName)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sStreet)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sCity)
|
|
|
|
InsertBookMarkString(", ")
|
|
|
|
InsertDBField(sAddressbook, Table, sState)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sPostalCode)
|
|
|
|
|
|
|
|
Case "sv"
|
|
|
|
InsertDBField(sAddressbook, Table, sCompany)
|
|
|
|
oBookMarkCursor.Text.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sFirstName)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sLastName)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sStreet)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sPostalCode)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sCity)
|
|
|
|
|
|
|
|
Case "ru"
|
|
|
|
InsertDBField(sAddressbook, Table, sPosition)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sCompany)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sLastName)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sInitials)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sPostalCode)
|
|
|
|
InsertBookMarkString(", ")
|
|
|
|
InsertDBField(sAddressbook, Table, sCity)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sStreet)
|
|
|
|
|
|
|
|
Case Else
|
|
|
|
InsertDBField(sAddressbook, Table, sCompany)
|
|
|
|
oBookMarkCursor.Text.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sFirstName)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sLastName)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sStreet)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
oBookText.insertControlCharacter(oBookMarkCursor, ParaBreak, False)
|
|
|
|
InsertDBField(sAddressbook, Table, sPostalCode)
|
|
|
|
InsertBookMarkString(" ")
|
|
|
|
InsertDBField(sAddressbook, Table, sCity)
|
|
|
|
End Select
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub InsertDBField(sDBName as String, sTableName as String, sColName as String)
|
|
|
|
Dim oFieldMaster, oField as Object
|
|
|
|
If sColname <> "" Then
|
|
|
|
oFieldMaster = oDocument.createInstance("com.sun.star.text.FieldMaster.Database")
|
|
|
|
oField = oDocument.createInstance("com.sun.star.text.TextField.Database")
|
|
|
|
oFieldMaster.DataBaseName = sDBName
|
|
|
|
oFieldMaster.DataBaseName = sDBName
|
|
|
|
oFieldMaster.DataTableName = sTableName
|
|
|
|
oFieldMaster.DataColumnName = sColName
|
|
|
|
oField.AttachTextfieldmaster (oFieldMaster)
|
|
|
|
oBookText.InsertTextContent(oBookMarkCursor, oField, True)
|
|
|
|
oField.Content = "<" & sColName & ">"
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub InsertBookmarkString(sBookmarkString as String)
|
|
|
|
oBookText.InsertString(oBookMarkCursor, sBookmarkString, True)
|
|
|
|
oBookMarkCursor.CollapseToEnd()
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub LoadLibrary(sLibname as String)
|
|
|
|
Dim oArg(0) as new com.sun.star.beans.PropertyValue
|
|
|
|
Dim oUrl as new com.sun.star.util.URL
|
|
|
|
Dim oTrans as Object
|
|
|
|
Dim oDisp as Object
|
|
|
|
|
|
|
|
oArg(0).Name = "LibraryName"
|
|
|
|
oArg(0).Value = sLibname
|
|
|
|
|
|
|
|
oTrans = createUNOService("com.sun.star.util.URLTransformer")
|
|
|
|
oUrl.Complete = "slot:6517"
|
|
|
|
oTrans.parsestrict(oUrl)
|
|
|
|
|
2001-04-25 04:10:51 -05:00
|
|
|
oDisp = StarDesktop.currentFrame.queryDispatch(oUrl, "_self", 0)
|
2001-04-23 04:46:42 -05:00
|
|
|
oDisp.dispatch(oUrl, oArg())
|
|
|
|
End Sub
|
2001-05-16 06:48:54 -05:00
|
|
|
</script:module>
|