]> git.saurik.com Git - wxWidgets.git/blob - samples/db/dbtest.h
1. more warnings fixes in gtk/region.cpp and common/tbarsmpl.cpp
[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 #ifndef MAX_PATH
29 #define MAX_PATH 200
30 #endif
31
32 // Name of the table to be created/opened
33 const char CONTACT_TABLE_NAME[] = "contacts";
34
35 // Nuber of columns in the above table
36 const int CONTACT_NO_COLS = 12; // 0-11
37
38 // Global structure for holding ODBC connection information
39 struct DbStuff DbConnectInf;
40
41 enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
42
43 // Forward class declarations
44 class CeditorDlg;
45 class CparameterDlg;
46
47 const char paramFilename[] = "dbtest.cfg";
48
49
50 /*
51 * This class contains the actual data members that are used for transferring
52 * data back and forth from the database to the program.
53 *
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
56 */
57 class CstructContact : public wxObject
58 {
59 public:
60 char Name[ 50+1 ]; // Contact's name
61 char Addr1[ 50+1 ];
62 char Addr2[ 50+1 ];
63 char City[ 25+1 ];
64 char State[ 25+1 ];
65 char PostalCode[ 15+1 ];
66 char Country[ 20+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
72 }; // CstructContact
73
74
75 //
76 // NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
77 //
78 class Ccontact : public wxTable, public CstructContact
79 {
80 private:
81 bool freeDbConn;
82 void SetupColumns();
83
84 public:
85 wxString whereStr;
86 wxString qryWhereStr; // Where string returned from the query dialog
87
88 Ccontact(wxDB *pwxDB=NULL);
89 ~Ccontact();
90
91 void Initialize();
92 bool CreateIndexes(void);
93 bool FetchByName(char *name);
94
95 }; // Ccontact class definition
96
97
98 typedef struct Cparameters
99 {
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];
103 char UserName[25+1];
104 char Password[25+1];
105 char DirPath[MAX_PATH+1];
106 } Cparameters;
107
108
109 // Define a new application type
110 class DatabaseDemoApp: public wxApp
111 {
112 public:
113 Cparameters params;
114 bool OnInit();
115 }; // DatabaseDemoApp
116
117 DECLARE_APP(DatabaseDemoApp)
118
119 // Define a new frame type
120 class DatabaseDemoFrame: public wxFrame
121 {
122 private:
123 CeditorDlg *pEditorDlg;
124 CparameterDlg *pParamDlg;
125
126 public:
127 DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
128
129 void OnCloseWindow(wxCloseEvent& event);
130 void OnCreate(wxCommandEvent& event);
131 void OnExit(wxCommandEvent& event);
132 void OnEditParameters(wxCommandEvent& event);
133 void OnAbout(wxCommandEvent& event);
134
135 void CreateDataTable();
136 void BuildEditorDialog();
137 void BuildParameterDialog(wxWindow *parent);
138
139 DECLARE_EVENT_TABLE()
140 }; // DatabaseDemoFrame
141
142
143
144 // *************************** CeditorDlg ***************************
145
146 class CeditorDlg : public wxPanel
147 {
148 private:
149 bool widgetPtrsSet;
150 wxString saveName;
151
152 // Pointers to all widgets on the dialog
153 wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
154 wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
155 wxButton *pNameListBtn;
156 wxTextCtrl *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
157 wxStaticText *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
158 wxTextCtrl *pJoinDateTxt,*pContribTxt, *pLinesTxt;
159 wxStaticText *pJoinDateMsg,*pContribMsg, *pLinesMsg;
160 wxRadioBox *pDeveloperRadio;
161 wxChoice *pNativeLangChoice;
162 wxStaticText *pNativeLangMsg;
163
164 public:
165 enum DialogModes mode;
166 Ccontact *Contact; // this is the table object that will be being manipulated
167
168 CeditorDlg(wxWindow *parent);
169 void OnCloseWindow(wxCloseEvent& event);
170 void OnButton( wxCommandEvent &event );
171 void OnCommand(wxWindow& win, wxCommandEvent& event);
172 void OnActivate(bool) {}; // necessary for hot keys
173
174 void FieldsEditable();
175 void SetMode(enum DialogModes m);
176 bool PutData();
177 bool GetData();
178 bool Save();
179 bool GetNextRec();
180 bool GetPrevRec();
181 bool GetRec(char *whereStr);
182
183 DECLARE_EVENT_TABLE()
184 }; // CeditorDlg
185
186 #define EDITOR_DIALOG 199
187
188 // Editor dialog control ids
189 #define EDITOR_DIALOG_FN_GROUP 200
190 #define EDITOR_DIALOG_SEARCH_GROUP 201
191 #define EDITOR_DIALOG_CREATE 202
192 #define EDITOR_DIALOG_EDIT 203
193 #define EDITOR_DIALOG_DELETE 204
194 #define EDITOR_DIALOG_COPY 205
195 #define EDITOR_DIALOG_SAVE 206
196 #define EDITOR_DIALOG_CANCEL 207
197 #define EDITOR_DIALOG_PREV 208
198 #define EDITOR_DIALOG_NEXT 209
199 #define EDITOR_DIALOG_QUERY 211
200 #define EDITOR_DIALOG_RESET 212
201 #define EDITOR_DIALOG_NAME_MSG 213
202 #define EDITOR_DIALOG_NAME_TEXT 214
203 #define EDITOR_DIALOG_LOOKUP 215
204 #define EDITOR_DIALOG_ADDRESS1_MSG 216
205 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
206 #define EDITOR_DIALOG_ADDRESS2_MSG 218
207 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
208 #define EDITOR_DIALOG_CITY_MSG 220
209 #define EDITOR_DIALOG_CITY_TEXT 221
210 #define EDITOR_DIALOG_COUNTRY_MSG 222
211 #define EDITOR_DIALOG_COUNTRY_TEXT 223
212 #define EDITOR_DIALOG_POSTAL_MSG 224
213 #define EDITOR_DIALOG_POSTAL_TEXT 225
214 #define EDITOR_DIALOG_LANG_MSG 226
215 #define EDITOR_DIALOG_LANG_CHOICE 227
216 #define EDITOR_DIALOG_DATE_MSG 228
217 #define EDITOR_DIALOG_DATE_TEXT 229
218 #define EDITOR_DIALOG_CONTRIB_MSG 230
219 #define EDITOR_DIALOG_CONTRIB_TEXT 231
220 #define EDITOR_DIALOG_LINES_MSG 232
221 #define EDITOR_DIALOG_LINES_TEXT 233
222 #define EDITOR_DIALOG_STATE_MSG 234
223 #define EDITOR_DIALOG_STATE_TEXT 235
224 #define EDITOR_DIALOG_DEVELOPER 236
225 #define EDITOR_DIALOG_JOIN_MSG 237
226 #define EDITOR_DIALOG_JOIN_TEXT 238
227
228 // *************************** CparameterDlg ***************************
229
230 class CparameterDlg : public wxDialog
231 {
232 private:
233 bool widgetPtrsSet;
234 enum DialogModes mode;
235 bool saved;
236 Cparameters savedParamSettings;
237
238 // Pointers to all widgets on the dialog
239 wxStaticText *pParamODBCSourceMsg;
240 wxListBox *pParamODBCSourceList;
241 wxStaticText *pParamUserNameMsg, *pParamPasswordMsg, *pParamDirPathMsg;
242 wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt, *pParamDirPathTxt;
243 wxButton *pParamSaveBtn, *pParamCancelBtn;
244
245 public:
246 CparameterDlg(wxWindow *parent);
247 void OnCloseWindow(wxCloseEvent& event);
248 void OnButton( wxCommandEvent &event );
249 void OnCommand(wxWindow& win, wxCommandEvent& event);
250 void OnActivate(bool) {}; // necessary for hot keys
251
252 bool PutData();
253 bool GetData();
254 bool Save();
255 void FillDataSourceList();
256
257 DECLARE_EVENT_TABLE()
258 }; // CparameterDlg
259
260 #define PARAMETER_DIALOG 400
261
262 // Parameter dialog control ids
263 #define PARAMETER_DIALOG_SOURCE_MSG 401
264 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
265 #define PARAMETER_DIALOG_NAME_MSG 403
266 #define PARAMETER_DIALOG_NAME_TEXT 404
267 #define PARAMETER_DIALOG_PASSWORD_MSG 405
268 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
269 #define PARAMETER_DIALOG_DIRPATH_MSG 407
270 #define PARAMETER_DIALOG_DIRPATH_TEXT 408
271 #define PARAMETER_DIALOG_SAVE 409
272 #define PARAMETER_DIALOG_CANCEL 410
273
274 // *************************** CqueryDlg ***************************
275
276
277 // QUERY DIALOG
278 enum qryOp
279 {
280 qryOpEQ,
281 qryOpLT,
282 qryOpGT,
283 qryOpLE,
284 qryOpGE,
285 qryOpBEGINS,
286 qryOpCONTAINS,
287 qryOpLIKE,
288 qryOpBETWEEN
289 };
290
291
292 // Query strings
293 char * const langQRY_EQ = "column = column | value";
294 char * const langQRY_LT = "column < column | value";
295 char * const langQRY_GT = "column > column | value";
296 char * const langQRY_LE = "column <= column | value";
297 char * const langQRY_GE = "column >= column | value";
298 char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
299 char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
300 char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
301 char * const langQRY_BETWEEN = "column BETWEEN value AND value";
302
303
304 class CqueryDlg : public wxDialog
305 {
306 private:
307 CcolInf *colInf; // Column inf. returned by db->GetColumns()
308 wxTable *dbTable;
309 char *masterTableName;
310 char *pWhere; // A pointer to the storage for the resulting where clause
311 wxDB *pDB;
312
313 public:
314 bool widgetPtrsSet;
315
316 // Widget pointers
317 wxStaticText *pQueryCol1Msg;
318 wxChoice *pQueryCol1Choice;
319 wxStaticText *pQueryNotMsg;
320 wxCheckBox *pQueryNotCheck;
321 wxStaticText *pQueryOperatorMsg;
322 wxChoice *pQueryOperatorChoice;
323 wxStaticText *pQueryCol2Msg;
324 wxChoice *pQueryCol2Choice;
325 wxStaticText *pQueryValue1Msg;
326 wxTextCtrl *pQueryValue1Txt;
327 wxStaticText *pQueryValue2Msg;
328 wxTextCtrl *pQueryValue2Txt;
329 wxStaticText *pQuerySqlWhereMsg;
330 wxTextCtrl *pQuerySqlWhereMtxt;
331 wxButton *pQueryAddBtn;
332 wxButton *pQueryAndBtn;
333 wxButton *pQueryOrBtn;
334 wxButton *pQueryLParenBtn;
335 wxButton *pQueryRParenBtn;
336 wxButton *pQueryDoneBtn;
337 wxButton *pQueryClearBtn;
338 wxButton *pQueryCountBtn;
339 wxButton *pQueryHelpBtn;
340 wxStaticBox *pQueryHintGrp;
341 wxStaticText *pQueryHintMsg;
342
343 wxTextCtrl *pFocusTxt;
344
345 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
346
347 void OnButton( wxCommandEvent &event );
348 void OnCommand(wxWindow& win, wxCommandEvent& event);
349 void OnCloseWindow(wxCloseEvent& event);
350 void OnActivate(bool) {}; // necessary for hot keys
351
352 // bool SetWidgetPtrs();
353 void AppendToWhere(char *s);
354 void ProcessAddBtn();
355 void ProcessCountBtn();
356 bool ValidateWhereClause();
357
358 DECLARE_EVENT_TABLE()
359 }; // CqueryDlg
360
361 #define QUERY_DIALOG 300
362
363 // Parameter dialog control ids
364 #define QUERY_DIALOG_COL_MSG 301
365 #define QUERY_DIALOG_COL_CHOICE 302
366 #define QUERY_DIALOG_NOT_MSG 303
367 #define QUERY_DIALOG_NOT_CHECKBOX 304
368 #define QUERY_DIALOG_OP_MSG 305
369 #define QUERY_DIALOG_OP_CHOICE 306
370 #define QUERY_DIALOG_COL2_MSG 307
371 #define QUERY_DIALOG_COL2_CHOICE 308
372 #define QUERY_DIALOG_WHERE_MSG 309
373 #define QUERY_DIALOG_WHERE_TEXT 310
374 #define QUERY_DIALOG_ADD 311
375 #define QUERY_DIALOG_AND 312
376 #define QUERY_DIALOG_OR 313
377 #define QUERY_DIALOG_LPAREN 314
378 #define QUERY_DIALOG_RPAREN 315
379 #define QUERY_DIALOG_DONE 316
380 #define QUERY_DIALOG_CLEAR 317
381 #define QUERY_DIALOG_COUNT 318
382 #define QUERY_DIALOG_VALUE1_MSG 319
383 #define QUERY_DIALOG_VALUE1_TEXT 320
384 #define QUERY_DIALOG_VALUE2_MSG 321
385 #define QUERY_DIALOG_VALUE2_TEXT 322
386 #define QUERY_DIALOG_HINT_GROUP 323
387 #define QUERY_DIALOG_HINT_MSG 324
388