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
43 const char paramFilename
[] = "database.cfg";
47 * This class contains the actual data members that are used for transferring
48 * data back and forth from the database to the program.
50 * NOTE: The object described in this class is just for example purposes, and has no
51 * real meaning other than to show each type of field being used by the database
53 class CstructContact
: public wxObject
56 char Name
[ 50+1 ]; // Contact's name
61 char PostalCode
[ 15+1 ];
63 TIMESTAMP_STRUCT JoinDate
; // Date on which this person joined the wxWindows project
64 Language NativeLanguage
; // Enumerated type indicating person's native language
65 bool IsDeveloper
; // Is this person a developer for wxWindows, or just a subscriber
66 int Contributions
; // Something to show off an integer field
67 ULONG LinesOfCode
; // Something to show off a 'long' field
72 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
74 class Ccontact
: public wxTable
, public CstructContact
82 wxString qryWhereStr
; // Where string returned from the query dialog
84 Ccontact(wxDB
*pwxDB
=NULL
);
88 bool CreateIndexes(void);
89 bool FetchByName(char *name
);
91 }; // Ccontact class definition
94 typedef struct Cparameters
96 // The length of these strings were arbitrarily picked, and are
97 // dependent on the OS and database engine you will be using.
98 char ODBCSource
[100+1];
104 // Define a new application type
105 class DatabaseDemoApp
: public wxApp
110 }; // DatabaseDemoApp
112 DECLARE_APP(DatabaseDemoApp
)
114 // Define a new frame type
115 class DatabaseDemoFrame
: public wxFrame
118 CeditorDlg
*pEditorDlg
;
119 CparameterDlg
*pParamDlg
;
122 DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& sz
);
124 void OnCloseWindow(wxCloseEvent
& event
);
125 void OnCreate(wxCommandEvent
& event
);
126 void OnExit(wxCommandEvent
& event
);
127 void OnEditParameters(wxCommandEvent
& event
);
128 void OnAbout(wxCommandEvent
& event
);
130 void CreateDataTable();
131 void BuildEditorDialog();
132 void BuildParameterDialog(wxWindow
*parent
);
134 DECLARE_EVENT_TABLE()
135 }; // DatabaseDemoFrame
139 // *************************** CeditorDlg ***************************
141 class CeditorDlg
: public wxPanel
147 // Pointers to all widgets on the dialog
148 wxButton
*pCreateBtn
, *pEditBtn
, *pDeleteBtn
, *pCopyBtn
, *pSaveBtn
, *pCancelBtn
;
149 wxButton
*pPrevBtn
, *pNextBtn
, *pQueryBtn
, *pResetBtn
, *pDoneBtn
, *pHelpBtn
;
150 wxButton
*pNameListBtn
;
151 wxTextCtrl
*pNameTxt
, *pAddress1Txt
, *pAddress2Txt
,*pCityTxt
, *pStateTxt
, *pCountryTxt
,*pPostalCodeTxt
;
152 wxStaticText
*pNameMsg
, *pAddress1Msg
, *pAddress2Msg
,*pCityMsg
, *pStateMsg
, *pCountryMsg
,*pPostalCodeMsg
;
153 wxTextCtrl
*pJoinDateTxt
,*pContribTxt
, *pLinesTxt
;
154 wxStaticText
*pJoinDateMsg
,*pContribMsg
, *pLinesMsg
;
155 wxRadioBox
*pDeveloperRadio
;
156 wxChoice
*pNativeLangChoice
;
157 wxStaticText
*pNativeLangMsg
;
160 enum DialogModes mode
;
161 Ccontact
*Contact
; // this is the table object that will be being manipulated
163 CeditorDlg(wxWindow
*parent
);
165 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
166 void OnActivate(bool) {}; // necessary for hot keys
168 void FieldsEditable();
169 void SetMode(enum DialogModes m
);
175 bool GetRec(char *whereStr
);
178 #define EDITOR_DIALOG 199
180 // Editor dialog control ids
181 #define EDITOR_DIALOG_FN_GROUP 200
182 #define EDITOR_DIALOG_SEARCH_GROUP 201
183 #define EDITOR_DIALOG_CREATE 202
184 #define EDITOR_DIALOG_EDIT 203
185 #define EDITOR_DIALOG_DELETE 204
186 #define EDITOR_DIALOG_COPY 205
187 #define EDITOR_DIALOG_SAVE 206
188 #define EDITOR_DIALOG_CANCEL 207
189 #define EDITOR_DIALOG_PREV 208
190 #define EDITOR_DIALOG_NEXT 209
191 #define EDITOR_DIALOG_QUERY 211
192 #define EDITOR_DIALOG_RESET 212
193 #define EDITOR_DIALOG_NAME_MSG 213
194 #define EDITOR_DIALOG_NAME_TEXT 214
195 #define EDITOR_DIALOG_LOOKUP 215
196 #define EDITOR_DIALOG_ADDRESS1_MSG 216
197 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
198 #define EDITOR_DIALOG_ADDRESS2_MSG 218
199 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
200 #define EDITOR_DIALOG_CITY_MSG 220
201 #define EDITOR_DIALOG_CITY_TEXT 221
202 #define EDITOR_DIALOG_COUNTRY_MSG 222
203 #define EDITOR_DIALOG_COUNTRY_TEXT 223
204 #define EDITOR_DIALOG_POSTAL_MSG 224
205 #define EDITOR_DIALOG_POSTAL_TEXT 225
206 #define EDITOR_DIALOG_LANG_MSG 226
207 #define EDITOR_DIALOG_LANG_CHOICE 227
208 #define EDITOR_DIALOG_DATE_MSG 228
209 #define EDITOR_DIALOG_DATE_TEXT 229
210 #define EDITOR_DIALOG_CONTRIB_MSG 230
211 #define EDITOR_DIALOG_CONTRIB_TEXT 231
212 #define EDITOR_DIALOG_LINES_MSG 232
213 #define EDITOR_DIALOG_LINES_TEXT 233
214 #define EDITOR_DIALOG_STATE_MSG 234
215 #define EDITOR_DIALOG_STATE_TEXT 235
216 #define EDITOR_DIALOG_DEVELOPER 236
217 #define EDITOR_DIALOG_JOIN_MSG 237
218 #define EDITOR_DIALOG_JOIN_TEXT 238
220 // *************************** CparameterDlg ***************************
222 class CparameterDlg
: public wxDialog
226 enum DialogModes mode
;
228 Cparameters savedParamSettings
;
230 // Pointers to all widgets on the dialog
231 wxStaticText
*pParamODBCSourceMsg
;
232 wxListBox
*pParamODBCSourceList
;
233 wxStaticText
*pParamUserNameMsg
, *pParamPasswordMsg
;
234 wxTextCtrl
*pParamUserNameTxt
, *pParamPasswordTxt
;
235 wxButton
*pParamSaveBtn
, *pParamCancelBtn
;
238 CparameterDlg(wxWindow
*parent
);
240 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
241 void OnActivate(bool) {}; // necessary for hot keys
246 void FillDataSourceList();
250 #define PARAMETER_DIALOG 400
252 // Parameter dialog control ids
253 #define PARAMETER_DIALOG_SOURCE_MSG 401
254 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
255 #define PARAMETER_DIALOG_NAME_MSG 403
256 #define PARAMETER_DIALOG_NAME_TEXT 404
257 #define PARAMETER_DIALOG_PASSWORD_MSG 405
258 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
259 #define PARAMETER_DIALOG_SAVE 407
260 #define PARAMETER_DIALOG_CANCEL 408
262 // *************************** CqueryDlg ***************************
281 char * const langQRY_EQ
= "column = column | value";
282 char * const langQRY_LT
= "column < column | value";
283 char * const langQRY_GT
= "column > column | value";
284 char * const langQRY_LE
= "column <= column | value";
285 char * const langQRY_GE
= "column >= column | value";
286 char * const langQRY_BEGINS
= "columns that BEGIN with the string entered";
287 char * const langQRY_CONTAINS
= "columns that CONTAIN the string entered";
288 char * const langQRY_LIKE
= "% matches 0 or more of any char; _ matches 1 char";
289 char * const langQRY_BETWEEN
= "column BETWEEN value AND value";
292 class CqueryDlg
: public wxDialog
295 CcolInf
*colInf
; // Column inf. returned by db->GetColumns()
297 char *masterTableName
;
298 char *pWhere
; // A pointer to the storage for the resulting where clause
305 wxStaticText
*pQueryCol1Msg
;
306 wxChoice
*pQueryCol1Choice
;
307 wxStaticText
*pQueryNotMsg
;
308 wxCheckBox
*pQueryNotCheck
;
309 wxStaticText
*pQueryOperatorMsg
;
310 wxChoice
*pQueryOperatorChoice
;
311 wxStaticText
*pQueryCol2Msg
;
312 wxChoice
*pQueryCol2Choice
;
313 wxStaticText
*pQueryValue1Msg
;
314 wxTextCtrl
*pQueryValue1Txt
;
315 wxStaticText
*pQueryValue2Msg
;
316 wxTextCtrl
*pQueryValue2Txt
;
317 wxStaticText
*pQuerySqlWhereMsg
;
318 wxTextCtrl
*pQuerySqlWhereMtxt
;
319 wxButton
*pQueryAddBtn
;
320 wxButton
*pQueryAndBtn
;
321 wxButton
*pQueryOrBtn
;
322 wxButton
*pQueryLParenBtn
;
323 wxButton
*pQueryRParenBtn
;
324 wxButton
*pQueryDoneBtn
;
325 wxButton
*pQueryClearBtn
;
326 wxButton
*pQueryCountBtn
;
327 wxButton
*pQueryHelpBtn
;
328 wxStaticBox
*pQueryHintGrp
;
329 wxStaticText
*pQueryHintMsg
;
331 wxTextCtrl
*pFocusTxt
;
333 CqueryDlg(wxWindow
*parent
, wxDB
*pDb
, char *tblName
[], char *pWhereArg
);
335 void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
337 void OnActivate(bool) {}; // necessary for hot keys
339 // bool SetWidgetPtrs();
340 void AppendToWhere(char *s
);
341 void ProcessAddBtn();
342 void ProcessCountBtn();
343 bool ValidateWhereClause();
347 #define QUERY_DIALOG 300
349 // Parameter dialog control ids
350 #define QUERY_DIALOG_COL_MSG 301
351 #define QUERY_DIALOG_COL_CHOICE 302
352 #define QUERY_DIALOG_NOT_MSG 303
353 #define QUERY_DIALOG_NOT_CHECKBOX 304
354 #define QUERY_DIALOG_OP_MSG 305
355 #define QUERY_DIALOG_OP_CHOICE 306
356 #define QUERY_DIALOG_COL2_MSG 307
357 #define QUERY_DIALOG_COL2_CHOICE 308
358 #define QUERY_DIALOG_WHERE_MSG 309
359 #define QUERY_DIALOG_WHERE_TEXT 310
360 #define QUERY_DIALOG_ADD 311
361 #define QUERY_DIALOG_AND 312
362 #define QUERY_DIALOG_OR 313
363 #define QUERY_DIALOG_LPAREN 314
364 #define QUERY_DIALOG_RPAREN 315
365 #define QUERY_DIALOG_DONE 316
366 #define QUERY_DIALOG_CLEAR 317
367 #define QUERY_DIALOG_COUNT 318
368 #define QUERY_DIALOG_VALUE1_MSG 319
369 #define QUERY_DIALOG_VALUE1_TEXT 320
370 #define QUERY_DIALOG_VALUE2_MSG 321
371 #define QUERY_DIALOG_VALUE2_TEXT 322
372 #define QUERY_DIALOG_HINT_GROUP 323
373 #define QUERY_DIALOG_HINT_MSG 324