]> git.saurik.com Git - wxWidgets.git/blame - samples/db/dbtest.h
Added wxVariant documentation; updated wxWindow, wxScrollBar docs
[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
12#pragma interface "dbtest.h"
13
14#include <wx/string.h>
15#include <wx/dbtable.h>
16
17enum DialogModes {mView,mCreate,mEdit,mSearch};
18
19// ID for the menu quit command
20#define FILE_CREATE 100
21#define FILE_EXIT 199
22#define EDIT_PARAMETERS 200
23#define ABOUT_DEMO 300
24
25
26// Name of the table to be created/opened
27const char CONTACT_TABLE_NAME[] = "CONTACTS";
28
29// Nuber of columns in the above table
30const int CONTACT_NO_COLS = 12; // 0-11
31
32// Global structure for holding ODBC connection information
33struct DbStuff DbConnectInf;
34
35enum Language {langENGLISH, langFRENCH, langGERMAN, langSPANISH, langOTHER};
36
37// Forward class declarations
38class CeditorDlg;
39class CparameterDlg;
40
41const char paramFilename[] = "database.cfg";
42
43
44/*
45 * This class contains the actual data members that are used for transferring
46 * data back and forth from the database to the program.
47 *
48 * NOTE: The object described in this class is just for example purposes, and has no
49 * real meaning other than to show each type of field being used by the database
50 */
51class CstructContact : public wxObject
52{
53 public:
54 char Name[ 50+1 ]; // Contact's name
55 char Addr1[ 50+1 ];
56 char Addr2[ 50+1 ];
57 char City[ 25+1 ];
58 char State[ 25+1 ];
59 char PostalCode[ 15+1 ];
60 char Country[ 20+1 ];
61 TIMESTAMP_STRUCT JoinDate; // Date on which this person joined the wxWindows project
62 Language NativeLanguage; // Enumerated type indicating person's native language
63 bool IsDeveloper; // Is this person a developer for wxWindows, or just a subscriber
64 int Contributions; // Something to show off an integer field
65 ULONG LinesOfCode; // Something to show off a 'long' field
66}; // CstructContact
67
68
69//
70// NOTE: Ccontact inherits wxTable, which gives access to all the database functionality
71//
72class Ccontact : public wxTable, public CstructContact
73{
74 private:
75 bool freeDbConn;
76 void SetupColumns();
77
78 public:
79 wxString whereStr;
80 wxString qryWhereStr; // Where string returned from the query dialog
81
82 Ccontact(wxDB *pwxDB=NULL);
83 ~Ccontact();
84
85 void Initialize();
86 bool CreateIndexes(void);
87 bool FetchByName(char *name);
88
89}; // Ccontact class definition
90
91
92typedef struct Cparameters
93{
94 // The length of these strings were arbitrarily picked, and are
95 // dependent on the OS and database engine you will be using.
96 char ODBCSource[100+1];
97 char UserName[25+1];
98 char Password[25+1];
99} Cparameters;
100
101
102// Define a new application type
103class DatabaseDemoApp: public wxApp
104{
105 public:
106 Cparameters params;
107 wxFrame *OnInit(void);
108}; // DatabaseDemoApp
109
110DECLARE_APP(DatabaseDemoApp)
111
112// Define a new frame type
113class DatabaseDemoFrame: public wxFrame
114{
115 private:
116 CeditorDlg *pEditorDlg;
117 CparameterDlg *pParamDlg;
118
119 public:
120 DatabaseDemoFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
121
122 void OnMenuCommand(int id);
123 bool OnClose(void);
124
125 void CreateDataTable();
126 void BuildEditorDialog();
127 void BuildParameterDialog(wxWindow *parent);
128}; // DatabaseDemoFrame
129
130
131
132// *************************** CeditorDlg ***************************
133
134class CeditorDlg : public wxPanel
135{
136 private:
137 bool widgetPtrsSet;
138 wxString saveName;
139
140 // Pointers to all widgets on the dialog
141 wxButton *pCreateBtn, *pEditBtn, *pDeleteBtn, *pCopyBtn, *pSaveBtn, *pCancelBtn;
142 wxButton *pPrevBtn, *pNextBtn, *pQueryBtn, *pResetBtn, *pDoneBtn, *pHelpBtn;
143 wxButton *pNameListBtn;
144 wxText *pNameTxt, *pAddress1Txt, *pAddress2Txt,*pCityTxt, *pStateTxt, *pCountryTxt,*pPostalCodeTxt;
145 wxMessage *pNameMsg, *pAddress1Msg, *pAddress2Msg,*pCityMsg, *pStateMsg, *pCountryMsg,*pPostalCodeMsg;
146 wxText *pJoinDateTxt,*pContribTxt, *pLinesTxt;
147 wxMessage *pJoinDateMsg,*pContribMsg, *pLinesMsg;
148 wxRadioBox *pDeveloperRadio;
149 wxChoice *pNativeLangChoice;
150 wxMessage *pNativeLangMsg;
151
152 public:
153 enum DialogModes mode;
154 Ccontact *Contact; // this is the table object that will be being manipulated
155
156 CeditorDlg(wxWindow *parent);
157 bool OnClose(void);
158 void OnCommand(wxWindow& win, wxCommandEvent& event);
159 void OnActivate(bool) {}; // necessary for hot keys
160
161 void FieldsEditable();
162 void SetMode(enum DialogModes m);
163 bool PutData();
164 bool GetData();
165 bool Save();
166 bool GetNextRec();
167 bool GetPrevRec();
168 bool GetRec(char *whereStr);
169}; // CeditorDlg
170
171
172// *************************** CparameterDlg ***************************
173
174class CparameterDlg : public wxDialogBox
175{
176 private:
177 bool widgetPtrsSet;
178 enum DialogModes mode;
179 bool saved;
180 Cparameters savedParamSettings;
181
182 // Pointers to all widgets on the dialog
183 wxMessage *pParamODBCSourceMsg;
184 wxListBox *pParamODBCSourceList;
185 wxMessage *pParamUserNameMsg, *pParamPasswordMsg;
186 wxText *pParamUserNameTxt, *pParamPasswordTxt;
187 wxButton *pParamSaveBtn, *pParamCancelBtn;
188
189 public:
190 CparameterDlg(wxWindow *parent);
191 bool OnClose(void);
192 void OnCommand(wxWindow& win, wxCommandEvent& event);
193 void OnActivate(bool) {}; // necessary for hot keys
194
195 bool PutData();
196 bool GetData();
197 bool Save();
198 void FillDataSourceList();
199
200}; // CparameterDlg
201
202
203// *************************** CqueryDlg ***************************
204
205
206// QUERY DIALOG
207enum qryOp
208{
209 qryOpEQ,
210 qryOpLT,
211 qryOpGT,
212 qryOpLE,
213 qryOpGE,
214 qryOpBEGINS,
215 qryOpCONTAINS,
216 qryOpLIKE,
217 qryOpBETWEEN
218};
219
220
221// Query strings
222char * const langQRY_EQ = "column = column | value";
223char * const langQRY_LT = "column < column | value";
224char * const langQRY_GT = "column > column | value";
225char * const langQRY_LE = "column <= column | value";
226char * const langQRY_GE = "column >= column | value";
227char * const langQRY_BEGINS = "columns that BEGIN with the string entered";
228char * const langQRY_CONTAINS = "columns that CONTAIN the string entered";
229char * const langQRY_LIKE = "% matches 0 or more of any char; _ matches 1 char";
230char * const langQRY_BETWEEN = "column BETWEEN value AND value";
231
232
233class CqueryDlg : public wxDialogBox
234{
235 private:
236 CcolInf *colInf; // Column inf. returned by db->GetColumns()
237 wxTable *dbTable;
238 char *masterTableName;
239 char *pWhere; // A pointer to the storage for the resulting where clause
240 wxDB *pDB;
241
242 public:
243 bool widgetPtrsSet;
244
245 // Widget pointers
246 wxMessage *pQueryCol1Msg;
247 wxChoice *pQueryCol1Choice;
248 wxMessage *pQueryNotMsg;
249 wxCheckBox *pQueryNotCheck;
250 wxMessage *pQueryOperatorMsg;
251 wxChoice *pQueryOperatorChoice;
252 wxMessage *pQueryCol2Msg;
253 wxChoice *pQueryCol2Choice;
254 wxMessage *pQueryValue1Msg;
255 wxText *pQueryValue1Txt;
256 wxMessage *pQueryValue2Msg;
257 wxText *pQueryValue2Txt;
258 wxMessage *pQuerySqlWhereMsg;
259 wxMultiText *pQuerySqlWhereMtxt;
260 wxButton *pQueryAddBtn;
261 wxButton *pQueryAndBtn;
262 wxButton *pQueryOrBtn;
263 wxButton *pQueryLParenBtn;
264 wxButton *pQueryRParenBtn;
265 wxButton *pQueryDoneBtn;
266 wxButton *pQueryClearBtn;
267 wxButton *pQueryCountBtn;
268 wxButton *pQueryHelpBtn;
269 wxGroupBox *pQueryHintGrp;
270 wxMessage *pQueryHintMsg;
271
272 wxText *pFocusTxt;
273
274 CqueryDlg(wxWindow *parent, wxDB *pDb, char *tblName[], char *pWhereArg);
275
276 void OnCommand(wxWindow& win, wxCommandEvent& event);
277 bool OnClose();
278 void OnActivate(bool) {}; // necessary for hot keys
279
280// bool SetWidgetPtrs();
281 void AppendToWhere(char *s);
282 void ProcessAddBtn();
283 void ProcessCountBtn();
284 bool ValidateWhereClause();
285
286}; // CqueryDlg