]> git.saurik.com Git - wxWidgets.git/blob - samples/db/dbtest.h
More SC++ fixes; HelpGen starting to compile with VC++; image sample now 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
28 // Name of the table to be created/opened
29 const char CONTACT_TABLE_NAME[] = "CONTACTS";
30
31 // Nuber of columns in the above table
32 const int CONTACT_NO_COLS = 12; // 0-11
33
34 // Global structure for holding ODBC connection information
35 struct DbStuff DbConnectInf;
36
37 enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
38
39 // Forward class declarations
40 class CeditorDlg;
41 class CparameterDlg;
42
43 #ifdef __WXGTK__
44 const char paramFilename[] = "../database.cfg";
45 #else
46 const char paramFilename[] = "database.cfg";
47 #endif
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 } 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 bool OnClose(void);
169 void OnCommand(wxWindow& win, wxCommandEvent& event);
170 void OnActivate(bool) {}; // necessary for hot keys
171
172 void FieldsEditable();
173 void SetMode(enum DialogModes m);
174 bool PutData();
175 bool GetData();
176 bool Save();
177 bool GetNextRec();
178 bool GetPrevRec();
179 bool GetRec(char *whereStr);
180 }; // CeditorDlg
181
182 #define EDITOR_DIALOG 199
183
184 // Editor dialog control ids
185 #define EDITOR_DIALOG_FN_GROUP 200
186 #define EDITOR_DIALOG_SEARCH_GROUP 201
187 #define EDITOR_DIALOG_CREATE 202
188 #define EDITOR_DIALOG_EDIT 203
189 #define EDITOR_DIALOG_DELETE 204
190 #define EDITOR_DIALOG_COPY 205
191 #define EDITOR_DIALOG_SAVE 206
192 #define EDITOR_DIALOG_CANCEL 207
193 #define EDITOR_DIALOG_PREV 208
194 #define EDITOR_DIALOG_NEXT 209
195 #define EDITOR_DIALOG_QUERY 211
196 #define EDITOR_DIALOG_RESET 212
197 #define EDITOR_DIALOG_NAME_MSG 213
198 #define EDITOR_DIALOG_NAME_TEXT 214
199 #define EDITOR_DIALOG_LOOKUP 215
200 #define EDITOR_DIALOG_ADDRESS1_MSG 216
201 #define EDITOR_DIALOG_ADDRESS1_TEXT 217
202 #define EDITOR_DIALOG_ADDRESS2_MSG 218
203 #define EDITOR_DIALOG_ADDRESS2_TEXT 219
204 #define EDITOR_DIALOG_CITY_MSG 220
205 #define EDITOR_DIALOG_CITY_TEXT 221
206 #define EDITOR_DIALOG_COUNTRY_MSG 222
207 #define EDITOR_DIALOG_COUNTRY_TEXT 223
208 #define EDITOR_DIALOG_POSTAL_MSG 224
209 #define EDITOR_DIALOG_POSTAL_TEXT 225
210 #define EDITOR_DIALOG_LANG_MSG 226
211 #define EDITOR_DIALOG_LANG_CHOICE 227
212 #define EDITOR_DIALOG_DATE_MSG 228
213 #define EDITOR_DIALOG_DATE_TEXT 229
214 #define EDITOR_DIALOG_CONTRIB_MSG 230
215 #define EDITOR_DIALOG_CONTRIB_TEXT 231
216 #define EDITOR_DIALOG_LINES_MSG 232
217 #define EDITOR_DIALOG_LINES_TEXT 233
218 #define EDITOR_DIALOG_STATE_MSG 234
219 #define EDITOR_DIALOG_STATE_TEXT 235
220 #define EDITOR_DIALOG_DEVELOPER 236
221 #define EDITOR_DIALOG_JOIN_MSG 237
222 #define EDITOR_DIALOG_JOIN_TEXT 238
223
224 // *************************** CparameterDlg ***************************
225
226 class CparameterDlg : public wxDialog
227 {
228 private:
229 bool widgetPtrsSet;
230 enum DialogModes mode;
231 bool saved;
232 Cparameters savedParamSettings;
233
234 // Pointers to all widgets on the dialog
235 wxStaticText *pParamODBCSourceMsg;
236 wxListBox *pParamODBCSourceList;
237 wxStaticText *pParamUserNameMsg, *pParamPasswordMsg;
238 wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt;
239 wxButton *pParamSaveBtn, *pParamCancelBtn;
240
241 public:
242 CparameterDlg(wxWindow *parent);
243 bool OnClose(void);
244 void OnCommand(wxWindow& win, wxCommandEvent& event);
245 void OnActivate(bool) {}; // necessary for hot keys
246
247 bool PutData();
248 bool GetData();
249 bool Save();
250 void FillDataSourceList();
251
252 }; // CparameterDlg
253
254 #define PARAMETER_DIALOG 400
255
256 // Parameter dialog control ids
257 #define PARAMETER_DIALOG_SOURCE_MSG 401
258 #define PARAMETER_DIALOG_SOURCE_LISTBOX 402
259 #define PARAMETER_DIALOG_NAME_MSG 403
260 #define PARAMETER_DIALOG_NAME_TEXT 404
261 #define PARAMETER_DIALOG_PASSWORD_MSG 405
262 #define PARAMETER_DIALOG_PASSWORD_TEXT 406
263 #define PARAMETER_DIALOG_SAVE 407
264 #define PARAMETER_DIALOG_CANCEL 408
265
266 // *************************** CqueryDlg ***************************
267
268
269 // QUERY DIALOG
270 enum qryOp
271 {
272 qryOpEQ,
273 qryOpLT,
274 qryOpGT,
275 qryOpLE,
276 qryOpGE,
277 qryOpBEGINS,
278 qryOpCONTAINS,
279 qryOpLIKE,
280 qryOpBETWEEN
281 };
282
283
284 // Query strings
285 char * const langQRY_EQ = "column = column | value";
286 char * const langQRY_LT = "column < column | value";
287 char * const langQRY_GT = "column > column | value";
288 char * const langQRY_LE = "column <= column | value";
289 char * const langQRY_GE = "column >= column | value";
290 char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
291 char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
292 char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
293 char * const langQRY_BETWEEN = "column BETWEEN value AND value";
294
295
296 class CqueryDlg : public wxDialog
297 {
298 private:
299 CcolInf *colInf; // Column inf. returned by db->GetColumns()
300 wxTable *dbTable;
301 char *masterTableName;
302 char *pWhere; // A pointer to the storage for the resulting where clause
303 wxDB *pDB;
304
305 public:
306 bool widgetPtrsSet;
307
308 // Widget pointers
309 wxStaticText *pQueryCol1Msg;
310 wxChoice *pQueryCol1Choice;
311 wxStaticText *pQueryNotMsg;
312 wxCheckBox *pQueryNotCheck;
313 wxStaticText *pQueryOperatorMsg;
314 wxChoice *pQueryOperatorChoice;
315 wxStaticText *pQueryCol2Msg;
316 wxChoice *pQueryCol2Choice;
317 wxStaticText *pQueryValue1Msg;
318 wxTextCtrl *pQueryValue1Txt;
319 wxStaticText *pQueryValue2Msg;
320 wxTextCtrl *pQueryValue2Txt;
321 wxStaticText *pQuerySqlWhereMsg;
322 wxTextCtrl *pQuerySqlWhereMtxt;
323 wxButton *pQueryAddBtn;
324 wxButton *pQueryAndBtn;
325 wxButton *pQueryOrBtn;
326 wxButton *pQueryLParenBtn;
327 wxButton *pQueryRParenBtn;
328 wxButton *pQueryDoneBtn;
329 wxButton *pQueryClearBtn;
330 wxButton *pQueryCountBtn;
331 wxButton *pQueryHelpBtn;
332 wxStaticBox *pQueryHintGrp;
333 wxStaticText *pQueryHintMsg;
334
335 wxTextCtrl *pFocusTxt;
336
337 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
338
339 void OnCommand(wxWindow& win, wxCommandEvent& event);
340 bool OnClose();
341 void OnActivate(bool) {}; // necessary for hot keys
342
343 // bool SetWidgetPtrs();
344 void AppendToWhere(char *s);
345 void ProcessAddBtn();
346 void ProcessCountBtn();
347 bool ValidateWhereClause();
348
349 }; // CqueryDlg
350
351 #define QUERY_DIALOG 300
352
353 // Parameter dialog control ids
354 #define QUERY_DIALOG_COL_MSG 301
355 #define QUERY_DIALOG_COL_CHOICE 302
356 #define QUERY_DIALOG_NOT_MSG 303
357 #define QUERY_DIALOG_NOT_CHECKBOX 304
358 #define QUERY_DIALOG_OP_MSG 305
359 #define QUERY_DIALOG_OP_CHOICE 306
360 #define QUERY_DIALOG_COL2_MSG 307
361 #define QUERY_DIALOG_COL2_CHOICE 308
362 #define QUERY_DIALOG_WHERE_MSG 309
363 #define QUERY_DIALOG_WHERE_TEXT 310
364 #define QUERY_DIALOG_ADD 311
365 #define QUERY_DIALOG_AND 312
366 #define QUERY_DIALOG_OR 313
367 #define QUERY_DIALOG_LPAREN 314
368 #define QUERY_DIALOG_RPAREN 315
369 #define QUERY_DIALOG_DONE 316
370 #define QUERY_DIALOG_CLEAR 317
371 #define QUERY_DIALOG_COUNT 318
372 #define QUERY_DIALOG_VALUE1_MSG 319
373 #define QUERY_DIALOG_VALUE1_TEXT 320
374 #define QUERY_DIALOG_VALUE2_MSG 321
375 #define QUERY_DIALOG_VALUE2_TEXT 322
376 #define QUERY_DIALOG_HINT_GROUP 323
377 #define QUERY_DIALOG_HINT_MSG 324
378