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