- // Since the ::OnCommand() function is overridden, this prevents the widget
- // detection in ::OnCommand() until all widgets have been initialized to prevent
- // uninitialized pointers from crashing the program
- widgetPtrsSet = FALSE;
-
- // Create the data structure and a new database connection.
- // (As there is not a pDb being passed in the constructor, a new database
- // connection is created)
- Contact = new Ccontact();
-
- if (!Contact)
- {
- wxMessageBox("Unable to instantiate an instance of Ccontact","Error...",wxOK | wxICON_EXCLAMATION);
- return;
- }
-
- // Check if the table exists or not. If it doesn't, ask the user if they want to
- // create the table. Continue trying to create the table until it exists, or user aborts
- while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME))
- {
- wxString tStr;
- tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME);
- tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
- wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
-
- bool createTable = (wxMessageBox("Do you wish to try to create/clear the CONTACTS table?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES);
-
- if (!createTable)
- {
- delete Contact;
- Close();
- DemoFrame->Close();
- return;
- }
- else
- DemoFrame->CreateDataTable();
- }
-
- // Tables must be "opened" before anything other than creating/deleting table can be done
- if (!Contact->Open())
- {
- // Table does exist, there was some problem opening it. Currently this should
- // never fail, except in the case of the table not exisiting. Open() basically
- // only sets up variable/pointer values, other than checking for table existence.
- if (Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME))
- {
- wxString tStr;
- tStr.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME);
- tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
- wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
- delete Contact;
- Close();
- DemoFrame->Close();
- return;
- }
- }
-
- // Build the dialog
-
- (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP, "", wxPoint(15, 1), wxSize(497, 69), 0, "FunctionGrp");
- (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP, "", wxPoint(417, 1), wxSize(95, 242), 0, "SearchGrp");
-
- pCreateBtn = new wxButton(this, EDITOR_DIALOG_CREATE, "&Create", wxPoint(25, 21), wxSize(70, 35), 0, wxDefaultValidator, "CreateBtn");
- pEditBtn = new wxButton(this, EDITOR_DIALOG_EDIT, "&Edit", wxPoint(102, 21), wxSize(70, 35), 0, wxDefaultValidator, "EditBtn");
- pDeleteBtn = new wxButton(this, EDITOR_DIALOG_DELETE, "&Delete", wxPoint(179, 21), wxSize(70, 35), 0, wxDefaultValidator, "DeleteBtn");
- pCopyBtn = new wxButton(this, EDITOR_DIALOG_COPY, "Cop&y", wxPoint(256, 21), wxSize(70, 35), 0, wxDefaultValidator, "CopyBtn");
- pSaveBtn = new wxButton(this, EDITOR_DIALOG_SAVE, "&Save", wxPoint(333, 21), wxSize(70, 35), 0, wxDefaultValidator, "SaveBtn");
- pCancelBtn = new wxButton(this, EDITOR_DIALOG_CANCEL, "C&ancel", wxPoint(430, 21), wxSize(70, 35), 0, wxDefaultValidator, "CancelBtn");
-
- pPrevBtn = new wxButton(this, EDITOR_DIALOG_PREV, "<< &Prev", wxPoint(430, 81), wxSize(70, 35), 0, wxDefaultValidator, "PrevBtn");
- pNextBtn = new wxButton(this, EDITOR_DIALOG_NEXT, "&Next >>", wxPoint(430, 121), wxSize(70, 35), 0, wxDefaultValidator, "NextBtn");
- pQueryBtn = new wxButton(this, EDITOR_DIALOG_QUERY, "&Query", wxPoint(430, 161), wxSize(70, 35), 0, wxDefaultValidator, "QueryBtn");
- pResetBtn = new wxButton(this, EDITOR_DIALOG_RESET, "&Reset", wxPoint(430, 200), wxSize(70, 35), 0, wxDefaultValidator, "ResetBtn");
-
- pNameMsg = new wxStaticText(this, EDITOR_DIALOG_NAME_MSG, "Name:", wxPoint(17, 80), wxSize(-1, -1), 0, "NameMsg");
- pNameTxt = new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT, "", wxPoint(17, 97), wxSize(308, 25), 0, wxDefaultValidator, "NameTxt");
- pNameListBtn = new wxButton(this, EDITOR_DIALOG_LOOKUP, "&Lookup", wxPoint(333, 99), wxSize(70, 24), 0, wxDefaultValidator, "LookupBtn");
-
- pAddress1Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG, "Address:", wxPoint(17, 130), wxSize(-1, -1), 0, "Address1Msg");
- pAddress1Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint(17, 147), wxSize(308, 25), 0, wxDefaultValidator, "Address1Txt");
-
- pAddress2Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG, "Address:", wxPoint(17, 180), wxSize(-1, -1), 0, "Address2Msg");
- pAddress2Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint(17, 197), wxSize(308, 25), 0, wxDefaultValidator, "Address2Txt");
-
- pCityMsg = new wxStaticText(this, EDITOR_DIALOG_CITY_MSG, "City:", wxPoint(17, 230), wxSize(-1, -1), 0, "CityMsg");
- pCityTxt = new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT, "", wxPoint(17, 247), wxSize(225, 25), 0, wxDefaultValidator, "CityTxt");
-
- pStateMsg = new wxStaticText(this, EDITOR_DIALOG_STATE_MSG, "State:", wxPoint(250, 230), wxSize(-1, -1), 0, "StateMsg");
- pStateTxt = new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT, "", wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator, "StateTxt");
-
- pCountryMsg = new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG, "Country:", wxPoint(17, 280), wxSize(-1, -1), 0, "CountryMsg");
- pCountryTxt = new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT, "", wxPoint(17, 297), wxSize(225, 25), 0, wxDefaultValidator, "CountryTxt");
-
- pPostalCodeMsg = new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG, "Postal Code:", wxPoint(250, 280), wxSize(-1, -1), 0, "PostalCodeMsg");
- pPostalCodeTxt = new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT, "", wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator, "PostalCodeTxt");
-
- wxString choice_strings[5];
- choice_strings[0] = "English";
- choice_strings[1] = "French";
- choice_strings[2] = "German";
- choice_strings[3] = "Spanish";
- choice_strings[4] = "Other";
- pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint(17, 346), wxSize(277, -1), 5, choice_strings);
- pNativeLangMsg = new wxStaticText(this, EDITOR_DIALOG_LANG_MSG, "Native language:", wxPoint(17, 330), wxSize(-1, -1), 0, "NativeLangMsg");
-
- wxString radio_strings[2];
- radio_strings[0] = "No";
- radio_strings[1] = "Yes";
- pDeveloperRadio = new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER,"Developer:",wxPoint(303,330),wxSize(-1,-1),2,radio_strings,2,wxHORIZONTAL);
-
- pJoinDateMsg = new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG, "Date joined:", wxPoint(17, 380), wxSize(-1, -1), 0, "JoinDateMsg");
- pJoinDateTxt = new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT, "", wxPoint(17, 397), wxSize(150, 25), 0, wxDefaultValidator, "JoinDateTxt");
-
- pContribMsg = new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG, "Contributions:", wxPoint(175, 380), wxSize(-1, -1), 0, "ContribMsg");
- pContribTxt = new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT, "", wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator, "ContribTxt");
-
- pLinesMsg = new wxStaticText(this, EDITOR_DIALOG_LINES_MSG, "Lines of code:", wxPoint(303, 380), wxSize(-1, -1), 0, "LinesMsg");
- pLinesTxt = new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT, "", wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator, "LinesTxt");
-
- // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
- // handle all widget processing
- widgetPtrsSet = TRUE;
-
- // Setup the orderBy and where clauses to return back a single record as the result set,
- // as there will only be one record being shown on the dialog at a time, this optimizes
- // network traffic by only returning a one row result
-
- Contact->orderBy = "NAME"; // field name to sort by
-
- // The wxString "whereStr" is not a member of the wxTable object, it is a member variable
- // specifically in the Ccontact class. It is used here for simpler construction of a varying
- // length string, and then after the string is built, the wxTable member variable "where" is
- // assigned the pointer to the constructed string.
- //
- // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
- // to achieve a single row (in this case the first name in alphabetical order).
-
- Contact->whereStr.Printf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName);
-
- // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
- Contact->where = (char*) (const char*) Contact->whereStr;
-
- // Perform the Query to get the result set.
- // NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE.
- // Only if there is a database error will Query() come back as FALSE
- if (!Contact->Query())
- {
- wxString tStr;
- tStr = "ODBC error during Query()\n\n";
- tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
- wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
- GetParent()->Close();
- return;
- }
-
- // Since Query succeeded, now get the row that was returned
- if (!Contact->GetNext())
- // If the GetNext() failed at this point, then there are no rows to retrieve,
- // so clear the values in the members of "Contact" so that PutData() blanks the
- // widgets on the dialog
- Contact->Initialize();
-
- SetMode(mView);
- PutData();
-
- Show(TRUE);
+ // Since the ::OnCommand() function is overridden, this prevents the widget
+ // detection in ::OnCommand() until all widgets have been initialized to prevent
+ // uninitialized pointers from crashing the program
+ widgetPtrsSet = FALSE;
+
+ // Create the data structure and a new database connection.
+ // (As there is not a pDb being passed in the constructor, a new database
+ // connection is created)
+ Contact = new Ccontact();
+
+ if (!Contact)
+ {
+ wxMessageBox("Unable to instantiate an instance of Ccontact","Error...",wxOK | wxICON_EXCLAMATION);
+ return;
+ }
+
+ // Check if the table exists or not. If it doesn't, ask the user if they want to
+ // create the table. Continue trying to create the table until it exists, or user aborts
+ while (!Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME,DbConnectInf.Uid,DbConnectInf.defaultDir))
+ {
+ wxString tStr;
+ tStr.Printf("Unable to open the table '%s'.\n\nTable may need to be created...?\n\n",CONTACT_TABLE_NAME);
+ tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+
+ bool createTable = (wxMessageBox("Do you wish to try to create/clear the CONTACTS table?","Confirm",wxYES_NO|wxICON_QUESTION) == wxYES);
+
+ if (!createTable)
+ {
+ delete Contact;
+ Close();
+ DemoFrame->Close();
+ return;
+ }
+ else
+ DemoFrame->CreateDataTable();
+ }
+
+ // Tables must be "opened" before anything other than creating/deleting table can be done
+ if (!Contact->Open())
+ {
+ // Table does exist, there was some problem opening it. Currently this should
+ // never fail, except in the case of the table not exisiting. Open() basically
+ // only sets up variable/pointer values, other than checking for table existence.
+ if (Contact->pDb->TableExists((char *)CONTACT_TABLE_NAME))
+ {
+ wxString tStr;
+ tStr.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME);
+ tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+ delete Contact;
+ Close();
+ DemoFrame->Close();
+ return;
+ }
+ }
+
+ // Build the dialog
+
+ (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP, "", wxPoint(15, 1), wxSize(497, 69), 0, "FunctionGrp");
+ (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP, "", wxPoint(417, 1), wxSize(95, 242), 0, "SearchGrp");
+
+ pCreateBtn = new wxButton(this, EDITOR_DIALOG_CREATE, "&Create", wxPoint( 25, 21), wxSize( 70, 35), 0, wxDefaultValidator, "CreateBtn");
+ pEditBtn = new wxButton(this, EDITOR_DIALOG_EDIT, "&Edit", wxPoint(102, 21), wxSize( 70, 35), 0, wxDefaultValidator, "EditBtn");
+ pDeleteBtn = new wxButton(this, EDITOR_DIALOG_DELETE, "&Delete", wxPoint(179, 21), wxSize( 70, 35), 0, wxDefaultValidator, "DeleteBtn");
+ pCopyBtn = new wxButton(this, EDITOR_DIALOG_COPY, "Cop&y", wxPoint(256, 21), wxSize( 70, 35), 0, wxDefaultValidator, "CopyBtn");
+ pSaveBtn = new wxButton(this, EDITOR_DIALOG_SAVE, "&Save", wxPoint(333, 21), wxSize( 70, 35), 0, wxDefaultValidator, "SaveBtn");
+ pCancelBtn = new wxButton(this, EDITOR_DIALOG_CANCEL, "C&ancel", wxPoint(430, 21), wxSize( 70, 35), 0, wxDefaultValidator, "CancelBtn");
+ pPrevBtn = new wxButton(this, EDITOR_DIALOG_PREV, "<< &Prev", wxPoint(430, 81), wxSize( 70, 35), 0, wxDefaultValidator, "PrevBtn");
+ pNextBtn = new wxButton(this, EDITOR_DIALOG_NEXT, "&Next >>", wxPoint(430, 121), wxSize( 70, 35), 0, wxDefaultValidator, "NextBtn");
+ pQueryBtn = new wxButton(this, EDITOR_DIALOG_QUERY, "&Query", wxPoint(430, 161), wxSize( 70, 35), 0, wxDefaultValidator, "QueryBtn");
+ pResetBtn = new wxButton(this, EDITOR_DIALOG_RESET, "&Reset", wxPoint(430, 200), wxSize( 70, 35), 0, wxDefaultValidator, "ResetBtn");
+ pNameMsg = new wxStaticText(this, EDITOR_DIALOG_NAME_MSG, "Name:", wxPoint( 17, 80), wxSize( -1, -1), 0, "NameMsg");
+ pNameTxt = new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT, "", wxPoint( 17, 97), wxSize(308, 25), 0, wxDefaultValidator, "NameTxt");
+ pNameListBtn = new wxButton(this, EDITOR_DIALOG_LOOKUP, "&Lookup", wxPoint(333, 99), wxSize( 70, 24), 0, wxDefaultValidator, "LookupBtn");
+ pAddress1Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG, "Address:", wxPoint( 17, 130), wxSize( -1, -1), 0, "Address1Msg");
+ pAddress1Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint( 17, 147), wxSize(308, 25), 0, wxDefaultValidator, "Address1Txt");
+ pAddress2Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG, "Address:", wxPoint( 17, 180), wxSize( -1, -1), 0, "Address2Msg");
+ pAddress2Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, "", wxPoint( 17, 197), wxSize(308, 25), 0, wxDefaultValidator, "Address2Txt");
+ pCityMsg = new wxStaticText(this, EDITOR_DIALOG_CITY_MSG, "City:", wxPoint( 17, 230), wxSize( -1, -1), 0, "CityMsg");
+ pCityTxt = new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT, "", wxPoint( 17, 247), wxSize(225, 25), 0, wxDefaultValidator, "CityTxt");
+ pStateMsg = new wxStaticText(this, EDITOR_DIALOG_STATE_MSG, "State:", wxPoint(250, 230), wxSize( -1, -1), 0, "StateMsg");
+ pStateTxt = new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT, "", wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator, "StateTxt");
+ pCountryMsg = new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG, "Country:", wxPoint( 17, 280), wxSize( -1, -1), 0, "CountryMsg");
+ pCountryTxt = new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT, "", wxPoint( 17, 297), wxSize(225, 25), 0, wxDefaultValidator, "CountryTxt");
+ pPostalCodeMsg = new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG, "Postal Code:",wxPoint(250, 280), wxSize( -1, -1), 0, "PostalCodeMsg");
+ pPostalCodeTxt = new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT, "", wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator, "PostalCodeTxt");
+
+ wxString choice_strings[5];
+ choice_strings[0] = "English";
+ choice_strings[1] = "French";
+ choice_strings[2] = "German";
+ choice_strings[3] = "Spanish";
+ choice_strings[4] = "Other";
+
+ pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint( 17, 346), wxSize(277, -1), 5, choice_strings);
+ pNativeLangMsg = new wxStaticText(this, EDITOR_DIALOG_LANG_MSG, "Native language:", wxPoint( 17, 330), wxSize( -1, -1), 0, "NativeLangMsg");
+
+ wxString radio_strings[2];
+ radio_strings[0] = "No";
+ radio_strings[1] = "Yes";
+ pDeveloperRadio = new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER, "Developer:", wxPoint(303, 330), wxSize( -1, -1), 2, radio_strings, 2, wxHORIZONTAL);
+ pJoinDateMsg = new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG, "Date joined:", wxPoint( 17, 380), wxSize( -1, -1), 0, "JoinDateMsg");
+ pJoinDateTxt = new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT, "", wxPoint( 17, 397), wxSize(150, 25), 0, wxDefaultValidator, "JoinDateTxt");
+ pContribMsg = new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG,"Contributions:", wxPoint(175, 380), wxSize( -1, -1), 0, "ContribMsg");
+ pContribTxt = new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT, "", wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator, "ContribTxt");
+ pLinesMsg = new wxStaticText(this, EDITOR_DIALOG_LINES_MSG, "Lines of code:", wxPoint(303, 380), wxSize( -1, -1), 0, "LinesMsg");
+ pLinesTxt = new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT, "", wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator, "LinesTxt");
+
+ // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
+ // handle all widget processing
+ widgetPtrsSet = TRUE;
+
+ // Setup the orderBy and where clauses to return back a single record as the result set,
+ // as there will only be one record being shown on the dialog at a time, this optimizes
+ // network traffic by only returning a one row result
+
+ Contact->orderBy = "NAME"; // field name to sort by
+
+ // The wxString "whereStr" is not a member of the wxTable object, it is a member variable
+ // specifically in the Ccontact class. It is used here for simpler construction of a varying
+ // length string, and then after the string is built, the wxTable member variable "where" is
+ // assigned the pointer to the constructed string.
+ //
+ // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
+ // to achieve a single row (in this case the first name in alphabetical order).
+
+ if (Contact->pDb->Dbms() != dbmsPOSTGRES)
+ {
+ Contact->whereStr.sprintf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->tableName);
+ // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
+ Contact->where = (char*) (const char*) Contact->whereStr;
+ }
+ else
+ Contact->where = 0;
+
+ // Perform the Query to get the result set.
+ // NOTE: If there are no rows returned, that is a valid result, so Query() would return TRUE.
+ // Only if there is a database error will Query() come back as FALSE
+ if (!Contact->Query())
+ {
+ wxString tStr;
+ tStr = "ODBC error during Query()\n\n";
+ tStr += GetExtendedDBErrorMsg(__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+ GetParent()->Close();
+ return;
+ }
+
+ // Since Query succeeded, now get the row that was returned
+ if (!Contact->GetNext())
+ // If the GetNext() failed at this point, then there are no rows to retrieve,
+ // so clear the values in the members of "Contact" so that PutData() blanks the
+ // widgets on the dialog
+ Contact->Initialize();
+
+ SetMode(mView);
+ PutData();
+
+ Show(TRUE);