1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows database demo app
4 // Author: George Tasker
8 // Copyright: (c) 1998 Remstar International, Inc.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 This sample program demonstrates the cross-platform ODBC database classes
16 donated by the development team at Remstar International.
18 The table this sample is based on is developer contact table, and shows
19 some of the simple uses of the database classes wxDB and wxTable.
25 #pragma implementation "dbtest.h"
28 #include "wx/wxprec.h"
42 #include <stdio.h> /* Included strictly for reading the text file with the database parameters */
44 #include <wx/db.h> /* Required in the file which will get the data source connection */
45 #include <wx/dbtable.h> /* Has the wxTable object from which all data objects will inherit their data table functionality */
47 extern DbList WXDLLEXPORT
*PtrBegDbList
; /* from db.cpp, used in getting back error results from db connections */
49 #include "dbtest.h" /* Header file for this demonstration program */
50 #include "listdb.h" /* Code to support the "Lookup" button on the editor dialog */
52 IMPLEMENT_APP(DatabaseDemoApp
)
54 extern char ListDB_Selection
[]; /* Used to return the first column value for the selected line from the listDB routines */
55 extern char ListDB_Selection2
[]; /* Used to return the second column value for the selected line from the listDB routines */
57 DatabaseDemoFrame
*DemoFrame
; /* Pointer to the main frame */
59 /* Pointer to the main database connection used in the program. This
60 * pointer would normally be used for doing things as database lookups
61 * for user login names and passwords, getting workstation settings, etc.
64 * For each database object created which uses this wxDB pointer
65 * connection to the database, when a CommitTrans() or RollBackTrans()
66 * will commit or rollback EVERY object which uses this wxDB pointer.
68 * To allow each table object (those derived from wxTable) to be
69 * individually committed or rolled back, you MUST use a different
70 * instance of wxDB in the constructor of the table. Doing so creates
71 * more overhead, and will use more database connections (some DBs have
72 * connection limits...), so use connections sparringly.
74 * It is recommended that one "main" database connection be created for
75 * the entire program to use for READ-ONLY database accesses, but for each
76 * table object which will do a CommitTrans() or RollbackTrans() that a
77 * new wxDB object be created and used for it.
83 * This function will return the exact string(s) from the database engine
84 * indicating all error conditions which have just occured during the
85 * last call to the database engine.
87 * This demo uses the returned string by displaying it in a wxMessageBox. The
88 * formatting therefore is not the greatest, but this is just a demo, not a
89 * finished product. :-) gt
91 * NOTE: The value returned by this function is for temporary use only and
92 * should be copied for long term use
94 char *GetExtendedDBErrorMsg(char *ErrFile
, int ErrLine
)
100 if (ErrFile
|| ErrLine
)
105 tStr
.Printf("%d",ErrLine
);
106 msg
+= tStr
.GetData();
110 msg
.Append ("\nODBC errors:\n");
113 /* Scan through each database connection displaying
114 * any ODBC errors that have occured. */
115 for (DbList
*pDbList
= PtrBegDbList
; pDbList
; pDbList
= pDbList
->PtrNext
)
117 // Skip over any free connections
120 // Display errors for this connection
122 for (i
= 0; i
< DB_MAX_ERROR_HISTORY
; i
++)
124 if (pDbList
->PtrDb
->errorList
[i
])
126 msg
.Append(pDbList
->PtrDb
->errorList
[i
]);
127 if (strcmp(pDbList
->PtrDb
->errorList
[i
],"") != 0)
134 return (char*) (const char*) msg
;
135 } // GetExtendedDBErrorMsg
138 bool DatabaseDemoApp::OnInit()
140 // Create the main frame window
141 DemoFrame
= new DatabaseDemoFrame(NULL
, "wxWindows Database Demo", wxPoint(50, 50), wxSize(537, 480));
144 DemoFrame
->SetIcon(wxICON(db
));
147 wxMenu
*file_menu
= new wxMenu
;
148 file_menu
->Append(FILE_CREATE
, "&Create contact table");
149 file_menu
->Append(FILE_EXIT
, "E&xit");
151 wxMenu
*edit_menu
= new wxMenu
;
152 edit_menu
->Append(EDIT_PARAMETERS
, "&Parameters...");
154 wxMenu
*about_menu
= new wxMenu
;
155 about_menu
->Append(ABOUT_DEMO
, "&About");
157 wxMenuBar
*menu_bar
= new wxMenuBar
;
158 menu_bar
->Append(file_menu
, "&File");
159 menu_bar
->Append(edit_menu
, "&Edit");
160 menu_bar
->Append(about_menu
, "&About");
161 DemoFrame
->SetMenuBar(menu_bar
);
163 // Initialize the ODBC Environment for Database Operations
164 if (SQLAllocEnv(&DbConnectInf
.Henv
) != SQL_SUCCESS
)
166 wxMessageBox("A problem occured while trying to get a connection to the data source","DB CONNECTION ERROR",wxOK
| wxICON_EXCLAMATION
);
170 params
.ODBCSource
[0] = 0;
171 params
.UserName
[0] = 0;
172 params
.Password
[0] = 0;
173 params
.DirPath
[0] = 0;
176 if ((paramFile
= fopen(paramFilename
, "r")) == NULL
)
179 tStr
.Printf("Unable to open the parameter file '%s' for reading.\n\nYou must specify the data source, user name, and\npassword that will be used and save those settings.",paramFilename
);
180 wxMessageBox(tStr
,"File I/O Error...",wxOK
| wxICON_EXCLAMATION
);
182 DemoFrame
->BuildParameterDialog(NULL
);
183 if ((paramFile
= fopen(paramFilename
, "r")) == NULL
)
188 fgets(buffer
, sizeof(params
.ODBCSource
), paramFile
);
189 buffer
[strlen(buffer
)-1] = '\0';
190 strcpy(params
.ODBCSource
,buffer
);
192 fgets(buffer
, sizeof(params
.UserName
), paramFile
);
193 buffer
[strlen(buffer
)-1] = '\0';
194 strcpy(params
.UserName
,buffer
);
196 fgets(buffer
, sizeof(params
.Password
), paramFile
);
197 buffer
[strlen(buffer
)-1] = '\0';
198 strcpy(params
.Password
,buffer
);
200 fgets(buffer
, sizeof(params
.DirPath
), paramFile
);
201 buffer
[strlen(buffer
)-1] = '\0';
202 strcpy(params
.DirPath
,buffer
);
206 // Connect to datasource
207 strcpy(DbConnectInf
.Dsn
, params
.ODBCSource
); // ODBC data source name (created with ODBC Administrator under Win95/NT)
208 strcpy(DbConnectInf
.Uid
, params
.UserName
); // database username - must already exist in the data source
209 strcpy(DbConnectInf
.AuthStr
, params
.Password
); // password database username
210 strcpy(DbConnectInf
.defaultDir
, params
.DirPath
); // path where the table exists (needed for dBase)
212 READONLY_DB
= GetDbConnection(&DbConnectInf
);
213 if (READONLY_DB
== 0)
215 wxMessageBox("Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the CONTACT table prior to making a connection\n(using tools provided by the database manufacturer)", "DB CONNECTION ERROR...",wxOK
| wxICON_EXCLAMATION
);
216 DemoFrame
->BuildParameterDialog(NULL
);
217 strcpy(DbConnectInf
.Dsn
, "");
218 strcpy(DbConnectInf
.Uid
, "");
219 strcpy(DbConnectInf
.AuthStr
, "");
220 wxMessageBox("Now exiting program.\n\nRestart program to try any new settings.","Notice...",wxOK
| wxICON_INFORMATION
);
224 DemoFrame
->BuildEditorDialog();
227 DemoFrame
->Show(TRUE
);
230 } // DatabaseDemoApp::OnInit()
232 BEGIN_EVENT_TABLE(DatabaseDemoFrame
, wxFrame
)
233 EVT_MENU(FILE_CREATE
, DatabaseDemoFrame::OnCreate
)
234 EVT_MENU(FILE_EXIT
, DatabaseDemoFrame::OnExit
)
235 EVT_MENU(EDIT_PARAMETERS
, DatabaseDemoFrame::OnEditParameters
)
236 EVT_MENU(ABOUT_DEMO
, DatabaseDemoFrame::OnAbout
)
237 EVT_CLOSE(DatabaseDemoFrame::OnCloseWindow
)
240 // DatabaseDemoFrame constructor
241 DatabaseDemoFrame::DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
,
242 const wxPoint
& pos
, const wxSize
& size
):
243 wxFrame(frame
, -1, title
, pos
, size
)
245 // Put any code in necessary for initializing the main frame here
248 void DatabaseDemoFrame::OnCreate(wxCommandEvent
& event
)
253 void DatabaseDemoFrame::OnExit(wxCommandEvent
& event
)
258 void DatabaseDemoFrame::OnEditParameters(wxCommandEvent
& event
)
260 if ((pEditorDlg
->mode
!= mCreate
) && (pEditorDlg
->mode
!= mEdit
))
261 BuildParameterDialog(this);
263 wxMessageBox("Cannot change database parameters while creating or editing a record","Notice...",wxOK
| wxICON_INFORMATION
);
266 void DatabaseDemoFrame::OnAbout(wxCommandEvent
& event
)
268 wxMessageBox("wxWindows sample program for database classes\n\nContributed on 27 July 1998","About...",wxOK
| wxICON_INFORMATION
);
271 void DatabaseDemoFrame::OnCloseWindow(wxCloseEvent
& event
)
273 // Put any additional checking necessary to make certain it is alright
274 // to close the program here that is not done elsewhere
277 } // DatabaseDemoFrame::OnCloseWindow()
280 void DatabaseDemoFrame::CreateDataTable()
282 bool Ok
= (wxMessageBox("Any data currently residing in the table will be erased.\n\nAre you sure?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
291 Ccontact
*Contact
= new Ccontact();
295 wxMessageBox("Error allocating memory for 'Ccontact'object.\n\nTable was not created.","Error...",wxOK
| wxICON_EXCLAMATION
);
299 if (!Contact
->CreateTable(FALSE
))
303 tStr
= "Error creating CONTACTS table.\nTable was not created.\n\n";
304 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
305 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
310 if (!Contact
->CreateIndexes())
314 tStr
= "Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n";
315 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
316 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
326 wxMessageBox("Table and index(es) were successfully created.","Notice...",wxOK
| wxICON_INFORMATION
);
327 } // DatabaseDemoFrame::CreateDataTable()
330 void DatabaseDemoFrame::BuildEditorDialog()
332 pEditorDlg
= new CeditorDlg(this);
334 wxMessageBox("Unable to create the editor dialog for some reason","Error...",wxOK
| wxICON_EXCLAMATION
);
335 } // DatabaseDemoFrame::BuildEditorDialog()
338 void DatabaseDemoFrame::BuildParameterDialog(wxWindow
*parent
)
340 pParamDlg
= new CparameterDlg(parent
);
343 wxMessageBox("Unable to create the parameter dialog for some reason","Error...",wxOK
| wxICON_EXCLAMATION
);
344 } // DatabaseDemoFrame::BuildParameterDialog()
348 * Constructor note: If no wxDB object is passed in, a new connection to the database
349 * is created for this instance of Ccontact. This can be a slow process depending
350 * on the database engine being used, and some database engines have a limit on the
351 * number of connections (either hard limits, or license restricted) so care should
352 * be used to use as few connections as is necessary.
354 * IMPORTANT: Objects which share a wxDB pointer are ALL acted upon whenever a member
355 * function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
356 * or creating a table objects which use the same pDb, know that all the objects
357 * will be committed or rolled back when any of the objects has this function call made.
359 Ccontact::Ccontact (wxDB
*pwxDB
) : wxTable(pwxDB
? pwxDB
: GetDbConnection(&DbConnectInf
),CONTACT_TABLE_NAME
,CONTACT_NO_COLS
,NULL
,!QUERY_ONLY
,DbConnectInf
.defaultDir
)
361 // This is used to represent whether the database connection should be released
362 // when this instance of the object is deleted. If using the same connection
363 // for multiple instance of database objects, then the connection should only be
364 // released when the last database instance using the connection is deleted
369 } // Ccontact Constructor
372 void Ccontact::Initialize()
381 JoinDate
.year
= 1980;
387 JoinDate
.fraction
= 0;
388 NativeLanguage
= langENGLISH
;
392 } // Ccontact::Initialize
395 Ccontact::~Ccontact()
399 if (!FreeDbConnection(pDb
))
402 tStr
= "Unable to Free the Ccontact data table handle\n\n";
403 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
404 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
407 } // Ccontract destructor
411 * Handles setting up all the connections for the interface from the wxTable
412 * functions to interface to the data structure used to store records in
413 * memory, and for all the column definitions that define the table structure
415 void Ccontact::SetupColumns()
417 // NOTE: Columns now are 8 character names, as that is all dBase can support. Longer
418 // names can be used for other database engines
419 SetColDefs ( 0,"NAME", DB_DATA_TYPE_VARCHAR
, Name
, SQL_C_CHAR
, sizeof(Name
), TRUE
, TRUE
); // Primary index
420 SetColDefs ( 1,"ADDRESS1", DB_DATA_TYPE_VARCHAR
, Addr1
, SQL_C_CHAR
, sizeof(Addr1
), FALSE
,TRUE
);
421 SetColDefs ( 2,"ADDRESS2", DB_DATA_TYPE_VARCHAR
, Addr2
, SQL_C_CHAR
, sizeof(Addr2
), FALSE
,TRUE
);
422 SetColDefs ( 3,"CITY", DB_DATA_TYPE_VARCHAR
, City
, SQL_C_CHAR
, sizeof(City
), FALSE
,TRUE
);
423 SetColDefs ( 4,"STATE", DB_DATA_TYPE_VARCHAR
, State
, SQL_C_CHAR
, sizeof(State
), FALSE
,TRUE
);
424 SetColDefs ( 5,"POSTCODE", DB_DATA_TYPE_VARCHAR
, PostalCode
, SQL_C_CHAR
, sizeof(PostalCode
), FALSE
,TRUE
);
425 SetColDefs ( 6,"COUNTRY", DB_DATA_TYPE_VARCHAR
, Country
, SQL_C_CHAR
, sizeof(Country
), FALSE
,TRUE
);
426 SetColDefs ( 7,"JOINDATE", DB_DATA_TYPE_DATE
, &JoinDate
, SQL_C_TIMESTAMP
, sizeof(JoinDate
), FALSE
,TRUE
);
427 SetColDefs ( 8,"IS_DEV", DB_DATA_TYPE_INTEGER
, &IsDeveloper
, SQL_C_BOOLEAN(IsDeveloper
), sizeof(IsDeveloper
), FALSE
,TRUE
);
428 SetColDefs ( 9,"CONTRIBS", DB_DATA_TYPE_INTEGER
, &Contributions
, SQL_C_USHORT
, sizeof(Contributions
), FALSE
,TRUE
);
429 SetColDefs (10,"LINE_CNT", DB_DATA_TYPE_INTEGER
, &LinesOfCode
, SQL_C_ULONG
, sizeof(LinesOfCode
), FALSE
,TRUE
);
430 SetColDefs (11,"LANGUAGE", DB_DATA_TYPE_INTEGER
, &NativeLanguage
, SQL_C_ENUM
, sizeof(NativeLanguage
), FALSE
,TRUE
);
431 } // Ccontact::SetupColumns
434 bool Ccontact::CreateIndexes(void)
436 // This index could easily be accomplished with an "orderBy" clause,
437 // but is done to show how to construct a non-primary index.
443 strcpy(idxDef
[0].ColName
, "IS_DEV");
444 idxDef
[0].Ascending
= TRUE
;
446 strcpy(idxDef
[1].ColName
, "NAME");
447 idxDef
[1].Ascending
= TRUE
;
449 indexName
= CONTACT_TABLE_NAME
;
450 indexName
+= "_IDX1";
451 Ok
= CreateIndex((char*) (const char*) indexName
, TRUE
, 2, idxDef
);
454 } // Ccontact::CreateIndexes()
458 * Having a function to do a query on the primary key (and possibly others) is
459 * very efficient and tighter coding so that it is available where ever the object
460 * is. Great for use with multiple tables when not using views or outer joins
462 bool Ccontact::FetchByName(char *name
)
464 whereStr
.Printf("NAME = '%s'",name
);
465 where
= (char*) (const char*) this->whereStr
;
474 } // Ccontact::FetchByName()
479 * ************* DIALOGS ***************
484 /* CeditorDlg constructor
486 * Creates the dialog used for creating/editing/deleting/copying a Ccontact object.
487 * This dialog actually is drawn in the main frame of the program
489 * An instance of Ccontact is created - "Contact" - which is used to hold the Ccontact
490 * object that is currently being worked with.
493 BEGIN_EVENT_TABLE(CeditorDlg
, wxPanel
)
494 EVT_BUTTON(-1, CeditorDlg::OnButton
)
497 CeditorDlg::CeditorDlg(wxWindow
*parent
) : wxPanel (parent
, 1, 1, 460, 455)
499 // Since the ::OnCommand() function is overridden, this prevents the widget
500 // detection in ::OnCommand() until all widgets have been initialized to prevent
501 // uninitialized pointers from crashing the program
502 widgetPtrsSet
= FALSE
;
504 // Create the data structure and a new database connection.
505 // (As there is not a pDb being passed in the constructor, a new database
506 // connection is created)
507 Contact
= new Ccontact();
511 wxMessageBox("Unable to instantiate an instance of Ccontact","Error...",wxOK
| wxICON_EXCLAMATION
);
515 // Check if the table exists or not. If it doesn't, ask the user if they want to
516 // create the table. Continue trying to create the table until it exists, or user aborts
517 while (!Contact
->pDb
->TableExists((char *)CONTACT_TABLE_NAME
,DbConnectInf
.Uid
,DbConnectInf
.defaultDir
))
520 tStr
.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME
);
521 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
522 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
524 bool createTable
= (wxMessageBox("Do you wish to try to create/clear the CONTACTS table?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
534 DemoFrame
->CreateDataTable();
537 // Tables must be "opened" before anything other than creating/deleting table can be done
538 if (!Contact
->Open())
540 // Table does exist, there was some problem opening it. Currently this should
541 // never fail, except in the case of the table not exisiting. Open() basically
542 // only sets up variable/pointer values, other than checking for table existence.
543 if (Contact
->pDb
->TableExists((char *)CONTACT_TABLE_NAME
))
546 tStr
.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME
);
547 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
548 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
558 (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP
, "", wxPoint(15, 1), wxSize(497, 69), 0, "FunctionGrp");
559 (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP
, "", wxPoint(417, 1), wxSize(95, 242), 0, "SearchGrp");
561 pCreateBtn
= new wxButton(this, EDITOR_DIALOG_CREATE
, "&Create", wxPoint( 25, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "CreateBtn");
562 pEditBtn
= new wxButton(this, EDITOR_DIALOG_EDIT
, "&Edit", wxPoint(102, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "EditBtn");
563 pDeleteBtn
= new wxButton(this, EDITOR_DIALOG_DELETE
, "&Delete", wxPoint(179, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "DeleteBtn");
564 pCopyBtn
= new wxButton(this, EDITOR_DIALOG_COPY
, "Cop&y", wxPoint(256, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "CopyBtn");
565 pSaveBtn
= new wxButton(this, EDITOR_DIALOG_SAVE
, "&Save", wxPoint(333, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "SaveBtn");
566 pCancelBtn
= new wxButton(this, EDITOR_DIALOG_CANCEL
, "C&ancel", wxPoint(430, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "CancelBtn");
567 pPrevBtn
= new wxButton(this, EDITOR_DIALOG_PREV
, "<< &Prev", wxPoint(430, 81), wxSize( 70, 35), 0, wxDefaultValidator
, "PrevBtn");
568 pNextBtn
= new wxButton(this, EDITOR_DIALOG_NEXT
, "&Next >>", wxPoint(430, 121), wxSize( 70, 35), 0, wxDefaultValidator
, "NextBtn");
569 pQueryBtn
= new wxButton(this, EDITOR_DIALOG_QUERY
, "&Query", wxPoint(430, 161), wxSize( 70, 35), 0, wxDefaultValidator
, "QueryBtn");
570 pResetBtn
= new wxButton(this, EDITOR_DIALOG_RESET
, "&Reset", wxPoint(430, 200), wxSize( 70, 35), 0, wxDefaultValidator
, "ResetBtn");
571 pNameMsg
= new wxStaticText(this, EDITOR_DIALOG_NAME_MSG
, "Name:", wxPoint( 17, 80), wxSize( -1, -1), 0, "NameMsg");
572 pNameTxt
= new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT
, "", wxPoint( 17, 97), wxSize(308, 25), 0, wxDefaultValidator
, "NameTxt");
573 pNameListBtn
= new wxButton(this, EDITOR_DIALOG_LOOKUP
, "&Lookup", wxPoint(333, 99), wxSize( 70, 24), 0, wxDefaultValidator
, "LookupBtn");
574 pAddress1Msg
= new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG
, "Address:", wxPoint( 17, 130), wxSize( -1, -1), 0, "Address1Msg");
575 pAddress1Txt
= new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT
, "", wxPoint( 17, 147), wxSize(308, 25), 0, wxDefaultValidator
, "Address1Txt");
576 pAddress2Msg
= new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG
, "Address:", wxPoint( 17, 180), wxSize( -1, -1), 0, "Address2Msg");
577 pAddress2Txt
= new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT
, "", wxPoint( 17, 197), wxSize(308, 25), 0, wxDefaultValidator
, "Address2Txt");
578 pCityMsg
= new wxStaticText(this, EDITOR_DIALOG_CITY_MSG
, "City:", wxPoint( 17, 230), wxSize( -1, -1), 0, "CityMsg");
579 pCityTxt
= new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT
, "", wxPoint( 17, 247), wxSize(225, 25), 0, wxDefaultValidator
, "CityTxt");
580 pStateMsg
= new wxStaticText(this, EDITOR_DIALOG_STATE_MSG
, "State:", wxPoint(250, 230), wxSize( -1, -1), 0, "StateMsg");
581 pStateTxt
= new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT
, "", wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator
, "StateTxt");
582 pCountryMsg
= new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG
, "Country:", wxPoint( 17, 280), wxSize( -1, -1), 0, "CountryMsg");
583 pCountryTxt
= new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT
, "", wxPoint( 17, 297), wxSize(225, 25), 0, wxDefaultValidator
, "CountryTxt");
584 pPostalCodeMsg
= new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG
, "Postal Code:",wxPoint(250, 280), wxSize( -1, -1), 0, "PostalCodeMsg");
585 pPostalCodeTxt
= new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT
, "", wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator
, "PostalCodeTxt");
587 wxString choice_strings
[5];
588 choice_strings
[0] = "English";
589 choice_strings
[1] = "French";
590 choice_strings
[2] = "German";
591 choice_strings
[3] = "Spanish";
592 choice_strings
[4] = "Other";
594 pNativeLangChoice
= new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE
, wxPoint( 17, 346), wxSize(277, -1), 5, choice_strings
);
595 pNativeLangMsg
= new wxStaticText(this, EDITOR_DIALOG_LANG_MSG
, "Native language:", wxPoint( 17, 330), wxSize( -1, -1), 0, "NativeLangMsg");
597 wxString radio_strings
[2];
598 radio_strings
[0] = "No";
599 radio_strings
[1] = "Yes";
600 pDeveloperRadio
= new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER
, "Developer:", wxPoint(303, 330), wxSize( -1, -1), 2, radio_strings
, 2, wxHORIZONTAL
);
601 pJoinDateMsg
= new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG
, "Date joined:", wxPoint( 17, 380), wxSize( -1, -1), 0, "JoinDateMsg");
602 pJoinDateTxt
= new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT
, "", wxPoint( 17, 397), wxSize(150, 25), 0, wxDefaultValidator
, "JoinDateTxt");
603 pContribMsg
= new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG
,"Contributions:", wxPoint(175, 380), wxSize( -1, -1), 0, "ContribMsg");
604 pContribTxt
= new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT
, "", wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator
, "ContribTxt");
605 pLinesMsg
= new wxStaticText(this, EDITOR_DIALOG_LINES_MSG
, "Lines of code:", wxPoint(303, 380), wxSize( -1, -1), 0, "LinesMsg");
606 pLinesTxt
= new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT
, "", wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator
, "LinesTxt");
608 // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
609 // handle all widget processing
610 widgetPtrsSet
= TRUE
;
612 // Setup the orderBy and where clauses to return back a single record as the result set,
613 // as there will only be one record being shown on the dialog at a time, this optimizes
614 // network traffic by only returning a one row result
616 Contact
->orderBy
= "NAME"; // field name to sort by
618 // The wxString "whereStr" is not a member of the wxTable object, it is a member variable
619 // specifically in the Ccontact class. It is used here for simpler construction of a varying
620 // length string, and then after the string is built, the wxTable member variable "where" is
621 // assigned the pointer to the constructed string.
623 // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
624 // to achieve a single row (in this case the first name in alphabetical order).
626 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
628 Contact
->whereStr
.sprintf("NAME = (SELECT MIN(NAME) FROM %s)",Contact
->tableName
);
629 // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
630 Contact
->where
= (char*) (const char*) Contact
->whereStr
;
635 // Perform the Query to get the result set.
636 // NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE.
637 // Only if there is a database error will Query() come back as FALSE
638 if (!Contact
->Query())
641 tStr
= "ODBC error during Query()\n\n";
642 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
643 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
644 GetParent()->Close();
648 // Since Query succeeded, now get the row that was returned
649 if (!Contact
->GetNext())
650 // If the GetNext() failed at this point, then there are no rows to retrieve,
651 // so clear the values in the members of "Contact" so that PutData() blanks the
652 // widgets on the dialog
653 Contact
->Initialize();
659 } // CeditorDlg constructor
662 void CeditorDlg::OnCloseWindow(wxCloseEvent
& event
)
665 if ((mode
!= mCreate
) && (mode
!= mEdit
))
673 wxMessageBox("Must finish processing the current record being created/modified before exiting","Notice...",wxOK
| wxICON_INFORMATION
);
676 } // CeditorDlg::OnCloseWindow()
679 void CeditorDlg::OnButton( wxCommandEvent
&event
)
681 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
682 OnCommand( *win
, event
);
686 void CeditorDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
690 widgetName
= win
.GetName();
695 if (widgetName
== pCreateBtn
->GetName())
697 Contact
->Initialize();
700 pNameTxt
->SetValue("");
701 pNameTxt
->SetFocus();
705 if (widgetName
== pEditBtn
->GetName())
707 saveName
= Contact
->Name
;
709 pNameTxt
->SetFocus();
713 if (widgetName
== pCopyBtn
->GetName())
716 pNameTxt
->SetValue("");
717 pNameTxt
->SetFocus();
721 if (widgetName
== pDeleteBtn
->GetName())
723 bool Ok
= (wxMessageBox("Are you sure?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
728 if (Ok
&& Contact
->Delete())
730 // NOTE: Deletions are not finalized until a CommitTrans() is performed.
731 // If the commit were not performed, the program will continue to
732 // show the table contents as if they were deleted until this instance
733 // of Ccontact is deleted. If the Commit wasn't performed, the
734 // database will automatically Rollback the changes when the database
735 // connection is terminated
736 Contact
->pDb
->CommitTrans();
738 // Try to get the row that followed the just deleted row in the orderBy sequence
741 // There was now row (in sequence) after the just deleted row, so get the
742 // row which preceded the just deleted row
745 // There are now no rows remaining, so clear the dialog widgets
746 Contact
->Initialize();
750 SetMode(mode
); // force reset of button enable/disable
754 Contact
->pDb
->RollbackTrans();
760 if (widgetName
== pSaveBtn
->GetName())
766 if (widgetName
== pCancelBtn
->GetName())
768 bool Ok
= (wxMessageBox("Are you sure?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
773 if (!strcmp((const char*) saveName
,""))
775 Contact
->Initialize();
782 // Requery previous record
783 if (Contact
->FetchByName((char*) (const char*) saveName
))
791 // Previous record not available, retrieve first record in table
792 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
794 Contact
->whereStr
= "NAME = (SELECT MIN(NAME) FROM ";
795 Contact
->whereStr
+= Contact
->tableName
;
796 Contact
->whereStr
+= ")";
797 Contact
->where
= (char*) (const char*) Contact
->whereStr
;
802 if (!Contact
->Query())
805 tStr
= "ODBC error during Query()\n\n";
806 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
807 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
811 if (Contact
->GetNext()) // Successfully read first record
817 // No contacts are available, clear dialog
818 Contact
->Initialize();
824 if (widgetName
== pPrevBtn
->GetName())
831 if (widgetName
== pNextBtn
->GetName())
838 if (widgetName
== pQueryBtn
->GetName())
840 // Display the query dialog box
841 char qryWhere
[DB_MAX_WHERE_CLAUSE_LEN
+1];
842 strcpy(qryWhere
, (const char*) Contact
->qryWhereStr
);
843 char *tblName
[] = {(char *)CONTACT_TABLE_NAME
, 0};
844 new CqueryDlg(GetParent(), Contact
->pDb
, tblName
, qryWhere
);
846 // Query the first record in the new record set and
847 // display it, if the query string has changed.
848 if (strcmp(qryWhere
, (const char*) Contact
->qryWhereStr
))
851 Contact
->whereStr
= "";
852 Contact
->orderBy
= "NAME";
854 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
856 Contact
->whereStr
= "NAME = (SELECT MIN(NAME) FROM ";
857 Contact
->whereStr
+= CONTACT_TABLE_NAME
;
860 // Append the query where string (if there is one)
861 Contact
->qryWhereStr
= qryWhere
;
862 if (strlen(qryWhere
))
864 Contact
->whereStr
+= " WHERE ";
865 Contact
->whereStr
+= Contact
->qryWhereStr
;
867 // Close the expression with a right paren
868 // Contact->whereStr += ")";
870 Contact
->where
= (char*) (const char*) Contact
->whereStr
;
871 if (!Contact
->Query())
874 tStr
= "ODBC error during Query()\n\n";
875 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
876 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
879 // Display the first record from the query set
880 if (!Contact
->GetNext())
881 Contact
->Initialize();
885 // Enable/Disable the reset button
886 pResetBtn
->Enable(!Contact
->qryWhereStr
.IsEmpty());
892 if (widgetName
== pResetBtn
->GetName())
894 // Clear the additional where criteria established by the query feature
895 Contact
->qryWhereStr
= "";
896 Contact
->orderBy
= "NAME";
898 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
900 Contact
->whereStr
= "NAME = (SELECT MIN(NAME) FROM ";
901 Contact
->whereStr
+= CONTACT_TABLE_NAME
;
902 Contact
->whereStr
+= ")";
905 Contact
->where
= (char*) (const char*) Contact
->whereStr
;
906 if (!Contact
->Query())
909 tStr
= "ODBC error during Query()\n\n";
910 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
911 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
914 if (!Contact
->GetNext())
915 Contact
->Initialize();
917 pResetBtn
->Enable(FALSE
);
923 if (widgetName
== pNameListBtn
->GetName())
925 new ClookUpDlg(/* wxWindow *parent */ this,
926 /* char *windowTitle */ "Select contact name",
927 /* char *tableName */ (char *) CONTACT_TABLE_NAME
,
928 /* char *dispCol1 */ "NAME",
929 /* char *dispCol2 */ "JOINDATE",
930 /* char *where */ "",
931 /* char *orderBy */ "NAME",
932 /* bool distinctValues */ TRUE
);
934 if (ListDB_Selection
&& strlen(ListDB_Selection
))
936 wxString w
= "NAME = '";
937 w
+= ListDB_Selection
;
939 GetRec((char*) (const char*) w
);
945 } // CeditorDlg::OnCommand()
948 void CeditorDlg::FieldsEditable()
950 pNameTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
951 pAddress1Txt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
952 pAddress2Txt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
953 pCityTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
954 pStateTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
955 pPostalCodeTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
956 pCountryTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
958 pJoinDateTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
959 pContribTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
960 pLinesTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
961 pNativeLangChoice
->Enable((mode
== mCreate
) || (mode
== mEdit
));
962 pDeveloperRadio
->Enable((mode
== mCreate
) || (mode
== mEdit
));
964 } // CeditorDlg::FieldsEditable()
967 void CeditorDlg::SetMode(enum DialogModes m
)
988 pCreateBtn
->Enable( !edit
);
989 pEditBtn
->Enable( !edit
&& (strcmp(Contact
->Name
,"")!=0) );
990 pDeleteBtn
->Enable( !edit
&& (strcmp(Contact
->Name
,"")!=0) );
991 pCopyBtn
->Enable( !edit
&& (strcmp(Contact
->Name
,"")!=0) );
992 pSaveBtn
->Enable( edit
);
993 pCancelBtn
->Enable( edit
);
994 pPrevBtn
->Enable( !edit
);
995 pNextBtn
->Enable( !edit
);
996 pQueryBtn
->Enable( !edit
);
997 pResetBtn
->Enable( !edit
&& !Contact
->qryWhereStr
.IsEmpty() );
998 pNameListBtn
->Enable( !edit
);
1002 } // CeditorDlg::SetMode()
1005 bool CeditorDlg::PutData()
1009 pNameTxt
->SetValue(Contact
->Name
);
1010 pAddress1Txt
->SetValue(Contact
->Addr1
);
1011 pAddress2Txt
->SetValue(Contact
->Addr2
);
1012 pCityTxt
->SetValue(Contact
->City
);
1013 pStateTxt
->SetValue(Contact
->State
);
1014 pCountryTxt
->SetValue(Contact
->Country
);
1015 pPostalCodeTxt
->SetValue(Contact
->PostalCode
);
1017 tStr
.Printf("%d/%d/%d",Contact
->JoinDate
.month
,Contact
->JoinDate
.day
,Contact
->JoinDate
.year
);
1018 pJoinDateTxt
->SetValue(tStr
);
1020 tStr
.Printf("%d",Contact
->Contributions
);
1021 pContribTxt
->SetValue(tStr
);
1023 tStr
.Printf("%lu",Contact
->LinesOfCode
);
1024 pLinesTxt
->SetValue(tStr
);
1026 pNativeLangChoice
->SetSelection(Contact
->NativeLanguage
);
1028 pDeveloperRadio
->SetSelection(Contact
->IsDeveloper
);
1031 } // Ceditor::PutData()
1035 * Reads the data out of all the widgets on the dialog. Some data evaluation is done
1036 * to ensure that there is a name entered and that the date field is valid.
1038 * A return value of TRUE means that valid data was retrieved from the dialog, otherwise
1039 * invalid data was found (and a message was displayed telling the user what to fix), and
1040 * the data was not placed into the appropraite fields of Ccontact
1042 bool CeditorDlg::GetData()
1044 // Validate that the data currently entered into the widgets is valid data
1047 tStr
= pNameTxt
->GetValue();
1048 if (!strcmp((const char*) tStr
,""))
1050 wxMessageBox("A name is required for entry into the contact table","Notice...",wxOK
| wxICON_INFORMATION
);
1054 bool invalid
= FALSE
;
1058 tStr
= pJoinDateTxt
->GetValue();
1059 if (tStr
.Freq('/') != 2)
1062 // Find the month, day, and year tokens
1065 first
= tStr
.First('/');
1066 second
= tStr
.Last('/');
1068 mm
= atoi(tStr
.SubString(0,first
));
1069 dd
= atoi(tStr
.SubString(first
+1,second
));
1070 yyyy
= atoi(tStr
.SubString(second
+1,tStr
.Length()-1));
1072 invalid
= !(mm
&& dd
&& yyyy
);
1075 // Force Year 2000 compliance
1076 if (!invalid
&& (yyyy
< 1000))
1079 // Check the token ranges for validity
1084 else if ((mm
< 1) || (mm
> 12))
1092 int days
[12] = {31,28,31,30,31,30,
1094 if (dd
> days
[mm
-1])
1097 if ((dd
== 29) && (mm
== 2))
1099 if (((yyyy
% 4) == 0) && (((yyyy
% 100) != 0) || ((yyyy
% 400) == 0)))
1109 Contact
->JoinDate
.month
= mm
;
1110 Contact
->JoinDate
.day
= dd
;
1111 Contact
->JoinDate
.year
= yyyy
;
1115 wxMessageBox("Improper date format. Please check the date\nspecified and try again.\n\nNOTE: Dates are in american format (MM/DD/YYYY)","Notice...",wxOK
| wxICON_INFORMATION
);
1119 tStr
= pNameTxt
->GetValue();
1120 strcpy(Contact
->Name
,(const char*) tStr
);
1121 strcpy(Contact
->Addr1
,pAddress1Txt
->GetValue());
1122 strcpy(Contact
->Addr2
,pAddress2Txt
->GetValue());
1123 strcpy(Contact
->City
,pCityTxt
->GetValue());
1124 strcpy(Contact
->State
,pStateTxt
->GetValue());
1125 strcpy(Contact
->Country
,pCountryTxt
->GetValue());
1126 strcpy(Contact
->PostalCode
,pPostalCodeTxt
->GetValue());
1128 Contact
->Contributions
= atoi(pContribTxt
->GetValue());
1129 Contact
->LinesOfCode
= atol(pLinesTxt
->GetValue());
1131 Contact
->NativeLanguage
= (enum Language
) pNativeLangChoice
->GetSelection();
1132 Contact
->IsDeveloper
= pDeveloperRadio
->GetSelection() > 0;
1135 } // CeditorDlg::GetData()
1139 * Retrieve data from the dialog, verify the validity of the data, and if it is valid,
1140 * try to insert/update the data to the table based on the current 'mode' the dialog
1143 * A return value of TRUE means the insert/update was completed successfully, a return
1144 * value of FALSE means that Save() failed. If returning FALSE, then this function
1145 * has displayed a detailed error message for the user.
1147 bool CeditorDlg::Save()
1149 bool failed
= FALSE
;
1151 // Read the data in the widgets of the dialog to get the user's data
1155 // Perform any other required validations necessary before saving
1158 wxBeginBusyCursor();
1160 if (mode
== mCreate
)
1162 RETCODE result
= Contact
->Insert();
1164 failed
= (result
!= DB_SUCCESS
);
1167 // Some errors may be expected, like a duplicate key, so handle those instances with
1168 // specific error messages.
1169 if (result
== DB_ERR_INTEGRITY_CONSTRAINT_VIOL
)
1172 tStr
= "A duplicate key value already exists in the table.\nUnable to save record\n\n";
1173 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
1174 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
1178 // Some other unexpexted error occurred
1180 tStr
= "Database insert failed\n\n";
1181 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
1182 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
1186 else // mode == mEdit
1188 if (!Contact
->Update())
1191 tStr
= "Database update failed\n\n";
1192 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
1193 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
1200 Contact
->pDb
->CommitTrans();
1201 SetMode(mView
); // Sets the dialog mode back to viewing after save is successful
1204 Contact
->pDb
->RollbackTrans();
1210 } // CeditorDlg::Save()
1214 * Where this program is only showing a single row at a time in the dialog,
1215 * a special where clause must be built to find just the single row which,
1216 * in sequence, would follow the currently displayed row.
1218 bool CeditorDlg::GetNextRec()
1222 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
1224 w
= "NAME = (SELECT MIN(NAME) FROM ";
1225 w
+= Contact
->tableName
;
1226 w
+= " WHERE NAME > '";
1234 // If a query where string is currently set, append that criteria
1235 if (!Contact
->qryWhereStr
.IsEmpty())
1238 w
+= Contact
->qryWhereStr
;
1243 return(GetRec((char*) (const char*) w
));
1245 } // CeditorDlg::GetNextRec()
1249 * Where this program is only showing a single row at a time in the dialog,
1250 * a special where clause must be built to find just the single row which,
1251 * in sequence, would precede the currently displayed row.
1253 bool CeditorDlg::GetPrevRec()
1257 if (Contact
->pDb
->Dbms() != dbmsPOSTGRES
)
1259 w
= "NAME = (SELECT MAX(NAME) FROM ";
1260 w
+= Contact
->tableName
;
1261 w
+= " WHERE NAME < '";
1269 // If a query where string is currently set, append that criteria
1270 if (!Contact
->qryWhereStr
.IsEmpty())
1273 w
+= Contact
->qryWhereStr
;
1279 return(GetRec((char*) (const char*)w
));
1281 } // CeditorDlg::GetPrevRec()
1285 * This function is here to avoid duplicating this same code in both the
1286 * GetPrevRec() and GetNextRec() functions
1288 bool CeditorDlg::GetRec(char *whereStr
)
1290 Contact
->where
= whereStr
;
1291 Contact
->orderBy
= "NAME";
1293 if (!Contact
->Query())
1296 tStr
= "ODBC error during Query()\n\n";
1297 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
1298 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
1303 if (Contact
->GetNext())
1310 } // CeditorDlg::GetRec()
1315 * CparameterDlg constructor
1318 BEGIN_EVENT_TABLE(CparameterDlg
, wxDialog
)
1319 EVT_BUTTON(PARAMETER_DIALOG_SAVE
, CparameterDlg::OnButton
)
1320 EVT_BUTTON(PARAMETER_DIALOG_CANCEL
, CparameterDlg::OnButton
)
1321 EVT_CLOSE(CparameterDlg::OnCloseWindow
)
1324 CparameterDlg::CparameterDlg(wxWindow
*parent
) : wxDialog (parent
, PARAMETER_DIALOG
, "ODBC parameter settings", wxPoint(-1, -1), wxSize(400, 325))
1326 // Since the ::OnCommand() function is overridden, this prevents the widget
1327 // detection in ::OnCommand() until all widgets have been initialized to prevent
1328 // uninitialized pointers from crashing the program
1329 widgetPtrsSet
= FALSE
;
1331 pParamODBCSourceMsg
= new wxStaticText(this, PARAMETER_DIALOG_SOURCE_MSG
, "ODBC data sources:", wxPoint( 10, 10), wxSize( -1, -1), 0, "ParamODBCSourceMsg");
1332 pParamODBCSourceList
= new wxListBox(this, PARAMETER_DIALOG_SOURCE_LISTBOX
, wxPoint( 10, 29), wxSize(285, 150), 0, 0, wxLB_SINGLE
|wxLB_ALWAYS_SB
, wxDefaultValidator
, "ParamODBCSourceList");
1333 pParamUserNameMsg
= new wxStaticText(this, PARAMETER_DIALOG_NAME_MSG
, "Database user name:", wxPoint( 10, 193), wxSize( -1, -1), 0, "ParamUserNameMsg");
1334 pParamUserNameTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_NAME_TEXT
, "", wxPoint(10, 209), wxSize( 140, 25), 0, wxDefaultValidator
, "ParamUserNameTxt");
1335 pParamPasswordMsg
= new wxStaticText(this, PARAMETER_DIALOG_PASSWORD_MSG
, "Password:", wxPoint(156, 193), wxSize( -1, -1), 0, "ParamPasswordMsg");
1336 pParamPasswordTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_PASSWORD_TEXT
, "", wxPoint(156, 209), wxSize( 140, 25), 0, wxDefaultValidator
, "ParamPasswordTxt");
1337 pParamDirPathMsg
= new wxStaticText(this, PARAMETER_DIALOG_DIRPATH_MSG
, "Directory:", wxPoint( 10, 243), wxSize( -1, -1), 0, "ParamDirPathMsg");
1338 pParamDirPathTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_DIRPATH_TEXT
, "", wxPoint( 10, 259), wxSize(140, 25), 0, wxDefaultValidator
, "ParamDirPathTxt");
1339 pParamSaveBtn
= new wxButton(this, PARAMETER_DIALOG_SAVE
, "&Save", wxPoint(310, 21), wxSize( 70, 35), 0, wxDefaultValidator
, "ParamSaveBtn");
1340 pParamCancelBtn
= new wxButton(this, PARAMETER_DIALOG_CANCEL
, "C&ancel", wxPoint(310, 66), wxSize( 70, 35), 0, wxDefaultValidator
, "ParamCancelBtn");
1342 // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
1343 // handle all widget processing
1344 widgetPtrsSet
= TRUE
;
1347 savedParamSettings
= wxGetApp().params
;
1352 } // CparameterDlg constructor
1355 void CparameterDlg::OnCloseWindow(wxCloseEvent
& event
)
1357 // Put any additional checking necessary to make certain it is alright
1358 // to close the program here that is not done elsewhere
1361 bool Ok
= (wxMessageBox("No changes have been saved.\n\nAre you sure you wish exit the parameter screen?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
1369 wxGetApp().params
= savedParamSettings
;
1372 if (GetParent() != NULL
)
1373 GetParent()->SetFocus();
1376 } // Cparameter::OnCloseWindow()
1379 void CparameterDlg::OnButton( wxCommandEvent
&event
)
1381 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
1382 OnCommand( *win
, event
);
1385 void CparameterDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1387 wxString widgetName
;
1389 widgetName
= win
.GetName();
1394 if (widgetName
== pParamSaveBtn
->GetName())
1399 tStr
= "Database parameters have been saved.";
1400 if (GetParent() != NULL
) // The parameter dialog was not called during startup due to a missing cfg file
1401 tStr
+= "\nNew parameters will take effect the next time the program is started.";
1402 wxMessageBox(tStr
,"Notice...",wxOK
| wxICON_INFORMATION
);
1409 if (widgetName
== pParamCancelBtn
->GetName())
1414 } // CparameterDlg::OnCommand()
1417 bool CparameterDlg::PutData()
1419 // Fill the data source list box
1420 FillDataSourceList();
1422 // Fill in the fields from the params object
1423 if (wxGetApp().params
.ODBCSource
&& wxStrlen(wxGetApp().params
.ODBCSource
))
1424 pParamODBCSourceList
->SetStringSelection(wxGetApp().params
.ODBCSource
);
1425 pParamUserNameTxt
->SetValue(wxGetApp().params
.UserName
);
1426 pParamPasswordTxt
->SetValue(wxGetApp().params
.Password
);
1427 pParamDirPathTxt
->SetValue(wxGetApp().params
.DirPath
);
1429 } // CparameterDlg::PutData()
1432 bool CparameterDlg::GetData()
1435 if (pParamODBCSourceList
->GetStringSelection() != "")
1437 tStr
= pParamODBCSourceList
->GetStringSelection();
1438 if (tStr
.Length() > (sizeof(wxGetApp().params
.ODBCSource
)-1))
1441 errmsg
.Printf("ODBC Data source name is longer than the data structure to hold it.\n'Cparameter.ODBCSource' must have a larger character array\nto handle a data source with this long of a name\n\nThe data source currently selected is %d characters long.",tStr
.Length());
1442 wxMessageBox(errmsg
,"Internal program error...",wxOK
| wxICON_EXCLAMATION
);
1445 strcpy(wxGetApp().params
.ODBCSource
, tStr
);
1450 tStr
= pParamUserNameTxt
->GetValue();
1451 if (tStr
.Length() > (sizeof(wxGetApp().params
.UserName
)-1))
1454 errmsg
.Printf("User name is longer than the data structure to hold it.\n'Cparameter.UserName' must have a larger character array\nto handle a data source with this long of a name\n\nThe user name currently specified is %d characters long.",tStr
.Length());
1455 wxMessageBox(errmsg
,"Internal program error...",wxOK
| wxICON_EXCLAMATION
);
1458 strcpy(wxGetApp().params
.UserName
, tStr
);
1460 tStr
= pParamPasswordTxt
->GetValue();
1461 if (tStr
.Length() > (sizeof(wxGetApp().params
.Password
)-1))
1464 errmsg
.Printf("Password is longer than the data structure to hold it.\n'Cparameter.Password' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long.",tStr
.Length());
1465 wxMessageBox(errmsg
,"Internal program error...",wxOK
| wxICON_EXCLAMATION
);
1468 strcpy(wxGetApp().params
.Password
,tStr
);
1470 tStr
= pParamDirPathTxt
->GetValue();
1471 tStr
.Replace("\\","/");
1472 if (tStr
.Length() > (sizeof(wxGetApp().params
.DirPath
)-1))
1475 errmsg
.Printf("DirPath is longer than the data structure to hold it.\n'Cparameter.DirPath' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long.",tStr
.Length());
1476 wxMessageBox(errmsg
,"Internal program error...",wxOK
| wxICON_EXCLAMATION
);
1479 strcpy(wxGetApp().params
.DirPath
,tStr
);
1481 } // CparameterDlg::GetData()
1484 bool CparameterDlg::Save()
1486 Cparameters saveParams
= wxGetApp().params
;
1489 wxGetApp().params
= saveParams
;
1494 if ((paramFile
= fopen(paramFilename
, "wt")) == NULL
)
1497 tStr
.Printf("Unable to write/overwrite '%s'.",paramFilename
);
1498 wxMessageBox(tStr
,"File I/O Error...",wxOK
| wxICON_EXCLAMATION
);
1502 fputs(wxGetApp().params
.ODBCSource
, paramFile
);
1503 fputc('\n', paramFile
);
1504 fputs(wxGetApp().params
.UserName
, paramFile
);
1505 fputc('\n', paramFile
);
1506 fputs(wxGetApp().params
.Password
, paramFile
);
1507 fputc('\n', paramFile
);
1508 fputs(wxGetApp().params
.DirPath
, paramFile
);
1509 fputc('\n', paramFile
);
1513 } // CparameterDlg::Save()
1516 void CparameterDlg::FillDataSourceList()
1518 char Dsn
[SQL_MAX_DSN_LENGTH
+ 1];
1520 wxStringList strList
;
1522 while(GetDataSource(DbConnectInf
.Henv
, Dsn
, SQL_MAX_DSN_LENGTH
+1, DsDesc
, 255))
1527 char **p
= strList
.ListToArray();
1530 for (i
= 0; strlen(p
[i
]); i
++)
1531 pParamODBCSourceList
->Append(p
[i
]);
1532 } // CparameterDlg::CparameterDlg::FillDataSourceList()
1535 BEGIN_EVENT_TABLE(CqueryDlg
, wxDialog
)
1536 EVT_BUTTON(-1, CqueryDlg::OnButton
)
1537 EVT_CLOSE(CqueryDlg::OnCloseWindow
)
1540 // CqueryDlg() constructor
1541 CqueryDlg::CqueryDlg(wxWindow
*parent
, wxDB
*pDb
, char *tblName
[], char *pWhereArg
) : wxDialog (parent
, QUERY_DIALOG
, "Query", wxPoint(-1, -1), wxSize(480, 360))
1543 wxBeginBusyCursor();
1547 masterTableName
= tblName
[0];
1548 widgetPtrsSet
= FALSE
;
1551 // Initialize the WHERE clause from the string passed in
1552 pWhere
= pWhereArg
; // Save a pointer to the output buffer
1553 if (strlen(pWhere
) > DB_MAX_WHERE_CLAUSE_LEN
) // Check the length of the buffer passed in
1556 s
.Printf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN
+1);
1557 wxMessageBox(s
,"Error...",wxOK
| wxICON_EXCLAMATION
);
1562 pQueryCol1Msg
= new wxStaticText(this, QUERY_DIALOG_COL_MSG
, "Column 1:", wxPoint( 10, 10), wxSize( 69, 16), 0, "QueryCol1Msg");
1563 pQueryCol1Choice
= new wxChoice(this, QUERY_DIALOG_COL_CHOICE
, wxPoint( 10, 27), wxSize(250, 27), 0, 0, 0, wxDefaultValidator
, "QueryCol1Choice");
1564 pQueryNotMsg
= new wxStaticText(this, QUERY_DIALOG_NOT_MSG
, "NOT", wxPoint(268, 10), wxSize( -1, -1), 0, "QueryNotMsg");
1565 pQueryNotCheck
= new wxCheckBox(this, QUERY_DIALOG_NOT_CHECKBOX
, "", wxPoint(275, 37), wxSize( 20, 20), 0, wxDefaultValidator
, "QueryNotCheck");
1567 wxString choice_strings
[9];
1568 choice_strings
[0] = "=";
1569 choice_strings
[1] = "<";
1570 choice_strings
[2] = ">";
1571 choice_strings
[3] = "<=";
1572 choice_strings
[4] = ">=";
1573 choice_strings
[5] = "Begins";
1574 choice_strings
[6] = "Contains";
1575 choice_strings
[7] = "Like";
1576 choice_strings
[8] = "Between";
1578 pQueryOperatorMsg
= new wxStaticText(this, QUERY_DIALOG_OP_MSG
, "Operator:", wxPoint(305, 10), wxSize( -1, -1), 0, "QueryOperatorMsg");
1579 pQueryOperatorChoice
= new wxChoice(this, QUERY_DIALOG_OP_CHOICE
, wxPoint(305, 27), wxSize( 80, 27), 9, choice_strings
, 0, wxDefaultValidator
, "QueryOperatorChoice");
1580 pQueryCol2Msg
= new wxStaticText(this, QUERY_DIALOG_COL2_MSG
, "Column 2:", wxPoint( 10, 65), wxSize( 69, 16), 0, "QueryCol2Msg");
1581 pQueryCol2Choice
= new wxChoice(this, QUERY_DIALOG_COL2_CHOICE
, wxPoint( 10, 82), wxSize(250, 27), 0, 0, 0, wxDefaultValidator
, "QueryCol2Choice");
1582 pQuerySqlWhereMsg
= new wxStaticText(this, QUERY_DIALOG_WHERE_MSG
, "SQL where clause:", wxPoint( 10, 141), wxSize( -1, -1), 0, "QuerySqlWhereMsg");
1583 pQuerySqlWhereMtxt
= new wxTextCtrl(this, QUERY_DIALOG_WHERE_TEXT
, "", wxPoint( 10, 159), wxSize(377, 134), wxTE_MULTILINE
, wxDefaultValidator
, "QuerySqlWhereMtxt");
1584 pQueryAddBtn
= new wxButton(this, QUERY_DIALOG_ADD
, "&Add", wxPoint(406, 24), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryAddBtn");
1585 pQueryAndBtn
= new wxButton(this, QUERY_DIALOG_AND
, "A&nd", wxPoint(406, 58), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryAndBtn");
1586 pQueryOrBtn
= new wxButton(this, QUERY_DIALOG_OR
, "&Or", wxPoint(406, 92), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryOrBtn");
1587 pQueryLParenBtn
= new wxButton(this, QUERY_DIALOG_LPAREN
, "(", wxPoint(406, 126), wxSize( 26, 26), 0, wxDefaultValidator
, "QueryLParenBtn");
1588 pQueryRParenBtn
= new wxButton(this, QUERY_DIALOG_RPAREN
, ")", wxPoint(436, 126), wxSize( 26, 26), 0, wxDefaultValidator
, "QueryRParenBtn");
1589 pQueryDoneBtn
= new wxButton(this, QUERY_DIALOG_DONE
, "&Done", wxPoint(406, 185), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryDoneBtn");
1590 pQueryClearBtn
= new wxButton(this, QUERY_DIALOG_CLEAR
, "C&lear", wxPoint(406, 218), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryClearBtn");
1591 pQueryCountBtn
= new wxButton(this, QUERY_DIALOG_COUNT
, "&Count", wxPoint(406, 252), wxSize( 56, 26), 0, wxDefaultValidator
, "QueryCountBtn");
1592 pQueryValue1Msg
= new wxStaticText(this, QUERY_DIALOG_VALUE1_MSG
, "Value:", wxPoint(277, 66), wxSize( -1, -1), 0, "QueryValue1Msg");
1593 pQueryValue1Txt
= new wxTextCtrl(this, QUERY_DIALOG_VALUE1_TEXT
, "", wxPoint(277, 83), wxSize(108, 25), 0, wxDefaultValidator
, "QueryValue1Txt");
1594 pQueryValue2Msg
= new wxStaticText(this, QUERY_DIALOG_VALUE2_MSG
, "AND", wxPoint(238, 126), wxSize( -1, -1), 0, "QueryValue2Msg");
1595 pQueryValue2Txt
= new wxTextCtrl(this, QUERY_DIALOG_VALUE2_TEXT
, "", wxPoint(277, 120), wxSize(108, 25), 0, wxDefaultValidator
, "QueryValue2Txt");
1596 pQueryHintGrp
= new wxStaticBox(this, QUERY_DIALOG_HINT_GROUP
, "", wxPoint( 10, 291), wxSize(377, 40), 0, "QueryHintGrp");
1597 pQueryHintMsg
= new wxStaticText(this, QUERY_DIALOG_HINT_MSG
, "", wxPoint( 16, 306), wxSize( -1, -1), 0, "QueryHintMsg");
1599 widgetPtrsSet
= TRUE
;
1600 // Initialize the dialog
1602 pQueryCol2Choice
->Append("VALUE -->");
1603 colInf
= pDB
->GetColumns(tblName
);
1609 tStr
= "ODBC error during GetColumns()\n\n";
1610 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
1611 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
1616 for (i
= 0; colInf
[i
].colName
&& strlen(colInf
[i
].colName
); i
++)
1618 // If there is more than one table being queried, qualify
1619 // the column names with the table name prefix.
1620 if (tblName
[1] && strlen(tblName
[1]))
1622 qualName
.Printf("%s.%s", colInf
[i
].tableName
, colInf
[i
].colName
);
1623 pQueryCol1Choice
->Append(qualName
);
1624 pQueryCol2Choice
->Append(qualName
);
1626 else // Single table query, append just the column names
1628 pQueryCol1Choice
->Append(colInf
[i
].colName
);
1629 pQueryCol2Choice
->Append(colInf
[i
].colName
);
1633 pQueryCol1Choice
->SetSelection(0);
1634 pQueryCol2Choice
->SetSelection(0);
1635 pQueryOperatorChoice
->SetSelection(0);
1637 pQueryValue2Msg
->Show(FALSE
);
1638 pQueryValue2Txt
->Show(FALSE
);
1640 pQueryHintMsg
->SetLabel(langQRY_EQ
);
1642 pQuerySqlWhereMtxt
->SetValue(pWhere
);
1646 // Display the dialog window
1650 } // CqueryDlg() constructor
1653 void CqueryDlg::OnButton( wxCommandEvent
&event
)
1655 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
1656 OnCommand( *win
, event
);
1659 void CqueryDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1661 // Widget pointers won't be set when the dialog is constructed.
1662 // Control is passed through this function once for each widget on
1663 // a dialog as the dialog is constructed.
1667 wxString widgetName
= win
.GetName();
1669 // Operator choice box
1670 if (widgetName
== pQueryOperatorChoice
->GetName())
1672 // Set the help text
1673 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
1676 pQueryHintMsg
->SetLabel(langQRY_EQ
);
1679 pQueryHintMsg
->SetLabel(langQRY_LT
);
1682 pQueryHintMsg
->SetLabel(langQRY_GT
);
1685 pQueryHintMsg
->SetLabel(langQRY_LE
);
1688 pQueryHintMsg
->SetLabel(langQRY_GE
);
1691 pQueryHintMsg
->SetLabel(langQRY_BEGINS
);
1694 pQueryHintMsg
->SetLabel(langQRY_CONTAINS
);
1697 pQueryHintMsg
->SetLabel(langQRY_LIKE
);
1700 pQueryHintMsg
->SetLabel(langQRY_BETWEEN
);
1704 // Hide the value2 widget
1705 pQueryValue2Msg
->Show(FALSE
); // BETWEEN will show this widget
1706 pQueryValue2Txt
->Show(FALSE
); // BETWEEN will show this widget
1708 // Disable the NOT operator for <, <=, >, >=
1709 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
1715 pQueryNotCheck
->SetValue(0);
1716 pQueryNotCheck
->Enable(FALSE
);
1719 pQueryNotCheck
->Enable(TRUE
);
1723 // Manipulate the dialog to handle the selected operator
1724 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
1731 pQueryCol2Choice
->Enable(TRUE
);
1732 if (pQueryCol2Choice
->GetSelection()) // Column name is highlighted
1734 pQueryValue1Msg
->Show(FALSE
);
1735 pQueryValue1Txt
->Show(FALSE
);
1737 else // "Value" is highlighted
1739 pQueryValue1Msg
->Show(TRUE
);
1740 pQueryValue1Txt
->Show(TRUE
);
1741 pQueryValue1Txt
->SetFocus();
1747 pQueryCol2Choice
->SetSelection(0);
1748 pQueryCol2Choice
->Enable(FALSE
);
1749 pQueryValue1Msg
->Show(TRUE
);
1750 pQueryValue1Txt
->Show(TRUE
);
1751 pQueryValue1Txt
->SetFocus();
1754 pQueryCol2Choice
->SetSelection(0);
1755 pQueryCol2Choice
->Enable(FALSE
);
1756 pQueryValue2Msg
->Show(TRUE
);
1757 pQueryValue2Txt
->Show(TRUE
);
1758 pQueryValue1Msg
->Show(TRUE
);
1759 pQueryValue1Txt
->Show(TRUE
);
1760 pQueryValue1Txt
->SetFocus();
1766 } // Operator choice box
1769 if (widgetName
== pQueryCol2Choice
->GetName())
1771 if (pQueryCol2Choice
->GetSelection()) // Column name is highlighted
1773 pQueryValue1Msg
->Show(FALSE
);
1774 pQueryValue1Txt
->Show(FALSE
);
1776 else // "Value" is highlighted
1778 pQueryValue1Msg
->Show(TRUE
);
1779 pQueryValue1Txt
->Show(TRUE
);
1780 pQueryValue1Txt
->SetFocus();
1784 } // Column 2 choice
1787 if (widgetName
== pQueryAddBtn
->GetName())
1795 if (widgetName
== pQueryAndBtn
->GetName())
1797 AppendToWhere(" AND\n");
1803 if (widgetName
== pQueryOrBtn
->GetName())
1805 AppendToWhere(" OR\n");
1810 // Left Paren button
1811 if (widgetName
== pQueryLParenBtn
->GetName())
1816 } // Left Paren button
1818 // Right paren button
1819 if (widgetName
== pQueryRParenBtn
->GetName())
1824 } // Right Paren button
1827 if (widgetName
== pQueryDoneBtn
->GetName())
1829 // Be sure the where clause will not overflow the output buffer
1830 if (strlen(pQuerySqlWhereMtxt
->GetValue()) > DB_MAX_WHERE_CLAUSE_LEN
)
1833 s
.Printf("Maximum where clause length exceeded.\nLength must be less than %d", DB_MAX_WHERE_CLAUSE_LEN
+1);
1834 wxMessageBox(s
,"Error...",wxOK
| wxICON_EXCLAMATION
);
1837 // Validate the where clause for things such as matching parens
1838 if (!ValidateWhereClause())
1840 // Copy the where clause to the output buffer and exit
1841 strcpy(pWhere
, pQuerySqlWhereMtxt
->GetValue());
1848 if (widgetName
== pQueryClearBtn
->GetName())
1850 bool Ok
= (wxMessageBox("Are you sure you wish to clear the Query?","Confirm",wxYES_NO
|wxICON_QUESTION
) == wxYES
);
1853 pQuerySqlWhereMtxt
->SetValue("");
1859 if (widgetName
== pQueryCountBtn
->GetName())
1861 wxBeginBusyCursor();
1868 } // CqueryDlg::OnCommand
1871 void CqueryDlg::OnCloseWindow(wxCloseEvent
& event
)
1886 GetParent()->SetFocus();
1892 } // CqueryDlg::OnCloseWindow()
1895 void CqueryDlg::AppendToWhere(char *s
)
1897 wxString whereStr
= pQuerySqlWhereMtxt
->GetValue();
1899 pQuerySqlWhereMtxt
->SetValue(whereStr
);
1901 } // CqueryDlg::AppendToWhere()
1904 void CqueryDlg::ProcessAddBtn()
1906 qryOp oper
= (qryOp
) pQueryOperatorChoice
->GetSelection();
1908 // Verify that eveything is filled in correctly
1909 if (pQueryCol2Choice
->GetSelection() == 0) // "Value" is selected
1911 // Verify that value 1 is filled in
1912 if (strlen(pQueryValue1Txt
->GetValue()) == 0)
1915 pQueryValue1Txt
->SetFocus();
1918 // For the BETWEEN operator, value 2 must be filled in as well
1919 if (oper
== qryOpBETWEEN
&&
1920 strlen(pQueryValue2Txt
->GetValue()) == 0)
1923 pQueryValue2Txt
->SetFocus();
1928 // Build the expression and append it to the where clause window
1929 wxString s
= pQueryCol1Choice
->GetStringSelection();
1931 if (pQueryNotCheck
->GetValue() && (oper
!= qryOpEQ
))
1937 if (pQueryNotCheck
->GetValue()) // NOT box is checked
1966 int col1Idx
= pQueryCol1Choice
->GetSelection();
1969 if (colInf
[col1Idx
].sqlDataType
== SQL_VARCHAR
||
1970 oper
== qryOpBEGINS
||
1971 oper
== qryOpCONTAINS
||
1975 if (pQueryCol2Choice
->GetSelection()) // Column name
1976 s
+= pQueryCol2Choice
->GetStringSelection();
1977 else // Column 2 is a "value"
1981 if (oper
== qryOpCONTAINS
)
1983 s
+= pQueryValue1Txt
->GetValue();
1984 if (oper
== qryOpCONTAINS
|| oper
== qryOpBEGINS
)
1990 if (oper
== qryOpBETWEEN
)
1995 s
+= pQueryValue2Txt
->GetValue();
2000 AppendToWhere((char*) (const char*) s
);
2002 } // CqueryDlg::ProcessAddBtn()
2005 void CqueryDlg::ProcessCountBtn()
2007 if (!ValidateWhereClause())
2010 if (dbTable
== 0) // wxTable object needs to be created and opened
2012 if (!(dbTable
= new wxTable(pDB
, masterTableName
, 0, NULL
, !QUERY_ONLY
, DbConnectInf
.defaultDir
)))
2014 wxMessageBox("Memory allocation failed creating a wxTable object.","Error...",wxOK
| wxICON_EXCLAMATION
);
2017 if (!dbTable
->Open())
2020 tStr
= "ODBC error during Open()\n\n";
2021 tStr
+= GetExtendedDBErrorMsg(__FILE__
,__LINE__
);
2022 wxMessageBox(tStr
,"ODBC Error...",wxOK
| wxICON_EXCLAMATION
);
2027 // Count() with WHERE clause
2028 dbTable
->where
= (char*) (const char*) pQuerySqlWhereMtxt
->GetValue();
2029 ULONG whereCnt
= dbTable
->Count();
2031 // Count() of all records in the table
2033 ULONG totalCnt
= dbTable
->Count();
2035 if (whereCnt
> 0 || totalCnt
== 0)
2038 tStr
.Printf("%lu of %lu records match the query criteria.",whereCnt
,totalCnt
);
2039 wxMessageBox(tStr
,"Notice...",wxOK
| wxICON_INFORMATION
);
2044 tStr
.Printf("%lu of %lu records match the query criteria.\n\nEither the criteria entered produced a result set\nwith no records, or there was a syntactical error\nin the clause you entered.\n\nPress the details button to see if any database errors were reported.",whereCnt
,totalCnt
);
2045 wxMessageBox(tStr
,"Notice...",wxOK
| wxICON_INFORMATION
);
2048 // After a wxMessageBox, the focus does not necessarily return to the
2049 // window which was the focus when the message box popped up, so return
2050 // focus to the Query dialog for certain
2053 } // CqueryDlg::ProcessCountBtn()
2056 bool CqueryDlg::ValidateWhereClause()
2058 wxString where
= pQuerySqlWhereMtxt
->GetValue();
2060 if (where
.Freq('(') != where
.Freq(')'))
2062 wxMessageBox("There are mismatched parenthesis in the constructed where clause","Error...",wxOK
| wxICON_EXCLAMATION
);
2065 // After a wxMessageBox, the focus does not necessarily return to the
2066 // window which was the focus when the message box popped up, so return
2067 // focus to the Query dialog for certain
2072 } // CqueryDlg::ValidateWhereClause()