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