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