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
28 // Name of the table to be created/opened
29 const char CONTACT_TABLE_NAME
[] = "CONTACTS";
31 // Nuber of columns in the above table
32 const int CONTACT_NO_COLS
= 12; // 0-11
34 // Global structure for holding ODBC connection information
35 struct DbStuff DbConnectInf
;
37 enum Language
{langENGLISH
, langFRENCH
, langGERMAN
, langSPANISH
, langOTHER
};
39 // Forward class declarations
44 const char paramFilename
[] = "../database.cfg";
46 const char paramFilename
[] = "database.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];
108 // Define a new application type
109 class DatabaseDemoApp
: public wxApp
114 }; // DatabaseDemoApp
116 DECLARE_APP(DatabaseDemoApp
)
118 // Define a new frame type
119 class DatabaseDemoFrame
: public wxFrame
122 CeditorDlg
*pEditorDlg
;
123 CparameterDlg
*pParamDlg
;
126 DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& sz
);
128 void OnCloseWindow(wxCloseEvent
& event
);
129 void OnCreate(wxCommandEvent
& event
);
130 void OnExit(wxCommandEvent
& event
);
131 void OnEditParameters(wxCommandEvent
& event
);
132 void OnAbout(wxCommandEvent
& event
);
134 void CreateDataTable();
135 void BuildEditorDialog();
136 void BuildParameterDialog(wxWindow
*parent
);
138 DECLARE_EVENT_TABLE()
139 }; // DatabaseDemoFrame
143 // *************************** CeditorDlg ***************************
145 class CeditorDlg
: public wxPanel
151 // Pointers to all widgets on the dialog
152 wxButton
*pCreateBtn
, *pEditBtn
, *pDeleteBtn
, *pCopyBtn
, *pSaveBtn
, *pCancelBtn
;
153 wxButton
*pPrevBtn
, *pNextBtn
, *pQueryBtn
, *pResetBtn
, *pDoneBtn
, *pHelpBtn
;
154 wxButton
*pNameListBtn
;
155 wxTextCtrl
*pNameTxt
, *pAddress1Txt
, *pAddress2Txt
,*pCityTxt
, *pStateTxt
, *pCountryTxt
,*pPostalCodeTxt
;
156 wxStaticText
*pNameMsg
, *pAddress1Msg
, *pAddress2Msg
,*pCityMsg
, *pStateMsg
, *pCountryMsg
,*pPostalCodeMsg
;
157 wxTextCtrl
*pJoinDateTxt
,*pContribTxt
, *pLinesTxt
;
158 wxStaticText
*pJoinDateMsg
,*pContribMsg
, *pLinesMsg
;
159 wxRadioBox
*pDeveloperRadio
;
160 wxChoice
*pNativeLangChoice
;
161 wxStaticText
*pNativeLangMsg
;
164 enum DialogModes mode
;
165 Ccontact
*Contact
; // this is the table object that will be being manipulated
167 CeditorDlg(wxWindow
*parent
);
169 void OnButton( wxCommandEvent
&event
);
170 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
171 void OnActivate(bool) {}; // necessary for hot keys
173 void FieldsEditable();
174 void SetMode(enum DialogModes m
);
180 bool GetRec(char *whereStr
);
182 DECLARE_EVENT_TABLE()
185 #define EDITOR_DIALOG 199
187 // Editor dialog control ids
188 #define EDITOR_DIALOG_FN_GROUP 200
189 #define EDITOR_DIALOG_SEARCH_GROUP 201
190 #define EDITOR_DIALOG_CREATE 202
191 #define EDITOR_DIALOG_EDIT 203
192 #define EDITOR_DIALOG_DELETE 204
193 #define EDITOR_DIALOG_COPY 205
194 #define EDITOR_DIALOG_SAVE 206
195 #define EDITOR_DIALOG_CANCEL 207
196 #define EDITOR_DIALOG_PREV 208
197 #define EDITOR_DIALOG_NEXT 209
198 #define EDITOR_DIALOG_QUERY 211
199 #define EDITOR_DIALOG_RESET 212
200 #define EDITOR_DIALOG_NAME_MSG 213
201 #define EDITOR_DIALOG_NAME_TEXT 214
202 #define EDITOR_DIALOG_LOOKUP 215
203 #define EDITOR_DIALOG_ADDRESS1_MSG 216
204 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
205 #define EDITOR_DIALOG_ADDRESS2_MSG 218
206 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
207 #define EDITOR_DIALOG_CITY_MSG 220
208 #define EDITOR_DIALOG_CITY_TEXT 221
209 #define EDITOR_DIALOG_COUNTRY_MSG 222
210 #define EDITOR_DIALOG_COUNTRY_TEXT 223
211 #define EDITOR_DIALOG_POSTAL_MSG 224
212 #define EDITOR_DIALOG_POSTAL_TEXT 225
213 #define EDITOR_DIALOG_LANG_MSG 226
214 #define EDITOR_DIALOG_LANG_CHOICE 227
215 #define EDITOR_DIALOG_DATE_MSG 228
216 #define EDITOR_DIALOG_DATE_TEXT 229
217 #define EDITOR_DIALOG_CONTRIB_MSG 230
218 #define EDITOR_DIALOG_CONTRIB_TEXT 231
219 #define EDITOR_DIALOG_LINES_MSG 232
220 #define EDITOR_DIALOG_LINES_TEXT 233
221 #define EDITOR_DIALOG_STATE_MSG 234
222 #define EDITOR_DIALOG_STATE_TEXT 235
223 #define EDITOR_DIALOG_DEVELOPER 236
224 #define EDITOR_DIALOG_JOIN_MSG 237
225 #define EDITOR_DIALOG_JOIN_TEXT 238
227 // *************************** CparameterDlg ***************************
229 class CparameterDlg
: public wxDialog
233 enum DialogModes mode
;
235 Cparameters savedParamSettings
;
237 // Pointers to all widgets on the dialog
238 wxStaticText
*pParamODBCSourceMsg
;
239 wxListBox
*pParamODBCSourceList
;
240 wxStaticText
*pParamUserNameMsg
, *pParamPasswordMsg
;
241 wxTextCtrl
*pParamUserNameTxt
, *pParamPasswordTxt
;
242 wxButton
*pParamSaveBtn
, *pParamCancelBtn
;
245 CparameterDlg(wxWindow
*parent
);
247 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
248 void OnActivate(bool) {}; // necessary for hot keys
253 void FillDataSourceList();
257 #define PARAMETER_DIALOG 400
259 // Parameter dialog control ids
260 #define PARAMETER_DIALOG_SOURCE_MSG 401
261 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
262 #define PARAMETER_DIALOG_NAME_MSG 403
263 #define PARAMETER_DIALOG_NAME_TEXT 404
264 #define PARAMETER_DIALOG_PASSWORD_MSG 405
265 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
266 #define PARAMETER_DIALOG_SAVE 407
267 #define PARAMETER_DIALOG_CANCEL 408
269 // *************************** CqueryDlg ***************************
288 char * const langQRY_EQ
= "column = column | value";
289 char * const langQRY_LT
= "column < column | value";
290 char * const langQRY_GT
= "column > column | value";
291 char * const langQRY_LE
= "column <= column | value";
292 char * const langQRY_GE
= "column >= column | value";
293 char * const langQRY_BEGINS
= "columns that BEGIN with the string entered";
294 char * const langQRY_CONTAINS
= "columns that CONTAIN the string entered";
295 char * const langQRY_LIKE
= "% matches 0 or more of any char; _ matches 1 char";
296 char * const langQRY_BETWEEN
= "column BETWEEN value AND value";
299 class CqueryDlg
: public wxDialog
302 CcolInf
*colInf
; // Column inf. returned by db->GetColumns()
304 char *masterTableName
;
305 char *pWhere
; // A pointer to the storage for the resulting where clause
312 wxStaticText
*pQueryCol1Msg
;
313 wxChoice
*pQueryCol1Choice
;
314 wxStaticText
*pQueryNotMsg
;
315 wxCheckBox
*pQueryNotCheck
;
316 wxStaticText
*pQueryOperatorMsg
;
317 wxChoice
*pQueryOperatorChoice
;
318 wxStaticText
*pQueryCol2Msg
;
319 wxChoice
*pQueryCol2Choice
;
320 wxStaticText
*pQueryValue1Msg
;
321 wxTextCtrl
*pQueryValue1Txt
;
322 wxStaticText
*pQueryValue2Msg
;
323 wxTextCtrl
*pQueryValue2Txt
;
324 wxStaticText
*pQuerySqlWhereMsg
;
325 wxTextCtrl
*pQuerySqlWhereMtxt
;
326 wxButton
*pQueryAddBtn
;
327 wxButton
*pQueryAndBtn
;
328 wxButton
*pQueryOrBtn
;
329 wxButton
*pQueryLParenBtn
;
330 wxButton
*pQueryRParenBtn
;
331 wxButton
*pQueryDoneBtn
;
332 wxButton
*pQueryClearBtn
;
333 wxButton
*pQueryCountBtn
;
334 wxButton
*pQueryHelpBtn
;
335 wxStaticBox
*pQueryHintGrp
;
336 wxStaticText
*pQueryHintMsg
;
338 wxTextCtrl
*pFocusTxt
;
340 CqueryDlg(wxWindow
*parent
, wxDB
*pDb
, char *tblName
[], char *pWhereArg
);
342 void OnButton( wxCommandEvent
&event
);
343 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
345 void OnActivate(bool) {}; // necessary for hot keys
347 // bool SetWidgetPtrs();
348 void AppendToWhere(char *s
);
349 void ProcessAddBtn();
350 void ProcessCountBtn();
351 bool ValidateWhereClause();
353 DECLARE_EVENT_TABLE()
356 #define QUERY_DIALOG 300
358 // Parameter dialog control ids
359 #define QUERY_DIALOG_COL_MSG 301
360 #define QUERY_DIALOG_COL_CHOICE 302
361 #define QUERY_DIALOG_NOT_MSG 303
362 #define QUERY_DIALOG_NOT_CHECKBOX 304
363 #define QUERY_DIALOG_OP_MSG 305
364 #define QUERY_DIALOG_OP_CHOICE 306
365 #define QUERY_DIALOG_COL2_MSG 307
366 #define QUERY_DIALOG_COL2_CHOICE 308
367 #define QUERY_DIALOG_WHERE_MSG 309
368 #define QUERY_DIALOG_WHERE_TEXT 310
369 #define QUERY_DIALOG_ADD 311
370 #define QUERY_DIALOG_AND 312
371 #define QUERY_DIALOG_OR 313
372 #define QUERY_DIALOG_LPAREN 314
373 #define QUERY_DIALOG_RPAREN 315
374 #define QUERY_DIALOG_DONE 316
375 #define QUERY_DIALOG_CLEAR 317
376 #define QUERY_DIALOG_COUNT 318
377 #define QUERY_DIALOG_VALUE1_MSG 319
378 #define QUERY_DIALOG_VALUE1_TEXT 320
379 #define QUERY_DIALOG_VALUE2_MSG 321
380 #define QUERY_DIALOG_VALUE2_TEXT 322
381 #define QUERY_DIALOG_HINT_GROUP 323
382 #define QUERY_DIALOG_HINT_MSG 324