+bool CeditorDlg::Initialize()
+{
+ // 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 FALSE;
+ }
+
+ // 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->GetDb()->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(Contact->GetDb(),__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)
+ {
+// Close();
+ return FALSE;
+ }
+ else
+ DemoFrame->CreateDataTable(TRUE);
+ }
+
+ // Tables must be "opened" before anything other than creating/deleting table can be done
+ if (!Contact->Open())
+ {
+ // Table does exist, or there was some problem opening it. Currently this should
+ // never fail, except in the case of the table not exisiting or the current
+ // user has insufficent privileges to access the table
+#if 0
+// This code is experimenting with a new function that will hopefully be available
+// in the 2.4 release. This check will determine whether the open failing was due
+// to the table not existing, or the users privileges being insufficient to
+// open the table.
+ if (!Contact->GetDb()->TablePrivileges(CONTACT_TABLE_NAME,"SELECT",Contact->GetDb()->GetUsername(),DbConnectInf.defaultDir))
+ {
+ wxString tStr;
+ tStr.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME);
+ tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+ }
+ else
+#endif
+ if (Contact->GetDb()->TableExists(CONTACT_TABLE_NAME,Contact->GetDb()->GetUsername(),DbConnectInf.defaultDir))
+ {
+ wxString tStr;
+ tStr.Printf("Unable to open the table '%s'.\n\n",CONTACT_TABLE_NAME);
+ tStr += GetExtendedDBErrorMsg(Contact->GetDb(),__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+ }
+
+ return FALSE;
+ }
+
+ // 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, 97), 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->SetOrderByClause("NAME"); // field name to sort by
+
+ // The wxString "whereStr" is not a member of the wxDbTable 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 wxDbTable 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->GetDb()->Dbms() != dbmsPOSTGRES && Contact->GetDb()->Dbms() != dbmsMY_SQL)
+ {
+ Contact->whereStr.sprintf("NAME = (SELECT MIN(NAME) FROM %s)",Contact->GetTableName());
+ // NOTE: (const char*) returns a pointer which may not be valid later, so this is short term use only
+ Contact->SetWhereClause(Contact->whereStr.c_str());
+ }
+ else
+ Contact->SetWhereClause("");
+
+ // 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(Contact->GetDb(),__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...",wxOK | wxICON_EXCLAMATION);
+// GetParent()->Close();
+ return FALSE;
+ }
+
+ // 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);
+
+ initialized = TRUE;
+ return TRUE;
+} // CeditorDlg::Initialize()
+
+