/////////////////////////////////////////////////////////////////////////////
// Name:        dbcard.cpp (generated and maintained by wxWorkshop's RAD)
// Purpose:     
// Author:      
// Modified by:
// Created:     02/18/01 10:36:22
// RCS-ID:      $ Id$
// Copyright:   (c) 
// Licence:   	
/////////////////////////////////////////////////////////////////////////////

// %%INFO-{
// { TEMPL = "wxCardCtrl for C++ (requires WSPP)" WND_RES = "DbCard" MENU_RES = "" DECL_FILE = "dbcard.h" CLASS = "DbCard" RES_FILE = "demo.xrc" }
// %%INFO-}

#ifdef __GNUG__
    #pragma implementation "dbcard.cpp"
    #pragma interface "dbcard.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "dbcard.h"
#include "wx/xml/xmlres.h"
#include "wx/wspp/init.h"



/***** Implementation for class DbCard *****/

IMPLEMENT_DYNAMIC_CLASS( DbCard, wxCardCtrl )

BEGIN_EVENT_TABLE( DbCard, wxCardCtrl )

// %%EVT_TBL-{
	EVT_BUTTON( XMLID("run"), DbCard::OnButtonRun )
	EVT_BUTTON( XMLID("clear"), DbCard::OnButtonClear )
	EVT_BUTTON( XMLID("back"), DbCard::OnButtonBack )
	EVT_INIT_DIALOG( DbCard::OnInitDialog )
	EVT_BUTTON( XMLID("results"), DbCard::OnButtonResults )
// %%EVT_TBL-}

END_EVENT_TABLE()

DbCard::DbCard()

	: wxCardCtrl()
{       
}

DbCard::~DbCard()
{         
}

// %%EVT_IMPS-{

void DbCard::OnButtonRun( wxCommandEvent& event )
{
	ExchangeValues( FALSE );

	m_pDblist->SetODBCDataSource( m_Dsn, m_User, m_Password );

	if ( m_Sortcol.Length() )

		m_pDblist->Sort( m_Sortcol, !m_Descending );

	m_pDblist->RunQuery( m_Query );

	ShowCard( XMLID( "resultspanel" ) );
}

void DbCard::OnButtonClear( wxCommandEvent& event )
{
	DoInit();
}

void DbCard::OnButtonBack( wxCommandEvent& event )
{
	ShowCard( XMLID( "setuppanel" ) );
}

void DbCard::OnInitDialog( wxInitDialogEvent& event )
{
	DoInit();
}

void DbCard::OnButtonResults( wxCommandEvent& event )
{                                       
	ShowCard( XMLID( "resultspanel" ) );
}
// %%EVT_IMPS-}

// %%GETTER_IMPLS-{
// %%GETTER_IMPLS-}

// %%SETTER_IMPLS-{
// %%SETTER_IMPLS-}

/*** protected members ***/

void DbCard::DoInit()
{
	// %%MEMBER_INITS-{
	m_Dsn = _("");
	m_User = _("");
	m_Password = _("");
	m_Query = _("");
	m_Sortcol = _("");
	m_Descending = FALSE;
	// %%MEMBER_INITS-}

	// %%CTL_MEMBER_INITS-{
	m_pDsn = (wxTextCtrl*)wxXmlFindWindow( "dsn", this );
	m_pUser = (wxTextCtrl*)wxXmlFindWindow( "user", this );
	m_pPassword = (wxTextCtrl*)wxXmlFindWindow( "password", this );
	m_pQuery = (wxTextCtrl*)wxXmlFindWindow( "query", this );
	m_pSortcol = (wxTextCtrl*)wxXmlFindWindow( "sortcol", this );
	m_pDescending = (wxCheckBox*)wxXmlFindWindow( "descending", this );
	m_pDblist = (wxDbListCtrl*)wxXmlFindWindow( "dblist", this );
	// %%CTL_MEMBER_INITS-}
	
	ExchangeValues( TRUE );	
}

void DbCard::ExchangeValues( bool toControls )
{
	if ( toControls )
	{
	// %%MEMBER_VALUES_TO_CTL-{
	m_pDsn->SetValue( m_Dsn );
	m_pUser->SetValue( m_User );
	m_pPassword->SetValue( m_Password );
	m_pQuery->SetValue( m_Query );
	m_pSortcol->SetValue( m_Sortcol );
	m_pDescending->SetValue( m_Descending );
	// %%MEMBER_VALUES_TO_CTL-}
	}
	else
	{
	// %%CTL_VALUES_TO_MEMBER-{
	m_Dsn = m_pDsn->GetValue();
	m_User = m_pUser->GetValue();
	m_Password = m_pPassword->GetValue();
	m_Query = m_pQuery->GetValue();
	m_Sortcol = m_pSortcol->GetValue();
	m_Descending = m_pDescending->GetValue();
	// %%CTL_VALUES_TO_MEMBER-}
	}
}

