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:
File diff suppressed because it is too large
Load Diff
@@ -14,15 +14,16 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
#include <wx/db.h>
|
||||||
#include <wx/dbtable.h>
|
#include <wx/dbtable.h>
|
||||||
|
|
||||||
enum DialogModes {mView,mCreate,mEdit,mSearch};
|
enum DialogModes {mView,mCreate,mEdit,mSearch};
|
||||||
|
|
||||||
// ID for the menu quit command
|
// ID for the menu quit command
|
||||||
#define FILE_CREATE 100
|
#define FILE_CREATE 100
|
||||||
#define FILE_EXIT 199
|
#define FILE_EXIT 199
|
||||||
#define EDIT_PARAMETERS 200
|
#define EDIT_PARAMETERS 200
|
||||||
#define ABOUT_DEMO 300
|
#define ABOUT_DEMO 300
|
||||||
|
|
||||||
// this seems to be missing, Robert Roebling (?)
|
// this seems to be missing, Robert Roebling (?)
|
||||||
#ifndef MAX_PATH
|
#ifndef MAX_PATH
|
||||||
@@ -30,13 +31,13 @@ enum DialogModes {mView,mCreate,mEdit,mSearch};
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Name of the table to be created/opened
|
// 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
|
// 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
|
// Global structure for holding ODBC connection information
|
||||||
struct DbStuff DbConnectInf;
|
struct DbStuff DbConnectInf;
|
||||||
|
|
||||||
enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
|
enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
|
||||||
|
|
||||||
@@ -56,19 +57,19 @@ const char paramFilename[] = "dbtest.cfg";
|
|||||||
*/
|
*/
|
||||||
class CstructContact : public wxObject
|
class CstructContact : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char Name[ 50+1 ]; // Contact's name
|
char Name[50+1]; // Contact's name
|
||||||
char Addr1[ 50+1 ];
|
char Addr1[50+1];
|
||||||
char Addr2[ 50+1 ];
|
char Addr2[50+1];
|
||||||
char City[ 25+1 ];
|
char City[25+1];
|
||||||
char State[ 25+1 ];
|
char State[25+1];
|
||||||
char PostalCode[ 15+1 ];
|
char PostalCode[15+1];
|
||||||
char Country[ 20+1 ];
|
char Country[20+1];
|
||||||
TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
|
TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
|
||||||
Language NativeLanguage; // Enumerated type indicating person's native language
|
Language NativeLanguage; // Enumerated type indicating person's native language
|
||||||
bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
|
bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
|
||||||
int Contributions; // Something to show off an integer field
|
UCHAR Contributions; // Something to show off an integer field
|
||||||
ULONG LinesOfCode; // Something to show off a 'long' field
|
ULONG LinesOfCode; // Something to show off a 'long' field
|
||||||
}; // CstructContact
|
}; // CstructContact
|
||||||
|
|
||||||
|
|
||||||
@@ -77,41 +78,41 @@ class CstructContact : public wxObject
|
|||||||
//
|
//
|
||||||
class Ccontact : public wxTable, public CstructContact
|
class Ccontact : public wxTable, public CstructContact
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool freeDbConn;
|
bool freeDbConn;
|
||||||
void SetupColumns();
|
void SetupColumns();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxString whereStr;
|
wxString whereStr;
|
||||||
wxString qryWhereStr; // Where string returned from the query dialog
|
wxString qryWhereStr; // Where string returned from the query dialog
|
||||||
|
|
||||||
Ccontact(wxDB *pwxDB=NULL);
|
Ccontact(wxDB *pwxDB=NULL);
|
||||||
~Ccontact();
|
~Ccontact();
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
bool CreateIndexes(void);
|
bool CreateIndexes(void);
|
||||||
bool FetchByName(char *name);
|
bool FetchByName(char *name);
|
||||||
|
|
||||||
}; // Ccontact class definition
|
}; // Ccontact class definition
|
||||||
|
|
||||||
|
|
||||||
typedef struct Cparameters
|
typedef struct Cparameters
|
||||||
{
|
{
|
||||||
// The length of these strings were arbitrarily picked, and are
|
// The length of these strings were arbitrarily picked, and are
|
||||||
// dependent on the OS and database engine you will be using.
|
// dependent on the OS and database engine you will be using.
|
||||||
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];
|
char DirPath[MAX_PATH+1];
|
||||||
} Cparameters;
|
} Cparameters;
|
||||||
|
|
||||||
|
|
||||||
// Define a new application type
|
// Define a new application type
|
||||||
class DatabaseDemoApp: public wxApp
|
class DatabaseDemoApp: public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cparameters params;
|
Cparameters params;
|
||||||
bool OnInit();
|
bool OnInit();
|
||||||
}; // DatabaseDemoApp
|
}; // DatabaseDemoApp
|
||||||
|
|
||||||
DECLARE_APP(DatabaseDemoApp)
|
DECLARE_APP(DatabaseDemoApp)
|
||||||
@@ -119,22 +120,22 @@ DECLARE_APP(DatabaseDemoApp)
|
|||||||
// Define a new frame type
|
// Define a new frame type
|
||||||
class DatabaseDemoFrame: public wxFrame
|
class DatabaseDemoFrame: public wxFrame
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CeditorDlg *pEditorDlg;
|
CeditorDlg *pEditorDlg;
|
||||||
CparameterDlg *pParamDlg;
|
CparameterDlg *pParamDlg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
|
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 OnCreate(wxCommandEvent& event);
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
void OnEditParameters(wxCommandEvent& event);
|
void OnEditParameters(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
|
||||||
void CreateDataTable();
|
void CreateDataTable();
|
||||||
void BuildEditorDialog();
|
void BuildEditorDialog();
|
||||||
void BuildParameterDialog(wxWindow *parent);
|
void BuildParameterDialog(wxWindow *parent);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
}; // DatabaseDemoFrame
|
}; // DatabaseDemoFrame
|
||||||
@@ -145,40 +146,41 @@ DECLARE_EVENT_TABLE()
|
|||||||
|
|
||||||
class CeditorDlg : public wxPanel
|
class CeditorDlg : public wxPanel
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool widgetPtrsSet;
|
bool widgetPtrsSet;
|
||||||
wxString saveName;
|
wxString saveName;
|
||||||
|
|
||||||
// Pointers to all widgets on the dialog
|
// Pointers to all widgets on the dialog
|
||||||
wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
|
wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
|
||||||
wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
|
wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
|
||||||
wxButton *pNameListBtn;
|
wxButton *pNameListBtn;
|
||||||
wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
|
wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
|
||||||
wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
|
wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
|
||||||
wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt;
|
wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt;
|
||||||
wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg;
|
wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg;
|
||||||
wxRadioBox *pDeveloperRadio;
|
wxRadioBox *pDeveloperRadio;
|
||||||
wxChoice *pNativeLangChoice;
|
wxChoice *pNativeLangChoice;
|
||||||
wxStaticText *pNativeLangMsg;
|
wxStaticText *pNativeLangMsg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum DialogModes mode;
|
enum DialogModes mode;
|
||||||
Ccontact *Contact; // this is the table object that will be being manipulated
|
Ccontact *Contact; // this is the table object that will be being manipulated
|
||||||
|
|
||||||
CeditorDlg(wxWindow *parent);
|
CeditorDlg(wxWindow *parent);
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
|
||||||
void OnButton( wxCommandEvent &event );
|
|
||||||
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
|
||||||
void OnActivate(bool) {}; // necessary for hot keys
|
|
||||||
|
|
||||||
void FieldsEditable();
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
void SetMode(enum DialogModes m);
|
void OnButton( wxCommandEvent &event );
|
||||||
bool PutData();
|
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
||||||
bool GetData();
|
void OnActivate(bool) {}; // necessary for hot keys
|
||||||
bool Save();
|
|
||||||
bool GetNextRec();
|
void FieldsEditable();
|
||||||
bool GetPrevRec();
|
void SetMode(enum DialogModes m);
|
||||||
bool GetRec(char *whereStr);
|
bool PutData();
|
||||||
|
bool GetData();
|
||||||
|
bool Save();
|
||||||
|
bool GetNextRec();
|
||||||
|
bool GetPrevRec();
|
||||||
|
bool GetRec(char *whereStr);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
}; // CeditorDlg
|
}; // CeditorDlg
|
||||||
@@ -229,30 +231,31 @@ DECLARE_EVENT_TABLE()
|
|||||||
|
|
||||||
class CparameterDlg : public wxDialog
|
class CparameterDlg : public wxDialog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool widgetPtrsSet;
|
bool widgetPtrsSet;
|
||||||
enum DialogModes mode;
|
enum DialogModes mode;
|
||||||
bool saved;
|
bool saved;
|
||||||
Cparameters savedParamSettings;
|
Cparameters savedParamSettings;
|
||||||
|
|
||||||
// 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, *pParamDirPathMsg;
|
wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
|
||||||
wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
|
wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
|
||||||
wxButton *pParamSaveBtn, *pParamCancelBtn;
|
wxButton *pParamSaveBtn, *pParamCancelBtn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CparameterDlg(wxWindow *parent);
|
CparameterDlg(wxWindow *parent);
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
|
||||||
void OnButton( wxCommandEvent &event );
|
|
||||||
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
|
||||||
void OnActivate(bool) {}; // necessary for hot keys
|
|
||||||
|
|
||||||
bool PutData();
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
bool GetData();
|
void OnButton( wxCommandEvent &event );
|
||||||
bool Save();
|
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
||||||
void FillDataSourceList();
|
void OnActivate(bool) {}; // necessary for hot keys
|
||||||
|
|
||||||
|
bool PutData();
|
||||||
|
bool GetData();
|
||||||
|
bool Save();
|
||||||
|
void FillDataSourceList();
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
}; // CparameterDlg
|
}; // CparameterDlg
|
||||||
@@ -266,8 +269,8 @@ 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_DIRPATH_MSG 407
|
#define PARAMETER_DIALOG_DIRPATH_MSG 407
|
||||||
#define PARAMETER_DIALOG_DIRPATH_TEXT 408
|
#define PARAMETER_DIALOG_DIRPATH_TEXT 408
|
||||||
#define PARAMETER_DIALOG_SAVE 409
|
#define PARAMETER_DIALOG_SAVE 409
|
||||||
#define PARAMETER_DIALOG_CANCEL 410
|
#define PARAMETER_DIALOG_CANCEL 410
|
||||||
|
|
||||||
@@ -277,83 +280,82 @@ DECLARE_EVENT_TABLE()
|
|||||||
// QUERY DIALOG
|
// QUERY DIALOG
|
||||||
enum qryOp
|
enum qryOp
|
||||||
{
|
{
|
||||||
qryOpEQ,
|
qryOpEQ,
|
||||||
qryOpLT,
|
qryOpLT,
|
||||||
qryOpGT,
|
qryOpGT,
|
||||||
qryOpLE,
|
qryOpLE,
|
||||||
qryOpGE,
|
qryOpGE,
|
||||||
qryOpBEGINS,
|
qryOpBEGINS,
|
||||||
qryOpCONTAINS,
|
qryOpCONTAINS,
|
||||||
qryOpLIKE,
|
qryOpLIKE,
|
||||||
qryOpBETWEEN
|
qryOpBETWEEN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Query strings
|
// Query strings
|
||||||
char * const langQRY_EQ = "column = column | value";
|
char * const langQRY_EQ = "column = column | value";
|
||||||
char * const langQRY_LT = "column < column | value";
|
char * const langQRY_LT = "column < column | value";
|
||||||
char * const langQRY_GT = "column > column | value";
|
char * const langQRY_GT = "column > column | value";
|
||||||
char * const langQRY_LE = "column <= column | value";
|
char * const langQRY_LE = "column <= column | value";
|
||||||
char * const langQRY_GE = "column >= column | value";
|
char * const langQRY_GE = "column >= column | value";
|
||||||
char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
|
char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
|
||||||
char * const langQRY_CONTAINS = "columns that CONTAIN 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_LIKE = "% matches 0 or more of any char; _ matches 1 char";
|
||||||
char * const langQRY_BETWEEN = "column BETWEEN value AND value";
|
char * const langQRY_BETWEEN = "column BETWEEN value AND value";
|
||||||
|
|
||||||
|
|
||||||
class CqueryDlg : public wxDialog
|
class CqueryDlg : public wxDialog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CcolInf *colInf; // Column inf. returned by db->GetColumns()
|
CcolInf *colInf; // Column inf. returned by db->GetColumns()
|
||||||
wxTable *dbTable;
|
wxTable *dbTable;
|
||||||
char *masterTableName;
|
char *masterTableName;
|
||||||
char *pWhere; // A pointer to the storage for the resulting where clause
|
char *pWhere; // A pointer to the storage for the resulting where clause
|
||||||
wxDB *pDB;
|
wxDB *pDB;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool widgetPtrsSet;
|
bool widgetPtrsSet;
|
||||||
|
|
||||||
// Widget pointers
|
// Widget pointers
|
||||||
wxStaticText *pQueryCol1Msg;
|
wxStaticText *pQueryCol1Msg;
|
||||||
wxChoice *pQueryCol1Choice;
|
wxChoice *pQueryCol1Choice;
|
||||||
wxStaticText *pQueryNotMsg;
|
wxStaticText *pQueryNotMsg;
|
||||||
wxCheckBox *pQueryNotCheck;
|
wxCheckBox *pQueryNotCheck;
|
||||||
wxStaticText *pQueryOperatorMsg;
|
wxStaticText *pQueryOperatorMsg;
|
||||||
wxChoice *pQueryOperatorChoice;
|
wxChoice *pQueryOperatorChoice;
|
||||||
wxStaticText *pQueryCol2Msg;
|
wxStaticText *pQueryCol2Msg;
|
||||||
wxChoice *pQueryCol2Choice;
|
wxChoice *pQueryCol2Choice;
|
||||||
wxStaticText *pQueryValue1Msg;
|
wxStaticText *pQueryValue1Msg;
|
||||||
wxTextCtrl *pQueryValue1Txt;
|
wxTextCtrl *pQueryValue1Txt;
|
||||||
wxStaticText *pQueryValue2Msg;
|
wxStaticText *pQueryValue2Msg;
|
||||||
wxTextCtrl *pQueryValue2Txt;
|
wxTextCtrl *pQueryValue2Txt;
|
||||||
wxStaticText *pQuerySqlWhereMsg;
|
wxStaticText *pQuerySqlWhereMsg;
|
||||||
wxTextCtrl *pQuerySqlWhereMtxt;
|
wxTextCtrl *pQuerySqlWhereMtxt;
|
||||||
wxButton *pQueryAddBtn;
|
wxButton *pQueryAddBtn;
|
||||||
wxButton *pQueryAndBtn;
|
wxButton *pQueryAndBtn;
|
||||||
wxButton *pQueryOrBtn;
|
wxButton *pQueryOrBtn;
|
||||||
wxButton *pQueryLParenBtn;
|
wxButton *pQueryLParenBtn;
|
||||||
wxButton *pQueryRParenBtn;
|
wxButton *pQueryRParenBtn;
|
||||||
wxButton *pQueryDoneBtn;
|
wxButton *pQueryDoneBtn;
|
||||||
wxButton *pQueryClearBtn;
|
wxButton *pQueryClearBtn;
|
||||||
wxButton *pQueryCountBtn;
|
wxButton *pQueryCountBtn;
|
||||||
wxButton *pQueryHelpBtn;
|
wxButton *pQueryHelpBtn;
|
||||||
wxStaticBox *pQueryHintGrp;
|
wxStaticBox *pQueryHintGrp;
|
||||||
wxStaticText *pQueryHintMsg;
|
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 OnButton( wxCommandEvent &event );
|
||||||
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
||||||
void OnCloseWindow(wxCloseEvent& event);
|
void OnCloseWindow(wxCloseEvent& event);
|
||||||
void OnActivate(bool) {}; // necessary for hot keys
|
void OnActivate(bool) {}; // necessary for hot keys
|
||||||
|
|
||||||
// bool SetWidgetPtrs();
|
void AppendToWhere(char *s);
|
||||||
void AppendToWhere(char *s);
|
void ProcessAddBtn();
|
||||||
void ProcessAddBtn();
|
void ProcessCountBtn();
|
||||||
void ProcessCountBtn();
|
bool ValidateWhereClause();
|
||||||
bool ValidateWhereClause();
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
}; // CqueryDlg
|
}; // CqueryDlg
|
||||||
|
@@ -14,28 +14,28 @@
|
|||||||
|
|
||||||
Member functions for the classes defined in LISTDB.H
|
Member functions for the classes defined in LISTDB.H
|
||||||
|
|
||||||
This class is used to present a generic ListBox lookup window for
|
This class is used to present a generic ListBox lookup window for
|
||||||
use with any of the object creation/selection choice widgets. This
|
use with any of the object creation/selection choice widgets. This
|
||||||
dialog window will present a (possibly) scrolling list of values
|
dialog window will present a (possibly) scrolling list of values
|
||||||
that come from a data table source. Based on the object type passed
|
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
|
in the constructor, a ListBox is built to present the user with a
|
||||||
single selection listbox.
|
single selection listbox.
|
||||||
|
|
||||||
The string selected from the list box is stored in the Global variable
|
The string selected from the list box is stored in the Global variable
|
||||||
"ListDB_Seclection", and will remain set until another interation of this
|
"ListDB_Seclection", and will remain set until another interation of this
|
||||||
routine is called.
|
routine is called.
|
||||||
|
|
||||||
For each object (database) type that is to be used, an overridden
|
For each object (database) type that is to be used, an overridden
|
||||||
constructor should be written to appropriately link to the proper
|
constructor should be written to appropriately link to the proper
|
||||||
data table/object for building the list.
|
data table/object for building the list.
|
||||||
|
|
||||||
The data table record access is all handled through the routines
|
The data table record access is all handled through the routines
|
||||||
in this module, interfacing with the methods defined in wxTable.
|
in this module, interfacing with the methods defined in wxTable.
|
||||||
|
|
||||||
All objects which use data table access must be initialized and
|
All objects which use data table access must be initialized and
|
||||||
have opened the table prior to passing them in the dialog
|
have opened the table prior to passing them in the dialog
|
||||||
constructor, and the 'where' query should already have been set
|
constructor, and the 'where' query should already have been set
|
||||||
and performed before creating this dialog instance.
|
and performed before creating this dialog instance.
|
||||||
|
|
||||||
// SYNOPSIS STOP
|
// SYNOPSIS STOP
|
||||||
*/
|
*/
|
||||||
@@ -95,44 +95,44 @@ const int LISTDB_NO_SPACES_BETWEEN_COLS = 3;
|
|||||||
*/
|
*/
|
||||||
char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
|
char *GetExtendedDBErrorMsg2(char *ErrFile, int ErrLine)
|
||||||
{
|
{
|
||||||
static wxString msg;
|
static wxString msg;
|
||||||
|
|
||||||
wxString tStr;
|
wxString tStr;
|
||||||
|
|
||||||
if (ErrFile || ErrLine)
|
if (ErrFile || ErrLine)
|
||||||
{
|
{
|
||||||
msg += "File: ";
|
msg += "File: ";
|
||||||
msg += ErrFile;
|
msg += ErrFile;
|
||||||
msg += " Line: ";
|
msg += " Line: ";
|
||||||
tStr.Printf("%d",ErrLine);
|
tStr.Printf("%d",ErrLine);
|
||||||
msg += tStr.GetData();
|
msg += tStr.GetData();
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Append ("\nODBC errors:\n");
|
msg.Append ("\nODBC errors:\n");
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
|
|
||||||
/* Scan through each database connection displaying
|
/* Scan through each database connection displaying
|
||||||
* any ODBC errors that have occured. */
|
* any ODBC errors that have occured. */
|
||||||
for (DbList *pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext)
|
for (DbList *pDbList = PtrBegDbList; pDbList; pDbList = pDbList->PtrNext)
|
||||||
{
|
{
|
||||||
// Skip over any free connections
|
// Skip over any free connections
|
||||||
if (pDbList->Free)
|
if (pDbList->Free)
|
||||||
continue;
|
continue;
|
||||||
// Display errors for this connection
|
// Display errors for this connection
|
||||||
for (int i = 0; i < DB_MAX_ERROR_HISTORY; i++)
|
for (int i = 0; i < DB_MAX_ERROR_HISTORY; i++)
|
||||||
{
|
{
|
||||||
if (pDbList->PtrDb->errorList[i])
|
if (pDbList->PtrDb->errorList[i])
|
||||||
{
|
{
|
||||||
msg.Append(pDbList->PtrDb->errorList[i]);
|
msg.Append(pDbList->PtrDb->errorList[i]);
|
||||||
if (strcmp(pDbList->PtrDb->errorList[i],"") != 0)
|
if (strcmp(pDbList->PtrDb->errorList[i],"") != 0)
|
||||||
msg.Append("\n");
|
msg.Append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
|
|
||||||
return (char*) (const char*) msg;
|
return (char*) (const char*) msg;
|
||||||
} // GetExtendedDBErrorMsg
|
} // 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)
|
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()
|
} // 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)
|
Clookup2::Clookup2(char *tblName, char *colName1, char *colName2, wxDB *pDb)
|
||||||
: wxTable(pDb, tblName, (1 + (strlen(colName2) > 0)), NULL, !QUERY_ONLY, DbConnectInf.defaultDir)
|
: 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)
|
if (strlen(colName2) > 0)
|
||||||
SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
|
SetColDefs (++i, colName2, DB_DATA_TYPE_VARCHAR, lookupCol2, SQL_C_CHAR, LOOKUP_COL_LEN+1, FALSE, FALSE);
|
||||||
|
|
||||||
} // Clookup2()
|
} // Clookup2()
|
||||||
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(ClookUpDlg, wxDialog)
|
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_OK, ClookUpDlg::OnButton)
|
||||||
EVT_BUTTON(LOOKUP_DIALOG_CANCEL, ClookUpDlg::OnButton)
|
EVT_BUTTON(LOOKUP_DIALOG_CANCEL, ClookUpDlg::OnButton)
|
||||||
EVT_CLOSE(ClookUpDlg::OnClose)
|
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
|
// 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))
|
||||||
{
|
{
|
||||||
wxBeginBusyCursor();
|
wxBeginBusyCursor();
|
||||||
|
|
||||||
strcpy(ListDB_Selection,"");
|
strcpy(ListDB_Selection,"");
|
||||||
widgetPtrsSet = FALSE;
|
widgetPtrsSet = FALSE;
|
||||||
lookup = 0;
|
lookup = 0;
|
||||||
lookup2 = 0;
|
lookup2 = 0;
|
||||||
noDisplayCols = 1;
|
noDisplayCols = 1;
|
||||||
col1Len = 0;
|
col1Len = 0;
|
||||||
|
|
||||||
pLookUpSelectList = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
|
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");
|
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");
|
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
|
// Query the lookup table and display the result set
|
||||||
if (!(lookup = new Clookup(tableName, colName)))
|
if (!(lookup = new Clookup(tableName, colName)))
|
||||||
{
|
{
|
||||||
wxMessageBox("Error allocating memory for 'Clookup'object.","Error...");
|
wxMessageBox("Error allocating memory for 'Clookup'object.","Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lookup->Open())
|
if (!lookup->Open())
|
||||||
{
|
{
|
||||||
wxString tStr;
|
wxString tStr;
|
||||||
tStr.Printf("Unable to open the table '%s'.",tableName);
|
tStr.Printf("Unable to open the table '%s'.",tableName);
|
||||||
wxMessageBox(tStr,"ODBC Error...");
|
wxMessageBox(tStr,"ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup->orderBy = orderBy;
|
lookup->orderBy = orderBy;
|
||||||
lookup->where = where;
|
lookup->where = where;
|
||||||
if (!lookup->Query())
|
if (!lookup->Query())
|
||||||
{
|
{
|
||||||
wxMessageBox("ODBC error during Query()","ODBC Error...");
|
wxMessageBox("ODBC error during Query()","ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the list box from the query result set
|
// Fill in the list box from the query result set
|
||||||
while (lookup->GetNext())
|
while (lookup->GetNext())
|
||||||
pLookUpSelectList->Append(lookup->lookupCol);
|
pLookUpSelectList->Append(lookup->lookupCol);
|
||||||
|
|
||||||
// Highlight the first list item
|
// Highlight the first list item
|
||||||
pLookUpSelectList->SetSelection(0);
|
pLookUpSelectList->SetSelection(0);
|
||||||
|
|
||||||
// Make the OK activate by pressing Enter
|
// Make the OK activate by pressing Enter
|
||||||
if (pLookUpSelectList->Number())
|
if (pLookUpSelectList->Number())
|
||||||
pLookUpOkBtn->SetDefault();
|
pLookUpOkBtn->SetDefault();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pLookUpCancelBtn->SetDefault();
|
pLookUpCancelBtn->SetDefault();
|
||||||
pLookUpOkBtn->Enable(FALSE);
|
pLookUpOkBtn->Enable(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the dialog window
|
// Display the dialog window
|
||||||
SetTitle(windowTitle);
|
SetTitle(windowTitle);
|
||||||
Centre(wxBOTH);
|
Centre(wxBOTH);
|
||||||
wxEndBusyCursor();
|
wxEndBusyCursor();
|
||||||
ShowModal();
|
ShowModal();
|
||||||
|
|
||||||
} // Generic lookup constructor
|
} // 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.
|
// 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:
|
// 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
|
// 2) The ability to select DISTINCT column values
|
||||||
//
|
//
|
||||||
// Only set distinctValues equal to true if necessary. In many cases, the constraints
|
// 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.
|
// in the lookup window.
|
||||||
//
|
//
|
||||||
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
|
ClookUpDlg::ClookUpDlg(wxWindow *parent, char *windowTitle, char *tableName,
|
||||||
char *dispCol1, char *dispCol2, char *where, char *orderBy, bool distinctValues,
|
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 *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_Selection,"");
|
||||||
strcpy(ListDB_Selection2,"");
|
strcpy(ListDB_Selection2,"");
|
||||||
widgetPtrsSet = FALSE;
|
widgetPtrsSet = FALSE;
|
||||||
lookup = 0;
|
lookup = 0;
|
||||||
lookup2 = 0;
|
lookup2 = 0;
|
||||||
noDisplayCols = (strlen(dispCol2) ? 2 : 1);
|
noDisplayCols = (strlen(dispCol2) ? 2 : 1);
|
||||||
col1Len = 0;
|
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
|
// this is done with fixed font so that the second column (if any) will be left
|
||||||
// justified in the second column
|
// 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 = new wxListBox(this, LOOKUP_DIALOG_SELECT, wxPoint(5, 15), wxSize(384, 195), 0, 0, wxLB_SINGLE|wxLB_ALWAYS_SB, wxDefaultValidator, "LookUpSelectList");
|
||||||
|
|
||||||
pLookUpSelectList->SetFont(fixedFont);
|
pLookUpSelectList->SetFont(fixedFont);
|
||||||
|
|
||||||
pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
|
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");
|
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
|
// Query the lookup table and display the result set
|
||||||
if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
|
if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
|
||||||
{
|
{
|
||||||
wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
|
wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lookup2->Open())
|
if (!lookup2->Open())
|
||||||
{
|
{
|
||||||
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__);
|
tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
|
||||||
wxMessageBox(tStr,"ODBC Error...");
|
wxMessageBox(tStr,"ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If displaying 2 columns, determine the maximum length of column1
|
// If displaying 2 columns, determine the maximum length of column1
|
||||||
int maxColLen;
|
int maxColLen;
|
||||||
if (maxLenCol1)
|
if (maxLenCol1)
|
||||||
maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
|
maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxColLen = LOOKUP_COL_LEN;
|
maxColLen = LOOKUP_COL_LEN;
|
||||||
if (strlen(dispCol2))
|
if (strlen(dispCol2))
|
||||||
{
|
{
|
||||||
wxString q = "SELECT MAX({fn LENGTH(";
|
wxString q = "SELECT MAX({fn LENGTH(";
|
||||||
q += dispCol1;
|
q += dispCol1;
|
||||||
q += ")}), NULL";
|
q += ")}), NULL";
|
||||||
q += " FROM ";
|
q += " FROM ";
|
||||||
q += tableName;
|
q += tableName;
|
||||||
if (strlen(where))
|
if (strlen(where))
|
||||||
{
|
{
|
||||||
q += " WHERE ";
|
q += " WHERE ";
|
||||||
q += where;
|
q += where;
|
||||||
}
|
}
|
||||||
if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
|
if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
|
||||||
{
|
{
|
||||||
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
|
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lookup2->GetNext())
|
if (lookup2->GetNext())
|
||||||
maxColLen = col1Len = atoi(lookup2->lookupCol1);
|
maxColLen = col1Len = atoi(lookup2->lookupCol1);
|
||||||
else
|
else
|
||||||
wxMessageBox("ODBC error during GetNext()","ODBC Error...");
|
wxMessageBox("ODBC error during GetNext()","ODBC Error...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the actual record set
|
// Query the actual record set
|
||||||
if (selectStmt && strlen(selectStmt)) // Query by sql stmt passed in
|
if (selectStmt && strlen(selectStmt)) // Query by sql stmt passed in
|
||||||
{
|
{
|
||||||
if (!lookup2->QueryBySqlStmt(selectStmt))
|
if (!lookup2->QueryBySqlStmt(selectStmt))
|
||||||
{
|
{
|
||||||
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
|
wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Query using where and order by clauses
|
else // Query using where and order by clauses
|
||||||
{
|
{
|
||||||
lookup2->orderBy = orderBy;
|
lookup2->orderBy = orderBy;
|
||||||
lookup2->where = where;
|
lookup2->where = where;
|
||||||
if (!lookup2->Query(FALSE, distinctValues))
|
if (!lookup2->Query(FALSE, distinctValues))
|
||||||
{
|
{
|
||||||
wxMessageBox("ODBC error during Query()","ODBC Error...");
|
wxMessageBox("ODBC error during Query()","ODBC Error...");
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the list box from the query result set
|
// Fill in the list box from the query result set
|
||||||
wxString s;
|
wxString s;
|
||||||
while (lookup2->GetNext())
|
while (lookup2->GetNext())
|
||||||
{
|
{
|
||||||
s = lookup2->lookupCol1;
|
s = lookup2->lookupCol1;
|
||||||
if (strlen(dispCol2)) // Append the optional column 2
|
if (strlen(dispCol2)) // Append the optional column 2
|
||||||
{
|
{
|
||||||
s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
|
s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
|
||||||
s.Append(lookup2->lookupCol2);
|
s.Append(lookup2->lookupCol2);
|
||||||
}
|
}
|
||||||
pLookUpSelectList->Append(s);
|
pLookUpSelectList->Append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight the first list item
|
// Highlight the first list item
|
||||||
pLookUpSelectList->SetSelection(0);
|
pLookUpSelectList->SetSelection(0);
|
||||||
|
|
||||||
// Make the OK activate by pressing Enter
|
// Make the OK activate by pressing Enter
|
||||||
if (pLookUpSelectList->Number())
|
if (pLookUpSelectList->Number())
|
||||||
pLookUpOkBtn->SetDefault();
|
pLookUpOkBtn->SetDefault();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pLookUpCancelBtn->SetDefault();
|
pLookUpCancelBtn->SetDefault();
|
||||||
pLookUpOkBtn->Enable(FALSE);
|
pLookUpOkBtn->Enable(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pLookUpOkBtn->Enable(allowOk);
|
pLookUpOkBtn->Enable(allowOk);
|
||||||
|
|
||||||
// Display the dialog window
|
// Display the dialog window
|
||||||
SetTitle(windowTitle);
|
SetTitle(windowTitle);
|
||||||
Centre(wxBOTH);
|
Centre(wxBOTH);
|
||||||
wxEndBusyCursor();
|
wxEndBusyCursor();
|
||||||
ShowModal();
|
ShowModal();
|
||||||
|
|
||||||
} // Generic lookup constructor 2
|
} // Generic lookup constructor 2
|
||||||
|
|
||||||
|
|
||||||
void ClookUpDlg::OnClose(wxCloseEvent& event)
|
void ClookUpDlg::OnClose(wxCloseEvent& event)
|
||||||
{
|
{
|
||||||
widgetPtrsSet = FALSE;
|
widgetPtrsSet = FALSE;
|
||||||
GetParent()->Enable(TRUE);
|
GetParent()->Enable(TRUE);
|
||||||
|
|
||||||
if (lookup)
|
if (lookup)
|
||||||
delete lookup;
|
delete lookup;
|
||||||
if (lookup2)
|
if (lookup2)
|
||||||
delete lookup2;
|
delete lookup2;
|
||||||
|
|
||||||
while (wxIsBusy()) wxEndBusyCursor();
|
while (wxIsBusy()) wxEndBusyCursor();
|
||||||
event.Skip();
|
event.Skip();
|
||||||
|
|
||||||
// return TRUE;
|
// return TRUE;
|
||||||
|
|
||||||
} // ClookUpDlg::OnClose
|
} // ClookUpDlg::OnClose
|
||||||
|
|
||||||
@@ -423,47 +423,47 @@ void ClookUpDlg::OnButton( wxCommandEvent &event )
|
|||||||
|
|
||||||
void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
|
void ClookUpDlg::OnCommand(wxWindow& win, wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxString widgetName = win.GetName();
|
wxString widgetName = win.GetName();
|
||||||
|
|
||||||
if (widgetPtrsSet)
|
if (widgetPtrsSet)
|
||||||
{
|
{
|
||||||
// OK Button
|
// OK Button
|
||||||
if (widgetName == pLookUpOkBtn->GetName())
|
if (widgetName == pLookUpOkBtn->GetName())
|
||||||
{
|
{
|
||||||
if (pLookUpSelectList->GetSelection() != -1)
|
if (pLookUpSelectList->GetSelection() != -1)
|
||||||
{
|
{
|
||||||
if (noDisplayCols == 1)
|
if (noDisplayCols == 1)
|
||||||
strcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
|
strcpy (ListDB_Selection, pLookUpSelectList->GetStringSelection());
|
||||||
else // 2 display columns
|
else // 2 display columns
|
||||||
{
|
{
|
||||||
wxString s = pLookUpSelectList->GetStringSelection();
|
wxString s = pLookUpSelectList->GetStringSelection();
|
||||||
// Column 1
|
// Column 1
|
||||||
s = s.SubString(0, col1Len-1);
|
s = s.SubString(0, col1Len-1);
|
||||||
s = s.Strip();
|
s = s.Strip();
|
||||||
strcpy(ListDB_Selection, s);
|
strcpy(ListDB_Selection, s);
|
||||||
// Column 2
|
// Column 2
|
||||||
s = pLookUpSelectList->GetStringSelection();
|
s = pLookUpSelectList->GetStringSelection();
|
||||||
s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS);
|
s = s.Mid(col1Len + LISTDB_NO_SPACES_BETWEEN_COLS);
|
||||||
s = s.Strip();
|
s = s.Strip();
|
||||||
strcpy(ListDB_Selection2, s);
|
strcpy(ListDB_Selection2, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(ListDB_Selection,"");
|
strcpy(ListDB_Selection,"");
|
||||||
strcpy(ListDB_Selection2,"");
|
strcpy(ListDB_Selection2,"");
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
} // OK Button
|
} // OK Button
|
||||||
|
|
||||||
// Cancel Button
|
// Cancel Button
|
||||||
if (widgetName == pLookUpCancelBtn->GetName())
|
if (widgetName == pLookUpCancelBtn->GetName())
|
||||||
{
|
{
|
||||||
strcpy (ListDB_Selection,"");
|
strcpy (ListDB_Selection,"");
|
||||||
strcpy (ListDB_Selection2,"");
|
strcpy (ListDB_Selection2,"");
|
||||||
Close();
|
Close();
|
||||||
} // Cancel Button
|
} // Cancel Button
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // ClookUpDlg::OnCommand
|
}; // ClookUpDlg::OnCommand
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#endif
|
#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
|
#ifndef LISTDB_DOT_H
|
||||||
@@ -31,91 +31,91 @@ extern wxDB *READONLY_DB;
|
|||||||
// Clookup class
|
// Clookup class
|
||||||
class Clookup : public wxTable
|
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
|
}; // Clookup
|
||||||
|
|
||||||
// Clookup2 class
|
// Clookup2 class
|
||||||
class Clookup2 : public wxTable
|
class Clookup2 : public wxTable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
char lookupCol1[LOOKUP_COL_LEN+1];
|
char lookupCol1[LOOKUP_COL_LEN+1];
|
||||||
char lookupCol2[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
|
}; // Clookup2
|
||||||
|
|
||||||
class ClookUpDlg : public wxDialog
|
class ClookUpDlg : public wxDialog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool widgetPtrsSet;
|
bool widgetPtrsSet;
|
||||||
int currentCursor;
|
int currentCursor;
|
||||||
Clookup *lookup;
|
Clookup *lookup;
|
||||||
Clookup2 *lookup2;
|
Clookup2 *lookup2;
|
||||||
int noDisplayCols;
|
int noDisplayCols;
|
||||||
int col1Len;
|
int col1Len;
|
||||||
|
|
||||||
wxListBox *pLookUpSelectList;
|
wxListBox *pLookUpSelectList;
|
||||||
wxButton *pLookUpOkBtn;
|
wxButton *pLookUpOkBtn;
|
||||||
wxButton *pLookUpCancelBtn;
|
wxButton *pLookUpCancelBtn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// 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(wxWindow *parent,
|
ClookUpDlg(wxWindow *parent,
|
||||||
char *windowTitle,
|
char *windowTitle,
|
||||||
char *tableName,
|
char *tableName,
|
||||||
char *colName,
|
char *colName,
|
||||||
char *where,
|
char *where,
|
||||||
char *orderBy);
|
char *orderBy);
|
||||||
|
|
||||||
//
|
//
|
||||||
// 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.
|
||||||
// It extends the capabilites of the lookup dialog in the following ways:
|
// 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
|
// 2) The ability to select DISTINCT column values
|
||||||
//
|
//
|
||||||
// Only set distinctValues equal to true if necessary. In many cases, the constraints
|
// 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
|
// 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,
|
// overhead by the database to ensure that all values returned are distinct. Therefore,
|
||||||
// use this ONLY when you need it.
|
// use this ONLY when you need it.
|
||||||
//
|
//
|
||||||
// For complicated queries, you can pass in the sql select statement. This would be
|
// 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
|
// necessary if joins are involved since by default both columns must come from the
|
||||||
// same table.
|
// same table.
|
||||||
//
|
//
|
||||||
// If you do query by sql statement, you must pass in the maximum length of column1,
|
// 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.
|
// 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
|
// 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
|
// 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
|
// records are being saved, but not committed to the db, yet should be included
|
||||||
// in the lookup window.
|
// in the lookup window.
|
||||||
//
|
//
|
||||||
ClookUpDlg(wxWindow *parent,
|
ClookUpDlg(wxWindow *parent,
|
||||||
char *windowTitle,
|
char *windowTitle,
|
||||||
char *tableName,
|
char *tableName,
|
||||||
char *dispCol1, // Must have at least 1 display column
|
char *dispCol1, // Must have at least 1 display column
|
||||||
char *dispCol2, // Optional
|
char *dispCol2, // Optional
|
||||||
char *where,
|
char *where,
|
||||||
char *orderBy,
|
char *orderBy,
|
||||||
bool distinctValues, // e.g. SELECT DISTINCT ...
|
bool distinctValues, // e.g. SELECT DISTINCT ...
|
||||||
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
|
char *selectStmt = 0, // If you wish to query by SQLstmt (complicated lookups)
|
||||||
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
|
int maxLenCol1 = 0, // Mandatory if querying by SQLstmt
|
||||||
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 OnButton( wxCommandEvent &event );
|
||||||
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
void OnCommand(wxWindow& win, wxCommandEvent& event);
|
||||||
void OnClose(wxCloseEvent& event);
|
void OnClose(wxCloseEvent& event);
|
||||||
void OnActivate(bool) {}; // necessary for hot keys
|
void OnActivate(bool) {}; // necessary for hot keys
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user