|
#pragma once
/***************************************************************************
PGWizConnect.h - This page gets the database name, user name, password,
etc from the user and attempts to connect when the "Next"
button is clicked.
Note that the entry fields are automatically stocked with
the previous execution's entries. It does this because I
got sick of typing things in.
begin : December 2004
copyright : (C) 2004-2006 by Phil Cairns
email : oti169@hotmail.com
$Id: PGWizConnect.h 2080 2006-08-18 01:53:19Z phil $
This code may be used in compiled form in any way you desire (including
commercial use). The code may be redistributed unmodified by any means
providing it is not sold for profit without the authors written consent,
and providing that this notice and the authors name and all copyright
notices remains intact.
This software is provided "as is" without express or implied warranty. Use
it at your own risk!
***************************************************************************/
#include "GlobalData.h"
class PGWizConnect
: public CPropertyPageImpl<PGWizConnect>
, public CPWinDataExchange<PGWizConnect>
{
public:
enum { IDD = IDD_CONNECT };
PGWizConnect(void)
{
GlobalData& gd = GlobalDataS::instance();
m_Server = gd.regParam("ServerName").c_str();
m_Username = gd.regParam("Username").c_str();
m_Database = gd.regParam("Database").c_str();
m_Port = gd.regParam("Port").c_str();
m_Schema = gd.regParam("Schema").c_str();
#ifdef _DEBUG
m_Password = "your development password";
#endif
if (m_Port == "")
{
m_Port = "5432";
}
if (m_Schema == "")
{
m_Schema = "public";
}
}
CString m_Server;
CString m_Port;
CString m_Username;
CString m_Password;
CString m_Database;
CString m_Schema;
BEGIN_MSG_MAP(PGWizConnect)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
CHAIN_MSG_MAP(CPropertyPageImpl<PGWizConnect>)
END_MSG_MAP()
BEGIN_DDX_MAP(PGWizConnect)
DDX_TEXT(IDC_SERVER, m_Server)
DDX_TEXT(IDC_PORT, m_Port)
DDX_TEXT(IDC_USERNAME, m_Username)
DDX_TEXT(IDC_PASSWORD, m_Password)
DDX_TEXT(IDC_DATABASE, m_Database)
DDX_TEXT(IDC_SCHEMA, m_Schema)
END_DDX_MAP()
// Ensure that what we have from the registry is put into the
// window when it is initialised.
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HICON hIcon = ::LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME));
GetParent().SetIcon(hIcon, FALSE);
GetParent().SetIcon(hIcon, TRUE);
DoDataExchange(FALSE);
return 1;
}
LRESULT OnSetActive()
{
DoDataExchange(FALSE);
return 1;
}
LRESULT OnWizardNext()
{
GlobalData& gd = GlobalDataS::instance();
DoDataExchange(TRUE);
std::stringstream ss;
if (m_Server != "")
{
ss << " host=" << (const char*)m_Server;
}
if (m_Port != "")
{
ss << " port=" << (const char*)m_Port;
}
if (m_Username != "")
{
ss << " user=" << (const char*)m_Username;
}
if (m_Password != "")
{
ss << " password=" << (const char*)m_Password;
}
if (m_Database != "")
{
ss << " dbname=" << (const char*)m_Database;
}
gd.dbConn(ss.str());
pqxx::connection* pConn = gd.dbConn();
if (pConn->is_open())
{
gd.schema((const char*)m_Schema);
gd.regParam("ServerName", m_Server);
gd.regParam("Username", m_Username);
gd.regParam("Database", m_Database);
gd.regParam("Port", m_Port);
gd.regParam("Schema", m_Schema);
return 0;
}
MessageBox("Failed to connect to the database!", "Connect Failed", MB_ICONSTOP);
return -1;
}
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.