1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows database demo app
4 // Author: George Tasker
8 // Copyright: (c) 1998 Remstar International, Inc.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #pragma interface "dbtest.h"
14 #include <wx/string.h>
15 #include <wx/dbtable.h>
17 enum DialogModes
{mView
,mCreate
,mEdit
,mSearch
};
19 // ID for the menu quit command
20 #define FILE_CREATE 100
22 #define EDIT_PARAMETERS 200
23 #define ABOUT_DEMO 300
26 // Name of the table to be created/opened
27 const char CONTACT_TABLE_NAME
[] = "CONTACTS";
29 // Nuber of columns in the above table
30 const int CONTACT_NO_COLS
= 12; // 0-11
32 // Global structure for holding ODBC connection information
33 struct DbStuff DbConnectInf
;
35 enum Language
{langENGLISH
, langFRENCH
, langGERMAN
, langSPANISH
, langOTHER
};
37 // Forward class declarations
41 const char paramFilename
[] = "database.cfg";
45 * This class contains the actual data members that are used for transferring
46 * data back and forth from the database to the program.
48 * NOTE: The object described in this class is just for example purposes, and has no
49 * real meaning other than to show each type of field being used by the database
51 class CstructContact
: public wxObject
54 char Name
[ 50+1 ]; // Contact's name
59 char PostalCode
[ 15+1 ];
61 TIMESTAMP_STRUCT JoinDate
; // Date on which this person joined the wxWindows project
62 Language NativeLanguage
; // Enumerated type indicating person's native language
63 bool IsDeveloper
; // Is this person a developer for wxWindows, or just a subscriber
64 int Contributions
; // Something to show off an integer field
65 ULONG LinesOfCode
; // Something to show off a 'long' field
70 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
72 class Ccontact
: public wxTable
, public CstructContact
80 wxString qryWhereStr
; // Where string returned from the query dialog
82 Ccontact(wxDB
*pwxDB
=NULL
);
86 bool CreateIndexes(void);
87 bool FetchByName(char *name
);
89 }; // Ccontact class definition
92 typedef struct Cparameters
94 // The length of these strings were arbitrarily picked, and are
95 // dependent on the OS and database engine you will be using.
96 char ODBCSource
[100+1];
102 // Define a new application type
103 class DatabaseDemoApp
: public wxApp
107 wxFrame
*OnInit(void);
108 }; // DatabaseDemoApp
110 DECLARE_APP(DatabaseDemoApp
)
112 // Define a new frame type
113 class DatabaseDemoFrame
: public wxFrame
116 CeditorDlg
*pEditorDlg
;
117 CparameterDlg
*pParamDlg
;
120 DatabaseDemoFrame(wxFrame
*frame
, char *title
, int x
, int y
, int w
, int h
);
122 void OnMenuCommand(int id
);
125 void CreateDataTable();
126 void BuildEditorDialog();
127 void BuildParameterDialog(wxWindow
*parent
);
128 }; // DatabaseDemoFrame
132 // *************************** CeditorDlg ***************************
134 class CeditorDlg
: public wxPanel
140 // Pointers to all widgets on the dialog
141 wxButton
*pCreateBtn
, *pEditBtn
, *pDeleteBtn
, *pCopyBtn
, *pSaveBtn
, *pCancelBtn
;
142 wxButton
*pPrevBtn
, *pNextBtn
, *pQueryBtn
, *pResetBtn
, *pDoneBtn
, *pHelpBtn
;
143 wxButton
*pNameListBtn
;
144 wxText
*pNameTxt
, *pAddress1Txt
, *pAddress2Txt
,*pCityTxt
, *pStateTxt
, *pCountryTxt
,*pPostalCodeTxt
;
145 wxMessage
*pNameMsg
, *pAddress1Msg
, *pAddress2Msg
,*pCityMsg
, *pStateMsg
, *pCountryMsg
,*pPostalCodeMsg
;
146 wxText
*pJoinDateTxt
,*pContribTxt
, *pLinesTxt
;
147 wxMessage
*pJoinDateMsg
,*pContribMsg
, *pLinesMsg
;
148 wxRadioBox
*pDeveloperRadio
;
149 wxChoice
*pNativeLangChoice
;
150 wxMessage
*pNativeLangMsg
;
153 enum DialogModes mode
;
154 Ccontact
*Contact
; // this is the table object that will be being manipulated
156 CeditorDlg(wxWindow
*parent
);
158 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
159 void OnActivate(bool) {}; // necessary for hot keys
161 void FieldsEditable();
162 void SetMode(enum DialogModes m
);
168 bool GetRec(char *whereStr
);
172 // *************************** CparameterDlg ***************************
174 class CparameterDlg
: public wxDialogBox
178 enum DialogModes mode
;
180 Cparameters savedParamSettings
;
182 // Pointers to all widgets on the dialog
183 wxMessage
*pParamODBCSourceMsg
;
184 wxListBox
*pParamODBCSourceList
;
185 wxMessage
*pParamUserNameMsg
, *pParamPasswordMsg
;
186 wxText
*pParamUserNameTxt
, *pParamPasswordTxt
;
187 wxButton
*pParamSaveBtn
, *pParamCancelBtn
;
190 CparameterDlg(wxWindow
*parent
);
192 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
193 void OnActivate(bool) {}; // necessary for hot keys
198 void FillDataSourceList();
203 // *************************** CqueryDlg ***************************
222 char * const langQRY_EQ
= "column = column | value";
223 char * const langQRY_LT
= "column < column | value";
224 char * const langQRY_GT
= "column > column | value";
225 char * const langQRY_LE
= "column <= column | value";
226 char * const langQRY_GE
= "column >= column | value";
227 char * const langQRY_BEGINS
= "columns that BEGIN with the string entered";
228 char * const langQRY_CONTAINS
= "columns that CONTAIN the string entered";
229 char * const langQRY_LIKE
= "% matches 0 or more of any char; _ matches 1 char";
230 char * const langQRY_BETWEEN
= "column BETWEEN value AND value";
233 class CqueryDlg
: public wxDialogBox
236 CcolInf
*colInf
; // Column inf. returned by db->GetColumns()
238 char *masterTableName
;
239 char *pWhere
; // A pointer to the storage for the resulting where clause
246 wxMessage
*pQueryCol1Msg
;
247 wxChoice
*pQueryCol1Choice
;
248 wxMessage
*pQueryNotMsg
;
249 wxCheckBox
*pQueryNotCheck
;
250 wxMessage
*pQueryOperatorMsg
;
251 wxChoice
*pQueryOperatorChoice
;
252 wxMessage
*pQueryCol2Msg
;
253 wxChoice
*pQueryCol2Choice
;
254 wxMessage
*pQueryValue1Msg
;
255 wxText
*pQueryValue1Txt
;
256 wxMessage
*pQueryValue2Msg
;
257 wxText
*pQueryValue2Txt
;
258 wxMessage
*pQuerySqlWhereMsg
;
259 wxMultiText
*pQuerySqlWhereMtxt
;
260 wxButton
*pQueryAddBtn
;
261 wxButton
*pQueryAndBtn
;
262 wxButton
*pQueryOrBtn
;
263 wxButton
*pQueryLParenBtn
;
264 wxButton
*pQueryRParenBtn
;
265 wxButton
*pQueryDoneBtn
;
266 wxButton
*pQueryClearBtn
;
267 wxButton
*pQueryCountBtn
;
268 wxButton
*pQueryHelpBtn
;
269 wxGroupBox
*pQueryHintGrp
;
270 wxMessage
*pQueryHintMsg
;
274 CqueryDlg(wxWindow
*parent
, wxDB
*pDb
, char *tblName
[], char *pWhereArg
);
276 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
278 void OnActivate(bool) {}; // necessary for hot keys
280 // bool SetWidgetPtrs();
281 void AppendToWhere(char *s
);
282 void ProcessAddBtn();
283 void ProcessCountBtn();
284 bool ValidateWhereClause();