1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _SWDBMGR_HXX 28 #define _SWDBMGR_HXX 29 30 31 #include <tools/string.hxx> 32 #include <tools/link.hxx> 33 #include <svl/svarray.hxx> 34 #include <com/sun/star/util/Date.hpp> 35 #include "swdllapi.h" 36 #include <swdbdata.hxx> 37 #include <com/sun/star/uno/Reference.h> 38 #include <com/sun/star/uno/Sequence.hxx> 39 #include <com/sun/star/lang/Locale.hpp> 40 #include <com/sun/star/beans/PropertyValue.hpp> 41 namespace com{namespace sun{namespace star{ 42 namespace sdbc{ 43 class XConnection; 44 class XStatement; 45 class XDataSource; 46 class XResultSet; 47 } 48 namespace beans{ 49 50 class XPropertySet; 51 struct PropertyValue; 52 } 53 namespace sdbcx{ 54 class XColumnsSupplier; 55 } 56 namespace util{ 57 class XNumberFormatter; 58 } 59 namespace mail{ 60 class XSmtpService; 61 } 62 }}} 63 namespace svx { 64 class ODataAccessDescriptor; 65 } 66 67 struct SwDBFormatData 68 { 69 com::sun::star::util::Date aNullDate; 70 com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter> xFormatter; 71 com::sun::star::lang::Locale aLocale; 72 }; 73 74 class SwView; 75 class SwWrtShell; 76 class SfxProgress; 77 class ListBox; 78 class Button; 79 class SvNumberFormatter; 80 class SwDbtoolsClient; 81 class SwXMailMerge; 82 class SwMailMergeConfigItem; 83 84 // ----------------------------------------------------------------------- 85 86 enum DBMgrOptions 87 { 88 DBMGR_MERGE, // Datensaetze in Felder 89 DBMGR_INSERT, // Datensaetze in Text 90 DBMGR_MERGE_MAILMERGE, // Serienbriefe drucken 91 DBMGR_MERGE_MAILING, // Serienbriefe als email versenden 92 DBMGR_MERGE_MAILFILES, // Serienbriefe als Datei(en) speichern 93 DBMGR_MERGE_DOCUMENTS, // Print merged documents 94 DBMGR_MERGE_SINGLE_FILE // save merge as single file 95 }; 96 97 // ----------------------------------------------------------------------- 98 99 /*-------------------------------------------------------------------- 100 Beschreibung: (neue) Logische Datenbanken verwalten 101 --------------------------------------------------------------------*/ 102 #define SW_DB_SELECT_UNKNOWN 0 103 #define SW_DB_SELECT_TABLE 1 104 #define SW_DB_SELECT_QUERY 2 105 106 struct SwDSParam : public SwDBData 107 { 108 com::sun::star::util::Date aNullDate; 109 110 ::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter> xFormatter; 111 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection; 112 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> xStatement; 113 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet; 114 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSelection; 115 sal_Bool bScrollable; 116 sal_Bool bEndOfDB; 117 sal_Bool bAfterSelection; 118 long nSelectionIndex; 119 120 SwDSParam(const SwDBData& rData) : 121 SwDBData(rData), 122 bScrollable(sal_False), 123 bEndOfDB(sal_False), 124 bAfterSelection(sal_False), 125 nSelectionIndex(0) 126 {} 127 128 SwDSParam(const SwDBData& rData, 129 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& xResSet, 130 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rSelection) : 131 SwDBData(rData), 132 xResultSet(xResSet), 133 aSelection(rSelection), 134 bScrollable(sal_True), 135 bEndOfDB(sal_False), 136 bAfterSelection(sal_False), 137 nSelectionIndex(0) 138 {} 139 140 void CheckEndOfDB() 141 { 142 if(bEndOfDB) 143 bAfterSelection = sal_True; 144 } 145 }; 146 typedef SwDSParam* SwDSParamPtr; 147 SV_DECL_PTRARR_DEL(SwDSParamArr, SwDSParamPtr, 0, 5) 148 149 struct SwMergeDescriptor 150 { 151 sal_uInt16 nMergeType; 152 SwWrtShell& rSh; 153 const ::svx::ODataAccessDescriptor& rDescriptor; 154 String sSaveToFilter; //export filter to save resulting files 155 String sSaveToFilterOptions; // 156 com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSaveToFilterData; 157 158 String sSubject; 159 String sAddressFromColumn; 160 String sMailBody; 161 String sAttachmentName; 162 ::com::sun::star::uno::Sequence< ::rtl::OUString > aCopiesTo; 163 ::com::sun::star::uno::Sequence< ::rtl::OUString > aBlindCopiesTo; 164 165 ::com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService > xSmtpServer; 166 167 sal_Bool bSendAsHTML; 168 sal_Bool bSendAsAttachment; 169 170 sal_Bool bPrintAsync; 171 sal_Bool bCreateSingleFile; 172 173 SwMailMergeConfigItem* pMailMergeConfigItem; 174 175 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aPrintOptions; 176 177 SwMergeDescriptor( sal_uInt16 nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) : 178 nMergeType(nType), 179 rSh(rShell), 180 rDescriptor(rDesc), 181 bSendAsHTML( sal_True ), 182 bSendAsAttachment( sal_False ), 183 bPrintAsync( sal_False ), 184 bCreateSingleFile( sal_False ), 185 pMailMergeConfigItem(0) 186 {} 187 188 }; 189 190 struct SwNewDBMgr_Impl; 191 class SwConnectionDisposedListener_Impl; 192 class AbstractMailMergeDlg; 193 194 class SW_DLLPUBLIC SwNewDBMgr 195 { 196 friend class SwConnectionDisposedListener_Impl; 197 198 static SwDbtoolsClient* pDbtoolsClient; 199 200 String sEMailAddrFld; // Mailing: Spaltenname der E-Mail Adresse 201 String sSubject; // Mailing: Subject 202 String sAttached; // Mailing: Attachte Files 203 sal_uInt16 nMergeType; 204 sal_Bool bInitDBFields : 1; // sal_True: Datenbank an Feldern beim Mergen 205 sal_Bool bSingleJobs : 1; // Einzelne Druckjobs bei Aufruf aus Basic 206 sal_Bool bCancel : 1; // Serienbrief-Save abgebrochen 207 208 sal_Bool bInMerge : 1; //merge process active 209 sal_Bool bMergeSilent : 1; // suppress display of dialogs/boxes (used when called over API) 210 sal_Bool bMergeLock : 1; // prevent update of database fields while document is 211 // actually printed at the ViewShell 212 SwDSParamArr aDataSourceParams; 213 SwNewDBMgr_Impl* pImpl; 214 const SwXMailMerge* pMergeEvtSrc; // != 0 if mail merge events are to be send 215 216 SW_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, sal_Bool bCreate); 217 SW_DLLPRIVATE SwDSParam* FindDSConnection(const ::rtl::OUString& rSource, sal_Bool bCreate); 218 219 220 SW_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * ); 221 222 // Datensaetze als Text ins Dokument einfuegen 223 SW_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh); 224 225 // Einzelnen Datensatz als Text ins Dokument einfuegen 226 SW_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh); 227 228 // merge to file _and_ merge to e-Mail 229 SW_DLLPRIVATE sal_Bool MergeMailFiles(SwWrtShell* pSh, 230 const SwMergeDescriptor& rMergeDescriptor ); 231 SW_DLLPRIVATE sal_Bool ToNextRecord(SwDSParam* pParam); 232 233 public: 234 SwNewDBMgr(); 235 ~SwNewDBMgr(); 236 237 // Art des aktellen Mergens. Siehe DBMgrOptions-enum 238 inline sal_uInt16 GetMergeType() const { return nMergeType; } 239 inline void SetMergeType( sal_uInt16 nTyp ) { nMergeType = nTyp; } 240 241 // MailMergeEvent source 242 const SwXMailMerge * GetMailMergeEvtSrc() const { return pMergeEvtSrc; } 243 void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; } 244 245 inline sal_Bool IsMergeSilent() const { return bMergeSilent != 0; } 246 inline void SetMergeSilent( sal_Bool bVal ) { bMergeSilent = bVal; } 247 248 // Mischen von Datensaetzen in Felder 249 sal_Bool MergeNew( const SwMergeDescriptor& rMergeDesc ); 250 sal_Bool Merge(SwWrtShell* pSh); 251 252 // Datenbankfelder mit fehlendem Datenbankname initialisieren 253 inline sal_Bool IsInitDBFields() const { return bInitDBFields; } 254 inline void SetInitDBFields(sal_Bool b) { bInitDBFields = b; } 255 256 // Serienbriefe einzelnd oder alle zusammen drucken/speichern 257 inline sal_Bool IsSingleJobs() const { return bSingleJobs; } 258 inline void SetSingleJobs(sal_Bool b) { bSingleJobs = b; } 259 260 // Mailing 261 // email-Daten setzen 262 inline void SetEMailColumn(const String& sColName) { sEMailAddrFld = sColName; } 263 inline void SetSubject(const String& sSbj) { sSubject = sSbj; } 264 inline void SetAttachment(const String& sAtt) { sAttached = sAtt; } 265 266 267 // Listbox mit allen Tabellennamen einer Datenbank fuellen 268 sal_Bool GetTableNames(ListBox* pListBox, const String& rDBName ); 269 270 // Listbox mit allen Spaltennamen einer Datenbanktabelle fuellen 271 sal_Bool GetColumnNames(ListBox* pListBox, 272 const String& rDBName, const String& rTableName, sal_Bool bAppend = sal_False); 273 sal_Bool GetColumnNames(ListBox* pListBox, 274 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection, 275 const String& rTableName, sal_Bool bAppend = sal_False); 276 277 sal_uLong GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource, 278 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection, 279 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn, 280 SvNumberFormatter* pNFmtr, 281 long nLanguage ); 282 283 sal_uLong GetColumnFmt( const String& rDBName, 284 const String& rTableName, 285 const String& rColNm, 286 SvNumberFormatter* pNFmtr, 287 long nLanguage ); 288 sal_Int32 GetColumnType( const String& rDBName, 289 const String& rTableName, 290 const String& rColNm ); 291 292 inline sal_Bool IsInMerge() const { return bInMerge; } 293 void EndMerge(); 294 295 void ExecuteFormLetter(SwWrtShell& rSh, 296 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties, 297 sal_Bool bWithDataSourceBrowser = sal_False); 298 299 void InsertText(SwWrtShell& rSh, 300 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties); 301 302 // check if a data source is open 303 sal_Bool IsDataSourceOpen(const String& rDataSource, 304 const String& rTableOrQuery, sal_Bool bMergeOnly); 305 306 // open the source while fields are updated - for the calculator only! 307 sal_Bool OpenDataSource(const String& rDataSource, const String& rTableOrQuery, 308 sal_Int32 nCommandType = -1, bool bCreate = false); 309 sal_uInt32 GetSelectedRecordId(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1); 310 sal_Bool GetColumnCnt(const String& rSourceName, const String& rTableName, 311 const String& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage, 312 String& rResult, double* pNumber); 313 //create and store or find an already stored connection to a data source for use 314 //in SwFldMgr and SwDBTreeList 315 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> 316 RegisterConnection(::rtl::OUString& rSource); 317 318 const SwDSParam* CreateDSData(const SwDBData& rData) 319 {return FindDSData(rData, sal_True);} 320 const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;} 321 322 323 //close all data sources - after fields were updated 324 void CloseAll(sal_Bool bIncludingMerge = sal_True); 325 326 sal_Bool GetMergeColumnCnt(const String& rColumnName, sal_uInt16 nLanguage, 327 String &rResult, double *pNumber, sal_uInt32 *pFormat); 328 sal_Bool ToNextMergeRecord(); 329 sal_Bool ToNextRecord(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1); 330 331 sal_Bool ExistsNextRecord()const; 332 sal_uInt32 GetSelectedRecordId(); 333 sal_Bool ToRecordId(sal_Int32 nSet); 334 335 const SwDBData& GetAddressDBName(); 336 337 static String GetDBField( 338 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp, 339 const SwDBFormatData& rDBFormatData, 340 double *pNumber = NULL); 341 342 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> 343 GetConnection(const String& rDataSource, 344 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource); 345 346 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> 347 GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>, 348 const String& rTableOrQuery, 349 sal_uInt8 eTableOrQuery = SW_DB_SELECT_UNKNOWN); 350 351 static ::com::sun::star::uno::Sequence<rtl::OUString> GetExistingDatabaseNames(); 352 353 /** 354 Loads a data source from file and registers it. Returns the registered name. 355 */ 356 static String LoadAndRegisterDataSource(); 357 358 static SwDbtoolsClient& GetDbtoolsClient(); 359 // has to be called from _FinitUI() 360 static void RemoveDbtoolsClient(); 361 362 /** try to get the data source from the given connection through the XChild interface. 363 If this is not possible, the data source will be created through its name. 364 @param _xConnection 365 The connection which should support the XChild interface. (not a must) 366 @param _sDataSourceName 367 The data source name will be used to create the data source when the connection can not be used for it. 368 @return 369 The data source. 370 */ 371 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> 372 getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const ::rtl::OUString& _sDataSourceName); 373 374 /** creates a RowSet, which must be disposed after use. 375 @param _sDataSourceName 376 The data source name 377 @param _sCommand 378 The command. 379 @param _nCommandType 380 The type of the command. 381 @param _xConnection 382 The active connection which may be <NULL/>. 383 @return 384 The new created RowSet. 385 386 */ 387 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> 388 createCursor( const ::rtl::OUString& _sDataSourceName, 389 const ::rtl::OUString& _sCommand, 390 sal_Int32 _nCommandType, 391 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection 392 ); 393 //merge into one document - returns the number of merged docs 394 sal_Int32 MergeDocuments( SwMailMergeConfigItem& rMMConfig, SwView& rSourceView ); 395 }; 396 397 #endif 398 399