2000-11-10 15:12:18 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: queryorder.cxx,v $
|
|
|
|
*
|
2004-03-19 11:11:29 +00:00
|
|
|
* $Revision: 1.11 $
|
2000-11-10 15:12:18 +00:00
|
|
|
*
|
2004-03-19 11:11:29 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2004-03-19 12:11:29 $
|
2000-11-10 15:12:18 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef DBAUI_QUERYORDER_HRC
|
|
|
|
#include "queryorder.hrc"
|
|
|
|
#endif
|
|
|
|
#ifndef DBAUI_QUERYORDER_HXX
|
|
|
|
#include "queryorder.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
|
|
|
|
#include "dbustrings.hrc"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
|
|
|
|
#include <com/sun/star/sdb/XSQLQueryComposer.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBC_COLUMNSEARCH_HPP_
|
|
|
|
#include <com/sun/star/sdbc/ColumnSearch.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _DBAUI_MODULE_DBU_HXX_
|
|
|
|
#include "moduledbu.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
|
|
|
|
#include <connectivity/sqliterator.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
|
|
|
|
#include <connectivity/dbtools.hxx>
|
|
|
|
#endif
|
2001-03-15 07:29:16 +00:00
|
|
|
#ifndef _COMPHELPER_EXTRACT_HXX_
|
|
|
|
#include <comphelper/extract.hxx>
|
2001-02-14 13:37:35 +00:00
|
|
|
#endif
|
|
|
|
|
2001-10-12 14:36:42 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2000-11-10 15:12:18 +00:00
|
|
|
|
|
|
|
using namespace dbaui;
|
|
|
|
using namespace connectivity;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::sdb;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
|
|
|
|
DBG_NAME(DlgOrderCrit);
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
DlgOrderCrit::DlgOrderCrit( Window * pParent,
|
|
|
|
const Reference< XConnection>& _rxConnection,
|
|
|
|
const Reference< XSQLQueryComposer>& _rxQueryComposer,
|
2002-03-04 12:02:32 +00:00
|
|
|
const Reference< XNameAccess>& _rxCols,
|
|
|
|
const Reference< XPropertySet >& _xColumn)
|
2000-11-10 15:12:18 +00:00
|
|
|
:ModalDialog( pParent, ModuleRes(DLG_ORDERCRIT) )
|
|
|
|
,aLB_ORDERFIELD1( this, ResId( LB_ORDERFIELD1 ) )
|
|
|
|
,aLB_ORDERVALUE1( this, ResId( LB_ORDERVALUE1 ) )
|
|
|
|
,aLB_ORDERFIELD2( this, ResId( LB_ORDERFIELD2 ) )
|
|
|
|
,aLB_ORDERVALUE2( this, ResId( LB_ORDERVALUE2 ) )
|
|
|
|
,aLB_ORDERFIELD3( this, ResId( LB_ORDERFIELD3 ) )
|
|
|
|
,aLB_ORDERVALUE3( this, ResId( LB_ORDERVALUE3 ) )
|
|
|
|
,aFT_ORDERFIELD( this, ResId( FT_ORDERFIELD ) )
|
|
|
|
,aFT_ORDERAFTER1( this, ResId( FT_ORDERAFTER1 ) )
|
|
|
|
,aFT_ORDERAFTER2( this, ResId( FT_ORDERAFTER2 ) )
|
|
|
|
,aFT_ORDEROPER( this, ResId( FT_ORDEROPER ) )
|
|
|
|
,aFT_ORDERDIR( this, ResId( FT_ORDERDIR ) )
|
|
|
|
,aBT_OK( this, ResId( BT_OK ) )
|
|
|
|
,aBT_CANCEL( this, ResId( BT_CANCEL ) )
|
|
|
|
,aBT_HELP( this, ResId( BT_HELP ) )
|
2001-06-21 14:07:11 +00:00
|
|
|
,aFL_ORDER( this, ResId( FL_ORDER ) )
|
2000-11-10 15:12:18 +00:00
|
|
|
,aSTR_NOENTRY( ResId( STR_NOENTRY ) )
|
|
|
|
,m_xQueryComposer(_rxQueryComposer)
|
|
|
|
,m_xColumns(_rxCols)
|
|
|
|
,m_xConnection(_rxConnection)
|
|
|
|
{
|
|
|
|
DBG_CTOR(DlgOrderCrit,NULL);
|
|
|
|
|
2004-03-19 11:11:29 +00:00
|
|
|
AllSettings aSettings( GetSettings() );
|
|
|
|
StyleSettings aStyle( aSettings.GetStyleSettings() );
|
|
|
|
aStyle.SetAutoMnemonic( FALSE );
|
|
|
|
aSettings.SetStyleSettings( aStyle );
|
|
|
|
SetSettings( aSettings );
|
|
|
|
|
2000-11-10 15:12:18 +00:00
|
|
|
arrLbFields[0] = &aLB_ORDERFIELD1;
|
|
|
|
arrLbFields[1] = &aLB_ORDERFIELD2;
|
|
|
|
arrLbFields[2] = &aLB_ORDERFIELD3;
|
|
|
|
|
|
|
|
arrLbValues[0] = &aLB_ORDERVALUE1;
|
|
|
|
arrLbValues[1] = &aLB_ORDERVALUE2;
|
|
|
|
arrLbValues[2] = &aLB_ORDERVALUE3;
|
|
|
|
|
|
|
|
xub_StrLen j;
|
|
|
|
for(j=0 ; j < DOG_ROWS ; j++ )
|
|
|
|
{
|
|
|
|
arrLbFields[j]->InsertEntry( aSTR_NOENTRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( j=0 ; j < DOG_ROWS ; j++ )
|
|
|
|
{
|
|
|
|
arrLbFields[j]->SelectEntryPos(0);
|
|
|
|
arrLbValues[j]->SelectEntryPos(0);
|
|
|
|
}
|
|
|
|
// ... sowie auch die restlichen Felder
|
|
|
|
Sequence< ::rtl::OUString> aNames = m_xColumns->getElementNames();
|
|
|
|
const ::rtl::OUString* pBegin = aNames.getConstArray();
|
|
|
|
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
|
|
|
|
Reference<XPropertySet> xColumn;
|
|
|
|
for(;pBegin != pEnd;++pBegin)
|
|
|
|
{
|
2001-02-14 13:37:35 +00:00
|
|
|
::cppu::extractInterface(xColumn,m_xColumns->getByName(*pBegin));
|
|
|
|
OSL_ENSURE(xColumn.is(),"Column is null!");
|
2000-11-10 15:12:18 +00:00
|
|
|
sal_Int32 nDataType;
|
|
|
|
xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
|
|
|
|
sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
|
|
|
|
if(eColumnSearch != ColumnSearch::NONE)
|
|
|
|
{
|
|
|
|
for( j=0 ; j < DOG_ROWS ; j++ )
|
|
|
|
{
|
|
|
|
arrLbFields[j]->InsertEntry(*pBegin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-04 12:02:32 +00:00
|
|
|
m_sOrgOrder = m_xQueryComposer->getOrder();
|
|
|
|
|
|
|
|
if ( _xColumn.is() )
|
|
|
|
m_xQueryComposer->appendOrderByColumn(_xColumn,sal_True);
|
|
|
|
|
|
|
|
SetOrderList( m_xQueryComposer->getOrder() );
|
2000-11-10 15:12:18 +00:00
|
|
|
EnableLines();
|
|
|
|
|
|
|
|
aLB_ORDERFIELD1.SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
|
|
|
|
aLB_ORDERFIELD2.SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
|
|
|
|
|
|
|
|
FreeResource();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define LbText(x) ((x).GetSelectEntry())
|
|
|
|
#define LbPos(x) ((x).GetSelectEntryPos())
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
DlgOrderCrit::~DlgOrderCrit()
|
|
|
|
{
|
|
|
|
DBG_DTOR(DlgOrderCrit,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
IMPL_LINK_INLINE_START( DlgOrderCrit, FieldListSelectHdl, ListBox *, pListBox )
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(DlgOrderCrit,NULL);
|
|
|
|
EnableLines();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IMPL_LINK_INLINE_END( DlgOrderCrit, FieldListSelectHdl, ListBox *, pListBox )
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void DlgOrderCrit::EnableLines()
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(DlgOrderCrit,NULL);
|
|
|
|
if( LbPos(aLB_ORDERFIELD1) == 0 )
|
|
|
|
{
|
|
|
|
String aOrderList(GetOrderList());
|
|
|
|
if(aOrderList.GetTokenCount(','))
|
|
|
|
SetOrderList(aOrderList);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLB_ORDERFIELD2.Disable();
|
|
|
|
aLB_ORDERVALUE2.Disable();
|
|
|
|
|
|
|
|
aLB_ORDERFIELD3.Disable();
|
|
|
|
aLB_ORDERVALUE3.Disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLB_ORDERFIELD2.Enable();
|
|
|
|
aLB_ORDERVALUE2.Enable();
|
|
|
|
|
|
|
|
aLB_ORDERFIELD3.Enable();
|
|
|
|
aLB_ORDERVALUE3.Enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( LbPos(aLB_ORDERFIELD2) == 0 )
|
|
|
|
{
|
|
|
|
String aOrderList(GetOrderList());
|
|
|
|
if(aOrderList.GetTokenCount(','))
|
|
|
|
SetOrderList(aOrderList);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLB_ORDERFIELD3.Disable();
|
|
|
|
aLB_ORDERVALUE3.Disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLB_ORDERFIELD3.Enable();
|
|
|
|
aLB_ORDERVALUE3.Enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void DlgOrderCrit::SetOrderList( const String& _rOrderList )
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(DlgOrderCrit,NULL);
|
2001-08-27 09:50:52 +00:00
|
|
|
Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
|
|
|
|
::rtl::OUString sQuote = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : ::rtl::OUString();
|
|
|
|
|
2000-11-10 15:12:18 +00:00
|
|
|
xub_StrLen nLen = _rOrderList.GetTokenCount(',');
|
|
|
|
xub_StrLen i;
|
|
|
|
for(i=0;i<nLen && i<DOG_ROWS;++i)
|
|
|
|
{
|
|
|
|
String aOrder = _rOrderList.GetToken(i,',');
|
2001-01-25 06:16:20 +00:00
|
|
|
aOrder.EraseTrailingChars();
|
2001-08-27 09:50:52 +00:00
|
|
|
String sColumnName = aOrder.GetToken(0,' ');
|
2002-03-04 12:02:32 +00:00
|
|
|
|
|
|
|
xub_StrLen nCount = sColumnName.GetTokenCount('.');
|
|
|
|
if ( nCount > 1)
|
|
|
|
sColumnName = sColumnName.GetToken(nCount-1,'.');
|
|
|
|
|
2001-08-27 09:50:52 +00:00
|
|
|
if(sQuote.getLength() && sColumnName.Len() && sColumnName.GetChar(0) == sQuote.getStr()[0] && sColumnName.GetChar(sColumnName.Len()-1) == sQuote.getStr()[0])
|
|
|
|
{
|
|
|
|
sColumnName.Erase(0,1);
|
|
|
|
sColumnName.Erase(sColumnName.Len()-1,1);
|
|
|
|
}
|
|
|
|
arrLbFields[i]->SelectEntry( sColumnName );
|
2002-03-04 12:02:32 +00:00
|
|
|
xub_StrLen nAsc = (aOrder.GetTokenCount(' ') == 2) ? (aOrder.GetToken(1,' ').EqualsAscii("ASC") ? 0 : 1) : 0;
|
2000-11-10 15:12:18 +00:00
|
|
|
arrLbValues[i]->SelectEntryPos( nAsc );
|
|
|
|
}
|
|
|
|
|
|
|
|
// die nicht gesetzten auf 'kein' 'aufsteigend'
|
2001-10-12 14:36:42 +00:00
|
|
|
xub_StrLen nItemsSet = std::min(nLen, xub_StrLen(DOG_ROWS));
|
2000-11-10 15:12:18 +00:00
|
|
|
for (i=0 ; i<DOG_ROWS-nItemsSet; ++i)
|
|
|
|
{
|
|
|
|
arrLbFields[2-i]->SelectEntryPos( 0 );
|
|
|
|
arrLbValues[2-i]->SelectEntryPos( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2001-08-27 09:50:52 +00:00
|
|
|
::rtl::OUString DlgOrderCrit::GetOrderList( ) const
|
2000-11-10 15:12:18 +00:00
|
|
|
{
|
|
|
|
DBG_CHKTHIS(DlgOrderCrit,NULL);
|
2001-08-27 09:50:52 +00:00
|
|
|
Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
|
|
|
|
::rtl::OUString sQuote = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : ::rtl::OUString();
|
|
|
|
static const ::rtl::OUString sDESC = ::rtl::OUString::createFromAscii(" DESC ");
|
|
|
|
static const ::rtl::OUString sASC = ::rtl::OUString::createFromAscii(" ASC ");
|
|
|
|
|
|
|
|
::rtl::OUString sOrder;
|
2000-11-10 15:12:18 +00:00
|
|
|
for( sal_uInt16 i=0 ; i<DOG_ROWS; i++ )
|
|
|
|
{
|
|
|
|
if(arrLbFields[i]->GetSelectEntryPos() != 0)
|
|
|
|
{
|
2001-08-27 09:50:52 +00:00
|
|
|
if(sOrder.getLength())
|
|
|
|
sOrder += ::rtl::OUString::createFromAscii(",");
|
2000-11-10 15:12:18 +00:00
|
|
|
|
2001-08-27 09:50:52 +00:00
|
|
|
sOrder += ::dbtools::quoteName(sQuote,arrLbFields[i]->GetSelectEntry());
|
2000-11-10 15:12:18 +00:00
|
|
|
if(arrLbValues[i]->GetSelectEntryPos())
|
2001-08-27 09:50:52 +00:00
|
|
|
sOrder += sDESC;
|
2000-11-10 15:12:18 +00:00
|
|
|
else
|
2001-08-27 09:50:52 +00:00
|
|
|
sOrder += sASC;
|
2000-11-10 15:12:18 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-27 09:50:52 +00:00
|
|
|
return sOrder;
|
2000-11-10 15:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void DlgOrderCrit::BuildOrderPart()
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(DlgOrderCrit,NULL);
|
|
|
|
m_xQueryComposer->setOrder(GetOrderList());
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|