1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows database demo app
4 // Author: George Tasker
8 // Copyright: (c) 1998 Remstar International, Inc.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma interface "dbtest.h"
16 #include <wx/string.h>
18 #include <wx/dbtable.h>
20 enum DialogModes
{mView
,mCreate
,mEdit
,mSearch
};
22 // ID for the menu quit command
23 #define FILE_CREATE 100
24 #define FILE_RECREATE_TABLE 110
25 #define FILE_RECREATE_INDEXES 120
27 #define EDIT_PARAMETERS 200
28 #define ABOUT_DEMO 300
30 // this seems to be missing, Robert Roebling (?)
35 // Name of the table to be created/opened
36 const wxChar CONTACT_TABLE_NAME
[] = "contacts";
38 // Nuber of columns in the above table
39 const int CONTACT_NO_COLS
= 12; // 0-11
41 // Global structure for holding ODBC connection information
42 struct wxDbConnectInf DbConnectInf
;
44 enum Language
{langENGLISH
, langFRENCH
, langGERMAN
, langSPANISH
, langOTHER
};
46 // Forward class declarations
50 const wxChar paramFilename
[] = "dbtest.cfg";
54 * This class contains the actual data members that are used for transferring
55 * data back and forth from the database to the program.
57 * NOTE: The object described in this class is just for example purposes, and has no
58 * real meaning other than to show each type of field being used by the database
60 class CstructContact
: public wxObject
63 wxChar Name
[50+1]; // Contact's name
68 wxChar PostalCode
[15+1];
70 TIMESTAMP_STRUCT JoinDate
; // Date on which this person joined the wxWindows project
71 Language NativeLanguage
; // Enumerated type indicating person's native language
72 bool IsDeveloper
; // Is this person a developer for wxWindows, or just a subscriber
73 UCHAR Contributions
; // Something to show off an integer field
74 ULONG LinesOfCode
; // Something to show off a 'long' field
79 // NOTE: Ccontact inherits wxDbTable, which gives access to all the database functionality
81 class Ccontact
: public wxDbTable
, public CstructContact
89 wxString qryWhereStr
; // Where string returned from the query dialog
91 Ccontact(wxDb
*pwxDb
=NULL
);
95 bool CreateIndexes(void);
96 bool FetchByName(wxChar
*name
);
98 }; // Ccontact class definition
101 typedef struct Cparameters
103 // The length of these strings were arbitrarily picked, and are
104 // dependent on the OS and database engine you will be using.
105 wxChar ODBCSource
[100+1];
106 wxChar UserName
[25+1];
107 wxChar Password
[25+1];
108 wxChar DirPath
[MAX_PATH
+1];
112 // Define a new application type
113 class DatabaseDemoApp
: public wxApp
118 }; // DatabaseDemoApp
120 DECLARE_APP(DatabaseDemoApp
)
122 // Define a new frame type
123 class DatabaseDemoFrame
: public wxFrame
126 CeditorDlg
*pEditorDlg
;
127 CparameterDlg
*pParamDlg
;
130 DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& sz
);
132 void OnCloseWindow(wxCloseEvent
& event
);
133 void OnCreate(wxCommandEvent
& event
);
134 void OnRecreateTable(wxCommandEvent
& event
);
135 void OnRecreateIndexes(wxCommandEvent
& event
);
136 void OnExit(wxCommandEvent
& event
);
137 void OnEditParameters(wxCommandEvent
& event
);
138 void OnAbout(wxCommandEvent
& event
);
140 void CreateDataTable(bool recreate
);
141 void BuildEditorDialog();
142 void BuildParameterDialog(wxWindow
*parent
);
144 DECLARE_EVENT_TABLE()
145 }; // DatabaseDemoFrame
149 // *************************** CeditorDlg ***************************
151 class CeditorDlg
: public wxPanel
157 // Pointers to all widgets on the dialog
158 wxButton
*pCreateBtn
, *pEditBtn
, *pDeleteBtn
, *pCopyBtn
, *pSaveBtn
, *pCancelBtn
;
159 wxButton
*pPrevBtn
, *pNextBtn
, *pQueryBtn
, *pResetBtn
, *pDoneBtn
, *pHelpBtn
;
160 wxButton
*pNameListBtn
;
161 wxTextCtrl
*pNameTxt
, *pAddress1Txt
, *pAddress2Txt
,*pCityTxt
, *pStateTxt
, *pCountryTxt
,*pPostalCodeTxt
;
162 wxStaticText
*pNameMsg
, *pAddress1Msg
, *pAddress2Msg
,*pCityMsg
, *pStateMsg
, *pCountryMsg
,*pPostalCodeMsg
;
163 wxTextCtrl
*pJoinDateTxt
,*pContribTxt
, *pLinesTxt
;
164 wxStaticText
*pJoinDateMsg
,*pContribMsg
, *pLinesMsg
;
165 wxRadioBox
*pDeveloperRadio
;
166 wxChoice
*pNativeLangChoice
;
167 wxStaticText
*pNativeLangMsg
;
171 enum DialogModes mode
;
172 Ccontact
*Contact
; // this is the table object that will be being manipulated
174 CeditorDlg(wxWindow
*parent
);
176 void OnCloseWindow(wxCloseEvent
& event
);
177 void OnButton( wxCommandEvent
&event
);
178 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
179 void OnActivate(bool) {}; // necessary for hot keys
182 void FieldsEditable();
183 void SetMode(enum DialogModes m
);
189 bool GetRec(wxChar
*whereStr
);
191 DECLARE_EVENT_TABLE()
194 #define EDITOR_DIALOG 199
196 // Editor dialog control ids
197 #define EDITOR_DIALOG_FN_GROUP 200
198 #define EDITOR_DIALOG_SEARCH_GROUP 201
199 #define EDITOR_DIALOG_CREATE 202
200 #define EDITOR_DIALOG_EDIT 203
201 #define EDITOR_DIALOG_DELETE 204
202 #define EDITOR_DIALOG_COPY 205
203 #define EDITOR_DIALOG_SAVE 206
204 #define EDITOR_DIALOG_CANCEL 207
205 #define EDITOR_DIALOG_PREV 208
206 #define EDITOR_DIALOG_NEXT 209
207 #define EDITOR_DIALOG_QUERY 211
208 #define EDITOR_DIALOG_RESET 212
209 #define EDITOR_DIALOG_NAME_MSG 213
210 #define EDITOR_DIALOG_NAME_TEXT 214
211 #define EDITOR_DIALOG_LOOKUP 215
212 #define EDITOR_DIALOG_ADDRESS1_MSG 216
213 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
214 #define EDITOR_DIALOG_ADDRESS2_MSG 218
215 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
216 #define EDITOR_DIALOG_CITY_MSG 220
217 #define EDITOR_DIALOG_CITY_TEXT 221
218 #define EDITOR_DIALOG_COUNTRY_MSG 222
219 #define EDITOR_DIALOG_COUNTRY_TEXT 223
220 #define EDITOR_DIALOG_POSTAL_MSG 224
221 #define EDITOR_DIALOG_POSTAL_TEXT 225
222 #define EDITOR_DIALOG_LANG_MSG 226
223 #define EDITOR_DIALOG_LANG_CHOICE 227
224 #define EDITOR_DIALOG_DATE_MSG 228
225 #define EDITOR_DIALOG_DATE_TEXT 229
226 #define EDITOR_DIALOG_CONTRIB_MSG 230
227 #define EDITOR_DIALOG_CONTRIB_TEXT 231
228 #define EDITOR_DIALOG_LINES_MSG 232
229 #define EDITOR_DIALOG_LINES_TEXT 233
230 #define EDITOR_DIALOG_STATE_MSG 234
231 #define EDITOR_DIALOG_STATE_TEXT 235
232 #define EDITOR_DIALOG_DEVELOPER 236
233 #define EDITOR_DIALOG_JOIN_MSG 237
234 #define EDITOR_DIALOG_JOIN_TEXT 238
236 // *************************** CparameterDlg ***************************
238 class CparameterDlg
: public wxDialog
242 enum DialogModes mode
;
244 Cparameters savedParamSettings
;
246 // Pointers to all widgets on the dialog
247 wxStaticText
*pParamODBCSourceMsg
;
248 wxListBox
*pParamODBCSourceList
;
249 wxStaticText
*pParamUserNameMsg
, *pParamPasswordMsg
, *pParamDirPathMsg
;
250 wxTextCtrl
*pParamUserNameTxt
, *pParamPasswordTxt
, *pParamDirPathTxt
;
251 wxButton
*pParamSaveBtn
, *pParamCancelBtn
;
254 CparameterDlg(wxWindow
*parent
);
256 void OnCloseWindow(wxCloseEvent
& event
);
257 void OnButton( wxCommandEvent
&event
);
258 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
259 void OnActivate(bool) {}; // necessary for hot keys
264 void FillDataSourceList();
266 DECLARE_EVENT_TABLE()
269 #define PARAMETER_DIALOG 400
271 // Parameter dialog control ids
272 #define PARAMETER_DIALOG_SOURCE_MSG 401
273 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
274 #define PARAMETER_DIALOG_NAME_MSG 403
275 #define PARAMETER_DIALOG_NAME_TEXT 404
276 #define PARAMETER_DIALOG_PASSWORD_MSG 405
277 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
278 #define PARAMETER_DIALOG_DIRPATH_MSG 407
279 #define PARAMETER_DIALOG_DIRPATH_TEXT 408
280 #define PARAMETER_DIALOG_SAVE 409
281 #define PARAMETER_DIALOG_CANCEL 410
283 // *************************** CqueryDlg ***************************
302 wxChar
* const langQRY_EQ
= "column = column | value";
303 wxChar
* const langQRY_LT
= "column < column | value";
304 wxChar
* const langQRY_GT
= "column > column | value";
305 wxChar
* const langQRY_LE
= "column <= column | value";
306 wxChar
* const langQRY_GE
= "column >= column | value";
307 wxChar
* const langQRY_BEGINS
= "columns that BEGIN with the string entered";
308 wxChar
* const langQRY_CONTAINS
= "columns that CONTAIN the string entered";
309 wxChar
* const langQRY_LIKE
= "% matches 0 or more of any char; _ matches 1 char";
310 wxChar
* const langQRY_BETWEEN
= "column BETWEEN value AND value";
313 class CqueryDlg
: public wxDialog
316 wxDbColInf
*colInf
; // Column inf. returned by db->GetColumns()
318 wxChar
*masterTableName
;
319 wxChar
*pWhere
; // A pointer to the storage for the resulting where clause
326 wxStaticText
*pQueryCol1Msg
;
327 wxChoice
*pQueryCol1Choice
;
328 wxStaticText
*pQueryNotMsg
;
329 wxCheckBox
*pQueryNotCheck
;
330 wxStaticText
*pQueryOperatorMsg
;
331 wxChoice
*pQueryOperatorChoice
;
332 wxStaticText
*pQueryCol2Msg
;
333 wxChoice
*pQueryCol2Choice
;
334 wxStaticText
*pQueryValue1Msg
;
335 wxTextCtrl
*pQueryValue1Txt
;
336 wxStaticText
*pQueryValue2Msg
;
337 wxTextCtrl
*pQueryValue2Txt
;
338 wxStaticText
*pQuerySqlWhereMsg
;
339 wxTextCtrl
*pQuerySqlWhereMtxt
;
340 wxButton
*pQueryAddBtn
;
341 wxButton
*pQueryAndBtn
;
342 wxButton
*pQueryOrBtn
;
343 wxButton
*pQueryLParenBtn
;
344 wxButton
*pQueryRParenBtn
;
345 wxButton
*pQueryDoneBtn
;
346 wxButton
*pQueryClearBtn
;
347 wxButton
*pQueryCountBtn
;
348 wxButton
*pQueryHelpBtn
;
349 wxStaticBox
*pQueryHintGrp
;
350 wxStaticText
*pQueryHintMsg
;
352 wxTextCtrl
*pFocusTxt
;
354 CqueryDlg(wxWindow
*parent
, wxDb
*pDb
, wxChar
*tblName
[], wxChar
*pWhereArg
);
357 void OnButton( wxCommandEvent
&event
);
358 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
359 void OnCloseWindow(wxCloseEvent
& event
);
360 void OnActivate(bool) {}; // necessary for hot keys
362 void AppendToWhere(wxChar
*s
);
363 void ProcessAddBtn();
364 void ProcessCountBtn();
365 bool ValidateWhereClause();
367 DECLARE_EVENT_TABLE()
370 #define QUERY_DIALOG 300
372 // Parameter dialog control ids
373 #define QUERY_DIALOG_COL_MSG 301
374 #define QUERY_DIALOG_COL_CHOICE 302
375 #define QUERY_DIALOG_NOT_MSG 303
376 #define QUERY_DIALOG_NOT_CHECKBOX 304
377 #define QUERY_DIALOG_OP_MSG 305
378 #define QUERY_DIALOG_OP_CHOICE 306
379 #define QUERY_DIALOG_COL2_MSG 307
380 #define QUERY_DIALOG_COL2_CHOICE 308
381 #define QUERY_DIALOG_WHERE_MSG 309
382 #define QUERY_DIALOG_WHERE_TEXT 310
383 #define QUERY_DIALOG_ADD 311
384 #define QUERY_DIALOG_AND 312
385 #define QUERY_DIALOG_OR 313
386 #define QUERY_DIALOG_LPAREN 314
387 #define QUERY_DIALOG_RPAREN 315
388 #define QUERY_DIALOG_DONE 316
389 #define QUERY_DIALOG_CLEAR 317
390 #define QUERY_DIALOG_COUNT 318
391 #define QUERY_DIALOG_VALUE1_MSG 319
392 #define QUERY_DIALOG_VALUE1_TEXT 320
393 #define QUERY_DIALOG_VALUE2_MSG 321
394 #define QUERY_DIALOG_VALUE2_TEXT 322
395 #define QUERY_DIALOG_HINT_GROUP 323
396 #define QUERY_DIALOG_HINT_MSG 324