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