]> git.saurik.com Git - wxWidgets.git/blob - samples/db/dbtest.h
and now it even compiles
[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/dbtable.h>
18
19 enum DialogModes {mView,mCreate,mEdit,mSearch};
20
21 // ID for the menu quit command
22 #define FILE_CREATE 100
23 #define FILE_EXIT 199
24 #define EDIT_PARAMETERS 200
25 #define ABOUT_DEMO 300
26
27 // this seems to be missing, Robert Roebling (?)
28 #define MAX_PATH 200
29
30
31 // Name of the table to be created/opened
32 const char CONTACT_TABLE_NAME[] = "contacts";
33
34 // Nuber of columns in the above table
35 const int CONTACT_NO_COLS = 12; // 0-11
36
37 // Global structure for holding ODBC connection information
38 struct DbStuff DbConnectInf;
39
40 enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
41
42 // Forward class declarations
43 class CeditorDlg;
44 class CparameterDlg;
45
46 const char paramFilename[] = "dbtest.cfg";
47
48
49 /*
50 * This class contains the actual data members that are used for transferring
51 * data back and forth from the database to the program.
52 *
53 * NOTE: The object described in this class is just for example purposes, and has no
54 * real meaning other than to show each type of field being used by the database
55 */
56 class CstructContact : public wxObject
57 {
58 public:
59 char Name[ 50+1 ]; // Contact's name
60 char Addr1[ 50+1 ];
61 char Addr2[ 50+1 ];
62 char City[ 25+1 ];
63 char State[ 25+1 ];
64 char PostalCode[ 15+1 ];
65 char Country[ 20+1 ];
66 TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
67 Language NativeLanguage; // Enumerated type indicating person's native language
68 bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
69 int Contributions; // Something to show off an integer field
70 ULONG LinesOfCode; // Something to show off a 'long' field
71 }; // CstructContact
72
73
74 //
75 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
76 //
77 class Ccontact : public wxTable, public CstructContact
78 {
79 private:
80 bool freeDbConn;
81 void SetupColumns();
82
83 public:
84 wxString whereStr;
85 wxString qryWhereStr; // Where string returned from the query dialog
86
87 Ccontact(wxDB *pwxDB=NULL);
88 ~Ccontact();
89
90 void Initialize();
91 bool CreateIndexes(void);
92 bool FetchByName(char *name);
93
94 }; // Ccontact class definition
95
96
97 typedef struct Cparameters
98 {
99 // The length of these strings were arbitrarily picked, and are
100 // dependent on the OS and database engine you will be using.
101 char ODBCSource[100+1];
102 char UserName[25+1];
103 char Password[25+1];
104 char DirPath[MAX_PATH+1];
105 } Cparameters;
106
107
108 // Define a new application type
109 class DatabaseDemoApp: public wxApp
110 {
111 public:
112 Cparameters params;
113 bool OnInit();
114 }; // DatabaseDemoApp
115
116 DECLARE_APP(DatabaseDemoApp)
117
118 // Define a new frame type
119 class DatabaseDemoFrame: public wxFrame
120 {
121 private:
122 CeditorDlg *pEditorDlg;
123 CparameterDlg *pParamDlg;
124
125 public:
126 DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
127
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);
133
134 void CreateDataTable();
135 void BuildEditorDialog();
136 void BuildParameterDialog(wxWindow *parent);
137
138 DECLARE_EVENT_TABLE()
139 }; // DatabaseDemoFrame
140
141
142
143 // *************************** CeditorDlg ***************************
144
145 class CeditorDlg : public wxPanel
146 {
147 private:
148 bool widgetPtrsSet;
149 wxString saveName;
150
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;
162
163 public:
164 enum DialogModes mode;
165 Ccontact *Contact; // this is the table object that will be being manipulated
166
167 CeditorDlg(wxWindow *parent);
168 void OnCloseWindow(wxCloseEvent& event);
169 void OnButton( wxCommandEvent &event );
170 void OnCommand(wxWindow& win, wxCommandEvent& event);
171 void OnActivate(bool) {}; // necessary for hot keys
172
173 void FieldsEditable();
174 void SetMode(enum DialogModes m);
175 bool PutData();
176 bool GetData();
177 bool Save();
178 bool GetNextRec();
179 bool GetPrevRec();
180 bool GetRec(char *whereStr);
181
182 DECLARE_EVENT_TABLE()
183 }; // CeditorDlg
184
185 #define EDITOR_DIALOG 199
186
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
226
227 // *************************** CparameterDlg ***************************
228
229 class CparameterDlg : public wxDialog
230 {
231 private:
232 bool widgetPtrsSet;
233 enum DialogModes mode;
234 bool saved;
235 Cparameters savedParamSettings;
236
237 // Pointers to all widgets on the dialog
238 wxStaticText *pParamODBCSourceMsg;
239 wxListBox *pParamODBCSourceList;
240 wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
241 wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
242 wxButton *pParamSaveBtn, *pParamCancelBtn;
243
244 public:
245 CparameterDlg(wxWindow *parent);
246 void OnCloseWindow(wxCloseEvent& event);
247 void OnButton( wxCommandEvent &event );
248 void OnCommand(wxWindow& win, wxCommandEvent& event);
249 void OnActivate(bool) {}; // necessary for hot keys
250
251 bool PutData();
252 bool GetData();
253 bool Save();
254 void FillDataSourceList();
255
256 DECLARE_EVENT_TABLE()
257 }; // CparameterDlg
258
259 #define PARAMETER_DIALOG 400
260
261 // Parameter dialog control ids
262 #define PARAMETER_DIALOG_SOURCE_MSG 401
263 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
264 #define PARAMETER_DIALOG_NAME_MSG 403
265 #define PARAMETER_DIALOG_NAME_TEXT 404
266 #define PARAMETER_DIALOG_PASSWORD_MSG 405
267 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
268 #define PARAMETER_DIALOG_DIRPATH_MSG 407
269 #define PARAMETER_DIALOG_DIRPATH_TEXT 408
270 #define PARAMETER_DIALOG_SAVE 409
271 #define PARAMETER_DIALOG_CANCEL 410
272
273 // *************************** CqueryDlg ***************************
274
275
276 // QUERY DIALOG
277 enum qryOp
278 {
279 qryOpEQ,
280 qryOpLT,
281 qryOpGT,
282 qryOpLE,
283 qryOpGE,
284 qryOpBEGINS,
285 qryOpCONTAINS,
286 qryOpLIKE,
287 qryOpBETWEEN
288 };
289
290
291 // Query strings
292 char * const langQRY_EQ = "column = column | value";
293 char * const langQRY_LT = "column < column | value";
294 char * const langQRY_GT = "column > column | value";
295 char * const langQRY_LE = "column <= column | value";
296 char * const langQRY_GE = "column >= column | value";
297 char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
298 char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
299 char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
300 char * const langQRY_BETWEEN = "column BETWEEN value AND value";
301
302
303 class CqueryDlg : public wxDialog
304 {
305 private:
306 CcolInf *colInf; // Column inf. returned by db->GetColumns()
307 wxTable *dbTable;
308 char *masterTableName;
309 char *pWhere; // A pointer to the storage for the resulting where clause
310 wxDB *pDB;
311
312 public:
313 bool widgetPtrsSet;
314
315 // Widget pointers
316 wxStaticText *pQueryCol1Msg;
317 wxChoice *pQueryCol1Choice;
318 wxStaticText *pQueryNotMsg;
319 wxCheckBox *pQueryNotCheck;
320 wxStaticText *pQueryOperatorMsg;
321 wxChoice *pQueryOperatorChoice;
322 wxStaticText *pQueryCol2Msg;
323 wxChoice *pQueryCol2Choice;
324 wxStaticText *pQueryValue1Msg;
325 wxTextCtrl *pQueryValue1Txt;
326 wxStaticText *pQueryValue2Msg;
327 wxTextCtrl *pQueryValue2Txt;
328 wxStaticText *pQuerySqlWhereMsg;
329 wxTextCtrl *pQuerySqlWhereMtxt;
330 wxButton *pQueryAddBtn;
331 wxButton *pQueryAndBtn;
332 wxButton *pQueryOrBtn;
333 wxButton *pQueryLParenBtn;
334 wxButton *pQueryRParenBtn;
335 wxButton *pQueryDoneBtn;
336 wxButton *pQueryClearBtn;
337 wxButton *pQueryCountBtn;
338 wxButton *pQueryHelpBtn;
339 wxStaticBox *pQueryHintGrp;
340 wxStaticText *pQueryHintMsg;
341
342 wxTextCtrl *pFocusTxt;
343
344 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
345
346 void OnButton( wxCommandEvent &event );
347 void OnCommand(wxWindow& win, wxCommandEvent& event);
348 void OnCloseWindow(wxCloseEvent& event);
349 void OnActivate(bool) {}; // necessary for hot keys
350
351 // bool SetWidgetPtrs();
352 void AppendToWhere(char *s);
353 void ProcessAddBtn();
354 void ProcessCountBtn();
355 bool ValidateWhereClause();
356
357 DECLARE_EVENT_TABLE()
358 }; // CqueryDlg
359
360 #define QUERY_DIALOG 300
361
362 // Parameter dialog control ids
363 #define QUERY_DIALOG_COL_MSG 301
364 #define QUERY_DIALOG_COL_CHOICE 302
365 #define QUERY_DIALOG_NOT_MSG 303
366 #define QUERY_DIALOG_NOT_CHECKBOX 304
367 #define QUERY_DIALOG_OP_MSG 305
368 #define QUERY_DIALOG_OP_CHOICE 306
369 #define QUERY_DIALOG_COL2_MSG 307
370 #define QUERY_DIALOG_COL2_CHOICE 308
371 #define QUERY_DIALOG_WHERE_MSG 309
372 #define QUERY_DIALOG_WHERE_TEXT 310
373 #define QUERY_DIALOG_ADD 311
374 #define QUERY_DIALOG_AND 312
375 #define QUERY_DIALOG_OR 313
376 #define QUERY_DIALOG_LPAREN 314
377 #define QUERY_DIALOG_RPAREN 315
378 #define QUERY_DIALOG_DONE 316
379 #define QUERY_DIALOG_CLEAR 317
380 #define QUERY_DIALOG_COUNT 318
381 #define QUERY_DIALOG_VALUE1_MSG 319
382 #define QUERY_DIALOG_VALUE1_TEXT 320
383 #define QUERY_DIALOG_VALUE2_MSG 321
384 #define QUERY_DIALOG_VALUE2_TEXT 322
385 #define QUERY_DIALOG_HINT_GROUP 323
386 #define QUERY_DIALOG_HINT_MSG 324
387