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>
17 #include <wx/dbtable.h>
19 enum DialogModes
{mView
,mCreate
,mEdit
,mSearch
};
21 // ID for the menu quit command
22 #define FILE_CREATE 100
24 #define EDIT_PARAMETERS 200
25 #define ABOUT_DEMO 300
27 // this seems to be missing, Robert Roebling (?)
32 // Name of the table to be created/opened
33 const char CONTACT_TABLE_NAME
[] = "contacts";
35 // Nuber of columns in the above table
36 const int CONTACT_NO_COLS
= 12; // 0-11
38 // Global structure for holding ODBC connection information
39 struct DbStuff DbConnectInf
;
41 enum Language
{langENGLISH
, langFRENCH
, langGERMAN
, langSPANISH
, langOTHER
};
43 // Forward class declarations
47 const char paramFilename
[] = "dbtest.cfg";
51 * This class contains the actual data members that are used for transferring
52 * data back and forth from the database to the program.
54 * NOTE: The object described in this class is just for example purposes, and has no
55 * real meaning other than to show each type of field being used by the database
57 class CstructContact
: public wxObject
60 char Name
[ 50+1 ]; // Contact's name
65 char PostalCode
[ 15+1 ];
67 TIMESTAMP_STRUCT JoinDate
; // Date on which this person joined the wxWindows project
68 Language NativeLanguage
; // Enumerated type indicating person's native language
69 bool IsDeveloper
; // Is this person a developer for wxWindows, or just a subscriber
70 int Contributions
; // Something to show off an integer field
71 ULONG LinesOfCode
; // Something to show off a 'long' field
76 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
78 class Ccontact
: public wxTable
, public CstructContact
86 wxString qryWhereStr
; // Where string returned from the query dialog
88 Ccontact(wxDB
*pwxDB
=NULL
);
92 bool CreateIndexes(void);
93 bool FetchByName(char *name
);
95 }; // Ccontact class definition
98 typedef struct Cparameters
100 // The length of these strings were arbitrarily picked, and are
101 // dependent on the OS and database engine you will be using.
102 char ODBCSource
[100+1];
105 char DirPath
[MAX_PATH
+1];
109 // Define a new application type
110 class DatabaseDemoApp
: public wxApp
115 }; // DatabaseDemoApp
117 DECLARE_APP(DatabaseDemoApp
)
119 // Define a new frame type
120 class DatabaseDemoFrame
: public wxFrame
123 CeditorDlg
*pEditorDlg
;
124 CparameterDlg
*pParamDlg
;
127 DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& sz
);
129 void OnCloseWindow(wxCloseEvent
& event
);
130 void OnCreate(wxCommandEvent
& event
);
131 void OnExit(wxCommandEvent
& event
);
132 void OnEditParameters(wxCommandEvent
& event
);
133 void OnAbout(wxCommandEvent
& event
);
135 void CreateDataTable();
136 void BuildEditorDialog();
137 void BuildParameterDialog(wxWindow
*parent
);
139 DECLARE_EVENT_TABLE()
140 }; // DatabaseDemoFrame
144 // *************************** CeditorDlg ***************************
146 class CeditorDlg
: public wxPanel
152 // Pointers to all widgets on the dialog
153 wxButton
*pCreateBtn
, *pEditBtn
, *pDeleteBtn
, *pCopyBtn
, *pSaveBtn
, *pCancelBtn
;
154 wxButton
*pPrevBtn
, *pNextBtn
, *pQueryBtn
, *pResetBtn
, *pDoneBtn
, *pHelpBtn
;
155 wxButton
*pNameListBtn
;
156 wxTextCtrl
*pNameTxt
, *pAddress1Txt
, *pAddress2Txt
,*pCityTxt
, *pStateTxt
, *pCountryTxt
,*pPostalCodeTxt
;
157 wxStaticText
*pNameMsg
, *pAddress1Msg
, *pAddress2Msg
,*pCityMsg
, *pStateMsg
, *pCountryMsg
,*pPostalCodeMsg
;
158 wxTextCtrl
*pJoinDateTxt
,*pContribTxt
, *pLinesTxt
;
159 wxStaticText
*pJoinDateMsg
,*pContribMsg
, *pLinesMsg
;
160 wxRadioBox
*pDeveloperRadio
;
161 wxChoice
*pNativeLangChoice
;
162 wxStaticText
*pNativeLangMsg
;
165 enum DialogModes mode
;
166 Ccontact
*Contact
; // this is the table object that will be being manipulated
168 CeditorDlg(wxWindow
*parent
);
169 void OnCloseWindow(wxCloseEvent
& event
);
170 void OnButton( wxCommandEvent
&event
);
171 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
172 void OnActivate(bool) {}; // necessary for hot keys
174 void FieldsEditable();
175 void SetMode(enum DialogModes m
);
181 bool GetRec(char *whereStr
);
183 DECLARE_EVENT_TABLE()
186 #define EDITOR_DIALOG 199
188 // Editor dialog control ids
189 #define EDITOR_DIALOG_FN_GROUP 200
190 #define EDITOR_DIALOG_SEARCH_GROUP 201
191 #define EDITOR_DIALOG_CREATE 202
192 #define EDITOR_DIALOG_EDIT 203
193 #define EDITOR_DIALOG_DELETE 204
194 #define EDITOR_DIALOG_COPY 205
195 #define EDITOR_DIALOG_SAVE 206
196 #define EDITOR_DIALOG_CANCEL 207
197 #define EDITOR_DIALOG_PREV 208
198 #define EDITOR_DIALOG_NEXT 209
199 #define EDITOR_DIALOG_QUERY 211
200 #define EDITOR_DIALOG_RESET 212
201 #define EDITOR_DIALOG_NAME_MSG 213
202 #define EDITOR_DIALOG_NAME_TEXT 214
203 #define EDITOR_DIALOG_LOOKUP 215
204 #define EDITOR_DIALOG_ADDRESS1_MSG 216
205 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
206 #define EDITOR_DIALOG_ADDRESS2_MSG 218
207 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
208 #define EDITOR_DIALOG_CITY_MSG 220
209 #define EDITOR_DIALOG_CITY_TEXT 221
210 #define EDITOR_DIALOG_COUNTRY_MSG 222
211 #define EDITOR_DIALOG_COUNTRY_TEXT 223
212 #define EDITOR_DIALOG_POSTAL_MSG 224
213 #define EDITOR_DIALOG_POSTAL_TEXT 225
214 #define EDITOR_DIALOG_LANG_MSG 226
215 #define EDITOR_DIALOG_LANG_CHOICE 227
216 #define EDITOR_DIALOG_DATE_MSG 228
217 #define EDITOR_DIALOG_DATE_TEXT 229
218 #define EDITOR_DIALOG_CONTRIB_MSG 230
219 #define EDITOR_DIALOG_CONTRIB_TEXT 231
220 #define EDITOR_DIALOG_LINES_MSG 232
221 #define EDITOR_DIALOG_LINES_TEXT 233
222 #define EDITOR_DIALOG_STATE_MSG 234
223 #define EDITOR_DIALOG_STATE_TEXT 235
224 #define EDITOR_DIALOG_DEVELOPER 236
225 #define EDITOR_DIALOG_JOIN_MSG 237
226 #define EDITOR_DIALOG_JOIN_TEXT 238
228 // *************************** CparameterDlg ***************************
230 class CparameterDlg
: public wxDialog
234 enum DialogModes mode
;
236 Cparameters savedParamSettings
;
238 // Pointers to all widgets on the dialog
239 wxStaticText
*pParamODBCSourceMsg
;
240 wxListBox
*pParamODBCSourceList
;
241 wxStaticText
*pParamUserNameMsg
, *pParamPasswordMsg
, *pParamDirPathMsg
;
242 wxTextCtrl
*pParamUserNameTxt
, *pParamPasswordTxt
, *pParamDirPathTxt
;
243 wxButton
*pParamSaveBtn
, *pParamCancelBtn
;
246 CparameterDlg(wxWindow
*parent
);
247 void OnCloseWindow(wxCloseEvent
& event
);
248 void OnButton( wxCommandEvent
&event
);
249 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
250 void OnActivate(bool) {}; // necessary for hot keys
255 void FillDataSourceList();
257 DECLARE_EVENT_TABLE()
260 #define PARAMETER_DIALOG 400
262 // Parameter dialog control ids
263 #define PARAMETER_DIALOG_SOURCE_MSG 401
264 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
265 #define PARAMETER_DIALOG_NAME_MSG 403
266 #define PARAMETER_DIALOG_NAME_TEXT 404
267 #define PARAMETER_DIALOG_PASSWORD_MSG 405
268 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
269 #define PARAMETER_DIALOG_DIRPATH_MSG 407
270 #define PARAMETER_DIALOG_DIRPATH_TEXT 408
271 #define PARAMETER_DIALOG_SAVE 409
272 #define PARAMETER_DIALOG_CANCEL 410
274 // *************************** CqueryDlg ***************************
293 char * const langQRY_EQ
= "column = column | value";
294 char * const langQRY_LT
= "column < column | value";
295 char * const langQRY_GT
= "column > column | value";
296 char * const langQRY_LE
= "column <= column | value";
297 char * const langQRY_GE
= "column >= column | value";
298 char * const langQRY_BEGINS
= "columns that BEGIN with the string entered";
299 char * const langQRY_CONTAINS
= "columns that CONTAIN the string entered";
300 char * const langQRY_LIKE
= "% matches 0 or more of any char; _ matches 1 char";
301 char * const langQRY_BETWEEN
= "column BETWEEN value AND value";
304 class CqueryDlg
: public wxDialog
307 CcolInf
*colInf
; // Column inf. returned by db->GetColumns()
309 char *masterTableName
;
310 char *pWhere
; // A pointer to the storage for the resulting where clause
317 wxStaticText
*pQueryCol1Msg
;
318 wxChoice
*pQueryCol1Choice
;
319 wxStaticText
*pQueryNotMsg
;
320 wxCheckBox
*pQueryNotCheck
;
321 wxStaticText
*pQueryOperatorMsg
;
322 wxChoice
*pQueryOperatorChoice
;
323 wxStaticText
*pQueryCol2Msg
;
324 wxChoice
*pQueryCol2Choice
;
325 wxStaticText
*pQueryValue1Msg
;
326 wxTextCtrl
*pQueryValue1Txt
;
327 wxStaticText
*pQueryValue2Msg
;
328 wxTextCtrl
*pQueryValue2Txt
;
329 wxStaticText
*pQuerySqlWhereMsg
;
330 wxTextCtrl
*pQuerySqlWhereMtxt
;
331 wxButton
*pQueryAddBtn
;
332 wxButton
*pQueryAndBtn
;
333 wxButton
*pQueryOrBtn
;
334 wxButton
*pQueryLParenBtn
;
335 wxButton
*pQueryRParenBtn
;
336 wxButton
*pQueryDoneBtn
;
337 wxButton
*pQueryClearBtn
;
338 wxButton
*pQueryCountBtn
;
339 wxButton
*pQueryHelpBtn
;
340 wxStaticBox
*pQueryHintGrp
;
341 wxStaticText
*pQueryHintMsg
;
343 wxTextCtrl
*pFocusTxt
;
345 CqueryDlg(wxWindow
*parent
, wxDB
*pDb
, char *tblName
[], char *pWhereArg
);
347 void OnButton( wxCommandEvent
&event
);
348 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
349 void OnCloseWindow(wxCloseEvent
& event
);
350 void OnActivate(bool) {}; // necessary for hot keys
352 // bool SetWidgetPtrs();
353 void AppendToWhere(char *s
);
354 void ProcessAddBtn();
355 void ProcessCountBtn();
356 bool ValidateWhereClause();
358 DECLARE_EVENT_TABLE()
361 #define QUERY_DIALOG 300
363 // Parameter dialog control ids
364 #define QUERY_DIALOG_COL_MSG 301
365 #define QUERY_DIALOG_COL_CHOICE 302
366 #define QUERY_DIALOG_NOT_MSG 303
367 #define QUERY_DIALOG_NOT_CHECKBOX 304
368 #define QUERY_DIALOG_OP_MSG 305
369 #define QUERY_DIALOG_OP_CHOICE 306
370 #define QUERY_DIALOG_COL2_MSG 307
371 #define QUERY_DIALOG_COL2_CHOICE 308
372 #define QUERY_DIALOG_WHERE_MSG 309
373 #define QUERY_DIALOG_WHERE_TEXT 310
374 #define QUERY_DIALOG_ADD 311
375 #define QUERY_DIALOG_AND 312
376 #define QUERY_DIALOG_OR 313
377 #define QUERY_DIALOG_LPAREN 314
378 #define QUERY_DIALOG_RPAREN 315
379 #define QUERY_DIALOG_DONE 316
380 #define QUERY_DIALOG_CLEAR 317
381 #define QUERY_DIALOG_COUNT 318
382 #define QUERY_DIALOG_VALUE1_MSG 319
383 #define QUERY_DIALOG_VALUE1_TEXT 320
384 #define QUERY_DIALOG_VALUE2_MSG 321
385 #define QUERY_DIALOG_VALUE2_TEXT 322
386 #define QUERY_DIALOG_HINT_GROUP 323
387 #define QUERY_DIALOG_HINT_MSG 324