]> git.saurik.com Git - wxWidgets.git/blob - samples/db/dbtest.h
updates to correct build errors (new locations, etc.)
[wxWidgets.git] / samples / db / dbtest.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dbtest.h
3 // Purpose: wxWindows database demo app
4 // Author: George Tasker
5 // Modified by:
6 // Created: 1998
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Remstar International, Inc.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma interface "dbtest.h"
14 #endif
15
16 #include <wx/string.h>
17 #include <wx/db.h>
18 #include <wx/dbtable.h>
19
20 enum DialogModes {mView,mCreate,mEdit,mSearch};
21
22 // ID for the menu quit command
23 #define FILE_CREATE 100
24 #define FILE_EXIT 199
25 #define EDIT_PARAMETERS 200
26 #define ABOUT_DEMO 300
27
28 // this seems to be missing, Robert Roebling (?)
29 #ifndef MAX_PATH
30 #define MAX_PATH 200
31 #endif
32
33 // Name of the table to be created/opened
34 const char CONTACT_TABLE_NAME[] = "contacts";
35
36 // Nuber of columns in the above table
37 const int CONTACT_NO_COLS = 12; // 0-11
38
39 // Global structure for holding ODBC connection information
40 struct DbStuff DbConnectInf;
41
42 enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
43
44 // Forward class declarations
45 class CeditorDlg;
46 class CparameterDlg;
47
48 const char paramFilename[] = "dbtest.cfg";
49
50
51 /*
52 * This class contains the actual data members that are used for transferring
53 * data back and forth from the database to the program.
54 *
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
57 */
58 class CstructContact : public wxObject
59 {
60 public:
61 char Name[50+1]; // Contact's name
62 char Addr1[50+1];
63 char Addr2[50+1];
64 char City[25+1];
65 char State[25+1];
66 char PostalCode[15+1];
67 char Country[20+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
73 }; // CstructContact
74
75
76 //
77 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
78 //
79 class Ccontact : public wxTable, public CstructContact
80 {
81 private:
82 bool freeDbConn;
83 void SetupColumns();
84
85 public:
86 wxString whereStr;
87 wxString qryWhereStr; // Where string returned from the query dialog
88
89 Ccontact(wxDB *pwxDB=NULL);
90 ~Ccontact();
91
92 void Initialize();
93 bool CreateIndexes(void);
94 bool FetchByName(char *name);
95
96 }; // Ccontact class definition
97
98
99 typedef struct Cparameters
100 {
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];
104 char UserName[25+1];
105 char Password[25+1];
106 char DirPath[MAX_PATH+1];
107 } Cparameters;
108
109
110 // Define a new application type
111 class DatabaseDemoApp: public wxApp
112 {
113 public:
114 Cparameters params;
115 bool OnInit();
116 }; // DatabaseDemoApp
117
118 DECLARE_APP(DatabaseDemoApp)
119
120 // Define a new frame type
121 class DatabaseDemoFrame: public wxFrame
122 {
123 private:
124 CeditorDlg *pEditorDlg;
125 CparameterDlg *pParamDlg;
126
127 public:
128 DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
129
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);
135
136 void CreateDataTable();
137 void BuildEditorDialog();
138 void BuildParameterDialog(wxWindow *parent);
139
140 DECLARE_EVENT_TABLE()
141 }; // DatabaseDemoFrame
142
143
144
145 // *************************** CeditorDlg ***************************
146
147 class CeditorDlg : public wxPanel
148 {
149 private:
150 bool widgetPtrsSet;
151 wxString saveName;
152
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;
164
165 public:
166 enum DialogModes mode;
167 Ccontact *Contact; // this is the table object that will be being manipulated
168
169 CeditorDlg(wxWindow *parent);
170
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
175
176 void FieldsEditable();
177 void SetMode(enum DialogModes m);
178 bool PutData();
179 bool GetData();
180 bool Save();
181 bool GetNextRec();
182 bool GetPrevRec();
183 bool GetRec(char *whereStr);
184
185 DECLARE_EVENT_TABLE()
186 }; // CeditorDlg
187
188 #define EDITOR_DIALOG 199
189
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
229
230 // *************************** CparameterDlg ***************************
231
232 class CparameterDlg : public wxDialog
233 {
234 private:
235 bool widgetPtrsSet;
236 enum DialogModes mode;
237 bool saved;
238 Cparameters savedParamSettings;
239
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;
246
247 public:
248 CparameterDlg(wxWindow *parent);
249
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
254
255 bool PutData();
256 bool GetData();
257 bool Save();
258 void FillDataSourceList();
259
260 DECLARE_EVENT_TABLE()
261 }; // CparameterDlg
262
263 #define PARAMETER_DIALOG 400
264
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
276
277 // *************************** CqueryDlg ***************************
278
279
280 // QUERY DIALOG
281 enum qryOp
282 {
283 qryOpEQ,
284 qryOpLT,
285 qryOpGT,
286 qryOpLE,
287 qryOpGE,
288 qryOpBEGINS,
289 qryOpCONTAINS,
290 qryOpLIKE,
291 qryOpBETWEEN
292 };
293
294
295 // Query strings
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";
305
306
307 class CqueryDlg : public wxDialog
308 {
309 private:
310 CcolInf *colInf; // Column inf. returned by db->GetColumns()
311 wxTable *dbTable;
312 char *masterTableName;
313 char *pWhere; // A pointer to the storage for the resulting where clause
314 wxDB *pDB;
315
316 public:
317 bool widgetPtrsSet;
318
319 // Widget pointers
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;
345
346 wxTextCtrl *pFocusTxt;
347
348 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
349 ~CqueryDlg();
350
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
355
356 void AppendToWhere(char *s);
357 void ProcessAddBtn();
358 void ProcessCountBtn();
359 bool ValidateWhereClause();
360
361 DECLARE_EVENT_TABLE()
362 }; // CqueryDlg
363
364 #define QUERY_DIALOG 300
365
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
391