Code: Alles auswählen
' Database
Dim oContext As Object, oDB As Object, oConnection As Object, oQueryRes As Object
Dim DBName$, SQL$
Dim vStatement
' FormObjects
Dim oForm As Object
Dim aField(16), aText(83), aOrder(23), aWorkHrs(83)
Dim aOpt1(), aOpt2(), aOpt3(), aOpt4()
Dim TempText$
Dim s1_1$, s1_2$, s2_1$, s2_2$, s3_1$, s3_2$, s4_1$, s4_2$
'clearForm
Dim n
Dim aFail(3), aGrpFail(3), aTxtField(41), aNumField(83), aAllField(83)
' ErrorProof
Dim vGrpFail
Dim errormsg1$
Dim iError As Integer
' save ODT
Dim datname$, path$, extension$, odturl$, pdfurl$
' addForm
' fillUform
Dim oMainForm As Object, oSubForm As Object
Sub clearForm
aFail() = Array ("grp1_fail","grp2_fail","grp3_fail","grp4_fail")
aTxtField() = Array ("txt_oKey", "txt_oName", "txt_oTitel", "txt_oStrasse", "txt_oOrt", "txt_oPersAnrede", "txt_oTelefon", "txt_oVerladeStNr", "txt_oGeraeteNr", _
"txt_rName", "txt_rTitel", "txt_rStrasse", "txt_rOrt", "txt_oUAuftrBest", "txt_oUAngebNr", "txt_oUBestNr", "txt_oIAuftrNr", "txt_oLangtext",_
"txt_Name1","txt_Name2","txt_Name3","txt_Name4","txt_Name5","txt_Name6","txt_Name7","txt_Name8", _
"txt_ArtNr1","txt_ArtBez1","txt_ArtNr2","txt_ArtBez2","txt_ArtNr3","txt_ArtBez3","txt_ArtNr4","txt_ArtBez4","txt_ArtNr5","txt_ArtBez5", _
"txt_ArtNr6","txt_ArtBez6","txt_ArtNr7","txt_ArtBez7","txt_ArtNr8","txt_ArtBez8")
aNumField() = Array ("num_StdMoName1","num_StdDiName1","num_StdMiName1","num_StdDoName1","num_StdFrName1","num_StdSaName1","num_StdSoName1","num_StdAzGesName1","num_StdFzGesName1", _
"num_StdMoName2","num_StdDiName2","num_StdMiName2","num_StdDoName2","num_StdFrName2","num_StdSaName2","num_StdSoName2","num_StdAzGesName2","num_StdFzGesName2", _
"num_StdMoName3","num_StdDiName3","num_StdMiName3","num_StdDoName3","num_StdFrName3","num_StdSaName3","num_StdSoName3","num_StdAzGesName3","num_StdFzGesName3", _
"num_StdMoName4","num_StdDiName4","num_StdMiName4","num_StdDoName4","num_StdFrName4","num_StdSaName4","num_StdSoName4","num_StdAzGesName4","num_StdFzGesName4", _
"num_StdMoName5","num_StdDiName5","num_StdMiName5","num_StdDoName5","num_StdFrName5","num_StdSaName5","num_StdSoName5","num_StdAzGesName5","num_StdFzGesName5", _
"num_StdMoName6","num_StdDiName6","num_StdMiName6","num_StdDoName6","num_StdFrName6","num_StdSaName6","num_StdSoName6","num_StdAzGesName6","num_StdFzGesName6", _
"num_StdMoName7","num_StdDiName7","num_StdMiName7","num_StdDoName7","num_StdFrName7","num_StdSaName7","num_StdSoName7","num_StdAzGesName7","num_StdFzGesName7", _
"num_StdMoName8","num_StdDiName8","num_StdMiName8","num_StdDoName8","num_StdFrName8","num_StdSaName8","num_StdSoName8","num_StdAzGesName8","num_StdFzGesName8", _
"num_KM","num_U25","num_U50","num_U100","num_ArtAnz1","num_ArtAnz2","num_ArtAnz3","num_ArtAnz4","num_ArtAnz5","num_ArtAnz6","num_ArtAnz7","num_ArtAnz8")
With ThisComponent.DrawPage.Forms.GetByName("mainForm1")
For n = 0 to .Count - 1
On Error Resume Next
If Right(.GetByIndex(n).ServiceName, 11) = "RadioButton" Then
.GetByIndex(n).State = 0
End If
Next n
End With
oForm = thisComponent.drawpage.forms.getbyindex(0)
For i = 0 to 3
aGrpFail(i) = oForm.getByName(aFail(i))
aGrpFail(i).Text=""
Next i
For i = 0 to 41
aAllField(i) = oForm.getByName(aTxtField(i))
aAllField(i).Text=""
aAllField(i).ReadOnly = true
aAllField(i).BackgroundColor = RGB(255,255,255)
Next i
For i = 0 to 83
aAllField(i) = oForm.getByName(aNumField(i))
aAllField(i).reset()
aAllField(i).ReadOnly = true
aAllField(i).BackgroundColor = RGB(255,255,255)
Next i
end Sub
Sub Value_ANr
clearForm
oANr = inputBox ("Auftragsnummer","Eingabe erforderlich","Bitte Auftragsnummer eingeben")
auftnr = oANr
oForm = thisComponent.drawpage.forms.getbyindex(0)
aField() = Array ("txt_oKey", "txt_oName", "txt_oTitel", "txt_oStrasse", "txt_oOrt", "txt_oPersAnrede", "txt_oTelefon", _
"txt_rName", "txt_rTitel", "txt_rStrasse", "txt_rOrt", "txt_oLangtext")
for i = 0 to 11
aText(i) = oForm.getByName(aField(i))
next i
DBName = "REPARATUR"
oContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDB = oContext.GetByName (DBName)
oConnection = oDB.GetConnection ("","")
Sql = "SELECT `key`,`objekt_name`,`objekt_titel`,`objekt_strasse`,`objekt_ort`,`objekt_persanrede`,`objekt_telefon`,`rechnung_name`,`rechnung_titel`,`rechnung_strasse`,`rechnung_ort`,`langtext` FROM `REPARATUR` WHERE `key` = '"+oANr+"';"
vStatement = oConnection.CreateStatement
oQueryRes = vStatement.ExecuteQuery(SQL)
for i = 0 to 11
aText(i).text = trim(oQueryRes.GetString(i+1))
if i = 11 then
TempText = trim(oQueryRes.GetString(i+1))
aText(i).text = Replace(TempText, Chr$(10)& Chr$(13), "")
end if
next i
oConnection.Close()
End Sub
Sub freeEdit
oForm = thisComponent.drawpage.forms.getbyindex(0)
oEdit = oForm.getByName("chk_edit")
aField() = Array ("txt_oName", "txt_oTitel", "txt_oStrasse", "txt_oOrt", "txt_oPersAnrede", "txt_oTelefon", "txt_oVerladeStNr", "txt_oGeraeteNr", _
"txt_rName", "txt_rTitel", "txt_rStrasse", "txt_rOrt", "txt_oUAuftrBest", "txt_oUAngebNr", "txt_oUBestNr", "txt_oIAuftrNr", "txt_oLangtext")
for i = 0 to 16
aText(i) = oForm.getByName(aField(i))
next i
if oEdit.State = 1 then
for i = 0 to 16
aText(i).ReadOnly = false
aText(i).BackgroundColor = RGB(200,2000,200)
next i
MsgBox "Alle grauen Felder können nun frei" & CHR$(10) & " geändert oder ergänzt werden", 0, "Hinweis!"
else
for i = 0 to 16
aText(i).ReadOnly = true
aText(i).BackgroundColor = RGB(255,255,255)
next i
end if
end Sub
Sub proofOptGrp1
iError = 0
oForm = thisComponent.drawpage.forms.getbyindex(0)
oForm.getGroupByName("opt_grp1", aOpt1)
vGrpFail = oForm.getbyName("grp1_fail")
errormsg1 = "In der markierten Optionsgruppe liegt ein Fehler vor" & CHR$(10) & "BITTE PRÜFEN!"
bSelected = False
For i = LBound(aOpt1) to UBound(aOpt1)
thisElement = aOpt1(i)
If thisElement.ServiceName = "stardiv.one.form.component.RadioButton" Then
If thisElement.State Then
bSelected = True
s1_1 = thisElement.Name
s1_2 = thisElement.Label
Exit For
End If
End If
Next i
If bSelected Then
vGrpFail.text = ""
Else
vGrpFail.text = "!"
MsgBox errormsg1, 0+48, "Achtung"
iError = 1
End If
end sub
Sub proofOptGrp2
oForm = thisComponent.drawpage.forms.getbyindex(0)
oForm.getGroupByName("opt_grp2", aOpt2)
vGrpFail = oForm.getbyName("grp2_fail")
aWorkHrs() = Array ("txt_Name1","num_StdMoName1","num_StdDiName1","num_StdMiName1","num_StdDoName1", _
"num_StdFrName1","num_StdSaName1","num_StdSoName1","num_StdAzGesName1","num_StdFzGesName1", _
"txt_Name2","num_StdMoName2","num_StdDiName2","num_StdMiName2","num_StdDoName2","num_StdFrName2", _
"num_StdSaName2","num_StdSoName2","num_StdAzGesName2","num_StdFzGesName2", _
"txt_Name3","num_StdMoName3","num_StdDiName3","num_StdMiName3","num_StdDoName3","num_StdFrName3", _
"num_StdSaName3","num_StdSoName3","num_StdAzGesName3","num_StdFzGesName3", _
"txt_Name4","num_StdMoName4","num_StdDiName4","num_StdMiName4","num_StdDoName4","num_StdFrName4", _
"num_StdSaName4","num_StdSoName4","num_StdAzGesName4","num_StdFzGesName4", _
"txt_Name5","num_StdMoName5","num_StdDiName5","num_StdMiName5","num_StdDoName5","num_StdFrName5", _
"num_StdSaName5","num_StdSoName5","num_StdAzGesName5","num_StdFzGesName5", _
"txt_Name6","num_StdMoName6","num_StdDiName6","num_StdMiName6","num_StdDoName6","num_StdFrName6", _
"num_StdSaName6","num_StdSoName6","num_StdAzGesName6","num_StdFzGesName6", _
"txt_Name7","num_StdMoName7","num_StdDiName7","num_StdMiName7","num_StdDoName7","num_StdFrName7", _
"num_StdSaName7","num_StdSoName7","num_StdAzGesName7","num_StdFzGesName7", _
"txt_Name8","num_StdMoName8","num_StdDiName8","num_StdMiName8","num_StdDoName8","num_StdFrName8", _
"num_StdSaName8","num_StdSoName8","num_StdAzGesName8","num_StdFzGesName8", _
"num_KM","num_U25","num_U50","num_U100")
errormsg1 = "In der markierten Optionsgruppe liegt ein Fehler vor" & CHR$(10) & "BITTE PRÜFEN!"
bSelected = False
For i = LBound(aOpt2) to UBound(aOpt2)
thisElement = aOpt2(i)
If thisElement.ServiceName = "stardiv.one.form.component.RadioButton" Then
If thisElement.State Then
bSelected = True
s2_1 = thisElement.Name
s2_2 = thisElement.Label
Exit For
End If
End If
Next i
If bSelected And s2_2 = "Lohnnachweis" Then
vGrpFail.text = ""
MsgBox "Einträge in den roten Feldern" & CHR$(10) & "sind zwingend erforderlich", 0+48, "Achtung"
for i = 0 to 83
aText(i) = oForm.getByName(aWorkHrs(i))
aText(i).ReadOnly = false
aText(i).BackgroundColor = RGB(255,119,119)
next i
Elseif bSelected And s2_2 = "zum Festpreis" Then
vGrpFail.text = ""
for i = 0 to 83
aText(i) = oForm.getByName(aWorkHrs(i))
aText(i).ReadOnly = true
aText(i).BackgroundColor = RGB(255,255,255)
next i
Else
vGrpFail.text = "!"
MsgBox errormsg1, 0+48, "Achtung"
iError = iError + 1
End If
end sub
Sub proofOptGrp3
oForm = thisComponent.drawpage.forms.getbyindex(0)
oForm.getGroupByName("opt_grp3", aOpt3)
vGrpFail = oForm.getbyName("grp3_fail")
errormsg1 = "In der markierten Optionsgruppe liegt ein Fehler vor" & CHR$(10) & "BITTE PRÜFEN!"
bSelected = False
For i = LBound(aOpt3) to UBound(aOpt3)
thisElement = aOpt3(i)
If thisElement.ServiceName = "stardiv.one.form.component.RadioButton" Then
If thisElement.State Then
bSelected = True
s3_1 = thisElement.Name
s3_2 = thisElement.Label
Exit For
End If
End If
Next i
If bSelected Then
vGrpFail.text = ""
Else
vGrpFail.text = "!"
MsgBox errormsg1, 0+48, "Achtung"
iError = iError + 1
End If
end sub
Sub proofOptGrp4
oForm = thisComponent.drawpage.forms.getbyindex(0)
oForm.getGroupByName("opt_grp4", aOpt4)
vGrpFail = oForm.getbyName("grp4_fail")
aOrder() = Array ("txt_ArtNr1","txt_ArtBez1","num_ArtAnz1","txt_ArtNr2","txt_ArtBez2","num_ArtAnz2","txt_ArtNr3","txt_ArtBez3","num_ArtAnz3", _
"txt_ArtNr4","txt_ArtBez4","num_ArtAnz4","txt_ArtNr5","txt_ArtBez5","num_ArtAnz5","txt_ArtNr6","txt_ArtBez6","num_ArtAnz6", _
"txt_ArtNr7","txt_ArtBez7","num_ArtAnz7","txt_ArtNr8","txt_ArtBez8","num_ArtAnz8")
errormsg1 = "In der markierten Optionsgruppe liegt ein Fehler vor" & CHR$(10) & "BITTE PRÜFEN!"
bSelected = False
For i = LBound(aOpt4) to UBound(aOpt4)
thisElement = aOpt4(i)
If thisElement.ServiceName = "stardiv.one.form.component.RadioButton" Then
If thisElement.State Then
bSelected = True
s4_1 = thisElement.Name
s4_2 = thisElement.Label
Exit For
End If
End If
Next i
If bSelected And s4_2 = "Ja" Then
vGrpFail.text = ""
MsgBox "Einträge in den roten Feldern" & CHR$(10) & "sind zwingend erforderlich", 0+48, "Achtung"
for i = 0 to 23
aText(i) = oForm.getByName(aOrder(i))
aText(i).ReadOnly = false
aText(i).BackgroundColor = RGB(255,119,119)
next i
Elseif bSelected And s4_2 = "Nein" Then
vGrpFail.text = ""
for i = 0 to 23
aText(i) = oForm.getByName(aOrder(i))
aText(i).ReadOnly = true
aText(i).BackgroundColor = RGB(255,255,255)
next i
Else
vGrpFail.text = "!"
MsgBox errormsg1, 0+48, "Achtung"
iError = iError + 1
End If
end sub
Sub proofAllOptGrp1
proofOptGrp1
proofOptGrp2
End Sub
Sub proofAllOptGrp2
proofOptGrp3
proofOptGrp4
End Sub
Sub Save_as_ODT
Dim Speichern
if thisComponent.title = "Auftrag_Form1.odt" then
proofAllOptGrp1
else
proofAllOptGrp2
endif
if iError > 0 then
MsgBox "Sie haben noch "& iError &" Fehler zu beheben", 0+48, "Achtung"
exit Sub
else
oform = thisComponent.drawpage.forms.getbyindex(0)
'aText = oForm.getByName("txt_oName")
aNum = oForm.getByName("txt_oKey")
if aText.text = "" then
datname = "leer"
else
'datname = aNum.text & "_" & aText.text
datname = aNum.text
end if
path = "C:/Roiger/Auftraege/"
extension = ".odt"
odturl = "file:///" + path + datname + extension
if FileExists (odturl) then
Speichern = MsgBox ("Eine Datei mit dem Namen" & CHR$(10) & odturl & CHR$(10) & "existiert bereits!" _
& CHR$(10) & "Soll sie überschrieben werden?",4+48, "Achtung")
if Speichern = 7 then
msgbox "Datei wurde nicht gespeichert", 0, "Information"
exit sub
end if
'thisComponent.storeToURL(odturl, Array())
if thisComponent.URL = path then
thisComponent.store
else
thisComponent.storeToURL(path, Array())
msgbox "Datei wurde gespeichert", 0, "Information"
endif
End Sub
'Sub Save_as_PDF
'
'proofAllOptGrp
'
' if iError > 0 then
' MsgBox "Sie haben noch "& iError &" Fehler zu beheben", 0+48, "Achtung"
' end if
' Sub verlassen
'
' oform = thisComponent.drawpage.forms.getbyindex(0)
' aText = oForm.getByName("txt_oName")
' if aText.text = "" then
' datname = "blanc"
' else
' datname = aText.text
' end if
' path = "C:/Roiger/Auftraege/PDF/"
' extension = ".pdf"
' pdfurl = "file:///" + path + datname + extension
' dim pdfProperties(1) as new com.sun.star.beans.PropertyValue
' pdfProperties(0).Name = "FilterName"
' pdfProperties(0).Value = "writer_pdf_Export"
' thisComponent.storeToURL(pdfurl, pdfProperties())
'
'clearForm
'
'End Sub
Sub addPruefForm_TT
oViewCursor = thisComponent.getCurrentController.getViewCursor
oViewCursor.jumpToLastPage(true)
oViewCursor.jumpToEndofPage(true)
Dim args2(0) as New com.sun.star.beans.PropertyValue
oText = thisComponent.getText()
oTextCursor = oText.createTextCursor
oTextCursor.gotoEnd(False)
oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_AFTER
oText.insertControlCharacter(oTextCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
sInhalt="file:///C:/Roiger/xtFormulare/subForm_TT.odt"
filetoinsert=converttourl(sInhalt)
oTextCursor.InsertDocumentFromUrl(FileToInsert,args2())
fillUform
End Sub
Sub addPruefForm_VT
oViewCursor = thisComponent.getCurrentController.getViewCursor
oViewCursor.jumpToLastPage(true)
oViewCursor.jumpToEndofPage(true)
Dim args2(0) as New com.sun.star.beans.PropertyValue
oText = thisComponent.getText()
oTextCursor = oText.createTextCursor
oTextCursor.gotoEnd(False)
oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_AFTER
oText.insertControlCharacter(oTextCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
sInhalt="file:///C:/Roiger/xtFormulare/subForm_VT.odt"
filetoinsert=converttourl(sInhalt)
oTextCursor.InsertDocumentFromUrl(FileToInsert,args2())
fillUform
End Sub
Sub fillUform
oMainForm = thisComponent.Drawpage.Forms.getByIndex(0)
oSubForm = thisComponent.Drawpage.Forms.getByIndex(thisComponent.Drawpage.Forms.Count - 1)
aField() = Array ("txt_oName", "txt_oTelefon","txt_oStrasse", "txt_oOrt")
for i = 0 to 3
aText(i) = oSubForm.getByName(aField(i))
If oMainForm.hasByName(aText(i).Name) Then
aText(i).Text = oMainForm.getByName(aText(i).Name).Text
else
aText(i).Text = "keine Daten"
End If
next i
End sub