]> git.saurik.com Git - wxWidgets.git/blame - samples/db/dbtest.h
code demonstrating wxMSW bug added
[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>
17#include <wx/dbtable.h>
18
19enum 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
0d2a2b60 29const char CONTACT_TABLE_NAME[] = "contacts";
108106cf
JS
30
31// Nuber of columns in the above table
32const int CONTACT_NO_COLS = 12; // 0-11
33
34// Global structure for holding ODBC connection information
35struct DbStuff DbConnectInf;
36
37enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
38
39// Forward class declarations
40class CeditorDlg;
41class CparameterDlg;
42
bbe0af5b
RR
43#ifdef __WXGTK__
44const char paramFilename[] = "../database.cfg";
45#else
108106cf 46const char paramFilename[] = "database.cfg";
bbe0af5b 47#endif
108106cf
JS
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 */
57class 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//
78class 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
98typedef 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
109class DatabaseDemoApp: public wxApp
110{
111 public:
112 Cparameters params;
1fc5dd6f 113 bool OnInit();
108106cf
JS
114}; // DatabaseDemoApp
115
116DECLARE_APP(DatabaseDemoApp)
117
118// Define a new frame type
119class DatabaseDemoFrame: public wxFrame
120{
121 private:
122 CeditorDlg *pEditorDlg;
123 CparameterDlg *pParamDlg;
124
125 public:
1fc5dd6f 126 DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz);
108106cf 127
1fc5dd6f
JS
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);
108106cf
JS
133
134 void CreateDataTable();
135 void BuildEditorDialog();
136 void BuildParameterDialog(wxWindow *parent);
1fc5dd6f
JS
137
138DECLARE_EVENT_TABLE()
108106cf
JS
139}; // DatabaseDemoFrame
140
141
142
143// *************************** CeditorDlg ***************************
144
145class 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;
1fc5dd6f
JS
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;
108106cf
JS
159 wxRadioBox *pDeveloperRadio;
160 wxChoice *pNativeLangChoice;
1fc5dd6f 161 wxStaticText *pNativeLangMsg;
108106cf
JS
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);
e3065973 168 void OnCloseWindow(wxCloseEvent& event);
f6fcbb63 169 void OnButton( wxCommandEvent &event );
108106cf
JS
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);
f6fcbb63
RR
181
182DECLARE_EVENT_TABLE()
108106cf
JS
183}; // CeditorDlg
184
1fc5dd6f
JS
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
108106cf
JS
226
227// *************************** CparameterDlg ***************************
228
1fc5dd6f 229class CparameterDlg : public wxDialog
108106cf
JS
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
1fc5dd6f 238 wxStaticText *pParamODBCSourceMsg;
108106cf 239 wxListBox *pParamODBCSourceList;
1fc5dd6f
JS
240 wxStaticText *pParamUserNameMsg, *pParamPasswordMsg;
241 wxTextCtrl *pParamUserNameTxt, *pParamPasswordTxt;
108106cf
JS
242 wxButton *pParamSaveBtn, *pParamCancelBtn;
243
244 public:
245 CparameterDlg(wxWindow *parent);
e3065973 246 void OnCloseWindow(wxCloseEvent& event);
108106cf
JS
247 void OnCommand(wxWindow& win, wxCommandEvent& event);
248 void OnActivate(bool) {}; // necessary for hot keys
249
250 bool PutData();
251 bool GetData();
252 bool Save();
253 void FillDataSourceList();
254
e3065973 255DECLARE_EVENT_TABLE()
108106cf
JS
256}; // CparameterDlg
257
1fc5dd6f
JS
258#define PARAMETER_DIALOG 400
259
260// Parameter dialog control ids
261#define PARAMETER_DIALOG_SOURCE_MSG 401
262#define PARAMETER_DIALOG_SOURCE_LISTBOX 402
263#define PARAMETER_DIALOG_NAME_MSG 403
264#define PARAMETER_DIALOG_NAME_TEXT 404
265#define PARAMETER_DIALOG_PASSWORD_MSG 405
266#define PARAMETER_DIALOG_PASSWORD_TEXT 406
267#define PARAMETER_DIALOG_SAVE 407
268#define PARAMETER_DIALOG_CANCEL 408
108106cf
JS
269
270// *************************** CqueryDlg ***************************
271
272
273// QUERY DIALOG
274enum qryOp
275{
276 qryOpEQ,
277 qryOpLT,
278 qryOpGT,
279 qryOpLE,
280 qryOpGE,
281 qryOpBEGINS,
282 qryOpCONTAINS,
283 qryOpLIKE,
284 qryOpBETWEEN
285};
286
287
288// Query strings
289char * const langQRY_EQ = "column = column | value";
290char * const langQRY_LT = "column < column | value";
291char * const langQRY_GT = "column > column | value";
292char * const langQRY_LE = "column <= column | value";
293char * const langQRY_GE = "column >= column | value";
294char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
295char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
296char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
297char * const langQRY_BETWEEN = "column BETWEEN value AND value";
298
299
1fc5dd6f 300class CqueryDlg : public wxDialog
108106cf
JS
301{
302 private:
303 CcolInf *colInf; // Column inf. returned by db->GetColumns()
304 wxTable *dbTable;
305 char *masterTableName;
306 char *pWhere; // A pointer to the storage for the resulting where clause
307 wxDB *pDB;
308
309 public:
310 bool widgetPtrsSet;
311
312 // Widget pointers
1fc5dd6f 313 wxStaticText *pQueryCol1Msg;
108106cf 314 wxChoice *pQueryCol1Choice;
1fc5dd6f 315 wxStaticText *pQueryNotMsg;
108106cf 316 wxCheckBox *pQueryNotCheck;
1fc5dd6f 317 wxStaticText *pQueryOperatorMsg;
108106cf 318 wxChoice *pQueryOperatorChoice;
1fc5dd6f 319 wxStaticText *pQueryCol2Msg;
108106cf 320 wxChoice *pQueryCol2Choice;
1fc5dd6f
JS
321 wxStaticText *pQueryValue1Msg;
322 wxTextCtrl *pQueryValue1Txt;
323 wxStaticText *pQueryValue2Msg;
324 wxTextCtrl *pQueryValue2Txt;
325 wxStaticText *pQuerySqlWhereMsg;
326 wxTextCtrl *pQuerySqlWhereMtxt;
108106cf
JS
327 wxButton *pQueryAddBtn;
328 wxButton *pQueryAndBtn;
329 wxButton *pQueryOrBtn;
330 wxButton *pQueryLParenBtn;
331 wxButton *pQueryRParenBtn;
332 wxButton *pQueryDoneBtn;
333 wxButton *pQueryClearBtn;
334 wxButton *pQueryCountBtn;
335 wxButton *pQueryHelpBtn;
1fc5dd6f
JS
336 wxStaticBox *pQueryHintGrp;
337 wxStaticText *pQueryHintMsg;
108106cf 338
1fc5dd6f 339 wxTextCtrl *pFocusTxt;
108106cf
JS
340
341 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
342
f6fcbb63 343 void OnButton( wxCommandEvent &event );
108106cf 344 void OnCommand(wxWindow& win, wxCommandEvent& event);
e3065973 345 void OnCloseWindow(wxCloseEvent& event);
108106cf
JS
346 void OnActivate(bool) {}; // necessary for hot keys
347
348// bool SetWidgetPtrs();
349 void AppendToWhere(char *s);
350 void ProcessAddBtn();
351 void ProcessCountBtn();
352 bool ValidateWhereClause();
353
f6fcbb63 354DECLARE_EVENT_TABLE()
108106cf 355}; // CqueryDlg
1fc5dd6f
JS
356
357#define QUERY_DIALOG 300
358
359// Parameter dialog control ids
360#define QUERY_DIALOG_COL_MSG 301
361#define QUERY_DIALOG_COL_CHOICE 302
362#define QUERY_DIALOG_NOT_MSG 303
363#define QUERY_DIALOG_NOT_CHECKBOX 304
364#define QUERY_DIALOG_OP_MSG 305
365#define QUERY_DIALOG_OP_CHOICE 306
366#define QUERY_DIALOG_COL2_MSG 307
367#define QUERY_DIALOG_COL2_CHOICE 308
368#define QUERY_DIALOG_WHERE_MSG 309
369#define QUERY_DIALOG_WHERE_TEXT 310
370#define QUERY_DIALOG_ADD 311
371#define QUERY_DIALOG_AND 312
372#define QUERY_DIALOG_OR 313
373#define QUERY_DIALOG_LPAREN 314
374#define QUERY_DIALOG_RPAREN 315
375#define QUERY_DIALOG_DONE 316
376#define QUERY_DIALOG_CLEAR 317
377#define QUERY_DIALOG_COUNT 318
378#define QUERY_DIALOG_VALUE1_MSG 319
379#define QUERY_DIALOG_VALUE1_TEXT 320
380#define QUERY_DIALOG_VALUE2_MSG 321
381#define QUERY_DIALOG_VALUE2_TEXT 322
382#define QUERY_DIALOG_HINT_GROUP 323
383#define QUERY_DIALOG_HINT_MSG 324
384