// Created: 19991127.mj10777
// Copyright: (c) Mark Johnson
// Licence: wxWindows license
+// RCS-ID: $Id$
//---------------------------------------------------------------------------
//-- 1)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <wx/dbtable.h>
#include "std.h"
+#include <iostream>
//---------------------------------------------------------------------------
// Global structure for holding ODBC connection information
// - darf nur einmal im Projekte definiert werden ?? Extra Databasse Klasse ?
msg += "\n";
return (char*) (const char*) msg;
} // GetExtendedDBErrorMsg
-//////////////////////////////////////////////////////////////////////////////////
-// BJO 20000115 : New stuff : dialog to ask for username and password
-//////////////////////////////////////////////////////////////////////////////////
-class UserDialog : public wxDialog
-{
-public:
- UserDialog(wxWindow* parent);
- virtual ~UserDialog();
- void OnOK(wxCommandEvent& event);
- wxString s_UserName, s_Password;
-
-private:
- wxButton *m_OK;
- wxStaticText *m_Label1, *m_Label2;
- wxTextCtrl *m_UserName, *m_Password;
-
-
- DECLARE_EVENT_TABLE()
- };
-//---------------------------------------------------------------------------
-BEGIN_EVENT_TABLE(UserDialog, wxDialog)
- EVT_BUTTON(wxID_OK, UserDialog::OnOK)
- END_EVENT_TABLE()
- //---------------------------------------------------------------------------
- UserDialog::UserDialog(wxWindow *parent):
- wxDialog(parent, -1, _("ODBC user"),wxDefaultPosition, wxSize(310, 300),wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE)
-{
- wxLayoutConstraints* layout;
- SetAutoLayout(TRUE);
- //-----------------------------------------------
- m_OK = new wxButton(this, wxID_OK, _("Ok"));
- layout = new wxLayoutConstraints;
- layout->left.SameAs(this, wxLeft, 10);
- layout->top.SameAs(this, wxTop,10);
- layout->height.AsIs();
- layout->width.Absolute(75);
- m_OK->SetConstraints(layout);
-
- m_Label1 = new wxStaticText(this, -1, _("User name:"));
- layout = new wxLayoutConstraints;
- layout->left.SameAs(m_OK, wxLeft);
- layout->top.SameAs(m_OK, wxBottom, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- m_Label1->SetConstraints(layout);
-
- m_UserName = new wxTextCtrl(this, -1, "");
- layout = new wxLayoutConstraints;
- layout->left.SameAs(m_OK, wxLeft);
- layout->top.SameAs(m_Label1, wxBottom, 3);
- layout->width.AsIs();
- layout->height.AsIs();
- m_UserName->SetConstraints(layout);
-
- m_Label2 = new wxStaticText(this, -1, _("Password:"));
- layout = new wxLayoutConstraints;
- layout->left.SameAs(m_OK, wxLeft);
- layout->top.SameAs(m_UserName, wxBottom, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- m_Label2->SetConstraints(layout);
-
- m_Password = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
- layout = new wxLayoutConstraints;
- layout->left.SameAs(m_OK, wxLeft);
- layout->width.AsIs();
- layout->top.SameAs(m_Label2, wxBottom, 3);
- layout->height.AsIs();
- m_Password->SetConstraints(layout);
-
- s_UserName = "";
- s_Password = "";
-
- Layout();
-}
-//---------------------------------------------------------------------------
-UserDialog::~UserDialog()
-{
-}
-//---------------------------------------------------------------------------
-void UserDialog::OnOK(wxCommandEvent& WXUNUSED(event))
-{
- strcpy(ConnectInf.Uid, m_UserName->GetValue());
- strcpy(ConnectInf.AuthStr, m_Password->GetValue());
- EndModal(1);
-}
-//////////////////////////////////////////////////////////////////////////////////
-// BJO 20000115 : end of new stuff
-//////////////////////////////////////////////////////////////////////////////////
+
//---------------------------------------------------------------------------
BrowserDB::BrowserDB()
{
//---------------------------------------------------------------------------
// Connect to datasource
//---------------------------
- DlgUser p_Dlg(pDoc->p_MainFrame, "Username and Password", wxPoint(100, 100), wxSize(340, 170));
- p_Dlg.s_DSN = ODBCSource;
- p_Dlg.s_User = UserName;
- p_Dlg.s_Password = Password;
- p_Dlg.OnInit();
- if (p_Dlg.ShowModal() == wxID_OK)
+ DlgUser *p_Dlg = new DlgUser(pDoc->p_MainFrame, "Username and Password");
+ p_Dlg->s_DSN = ODBCSource;
+ p_Dlg->s_User = UserName;
+ p_Dlg->s_Password = Password;
+ p_Dlg->OnInit();
+ p_Dlg->Fit();
+
+ bool OK = FALSE;
+ if (p_Dlg->ShowModal() == wxID_OK)
{
- (pDoc->p_DSN+i_Which)->Usr = p_Dlg.s_User;
- (pDoc->p_DSN+i_Which)->Pas = p_Dlg.s_Password;
- UserName = p_Dlg.s_User;
- Password = p_Dlg.s_Password;
+ (pDoc->p_DSN+i_Which)->Usr = p_Dlg->s_User;
+ (pDoc->p_DSN+i_Which)->Pas = p_Dlg->s_Password;
+ UserName = p_Dlg->s_User;
+ Password = p_Dlg->s_Password;
+ OK = TRUE;
}
- p_Dlg.Destroy();
- //---------------------------
- strcpy(ConnectInf.Dsn, ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT)
- strcpy(ConnectInf.Uid, UserName); // database username - must already exist in the data source
- strcpy(ConnectInf.AuthStr, Password); // password database username
- db_BrowserDB = GetDbConnection(&ConnectInf);
- // wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
- if (db_BrowserDB == NULL)
- {
- strcpy(ConnectInf.Dsn, "");
- strcpy(ConnectInf.Uid, "");
- strcpy(ConnectInf.AuthStr, "");
+ //p_Dlg.Destroy();
+ delete p_Dlg;
+
+ if (OK)
+ {
+ //---------------------------
+ strcpy(ConnectInf.Dsn, ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT)
+ strcpy(ConnectInf.Uid, UserName); // database username - must already exist in the data source
+ strcpy(ConnectInf.AuthStr, Password); // password database username
+ db_BrowserDB = GetDbConnection(&ConnectInf);
+ // wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
+ if (db_BrowserDB == NULL)
+ {
+ strcpy(ConnectInf.Dsn, "");
+ strcpy(ConnectInf.Uid, "");
+ strcpy(ConnectInf.AuthStr, "");
+ if (!Quite)
+ {
+ wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)"));
+ wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End "),ODBCSource.c_str());
+ }
+ return FALSE;
+ }
+ //--------------------------------------------------------------------------
if (!Quite)
{
- wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)"));
+ Temp1 = db_BrowserDB->GetDatabaseName();
+ Temp2 = db_BrowserDB->GetDataSource();
+ wxLogMessage(_("-I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s)"),Temp1.c_str(),Temp2.c_str());
wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End "),ODBCSource.c_str());
}
- return FALSE;
- }
- //--------------------------------------------------------------------------
- if (!Quite)
- {
- Temp1 = db_BrowserDB->GetDatabaseName();
- Temp2 = db_BrowserDB->GetDataSource();
- wxLogMessage(_("-I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s)"),Temp1.c_str(),Temp2.c_str());
- wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End "),ODBCSource.c_str());
- }
- return TRUE;
+ return TRUE;
+ } else return FALSE;
}
//--------------------------------------------------------------------------------------------
bool BrowserDB::OnCloseDB(int Quite)