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