]>
Commit | Line | Data |
---|---|---|
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/db.h> | |
18 | #include <wx/dbtable.h> | |
19 | ||
20 | enum DialogModes {mView,mCreate,mEdit,mSearch}; | |
21 | ||
22 | // ID for the menu quit command | |
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 | |
28 | #define ABOUT_DEMO 300 | |
29 | ||
30 | // this seems to be missing, Robert Roebling (?) | |
31 | #ifndef MAX_PATH | |
32 | #define MAX_PATH 200 | |
33 | #endif | |
34 | ||
35 | // Name of the table to be created/opened | |
36 | const char CONTACT_TABLE_NAME[] = "contacts"; | |
37 | ||
38 | // Nuber of columns in the above table | |
39 | const int CONTACT_NO_COLS = 12; // 0-11 | |
40 | ||
41 | // Global structure for holding ODBC connection information | |
42 | struct wxDbConnectInf DbConnectInf; | |
43 | ||
44 | enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER}; | |
45 | ||
46 | // Forward class declarations | |
47 | class CeditorDlg; | |
48 | class CparameterDlg; | |
49 | ||
50 | const char paramFilename[] = "dbtest.cfg"; | |
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 | */ | |
60 | class CstructContact : public wxObject | |
61 | { | |
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 | |
75 | }; // CstructContact | |
76 | ||
77 | ||
78 | // | |
79 | // NOTE: Ccontact inherits wxDbTable, which gives access to all the database functionality | |
80 | // | |
81 | class Ccontact : public wxDbTable, public CstructContact | |
82 | { | |
83 | private: | |
84 | bool freeDbConn; | |
85 | void SetupColumns(); | |
86 | ||
87 | public: | |
88 | wxString whereStr; | |
89 | wxString qryWhereStr; // Where string returned from the query dialog | |
90 | ||
91 | Ccontact(wxDb *pwxDb=NULL); | |
92 | ~Ccontact(); | |
93 | ||
94 | void Initialize(); | |
95 | bool CreateIndexes(void); | |
96 | bool FetchByName(char *name); | |
97 | ||
98 | }; // Ccontact class definition | |
99 | ||
100 | ||
101 | typedef struct Cparameters | |
102 | { | |
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]; | |
109 | } Cparameters; | |
110 | ||
111 | ||
112 | // Define a new application type | |
113 | class DatabaseDemoApp: public wxApp | |
114 | { | |
115 | public: | |
116 | Cparameters params; | |
117 | bool OnInit(); | |
118 | }; // DatabaseDemoApp | |
119 | ||
120 | DECLARE_APP(DatabaseDemoApp) | |
121 | ||
122 | // Define a new frame type | |
123 | class DatabaseDemoFrame: public wxFrame | |
124 | { | |
125 | private: | |
126 | CeditorDlg *pEditorDlg; | |
127 | CparameterDlg *pParamDlg; | |
128 | ||
129 | public: | |
130 | DatabaseDemoFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& sz); | |
131 | ||
132 | void OnCloseWindow(wxCloseEvent& event); | |
133 | void OnCreate(wxCommandEvent& event); | |
134 | void OnRecreateTable(wxCommandEvent& event); | |
135 | void OnRecreateIndexes(wxCommandEvent& event); | |
136 | void OnExit(wxCommandEvent& event); | |
137 | void OnEditParameters(wxCommandEvent& event); | |
138 | void OnAbout(wxCommandEvent& event); | |
139 | ||
140 | void CreateDataTable(bool recreate); | |
141 | void BuildEditorDialog(); | |
142 | void BuildParameterDialog(wxWindow *parent); | |
143 | ||
144 | DECLARE_EVENT_TABLE() | |
145 | }; // DatabaseDemoFrame | |
146 | ||
147 | ||
148 | ||
149 | // *************************** CeditorDlg *************************** | |
150 | ||
151 | class CeditorDlg : public wxPanel | |
152 | { | |
153 | private: | |
154 | bool widgetPtrsSet; | |
155 | wxString saveName; | |
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: | |
170 | bool initialized; | |
171 | enum DialogModes mode; | |
172 | Ccontact *Contact; // this is the table object that will be being manipulated | |
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 | ||
181 | bool Initialize(); | |
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 | ||
191 | DECLARE_EVENT_TABLE() | |
192 | }; // CeditorDlg | |
193 | ||
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 | |
235 | ||
236 | // *************************** CparameterDlg *************************** | |
237 | ||
238 | class CparameterDlg : public wxDialog | |
239 | { | |
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(); | |
265 | ||
266 | DECLARE_EVENT_TABLE() | |
267 | }; // CparameterDlg | |
268 | ||
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 | |
278 | #define PARAMETER_DIALOG_DIRPATH_MSG 407 | |
279 | #define PARAMETER_DIALOG_DIRPATH_TEXT 408 | |
280 | #define PARAMETER_DIALOG_SAVE 409 | |
281 | #define PARAMETER_DIALOG_CANCEL 410 | |
282 | ||
283 | // *************************** CqueryDlg *************************** | |
284 | ||
285 | ||
286 | // QUERY DIALOG | |
287 | enum qryOp | |
288 | { | |
289 | qryOpEQ, | |
290 | qryOpLT, | |
291 | qryOpGT, | |
292 | qryOpLE, | |
293 | qryOpGE, | |
294 | qryOpBEGINS, | |
295 | qryOpCONTAINS, | |
296 | qryOpLIKE, | |
297 | qryOpBETWEEN | |
298 | }; | |
299 | ||
300 | ||
301 | // Query strings | |
302 | char * const langQRY_EQ = "column = column | value"; | |
303 | char * const langQRY_LT = "column < column | value"; | |
304 | char * const langQRY_GT = "column > column | value"; | |
305 | char * const langQRY_LE = "column <= column | value"; | |
306 | char * const langQRY_GE = "column >= column | value"; | |
307 | char * const langQRY_BEGINS = "columns that BEGIN with the string entered"; | |
308 | char * const langQRY_CONTAINS = "columns that CONTAIN the string entered"; | |
309 | char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char"; | |
310 | char * const langQRY_BETWEEN = "column BETWEEN value AND value"; | |
311 | ||
312 | ||
313 | class CqueryDlg : public wxDialog | |
314 | { | |
315 | private: | |
316 | wxDbColInf *colInf; // Column inf. returned by db->GetColumns() | |
317 | wxDbTable *dbTable; | |
318 | char *masterTableName; | |
319 | char *pWhere; // A pointer to the storage for the resulting where clause | |
320 | wxDb *pDB; | |
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 | ||
352 | wxTextCtrl *pFocusTxt; | |
353 | ||
354 | CqueryDlg(wxWindow *parent, wxDb *pDb, char *tblName[], char *pWhereArg); | |
355 | ~CqueryDlg(); | |
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(); | |
366 | ||
367 | DECLARE_EVENT_TABLE() | |
368 | }; // CqueryDlg | |
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 |