Fixed code that did not work with Postgres

Removed all tabs, and replaced with spaces accordingly


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5653 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker
2000-01-25 16:18:40 +00:00
parent 176513eb42
commit e70e8f4cf3
4 changed files with 1951 additions and 1999 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -14,15 +14,16 @@
#endif
#include <wx/string.h>
#include <wx/db.h>
#include <wx/dbtable.h>
enum DialogModes {mView,mCreate,mEdit,mSearch};
enum DialogModes {mView,mCreate,mEdit,mSearch};
// ID for the menu quit command
#define FILE_CREATE 100
#define FILE_EXIT 199
#define EDIT_PARAMETERS 200
#define ABOUT_DEMO 300
#define FILE_CREATE 100
#define FILE_EXIT 199
#define EDIT_PARAMETERS 200
#define ABOUT_DEMO 300
// this seems to be missing, Robert Roebling (?)
#ifndef MAX_PATH
@@ -30,13 +31,13 @@ enum DialogModes {mView,mCreate,mEdit,mSearch};
#endif
// Name of the table to be created/opened
const char CONTACT_TABLE_NAME[] = "contacts";
const char CONTACT_TABLE_NAME[] = "contacts";
// Nuber of columns in the above table
const int CONTACT_NO_COLS = 12; // 0-11
const int CONTACT_NO_COLS = 12; // 0-11
// Global structure for holding ODBC connection information
struct DbStuff DbConnectInf;
struct DbStuff DbConnectInf;
enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
@@ -56,19 +57,19 @@ const char paramFilename[] = "dbtest.cfg";
*/
class CstructContact : public wxObject
{
public:
char Name[ 50+1 ]; // Contact's name
char Addr1[ 50+1 ];
char Addr2[ 50+1 ];
char City[ 25+1 ];
char State[ 25+1 ];
char PostalCode[ 15+1 ];
char Country[ 20+1 ];
TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
Language NativeLanguage; // Enumerated type indicating person's native language
bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
int Contributions; // Something to show off an integer field
ULONG LinesOfCode; // Something to show off a 'long' field
public:
char Name[50+1]; // Contact's name
char Addr1[50+1];
char Addr2[50+1];
char City[25+1];
char State[25+1];
char PostalCode[15+1];
char Country[20+1];
TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
Language NativeLanguage; // Enumerated type indicating person's native language
bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
UCHAR Contributions; // Something to show off an integer field
ULONG LinesOfCode; // Something to show off a 'long' field
}; // CstructContact
@@ -77,41 +78,41 @@ class CstructContact : public wxObject
//
class Ccontact : public wxTable, public CstructContact
{
private:
bool freeDbConn;
void SetupColumns();
private:
bool freeDbConn;
void SetupColumns();
public:
wxString whereStr;
wxString qryWhereStr; // Where string returned from the query dialog
public:
wxString whereStr;
wxString qryWhereStr; // Where string returned from the query dialog
Ccontact(wxDB *pwxDB=NULL);
~Ccontact();
Ccontact(wxDB *pwxDB=NULL);
~Ccontact();
void Initialize();
bool CreateIndexes(void);
bool FetchByName(char *name);
void Initialize();
bool CreateIndexes(void);
bool FetchByName(char *name);
}; // Ccontact class definition
typedef struct Cparameters
{
// The length of these strings were arbitrarily picked, and are
// dependent on the OS and database engine you will be using.
char ODBCSource[100+1];
char UserName[25+1];
char Password[25+1];
char DirPath[MAX_PATH+1];
// The length of these strings were arbitrarily picked, and are
// dependent on the OS and database engine you will be using.
char ODBCSource[100+1];
char UserName[25+1];
char Password[25+1];
char DirPath[MAX_PATH+1];
} Cparameters;
// Define a new application type
class DatabaseDemoApp: public wxApp
{
public:
Cparameters params;
bool OnInit();
public:
Cparameters params;
bool OnInit();
}; // DatabaseDemoApp
DECLARE_APP(DatabaseDemoApp)
@@ -119,22 +120,22 @@ DECLARE_APP(DatabaseDemoApp)
// Define a new frame type
class DatabaseDemoFrame: public wxFrame
{
private:
CeditorDlg *pEditorDlg;
CparameterDlg *pParamDlg;
private:
CeditorDlg *pEditorDlg;
CparameterDlg *pParamDlg;
public:
DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
public:
DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
void OnCloseWindow(wxCloseEvent& event);
void OnCloseWindow(wxCloseEvent& event);
void OnCreate(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnEditParameters(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void CreateDataTable();
void BuildEditorDialog();
void BuildParameterDialog(wxWindow *parent);
void CreateDataTable();
void BuildEditorDialog();
void BuildParameterDialog(wxWindow *parent);
DECLARE_EVENT_TABLE()
}; // DatabaseDemoFrame
@@ -145,40 +146,41 @@ DECLARE_EVENT_TABLE()
class CeditorDlg : public wxPanel
{
private:
bool widgetPtrsSet;
wxString saveName;
private:
bool widgetPtrsSet;
wxString saveName;
// Pointers to all widgets on the dialog
wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
wxButton *pNameListBtn;
wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt;
wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg;
wxRadioBox *pDeveloperRadio;
wxChoice *pNativeLangChoice;
wxStaticText *pNativeLangMsg;
// Pointers to all widgets on the dialog
wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
wxButton *pNameListBtn;
wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt;
wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg;
wxRadioBox *pDeveloperRadio;
wxChoice *pNativeLangChoice;
wxStaticText *pNativeLangMsg;
public:
enum DialogModes mode;
Ccontact *Contact; // this is the table object that will be being manipulated
public:
enum DialogModes mode;
Ccontact *Contact; // this is the table object that will be being manipulated
CeditorDlg(wxWindow *parent);
void OnCloseWindow(wxCloseEvent& event);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
CeditorDlg(wxWindow *parent);
void FieldsEditable();
void SetMode(enum DialogModes m);
bool PutData();
bool GetData();
bool Save();
bool GetNextRec();
bool GetPrevRec();
bool GetRec(char *whereStr);
void OnCloseWindow(wxCloseEvent& event);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
void FieldsEditable();
void SetMode(enum DialogModes m);
bool PutData();
bool GetData();
bool Save();
bool GetNextRec();
bool GetPrevRec();
bool GetRec(char *whereStr);
DECLARE_EVENT_TABLE()
}; // CeditorDlg
@@ -229,30 +231,31 @@ DECLARE_EVENT_TABLE()
class CparameterDlg : public wxDialog
{
private:
bool widgetPtrsSet;
enum DialogModes mode;
bool saved;
Cparameters savedParamSettings;
private:
bool widgetPtrsSet;
enum DialogModes mode;
bool saved;
Cparameters savedParamSettings;
// Pointers to all widgets on the dialog
wxStaticText *pParamODBCSourceMsg;
wxListBox *pParamODBCSourceList;
wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
wxButton *pParamSaveBtn, *pParamCancelBtn;
// Pointers to all widgets on the dialog
wxStaticText *pParamODBCSourceMsg;
wxListBox *pParamODBCSourceList;
wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
wxButton *pParamSaveBtn, *pParamCancelBtn;
public:
CparameterDlg(wxWindow *parent);
void OnCloseWindow(wxCloseEvent& event);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
public:
CparameterDlg(wxWindow *parent);
bool PutData();
bool GetData();
bool Save();
void FillDataSourceList();
void OnCloseWindow(wxCloseEvent& event);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
bool PutData();
bool GetData();
bool Save();
void FillDataSourceList();
DECLARE_EVENT_TABLE()
}; // CparameterDlg
@@ -266,8 +269,8 @@ DECLARE_EVENT_TABLE()
#define PARAMETER_DIALOG_NAME_TEXT 404
#define PARAMETER_DIALOG_PASSWORD_MSG 405
#define PARAMETER_DIALOG_PASSWORD_TEXT 406
#define PARAMETER_DIALOG_DIRPATH_MSG 407
#define PARAMETER_DIALOG_DIRPATH_TEXT 408
#define PARAMETER_DIALOG_DIRPATH_MSG 407
#define PARAMETER_DIALOG_DIRPATH_TEXT 408
#define PARAMETER_DIALOG_SAVE 409
#define PARAMETER_DIALOG_CANCEL 410
@@ -277,83 +280,82 @@ DECLARE_EVENT_TABLE()
// QUERY DIALOG
enum qryOp
{
qryOpEQ,
qryOpLT,
qryOpGT,
qryOpLE,
qryOpGE,
qryOpBEGINS,
qryOpCONTAINS,
qryOpLIKE,
qryOpBETWEEN
qryOpEQ,
qryOpLT,
qryOpGT,
qryOpLE,
qryOpGE,
qryOpBEGINS,
qryOpCONTAINS,
qryOpLIKE,
qryOpBETWEEN
};
// Query strings
char * const langQRY_EQ = "column = column | value";
char * const langQRY_LT = "column < column | value";
char * const langQRY_GT = "column > column | value";
char * const langQRY_LE = "column <= column | value";
char * const langQRY_GE = "column >= column | value";
char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
char * const langQRY_BETWEEN = "column BETWEEN value AND value";
char * const langQRY_EQ = "column = column | value";
char * const langQRY_LT = "column < column | value";
char * const langQRY_GT = "column > column | value";
char * const langQRY_LE = "column <= column | value";
char * const langQRY_GE = "column >= column | value";
char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
char * const langQRY_BETWEEN = "column BETWEEN value AND value";
class CqueryDlg : public wxDialog
{
private:
CcolInf *colInf; // Column inf. returned by db->GetColumns()
wxTable *dbTable;
char *masterTableName;
char *pWhere; // A pointer to the storage for the resulting where clause
wxDB *pDB;
private:
CcolInf *colInf; // Column inf. returned by db->GetColumns()
wxTable *dbTable;
char *masterTableName;
char *pWhere; // A pointer to the storage for the resulting where clause
wxDB *pDB;
public:
bool widgetPtrsSet;
public:
bool widgetPtrsSet;
// Widget pointers
wxStaticText *pQueryCol1Msg;
wxChoice *pQueryCol1Choice;
wxStaticText *pQueryNotMsg;
wxCheckBox *pQueryNotCheck;
wxStaticText *pQueryOperatorMsg;
wxChoice *pQueryOperatorChoice;
wxStaticText *pQueryCol2Msg;
wxChoice *pQueryCol2Choice;
wxStaticText *pQueryValue1Msg;
wxTextCtrl *pQueryValue1Txt;
wxStaticText *pQueryValue2Msg;
wxTextCtrl *pQueryValue2Txt;
wxStaticText *pQuerySqlWhereMsg;
wxTextCtrl *pQuerySqlWhereMtxt;
wxButton *pQueryAddBtn;
wxButton *pQueryAndBtn;
wxButton *pQueryOrBtn;
wxButton *pQueryLParenBtn;
wxButton *pQueryRParenBtn;
wxButton *pQueryDoneBtn;
wxButton *pQueryClearBtn;
wxButton *pQueryCountBtn;
wxButton *pQueryHelpBtn;
wxStaticBox *pQueryHintGrp;
wxStaticText *pQueryHintMsg;
// Widget pointers
wxStaticText *pQueryCol1Msg;
wxChoice *pQueryCol1Choice;
wxStaticText *pQueryNotMsg;
wxCheckBox *pQueryNotCheck;
wxStaticText *pQueryOperatorMsg;
wxChoice *pQueryOperatorChoice;
wxStaticText *pQueryCol2Msg;
wxChoice *pQueryCol2Choice;
wxStaticText *pQueryValue1Msg;
wxTextCtrl *pQueryValue1Txt;
wxStaticText *pQueryValue2Msg;
wxTextCtrl *pQueryValue2Txt;
wxStaticText *pQuerySqlWhereMsg;
wxTextCtrl *pQuerySqlWhereMtxt;
wxButton *pQueryAddBtn;
wxButton *pQueryAndBtn;
wxButton *pQueryOrBtn;
wxButton *pQueryLParenBtn;
wxButton *pQueryRParenBtn;
wxButton *pQueryDoneBtn;
wxButton *pQueryClearBtn;
wxButton *pQueryCountBtn;
wxButton *pQueryHelpBtn;
wxStaticBox *pQueryHintGrp;
wxStaticText *pQueryHintMsg;
wxTextCtrl *pFocusTxt;
wxTextCtrl *pFocusTxt;
CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnCloseWindow(wxCloseEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnCloseWindow(wxCloseEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
// bool SetWidgetPtrs();
void AppendToWhere(char *s);
void ProcessAddBtn();
void ProcessCountBtn();
bool ValidateWhereClause();
void AppendToWhere(char *s);
void ProcessAddBtn();
void ProcessCountBtn();
bool ValidateWhereClause();
DECLARE_EVENT_TABLE()
}; // CqueryDlg

View File

@@ -14,28 +14,28 @@
Member functions for the classes defined in LISTDB.H
This class is used to present a generic ListBox lookup window for
use with any of the object creation/selection choice widgets. This
dialog window will present a (possibly) scrolling list of values
that come from a data table source. Based on the object type passed
in the constructor, a ListBox is built to present the user with a
single selection listbox.
This class is used to present a generic ListBox lookup window for
use with any of the object creation/selection choice widgets. This
dialog window will present a (possibly) scrolling list of values
that come from a data table source. Based on the object type passed
in the constructor, a ListBox is built to present the user with a
single selection listbox.
The string selected from the list box is stored in the Global variable
"ListDB_Seclection", and will remain set until another interation of this
routine is called.
The string selected from the list box is stored in the Global variable
"ListDB_Seclection", and will remain set until another interation of this
routine is called.
For each object (database) type that is to be used, an overridden
constructor should be written to appropriately link to the proper
data table/object for building the list.
For each object (database) type that is to be used, an overridden
constructor should be written to appropriately link to the proper
data table/object for building the list.
The data table record access is all handled through the routines
in this module, interfacing with the methods defined in wxTable.
All objects which use data table access must be initialized and
have opened the table prior to passing them in the dialog
constructor, and the 'where' query should already have been set
and performed before creating this dialog instance.
All objects which use data table access must be initialized and
have opened the table prior to passing them in the dialog
constructor, and the 'where' query should already have been set
and performed before creating this dialog instance.
// SYNOPSIS STOP
*/
@@ -95,44 +95,44 @@ const int LISTDB_NO_SPACES_BETWEEN_COLS = 3;
*/
char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
{
static wxString msg;
static wxString msg;
wxString tStr;
wxString tStr;
if (ErrFile || ErrLine)
{
msg += "File: ";
msg += ErrFile;
msg += " Line: ";
tStr.Printf("%d",ErrLine);
msg += tStr.GetData();
msg += "\n";
}
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";
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";
/* 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;
return (char*) (const char*) msg;
} // GetExtendedDBErrorMsg
@@ -141,7 +141,7 @@ char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
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);
} // Clookup()
@@ -150,18 +150,18 @@ Clookup::Clookup(char *tblName, char *colName) : wxTable(READONLY_DB, tblName, 1
Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
: wxTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
{
int i = 0;
int i = 0;
SetColDefs (i, colName1, DB_DATA_TYPE_VARCHAR, lookupCol1, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
SetColDefs (i, colName1, DB_DATA_TYPE_VARCHAR, lookupCol1, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
if (strlen(colName2) > 0)
SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
if (strlen(colName2) > 0)
SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
} // Clookup2()
BEGIN_EVENT_TABLE(ClookUpDlg, wxDialog)
// EVT_LISTBOX(LOOKUP_DIALOG_SELECT, ClookUpDlg::SelectCallback)
// 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)
@@ -169,70 +169,70 @@ END_EVENT_TABLE()
// 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,
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))
{
wxBeginBusyCursor();
wxBeginBusyCursor();
strcpy(ListDB_Selection,"");
widgetPtrsSet = FALSE;
lookup = 0;
lookup2 = 0;
noDisplayCols = 1;
col1Len = 0;
strcpy(ListDB_Selection,"");
widgetPtrsSet = FALSE;
lookup = 0;
lookup2 = 0;
noDisplayCols = 1;
col1Len = 0;
pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint( 5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize( 70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize( 70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
widgetPtrsSet = TRUE;
widgetPtrsSet = TRUE;
// Query the lookup table and display the result set
if (!(lookup = new Clookup(tableName, colName)))
{
wxMessageBox("Error allocating memory for 'Clookup'object.","Error...");
Close();
return;
}
// Query the lookup table and display the result set
if (!(lookup = new Clookup(tableName, colName)))
{
wxMessageBox("Error allocating memory for 'Clookup'object.","Error...");
Close();
return;
}
if (!lookup->Open())
{
wxString tStr;
tStr.Printf("Unable to open the table '%s'.",tableName);
wxMessageBox(tStr,"ODBC Error...");
Close();
return;
}
if (!lookup->Open())
{
wxString tStr;
tStr.Printf("Unable to open the table '%s'.",tableName);
wxMessageBox(tStr,"ODBC Error...");
Close();
return;
}
lookup->orderBy = orderBy;
lookup->where = where;
if (!lookup->Query())
{
wxMessageBox("ODBC error during Query()","ODBC Error...");
Close();
return;
}
lookup->orderBy = orderBy;
lookup->where = where;
if (!lookup->Query())
{
wxMessageBox("ODBC error during Query()","ODBC Error...");
Close();
return;
}
// Fill in the list box from the query result set
while (lookup->GetNext())
pLookUpSelectList->Append(lookup->lookupCol);
// Fill in the list box from the query result set
while (lookup->GetNext())
pLookUpSelectList->Append(lookup->lookupCol);
// Highlight the first list item
pLookUpSelectList->SetSelection(0);
// Highlight the first list item
pLookUpSelectList->SetSelection(0);
// Make the OK activate by pressing Enter
if (pLookUpSelectList->Number())
pLookUpOkBtn->SetDefault();
else
{
pLookUpCancelBtn->SetDefault();
pLookUpOkBtn->Enable(FALSE);
}
// Make the OK activate by pressing Enter
if (pLookUpSelectList->Number())
pLookUpOkBtn->SetDefault();
else
{
pLookUpCancelBtn->SetDefault();
pLookUpOkBtn->Enable(FALSE);
}
// Display the dialog window
SetTitle(windowTitle);
Centre(wxBOTH);
wxEndBusyCursor();
ShowModal();
// Display the dialog window
SetTitle(windowTitle);
Centre(wxBOTH);
wxEndBusyCursor();
ShowModal();
} // Generic lookup constructor
@@ -241,7 +241,7 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
// This is a generic lookup constructor that will work with any table and any column.
// It extends the capabilites of the lookup dialog in the following ways:
//
// 1) 2 columns rather than one
// 1) 2 columns rather than one
// 2) The ability to select DISTINCT column values
//
// Only set distinctValues equal to true if necessary. In many cases, the constraints
@@ -262,154 +262,154 @@ ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName, cha
// in the lookup window.
//
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
char *selectStmt, int maxLenCol1, wxDB *pDb, bool allowOk) : wxDialog (parent, LOOKUP_DIALOG, "Select...", wxPoint(-1, -1), wxSize(400, 290))
{
wxBeginBusyCursor();
wxBeginBusyCursor();
strcpy(ListDB_Selection,"");
strcpy(ListDB_Selection2,"");
widgetPtrsSet = FALSE;
lookup = 0;
lookup2 = 0;
noDisplayCols = (strlen(dispCol2) ? 2 : 1);
col1Len = 0;
strcpy(ListDB_Selection,"");
strcpy(ListDB_Selection2,"");
widgetPtrsSet = FALSE;
lookup = 0;
lookup2 = 0;
noDisplayCols = (strlen(dispCol2) ? 2 : 1);
col1Len = 0;
wxFont fixedFont(12,wxMODERN,wxNORMAL,wxNORMAL);
wxFont fixedFont(12,wxMODERN,wxNORMAL,wxNORMAL);
// this is done with fixed font so that the second column (if any) will be left
// justified in the second column
pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
// this is done with fixed font so that the second column (if any) will be left
// justified in the second column
pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
pLookUpSelectList->SetFont(fixedFont);
pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
widgetPtrsSet = TRUE;
widgetPtrsSet = TRUE;
// Query the lookup table and display the result set
if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
{
wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
Close();
return;
}
// Query the lookup table and display the result set
if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
{
wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
Close();
return;
}
if (!lookup2->Open())
{
wxString tStr;
tStr.Printf("Unable to open the table '%s'.",tableName);
tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
wxMessageBox(tStr,"ODBC Error...");
Close();
return;
}
if (!lookup2->Open())
{
wxString tStr;
tStr.Printf("Unable to open the table '%s'.",tableName);
tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
wxMessageBox(tStr,"ODBC Error...");
Close();
return;
}
// If displaying 2 columns, determine the maximum length of column1
int maxColLen;
if (maxLenCol1)
maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
else
{
maxColLen = LOOKUP_COL_LEN;
if (strlen(dispCol2))
{
wxString q = "SELECT MAX({fn LENGTH(";
q += dispCol1;
q += ")}), NULL";
q += " FROM ";
q += tableName;
if (strlen(where))
{
q += " WHERE ";
q += where;
}
if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
{
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
Close();
return;
}
if (lookup2->GetNext())
maxColLen = col1Len = atoi(lookup2->lookupCol1);
else
wxMessageBox("ODBC error during GetNext()","ODBC Error...");
}
}
// If displaying 2 columns, determine the maximum length of column1
int maxColLen;
if (maxLenCol1)
maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
else
{
maxColLen = LOOKUP_COL_LEN;
if (strlen(dispCol2))
{
wxString q = "SELECT MAX({fn LENGTH(";
q += dispCol1;
q += ")}), NULL";
q += " FROM ";
q += tableName;
if (strlen(where))
{
q += " WHERE ";
q += where;
}
if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
{
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
Close();
return;
}
if (lookup2->GetNext())
maxColLen = col1Len = atoi(lookup2->lookupCol1);
else
wxMessageBox("ODBC error during GetNext()","ODBC Error...");
}
}
// Query the actual record set
if (selectStmt && strlen(selectStmt)) // Query by sql stmt passed in
{
if (!lookup2->QueryBySqlStmt(selectStmt))
{
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
Close();
return;
}
}
else // Query using where and order by clauses
{
lookup2->orderBy = orderBy;
lookup2->where = where;
if (!lookup2->Query(FALSE, distinctValues))
{
wxMessageBox("ODBC error during Query()","ODBC Error...");
Close();
return;
}
}
// Query the actual record set
if (selectStmt && strlen(selectStmt)) // Query by sql stmt passed in
{
if (!lookup2->QueryBySqlStmt(selectStmt))
{
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
Close();
return;
}
}
else // Query using where and order by clauses
{
lookup2->orderBy = orderBy;
lookup2->where = where;
if (!lookup2->Query(FALSE, distinctValues))
{
wxMessageBox("ODBC error during Query()","ODBC Error...");
Close();
return;
}
}
// Fill in the list box from the query result set
wxString s;
while (lookup2->GetNext())
{
s = lookup2->lookupCol1;
if (strlen(dispCol2)) // Append the optional column 2
{
s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
s.Append(lookup2->lookupCol2);
}
pLookUpSelectList->Append(s);
}
// Fill in the list box from the query result set
wxString s;
while (lookup2->GetNext())
{
s = lookup2->lookupCol1;
if (strlen(dispCol2)) // Append the optional column 2
{
s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
s.Append(lookup2->lookupCol2);
}
pLookUpSelectList->Append(s);
}
// Highlight the first list item
pLookUpSelectList->SetSelection(0);
// Highlight the first list item
pLookUpSelectList->SetSelection(0);
// Make the OK activate by pressing Enter
if (pLookUpSelectList->Number())
pLookUpOkBtn->SetDefault();
else
{
pLookUpCancelBtn->SetDefault();
pLookUpOkBtn->Enable(FALSE);
}
// Make the OK activate by pressing Enter
if (pLookUpSelectList->Number())
pLookUpOkBtn->SetDefault();
else
{
pLookUpCancelBtn->SetDefault();
pLookUpOkBtn->Enable(FALSE);
}
pLookUpOkBtn->Enable(allowOk);
pLookUpOkBtn->Enable(allowOk);
// Display the dialog window
SetTitle(windowTitle);
Centre(wxBOTH);
wxEndBusyCursor();
ShowModal();
// Display the dialog window
SetTitle(windowTitle);
Centre(wxBOTH);
wxEndBusyCursor();
ShowModal();
} // Generic lookup constructor 2
void ClookUpDlg::OnClose(wxCloseEvent& event)
{
widgetPtrsSet = FALSE;
GetParent()->Enable(TRUE);
widgetPtrsSet = FALSE;
GetParent()->Enable(TRUE);
if (lookup)
delete lookup;
if (lookup2)
delete lookup2;
if (lookup)
delete lookup;
if (lookup2)
delete lookup2;
while (wxIsBusy()) wxEndBusyCursor();
while (wxIsBusy()) wxEndBusyCursor();
event.Skip();
// return TRUE;
// return TRUE;
} // ClookUpDlg::OnClose
@@ -423,47 +423,47 @@ void ClookUpDlg::OnButton( wxCommandEvent &event )
void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
{
wxString widgetName = win.GetName();
wxString widgetName = win.GetName();
if (widgetPtrsSet)
{
// OK Button
if (widgetName == pLookUpOkBtn->GetName())
{
if (pLookUpSelectList->GetSelection() != -1)
{
if (noDisplayCols == 1)
strcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
else // 2 display columns
{
wxString s = pLookUpSelectList->GetStringSelection();
// Column 1
s = s.SubString(0, col1Len-1);
s = s.Strip();
strcpy(ListDB_Selection, s);
// Column 2
s = pLookUpSelectList->GetStringSelection();
s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS);
s = s.Strip();
strcpy(ListDB_Selection2, s);
}
}
else
{
strcpy(ListDB_Selection,"");
strcpy(ListDB_Selection2,"");
}
Close();
} // OK Button
if (widgetPtrsSet)
{
// OK Button
if (widgetName == pLookUpOkBtn->GetName())
{
if (pLookUpSelectList->GetSelection() != -1)
{
if (noDisplayCols == 1)
strcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
else // 2 display columns
{
wxString s = pLookUpSelectList->GetStringSelection();
// Column 1
s = s.SubString(0, col1Len-1);
s = s.Strip();
strcpy(ListDB_Selection, s);
// Column 2
s = pLookUpSelectList->GetStringSelection();
s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS);
s = s.Strip();
strcpy(ListDB_Selection2, s);
}
}
else
{
strcpy(ListDB_Selection,"");
strcpy(ListDB_Selection2,"");
}
Close();
} // OK Button
// Cancel Button
if (widgetName == pLookUpCancelBtn->GetName())
{
strcpy (ListDB_Selection,"");
strcpy (ListDB_Selection2,"");
Close();
} // Cancel Button
}
// Cancel Button
if (widgetName == pLookUpCancelBtn->GetName())
{
strcpy (ListDB_Selection,"");
strcpy (ListDB_Selection2,"");
Close();
} // Cancel Button
}
}; // ClookUpDlg::OnCommand

View File

@@ -14,7 +14,7 @@
#endif
/*
Contains dialog class for creating a data table lookup listbox
Contains dialog class for creating a data table lookup listbox
*/
#ifndef LISTDB_DOT_H
@@ -31,91 +31,91 @@ extern wxDB *READONLY_DB;
// Clookup class
class Clookup : public wxTable
{
public:
public:
char lookupCol[LOOKUP_COL_LEN+1];
char lookupCol[LOOKUP_COL_LEN+1];
Clookup(char *tblName, char *colName);
Clookup(char *tblName, char *colName);
}; // Clookup
// Clookup2 class
class Clookup2 : public wxTable
{
public:
public:
char lookupCol1[LOOKUP_COL_LEN+1];
char lookupCol2[LOOKUP_COL_LEN+1];
char lookupCol1[LOOKUP_COL_LEN+1];
char lookupCol2[LOOKUP_COL_LEN+1];
Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb);
Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb);
}; // Clookup2
class ClookUpDlg : public wxDialog
{
private:
bool widgetPtrsSet;
int currentCursor;
Clookup *lookup;
Clookup2 *lookup2;
int noDisplayCols;
int col1Len;
private:
bool widgetPtrsSet;
int currentCursor;
Clookup *lookup;
Clookup2 *lookup2;
int noDisplayCols;
int col1Len;
wxListBox *pLookUpSelectList;
wxButton *pLookUpOkBtn;
wxButton *pLookUpCancelBtn;
wxListBox *pLookUpSelectList;
wxButton *pLookUpOkBtn;
wxButton *pLookUpCancelBtn;
public:
public:
// This is a generic lookup constructor that will work with any table and any column
ClookUpDlg(wxWindow *parent,
char *windowTitle,
char *tableName,
char *colName,
char *where,
char *orderBy);
// This is a generic lookup constructor that will work with any table and any column
ClookUpDlg(wxWindow *parent,
char *windowTitle,
char *tableName,
char *colName,
char *where,
char *orderBy);
//
// This is a generic lookup constructor that will work with any table and any column.
// It extends the capabilites of the lookup dialog in the following ways:
//
// 1) 2 columns rather than one
// 2) The ability to select DISTINCT column values
//
// Only set distinctValues equal to true if necessary. In many cases, the constraints
// of the index(es) will enforce this uniqueness. Selecting DISTINCT does require
// overhead by the database to ensure that all values returned are distinct. Therefore,
// use this ONLY when you need it.
//
// For complicated queries, you can pass in the sql select statement. This would be
// necessary if joins are involved since by default both columns must come from the
// same table.
//
// If you do query by sql statement, you must pass in the maximum length of column1,
// since it cannot be derived when you query using your own sql statement.
//
// The optional database connection can be used if you'd like the lookup class
// to use a database pointer other than the global READONLY_DB. This is necessary if
// records are being saved, but not committed to the db, yet should be included
// in the lookup window.
//
ClookUpDlg(wxWindow *parent,
char *windowTitle,
char *tableName,
char *dispCol1, // Must have at least 1 display column
char *dispCol2, // Optional
char *where,
char *orderBy,
bool distinctValues, // e.g. SELECT DISTINCT ...
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
wxDB *pDb = READONLY_DB, // Database connection pointer
bool allowOk = TRUE); // is the OK button enabled
//
// This is a generic lookup constructor that will work with any table and any column.
// It extends the capabilites of the lookup dialog in the following ways:
//
// 1) 2 columns rather than one
// 2) The ability to select DISTINCT column values
//
// Only set distinctValues equal to true if necessary. In many cases, the constraints
// of the index(es) will enforce this uniqueness. Selecting DISTINCT does require
// overhead by the database to ensure that all values returned are distinct. Therefore,
// use this ONLY when you need it.
//
// For complicated queries, you can pass in the sql select statement. This would be
// necessary if joins are involved since by default both columns must come from the
// same table.
//
// If you do query by sql statement, you must pass in the maximum length of column1,
// since it cannot be derived when you query using your own sql statement.
//
// The optional database connection can be used if you'd like the lookup class
// to use a database pointer other than the global READONLY_DB. This is necessary if
// records are being saved, but not committed to the db, yet should be included
// in the lookup window.
//
ClookUpDlg(wxWindow *parent,
char *windowTitle,
char *tableName,
char *dispCol1, // Must have at least 1 display column
char *dispCol2, // Optional
char *where,
char *orderBy,
bool distinctValues, // e.g. SELECT DISTINCT ...
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
wxDB *pDb = READONLY_DB, // Database connection pointer
bool allowOk = TRUE); // is the OK button enabled
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
void OnButton( wxCommandEvent &event );
void OnCommand(wxWindow& win, wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void OnActivate(bool) {}; // necessary for hot keys
DECLARE_EVENT_TABLE()
};