Fixed the GUI so it will now work correctly when widgets are clicked/used. This demo program was not really even usable, although the database portions worked correctly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3864 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker 1999-10-07 11:04:06 +00:00
parent d604ea3355
commit 65d7ddc4eb
5 changed files with 208 additions and 61 deletions

View File

@ -93,7 +93,6 @@ wxDB *READONLY_DB;
* NOTE: The value returned by this function is for temporary use only and * NOTE: The value returned by this function is for temporary use only and
* should be copied for long term use * should be copied for long term use
*/ */
char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine) char *GetExtendedDBErrorMsg(char *ErrFile, int ErrLine)
{ {
static wxString msg; static wxString msg;
@ -193,12 +192,18 @@ bool DatabaseDemoApp::OnInit()
buffer[strlen(buffer)-1] = '\0'; buffer[strlen(buffer)-1] = '\0';
strcpy(params.Password,buffer); strcpy(params.Password,buffer);
fgets(buffer, sizeof(params.DirPath), paramFile);
buffer[strlen(buffer)-1] = '\0';
strcpy(params.DirPath,buffer);
fclose(paramFile); fclose(paramFile);
// Connect to datasource // Connect to datasource
strcpy(DbConnectInf.Dsn, params.ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT) strcpy(DbConnectInf.Dsn, params.ODBCSource); // ODBC data source name (created with ODBC Administrator under Win95/NT)
strcpy(DbConnectInf.Uid, params.UserName); // database username - must already exist in the data source strcpy(DbConnectInf.Uid, params.UserName); // database username - must already exist in the data source
strcpy(DbConnectInf.AuthStr, params.Password); // password database username strcpy(DbConnectInf.AuthStr, params.Password); // password database username
strcpy(DbConnectInf.defaultDir,params.DirPath); // path where the table exists (needed for dBase)
READONLY_DB = GetDbConnection(&DbConnectInf); READONLY_DB = GetDbConnection(&DbConnectInf);
if (READONLY_DB == 0) if (READONLY_DB == 0)
{ {
@ -286,7 +291,7 @@ void DatabaseDemoFrame::CreateDataTable()
return; return;
} }
if (!Contact->CreateTable()) if (!Contact->CreateTable(FALSE))
{ {
wxEndBusyCursor(); wxEndBusyCursor();
wxString tStr; wxString tStr;
@ -307,7 +312,8 @@ void DatabaseDemoFrame::CreateDataTable()
success = FALSE; success = FALSE;
} }
} }
wxEndBusyCursor(); while (wxIsBusy())
wxEndBusyCursor();
delete Contact; delete Contact;
@ -344,7 +350,7 @@ void DatabaseDemoFrame::BuildParameterDialog(wxWindow *parent)
* or creating a table objects which use the same pDb, know that all the objects * or creating a table objects which use the same pDb, know that all the objects
* will be committed or rolled back when any of the objects has this function call made. * will be committed or rolled back when any of the objects has this function call made.
*/ */
Ccontact::Ccontact (wxDB *pwxDB) : wxTable(pwxDB ? pwxDB : GetDbConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS) Ccontact::Ccontact (wxDB *pwxDB) : wxTable(pwxDB ? pwxDB : GetDbConnection(&DbConnectInf),CONTACT_TABLE_NAME,CONTACT_NO_COLS,NULL,!QUERY_ONLY,DbConnectInf.defaultDir)
{ {
// This is used to represent whether the database connection should be released // This is used to represent whether the database connection should be released
// when this instance of the object is deleted. If using the same connection // when this instance of the object is deleted. If using the same connection
@ -402,18 +408,20 @@ Ccontact::~Ccontact()
*/ */
void Ccontact::SetupColumns() void Ccontact::SetupColumns()
{ {
SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index // NOTE: Columns now are 8 character names, as that is all dBase can support. Longer
SetColDefs ( 1,"ADDRESS1", DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), FALSE,TRUE); // names can be used for other database engines
SetColDefs ( 2,"ADDRESS2", DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), FALSE,TRUE); SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR, Name, SQL_C_CHAR, sizeof(Name), TRUE, TRUE); // Primary index
SetColDefs ( 3,"CITY", DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), FALSE,TRUE); SetColDefs ( 1,"ADDRESS1", DB_DATA_TYPE_VARCHAR, Addr1, SQL_C_CHAR, sizeof(Addr1), FALSE,TRUE);
SetColDefs ( 4,"STATE", DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), FALSE,TRUE); SetColDefs ( 2,"ADDRESS2", DB_DATA_TYPE_VARCHAR, Addr2, SQL_C_CHAR, sizeof(Addr2), FALSE,TRUE);
SetColDefs ( 5,"POSTAL_CODE", DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), FALSE,TRUE); SetColDefs ( 3,"CITY", DB_DATA_TYPE_VARCHAR, City, SQL_C_CHAR, sizeof(City), FALSE,TRUE);
SetColDefs ( 6,"COUNTRY", DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), FALSE,TRUE); SetColDefs ( 4,"STATE", DB_DATA_TYPE_VARCHAR, State, SQL_C_CHAR, sizeof(State), FALSE,TRUE);
SetColDefs ( 7,"JOIN_DATE", DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), FALSE,TRUE); SetColDefs ( 5,"POSTCODE", DB_DATA_TYPE_VARCHAR, PostalCode, SQL_C_CHAR, sizeof(PostalCode), FALSE,TRUE);
SetColDefs ( 8,"NATIVE_LANGUAGE", DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), FALSE,TRUE); SetColDefs ( 6,"COUNTRY", DB_DATA_TYPE_VARCHAR, Country, SQL_C_CHAR, sizeof(Country), FALSE,TRUE);
SetColDefs ( 9,"IS_DEVELOPER", DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN, sizeof(bool), FALSE,TRUE); SetColDefs ( 7,"JOINDATE", DB_DATA_TYPE_DATE, &JoinDate, SQL_C_TIMESTAMP, sizeof(JoinDate), FALSE,TRUE);
SetColDefs (10,"CONTRIBUTIONS", DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_USHORT, sizeof(Contributions), FALSE,TRUE); SetColDefs ( 8,"IS_DEV", DB_DATA_TYPE_INTEGER, &IsDeveloper, SQL_C_BOOLEAN(IsDeveloper),sizeof(IsDeveloper), FALSE,TRUE);
SetColDefs (11,"LINES_OF_CODE", DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), FALSE,TRUE); SetColDefs ( 9,"CONTRIBS", DB_DATA_TYPE_INTEGER, &Contributions, SQL_C_USHORT, sizeof(Contributions), FALSE,TRUE);
SetColDefs (10,"LINE_CNT", DB_DATA_TYPE_INTEGER, &LinesOfCode, SQL_C_ULONG, sizeof(LinesOfCode), FALSE,TRUE);
SetColDefs (11,"LANGUAGE", DB_DATA_TYPE_INTEGER, &NativeLanguage, SQL_C_ENUM, sizeof(NativeLanguage), FALSE,TRUE);
} // Ccontact::SetupColumns } // Ccontact::SetupColumns
@ -488,7 +496,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
widgetPtrsSet = FALSE; widgetPtrsSet = FALSE;
// Create the data structure and a new database connection. // Create the data structure and a new database connection.
// (As there is not a pDb being passed in the constructor, a new database // (As there is not a pDb being passed in the constructor, a new database
// connection is created) // connection is created)
Contact = new Ccontact(); Contact = new Ccontact();
@ -500,7 +508,7 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
// Check if the table exists or not. If it doesn't, ask the user if they want to // Check if the table exists or not. If it doesn't, ask the user if they want to
// create the table. Continue trying to create the table until it exists, or user aborts // create the table. Continue trying to create the table until it exists, or user aborts
while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME)) while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME,DbConnectInf.Uid,DbConnectInf.defaultDir))
{ {
wxString tStr; wxString tStr;
tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME); tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME);
@ -620,10 +628,14 @@ CeditorDlg::CeditorDlg(wxWindow *parent) : wxPanel (parent, 1, 1, 460, 455)
// to achieve a single row (in this case the first name in alphabetical order). // to achieve a single row (in this case the first name in alphabetical order).
// commented out because PostgreSQL can't do this // commented out because PostgreSQL can't do this
//Contact->whereStr.Printf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName); if (Contact->pDb->Dbms() != dbmsPOSTGRES)
{
// NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only Contact->whereStr.sprintf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName);
Contact->where = (char*) (const char*) Contact->whereStr; // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
Contact->where = (char*) (const char*) Contact->whereStr;
}
else
Contact->where = 0;
// Perform the Query to get the result set. // Perform the Query to get the result set.
// NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE. // NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE.
@ -675,6 +687,7 @@ void CeditorDlg::OnButton( wxCommandEvent &event )
OnCommand( *win, event ); OnCommand( *win, event );
} }
void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event) void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
{ {
wxString widgetName; wxString widgetName;
@ -780,14 +793,18 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
} }
} }
// commented out because PostgreSQL can't do this
// Previous record not available, retrieve first record in table // Previous record not available, retrieve first record in table
//Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM "; if (Contact->pDb->Dbms() != dbmsPOSTGRES)
//Contact->whereStr += Contact->tableName; {
//Contact->whereStr += ")"; // PostgreSQL can't do this
Contact->whereStr = "NAME = (SELECT MIN(NAME) FROM ";
Contact->where = (char*) (const char*) Contact->whereStr; Contact->whereStr += Contact->tableName;
Contact->whereStr += ")";
Contact->where = (char*) (const char*) Contact->whereStr;
}
else
Contact->where = 0;
if (!Contact->Query()) if (!Contact->Query())
{ {
wxString tStr; wxString tStr;
@ -912,7 +929,7 @@ void CeditorDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
/* char *windowTitle */ "Select contact name", /* char *windowTitle */ "Select contact name",
/* char *tableName */ (char *) CONTACT_TABLE_NAME, /* char *tableName */ (char *) CONTACT_TABLE_NAME,
/* char *dispCol1 */ "NAME", /* char *dispCol1 */ "NAME",
/* char *dispCol2 */ "JOIN_DATE", /* char *dispCol2 */ "JOINDATE",
/* char *where */ "", /* char *where */ "",
/* char *orderBy */ "NAME", /* char *orderBy */ "NAME",
/* bool distinctValues */ TRUE); /* bool distinctValues */ TRUE);
@ -1115,7 +1132,7 @@ bool CeditorDlg::GetData()
Contact->LinesOfCode = atol(pLinesTxt->GetValue()); Contact->LinesOfCode = atol(pLinesTxt->GetValue());
Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection(); Contact->NativeLanguage = (enum Language) pNativeLangChoice->GetSelection();
Contact->IsDeveloper = (bool) pDeveloperRadio->GetSelection(); Contact->IsDeveloper = pDeveloperRadio->GetSelection() > 0;
return TRUE; return TRUE;
} // CeditorDlg::GetData() } // CeditorDlg::GetData()
@ -1139,8 +1156,6 @@ bool CeditorDlg::Save()
failed = TRUE; failed = TRUE;
// Perform any other required validations necessary before saving // Perform any other required validations necessary before saving
if (!failed) if (!failed)
{ {
wxBeginBusyCursor(); wxBeginBusyCursor();
@ -1207,11 +1222,16 @@ bool CeditorDlg::GetNextRec()
{ {
wxString w; wxString w;
// commented out because PostgreSQL can't do this if (Contact->pDb->Dbms() != dbmsPOSTGRES)
//w = "NAME = (SELECT MIN(NAME) FROM "; {
//w += Contact->tableName; // PostgreSQL can't do this
// w += " WHERE NAME > '"; w = "NAME = (SELECT MIN(NAME) FROM ";
w = "(NAME > '"; w += Contact->tableName;
w += " WHERE NAME > '";
}
else
w = "(NAME > '";
w += Contact->Name; w += Contact->Name;
w += "'"; w += "'";
@ -1238,11 +1258,16 @@ bool CeditorDlg::GetPrevRec()
{ {
wxString w; wxString w;
// commented out because PostgreSQL can't do this if (Contact->pDb->Dbms() != dbmsPOSTGRES)
//w = "NAME = (SELECT MAX(NAME) FROM "; {
//w += Contact->tableName; // PostgreSQL can't do this
//w += " WHERE NAME < '"; w = "NAME = (SELECT MAX(NAME) FROM ";
w = "(NAME < '"; w += Contact->tableName;
w += " WHERE NAME < '";
}
else
w = "(NAME < '";
w += Contact->Name; w += Contact->Name;
w += "'"; w += "'";
@ -1269,7 +1294,7 @@ bool CeditorDlg::GetRec(char *whereStr)
{ {
Contact->where = whereStr; Contact->where = whereStr;
Contact->orderBy = "NAME"; Contact->orderBy = "NAME";
if (!Contact->Query()) if (!Contact->Query())
{ {
wxString tStr; wxString tStr;
@ -1296,10 +1321,12 @@ bool CeditorDlg::GetRec(char *whereStr)
*/ */
BEGIN_EVENT_TABLE(CparameterDlg, wxDialog) BEGIN_EVENT_TABLE(CparameterDlg, wxDialog)
EVT_BUTTON(PARAMETER_DIALOG_SAVE, CparameterDlg::OnButton)
EVT_BUTTON(PARAMETER_DIALOG_CANCEL, CparameterDlg::OnButton)
EVT_CLOSE(CparameterDlg::OnCloseWindow) EVT_CLOSE(CparameterDlg::OnCloseWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIALOG, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 275)) CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIALOG, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 325))
{ {
// Since the ::OnCommand() function is overridden, this prevents the widget // Since the ::OnCommand() function is overridden, this prevents the widget
// detection in ::OnCommand() until all widgets have been initialized to prevent // detection in ::OnCommand() until all widgets have been initialized to prevent
@ -1315,6 +1342,9 @@ CparameterDlg::CparameterDlg(wxWindow *parent) : wxDialog (parent, PARAMETER_DIA
pParamPasswordMsg = new wxStaticText(this, PARAMETER_DIALOG_PASSWORD_MSG, "Password:", wxPoint(156, 193), wxSize(-1, -1), 0, "ParamPasswordMsg"); pParamPasswordMsg = new wxStaticText(this, PARAMETER_DIALOG_PASSWORD_MSG, "Password:", wxPoint(156, 193), wxSize(-1, -1), 0, "ParamPasswordMsg");
pParamPasswordTxt = new wxTextCtrl(this, PARAMETER_DIALOG_PASSWORD_TEXT, "", wxPoint(156, 209), wxSize(140, 25), 0, wxDefaultValidator, "ParamPasswordTxt"); pParamPasswordTxt = new wxTextCtrl(this, PARAMETER_DIALOG_PASSWORD_TEXT, "", wxPoint(156, 209), wxSize(140, 25), 0, wxDefaultValidator, "ParamPasswordTxt");
pParamDirPathMsg = new wxStaticText(this, PARAMETER_DIALOG_DIRPATH_MSG, "Directory:", wxPoint(10, 243), wxSize(-1, -1), 0, "ParamDirPathMsg");
pParamDirPathTxt = new wxTextCtrl(this, PARAMETER_DIALOG_DIRPATH_TEXT, "", wxPoint(10, 259), wxSize(140, 25), 0, wxDefaultValidator, "ParamDirPathTxt");
pParamSaveBtn = new wxButton(this, PARAMETER_DIALOG_SAVE, "&Save", wxPoint(310, 21), wxSize(70, 35), 0, wxDefaultValidator, "ParamSaveBtn"); pParamSaveBtn = new wxButton(this, PARAMETER_DIALOG_SAVE, "&Save", wxPoint(310, 21), wxSize(70, 35), 0, wxDefaultValidator, "ParamSaveBtn");
pParamCancelBtn = new wxButton(this, PARAMETER_DIALOG_CANCEL, "C&ancel", wxPoint(310, 66), wxSize(70, 35), 0, wxDefaultValidator, "ParamCancelBtn"); pParamCancelBtn = new wxButton(this, PARAMETER_DIALOG_CANCEL, "C&ancel", wxPoint(310, 66), wxSize(70, 35), 0, wxDefaultValidator, "ParamCancelBtn");
@ -1355,6 +1385,12 @@ void CparameterDlg::OnCloseWindow(wxCloseEvent& event)
} // Cparameter::OnCloseWindow() } // Cparameter::OnCloseWindow()
void CparameterDlg::OnButton( wxCommandEvent &event )
{
wxWindow *win = (wxWindow*) event.GetEventObject();
OnCommand( *win, event );
}
void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event) void CparameterDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
{ {
wxString widgetName; wxString widgetName;
@ -1396,6 +1432,7 @@ bool CparameterDlg::PutData()
pParamODBCSourceList->SetStringSelection(wxGetApp().params.ODBCSource); pParamODBCSourceList->SetStringSelection(wxGetApp().params.ODBCSource);
pParamUserNameTxt->SetValue(wxGetApp().params.UserName); pParamUserNameTxt->SetValue(wxGetApp().params.UserName);
pParamPasswordTxt->SetValue(wxGetApp().params.Password); pParamPasswordTxt->SetValue(wxGetApp().params.Password);
pParamDirPathTxt->SetValue(wxGetApp().params.DirPath);
return TRUE; return TRUE;
} // CparameterDlg::PutData() } // CparameterDlg::PutData()
@ -1437,6 +1474,17 @@ bool CparameterDlg::GetData()
return FALSE; return FALSE;
} }
strcpy(wxGetApp().params.Password,tStr); strcpy(wxGetApp().params.Password,tStr);
tStr = pParamDirPathTxt->GetValue();
tStr.Replace("\\","/");
if (tStr.Length() > (sizeof(wxGetApp().params.DirPath)-1))
{
wxString errmsg;
errmsg.Printf("DirPath is longer than the data structure to hold it.\n'Cparameter.DirPath' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long.",tStr.Length());
wxMessageBox(errmsg,"Internal program error...",wxOK | wxICON_EXCLAMATION);
return FALSE;
}
strcpy(wxGetApp().params.DirPath,tStr);
return TRUE; return TRUE;
} // CparameterDlg::GetData() } // CparameterDlg::GetData()
@ -1465,6 +1513,8 @@ bool CparameterDlg::Save()
fputc('\n', paramFile); fputc('\n', paramFile);
fputs(wxGetApp().params.Password, paramFile); fputs(wxGetApp().params.Password, paramFile);
fputc('\n', paramFile); fputc('\n', paramFile);
fputs(wxGetApp().params.DirPath, paramFile);
fputc('\n', paramFile);
fclose(paramFile); fclose(paramFile);
return TRUE; return TRUE;
@ -1566,6 +1616,17 @@ CqueryDlg::CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereA
wxString qualName; wxString qualName;
pQueryCol2Choice->Append("VALUE -->"); pQueryCol2Choice->Append("VALUE -->");
colInf = pDB->GetColumns(tblName); colInf = pDB->GetColumns(tblName);
if (!colInf)
{
wxEndBusyCursor();
wxString tStr;
tStr = "ODBC error during GetColumns()\n\n";
tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
return;
}
for (int i = 0; colInf[i].colName && strlen(colInf[i].colName); i++) for (int i = 0; colInf[i].colName && strlen(colInf[i].colName); i++)
{ {
// If there is more than one table being queried, qualify // If there is more than one table being queried, qualify
@ -1837,7 +1898,8 @@ void CqueryDlg::OnCloseWindow(wxCloseEvent& event)
} }
GetParent()->SetFocus(); GetParent()->SetFocus();
wxEndBusyCursor(); while (wxIsBusy())
wxEndBusyCursor();
this->Destroy(); this->Destroy();
@ -1990,7 +2052,7 @@ void CqueryDlg::ProcessCountBtn()
if (dbTable == 0) // wxTable object needs to be created and opened if (dbTable == 0) // wxTable object needs to be created and opened
{ {
if (!(dbTable = new wxTable(pDB, masterTableName, 0))) if (!(dbTable = new wxTable(pDB, masterTableName, 0, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)))
{ {
wxMessageBox("Memory allocation failed creating a wxTable object.","Error...",wxOK | wxICON_EXCLAMATION); wxMessageBox("Memory allocation failed creating a wxTable object.","Error...",wxOK | wxICON_EXCLAMATION);
return; return;

View File

@ -40,10 +40,10 @@ enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
class CeditorDlg; class CeditorDlg;
class CparameterDlg; class CparameterDlg;
#ifdef __WXGTK__ #ifdef __UNIX__
const char paramFilename[] = "../database.cfg"; const char paramFilename[] = "../dbtest.cfg";
#else #else
const char paramFilename[] = "database.cfg"; const char paramFilename[] = "dbtest.cfg";
#endif #endif
@ -102,6 +102,7 @@ typedef struct Cparameters
char ODBCSource[100+1]; char ODBCSource[100+1];
char UserName[25+1]; char UserName[25+1];
char Password[25+1]; char Password[25+1];
char DirPath[MAX_PATH+1];
} Cparameters; } Cparameters;
@ -236,14 +237,15 @@ class CparameterDlg : public wxDialog
// Pointers to all widgets on the dialog // Pointers to all widgets on the dialog
wxStaticText *pParamODBCSourceMsg; wxStaticText *pParamODBCSourceMsg;
wxListBox *pParamODBCSourceList; wxListBox *pParamODBCSourceList;
wxStaticText *pParamUserNameMsg, *pParamPasswordMsg; wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt; wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
wxButton *pParamSaveBtn, *pParamCancelBtn; wxButton *pParamSaveBtn, *pParamCancelBtn;
public: public:
CparameterDlg(wxWindow *parent); CparameterDlg(wxWindow *parent);
void OnCloseWindow(wxCloseEvent& event); void OnCloseWindow(wxCloseEvent& event);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event); void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnActivate(bool) {}; // necessary for hot keys void OnActivate(bool) {}; // necessary for hot keys
@ -264,8 +266,10 @@ DECLARE_EVENT_TABLE()
#define PARAMETER_DIALOG_NAME_TEXT 404 #define PARAMETER_DIALOG_NAME_TEXT 404
#define PARAMETER_DIALOG_PASSWORD_MSG 405 #define PARAMETER_DIALOG_PASSWORD_MSG 405
#define PARAMETER_DIALOG_PASSWORD_TEXT 406 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
#define PARAMETER_DIALOG_SAVE 407 #define PARAMETER_DIALOG_DIRPATH_MSG 407
#define PARAMETER_DIALOG_CANCEL 408 #define PARAMETER_DIALOG_DIRPATH_TEXT 408
#define PARAMETER_DIALOG_SAVE 409
#define PARAMETER_DIALOG_CANCEL 410
// *************************** CqueryDlg *************************** // *************************** CqueryDlg ***************************

View File

@ -56,6 +56,8 @@
#include <wx/dbtable.h> #include <wx/dbtable.h>
extern DbList* WXDLLEXPORT PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
#include "listdb.h" #include "listdb.h"
// Global structure for holding ODBC connection information // Global structure for holding ODBC connection information
@ -78,8 +80,65 @@ char ListDB_Selection2[LOOKUP_COL_LEN+1];
const int LISTDB_NO_SPACES_BETWEEN_COLS = 3; const int LISTDB_NO_SPACES_BETWEEN_COLS = 3;
/*
* This function will return the exact string(s) from the database engine
* indicating all error conditions which have just occured during the
* last call to the database engine.
*
* This demo uses the returned string by displaying it in a wxMessageBox. The
* formatting therefore is not the greatest, but this is just a demo, not a
* finished product. :-) gt
*
* NOTE: The value returned by this function is for temporary use only and
* should be copied for long term use
*/
char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
{
static wxString msg;
wxString tStr;
if (ErrFile || ErrLine)
{
msg += "File: ";
msg += ErrFile;
msg += " Line: ";
tStr.Printf("%d",ErrLine);
msg += tStr.GetData();
msg += "\n";
}
msg.Append ("\nODBC errors:\n");
msg += "\n";
/* Scan through each database connection displaying
* any ODBC errors that have occured. */
for (DbList *pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext)
{
// Skip over any free connections
if (pDbList->Free)
continue;
// Display errors for this connection
for (int i = 0; i < DB_MAX_ERROR_HISTORY; i++)
{
if (pDbList->PtrDb->errorList[i])
{
msg.Append(pDbList->PtrDb->errorList[i]);
if (strcmp(pDbList->PtrDb->errorList[i],"") != 0)
msg.Append("\n");
}
}
}
msg += "\n";
return (char*) (const char*) msg;
} // GetExtendedDBErrorMsg
// Clookup constructor // Clookup constructor
Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1) Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1, NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
{ {
SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE); SetColDefs (0, colName, DB_DATA_TYPE_VARCHAR, lookupCol, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
@ -89,7 +148,7 @@ Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1
// Clookup2 constructor // Clookup2 constructor
Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb) Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
: wxTable(pDb, tblName, (1 + (strlen(colName2) > 0))) : wxTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
{ {
int i = 0; int i = 0;
@ -101,6 +160,13 @@ Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
} // Clookup2() } // Clookup2()
BEGIN_EVENT_TABLE(ClookUpDlg, wxDialog)
// EVT_LISTBOX(LOOKUP_DIALOG_SELECT, ClookUpDlg::SelectCallback)
EVT_BUTTON(LOOKUP_DIALOG_OK, ClookUpDlg::OnButton)
EVT_BUTTON(LOOKUP_DIALOG_CANCEL, ClookUpDlg::OnButton)
EVT_CLOSE(ClookUpDlg::OnClose)
END_EVENT_TABLE()
// This is a generic lookup constructor that will work with any table and any column // This is a generic lookup constructor that will work with any table and any column
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, char *colName, ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, char *colName,
char *where, char *orderBy) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290)) char *where, char *orderBy) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
@ -234,6 +300,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
{ {
wxString tStr; wxString tStr;
tStr.Printf("Unable to open the table '%s'.",tableName); tStr.Printf("Unable to open the table '%s'.",tableName);
tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
wxMessageBox(tStr,"ODBC Error..."); wxMessageBox(tStr,"ODBC Error...");
Close(); Close();
return; return;
@ -329,7 +396,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
} // Generic lookup constructor 2 } // Generic lookup constructor 2
bool ClookUpDlg::OnClose(void) void ClookUpDlg::OnClose(wxCloseEvent& event)
{ {
widgetPtrsSet = FALSE; widgetPtrsSet = FALSE;
GetParent()->Enable(TRUE); GetParent()->Enable(TRUE);
@ -340,11 +407,20 @@ bool ClookUpDlg::OnClose(void)
delete lookup2; delete lookup2;
wxEndBusyCursor(); wxEndBusyCursor();
return TRUE; event.Skip();
// return TRUE;
} // ClookUpDlg::OnClose } // ClookUpDlg::OnClose
void ClookUpDlg::OnButton( wxCommandEvent &event )
{
wxWindow *win = (wxWindow*) event.GetEventObject();
OnCommand( *win, event );
}
void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event) void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
{ {
wxString widgetName = win.GetName(); wxString widgetName = win.GetName();

View File

@ -112,9 +112,12 @@ class ClookUpDlg : public wxDialog
wxDB *pDb = READONLY_DB, // Database connection pointer wxDB *pDb = READONLY_DB, // Database connection pointer
bool allowOk = TRUE); // is the OK button enabled bool allowOk = TRUE); // is the OK button enabled
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event); void OnCommand(wxWindow& win, wxCommandEvent& event);
bool OnClose(); void OnClose(wxCloseEvent& event);
void OnActivate(bool) {}; // necessary for hot keys void OnActivate(bool) {}; // necessary for hot keys
DECLARE_EVENT_TABLE()
}; };
#define LOOKUP_DIALOG 500 #define LOOKUP_DIALOG 500

View File

@ -10,6 +10,8 @@
# Set WXDIR for your system # Set WXDIR for your system
WXDIR = $(WXWIN) WXDIR = $(WXWIN)
# added by glt for my own environment
WXDIR = D:\wx2\wxWindows
PROGRAM=dbtest PROGRAM=dbtest
OBJECTS = $(PROGRAM).obj listdb.obj OBJECTS = $(PROGRAM).obj listdb.obj