+ new ClookUpDlg(/* wxWindow *parent */ this,
+ /* wxChar *windowTitle */ wxT("Select contact name"),
+ /* wxChar *tableName */ (wxChar *) CONTACT_TABLE_NAME,
+ /* wxChar *dispCol1 */ wxT("NAME"),
+ /* wxChar *dispCol2 */ wxT("JOINDATE"),
+ /* wxChar *where */ wxT(""),
+ /* wxChar *orderBy */ wxT("NAME"),
+ /* wxDb *pDb */ wxGetApp().READONLY_DB,
+ /* const wxString &defDir */ wxGetApp().DbConnectInf->GetDefaultDir(),
+ /* bool distinctValues */ true);
+
+ if (ListDB_Selection && wxStrlen(ListDB_Selection))
+ {
+ wxString w = wxT("NAME = '");
+ w += ListDB_Selection;
+ w += wxT("'");
+ GetRec(w);
+ }
+
+ return;
+ }
+
+ if (widgetName == pDataTypesBtn->GetName())
+ {
+ CheckSupportForAllDataTypes(wxGetApp().READONLY_DB);
+ wxMessageBox(wxT("Support datatypes was dumped to stdout."));
+ return;
+ } // Data types Button
+
+ if (widgetName == pDbDiagsBtn->GetName())
+ {
+ DisplayDbDiagnostics(wxGetApp().READONLY_DB);
+ wxMessageBox(wxT("Diagnostics info was dumped to stdout."));
+ return;
+ }
+
+ if (widgetName == pCatalogBtn->GetName())
+ {
+ if (wxGetApp().Contact->GetDb()->Catalog(wxEmptyString, wxT("catalog.txt")))
+ wxMessageBox(wxT("The file 'catalog.txt' was created."));
+ else
+ wxMessageBox(wxT("Creation of the file 'catalog.txt' was failed."));
+ return;
+ }
+
+#ifdef wxODBC_BLOB_SUPPORT
+ if (widgetName == pChooseImageBtn->GetName())
+ {
+ OnSelectPict();
+ }
+
+ if (widgetName == pShowImageBtn->GetName())
+ {
+ OnShowImage();
+ }
+#endif
+
+} // CeditorDlg::OnCommand()
+
+
+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)
+ wxGetApp().Contact = new Ccontact();
+
+ if (!wxGetApp().Contact)
+ {
+ wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"),wxT("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 (!wxGetApp().Contact->GetDb()->TableExists((wxChar *)CONTACT_TABLE_NAME,
+ wxGetApp().DbConnectInf->GetUserID(),
+ wxGetApp().DbConnectInf->GetDefaultDir()))
+ {
+ wxString tStr;
+ tStr.Printf(wxT("Unable to open the table '%s'. The table may\nneed to be created.\n\nDo you wish to try to create/clear the table?\n\n"),CONTACT_TABLE_NAME);
+ bool createTable = (wxMessageBox(tStr.c_str(),wxT("Confirm"),wxYES_NO|wxICON_QUESTION) == wxYES);
+
+ if (!createTable)
+ {
+// Close();
+ return false;
+ }
+ else
+ wxGetApp().CreateDataTable(false);
+ }
+
+ // Tables must be "opened" before anything other than creating/deleting table can be done
+ if (!wxGetApp().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 1
+// 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 (!wxGetApp().Contact->GetDb()->TablePrivileges(CONTACT_TABLE_NAME, wxT("SELECT"),
+ wxGetApp().Contact->GetDb()->GetUsername(),
+ wxGetApp().Contact->GetDb()->GetUsername(),
+ wxGetApp().DbConnectInf->GetDefaultDir()))
+ {
+ wxString tStr;
+ tStr.Printf(wxT("Unable to open the table '%s' (likely due to\ninsufficient privileges of the logged in user).\n\n"),CONTACT_TABLE_NAME);
+
+ wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
+ wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+ }
+ else
+#endif
+ if (!wxGetApp().Contact->GetDb()->TableExists(CONTACT_TABLE_NAME,
+ wxGetApp().Contact->GetDb()->GetUsername(),
+ wxGetApp().DbConnectInf->GetDefaultDir()))
+ {
+ wxString tStr;
+ tStr.Printf(wxT("Unable to open the table '%s' as the table\ndoes not appear to exist in the tablespace available\nto the currently logged in user.\n\n"),CONTACT_TABLE_NAME);
+ wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
+ wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+ }
+
+ return false;
+ }
+
+ // Build the dialog
+
+ (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP, wxEmptyString, wxPoint(15, 1), wxSize(497, 69), 0, wxT("FunctionGrp"));
+ (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP, wxEmptyString, wxPoint(417, 1), wxSize(95, 242), 0, wxT("SearchGrp"));
+
+ pCreateBtn = new wxButton(this, EDITOR_DIALOG_CREATE, wxT("&Create"), wxPoint( 25, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("CreateBtn"));
+ pEditBtn = new wxButton(this, EDITOR_DIALOG_EDIT, wxT("&Edit"), wxPoint(102, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("EditBtn"));
+ pDeleteBtn = new wxButton(this, EDITOR_DIALOG_DELETE, wxT("&Delete"), wxPoint(179, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("DeleteBtn"));
+ pCopyBtn = new wxButton(this, EDITOR_DIALOG_COPY, wxT("Cop&y"), wxPoint(256, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("CopyBtn"));
+ pSaveBtn = new wxButton(this, EDITOR_DIALOG_SAVE, wxT("&Save"), wxPoint(333, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("SaveBtn"));
+ pCancelBtn = new wxButton(this, EDITOR_DIALOG_CANCEL, wxT("C&ancel"), wxPoint(430, 21), wxSize( 70, 35), 0, wxDefaultValidator, wxT("CancelBtn"));
+ pPrevBtn = new wxButton(this, EDITOR_DIALOG_PREV, wxT("<< &Prev"), wxPoint(430, 81), wxSize( 70, 35), 0, wxDefaultValidator, wxT("PrevBtn"));
+ pNextBtn = new wxButton(this, EDITOR_DIALOG_NEXT, wxT("&Next >>"), wxPoint(430, 121), wxSize( 70, 35), 0, wxDefaultValidator, wxT("NextBtn"));
+ pQueryBtn = new wxButton(this, EDITOR_DIALOG_QUERY, wxT("&Query"), wxPoint(430, 161), wxSize( 70, 35), 0, wxDefaultValidator, wxT("QueryBtn"));
+ pResetBtn = new wxButton(this, EDITOR_DIALOG_RESET, wxT("&Reset"), wxPoint(430, 200), wxSize( 70, 35), 0, wxDefaultValidator, wxT("ResetBtn"));
+ pNameMsg = new wxStaticText(this, EDITOR_DIALOG_NAME_MSG, wxT("Name:"), wxPoint( 17, 80), wxDefaultSize, 0, wxT("NameMsg"));
+ pNameTxt = new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT, wxEmptyString, wxPoint( 17, 97), wxSize(308, 25), 0, wxDefaultValidator, wxT("NameTxt"));
+ pNameListBtn = new wxButton(this, EDITOR_DIALOG_LOOKUP, wxT("&Lookup"), wxPoint(333, 97), wxSize( 70, 24), 0, wxDefaultValidator, wxT("LookupBtn"));
+ pAddress1Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG, wxT("Address:"), wxPoint( 17, 130), wxDefaultSize, 0, wxT("Address1Msg"));
+ pAddress1Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, wxEmptyString, wxPoint( 17, 147), wxSize(308, 25), 0, wxDefaultValidator, wxT("Address1Txt"));
+ pAddress2Msg = new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG, wxT("Address:"), wxPoint( 17, 180), wxDefaultSize, 0, wxT("Address2Msg"));
+ pAddress2Txt = new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT, wxEmptyString, wxPoint( 17, 197), wxSize(308, 25), 0, wxDefaultValidator, wxT("Address2Txt"));
+ pCityMsg = new wxStaticText(this, EDITOR_DIALOG_CITY_MSG, wxT("City:"), wxPoint( 17, 230), wxDefaultSize, 0, wxT("CityMsg"));
+ pCityTxt = new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT, wxEmptyString, wxPoint( 17, 247), wxSize(225, 25), 0, wxDefaultValidator, wxT("CityTxt"));
+ pStateMsg = new wxStaticText(this, EDITOR_DIALOG_STATE_MSG, wxT("State:"), wxPoint(250, 230), wxDefaultSize, 0, wxT("StateMsg"));
+ pStateTxt = new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT, wxEmptyString, wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator, wxT("StateTxt"));
+ pCountryMsg = new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG, wxT("Country:"), wxPoint( 17, 280), wxDefaultSize, 0, wxT("CountryMsg"));
+ pCountryTxt = new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT, wxEmptyString, wxPoint( 17, 297), wxSize(225, 25), 0, wxDefaultValidator, wxT("CountryTxt"));
+ pPostalCodeMsg = new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG, wxT("Postal Code:"),wxPoint(250, 280), wxDefaultSize, 0, wxT("PostalCodeMsg"));
+ pPostalCodeTxt = new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT, wxEmptyString, wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator, wxT("PostalCodeTxt"));
+
+ wxString choice_strings[5];
+ choice_strings[0] = wxT("English");
+ choice_strings[1] = wxT("French");
+ choice_strings[2] = wxT("German");
+ choice_strings[3] = wxT("Spanish");
+ choice_strings[4] = wxT("Other");
+
+ pNativeLangChoice = new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE, wxPoint( 17, 346), wxSize(277, wxDefaultCoord), 5, choice_strings);
+ pNativeLangMsg = new wxStaticText(this, EDITOR_DIALOG_LANG_MSG, wxT("Native language:"), wxPoint( 17, 330), wxDefaultSize, 0, wxT("NativeLangMsg"));
+
+ wxString radio_strings[2];
+ radio_strings[0] = wxT("No");
+ radio_strings[1] = wxT("Yes");
+ pDeveloperRadio = new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER, wxT("Developer:"), wxPoint(303, 330), wxDefaultSize, 2, radio_strings, 2, wxHORIZONTAL);
+ pJoinDateMsg = new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG, wxT("Date joined:"), wxPoint( 17, 380), wxDefaultSize, 0, wxT("JoinDateMsg"));
+ pJoinDateTxt = new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT, wxEmptyString, wxPoint( 17, 397), wxSize(150, 25), 0, wxDefaultValidator, wxT("JoinDateTxt"));
+ pContribMsg = new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG,wxT("Contributions:"), wxPoint(175, 380), wxDefaultSize, 0, wxT("ContribMsg"));
+ pContribTxt = new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT, wxEmptyString, wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator, wxT("ContribTxt"));
+ pLinesMsg = new wxStaticText(this, EDITOR_DIALOG_LINES_MSG, wxT("Lines of code:"), wxPoint(303, 380), wxDefaultSize, 0, wxT("LinesMsg"));
+ pLinesTxt = new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT, wxEmptyString, wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator, wxT("LinesTxt"));
+
+ pCatalogBtn = new wxButton(this, EDITOR_DIALOG_CATALOG, wxT("Catalo&g"), wxPoint(430, 287), wxSize( 70, 35), 0, wxDefaultValidator, wxT("CatalogBtn"));
+ pDataTypesBtn = new wxButton(this, EDITOR_DIALOG_DATATYPES, wxT("Data&types"), wxPoint(430, 337), wxSize( 70, 35), 0, wxDefaultValidator, wxT("DataTypesBtn"));
+ pDbDiagsBtn = new wxButton(this, EDITOR_DIALOG_DB_DIAGS, wxT("DB Dia&gs"), wxPoint(430, 387), wxSize( 70, 35), 0, wxDefaultValidator, wxT("DbDiagsBtn"));
+
+#ifdef wxODBC_BLOB_SUPPORT
+ pPictureMsg = new wxStaticText(this, EDITOR_DIALOG_PIC_MSG, wxT("Picture:"), wxPoint( 17,430), wxDefaultSize, 0, wxT("PicMsg"));
+ pPictSizeMsg = new wxStaticText(this, EDITOR_DIALOG_PICSIZE_MSG, wxT("Picture Bytes:"), wxPoint(175,430), wxDefaultSize, 0, wxT("PicSizeMsg"));
+ pChooseImageBtn = new wxButton(this, EDITOR_DIALOG_PIC_BROWSE, wxT("Select..."), wxPoint( 17,447), wxSize( 70, 24), 0, wxDefaultValidator, wxT("PicBrowseBtn"));
+ pShowImageBtn = new wxButton(this, EDITOR_DIALOG_PIC_SHOW, wxT("Show..."), wxPoint( 97,447), wxSize( 70, 24), 0, wxDefaultValidator, wxT("PictShowBtn"));
+ pPictSizeTxt = new wxTextCtrl(this, EDITOR_DIALOG_PIC_SIZE_TEXT, wxEmptyString, wxPoint(175,447), wxSize(120, 25), 0, wxDefaultValidator, wxT("PictSizeTxt"));
+#endif
+
+ // 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
+
+ wxGetApp().Contact->SetOrderByClause(wxT("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 (wxGetApp().Contact->GetDb()->Dbms() != dbmsPOSTGRES &&
+ wxGetApp().Contact->GetDb()->Dbms() != dbmsMY_SQL)
+ {
+ wxGetApp().Contact->whereStr.Printf(wxT("NAME = (SELECT MIN(NAME) FROM %s)"),
+ wxGetApp().Contact->GetTableName().c_str());
+ // NOTE: (const wxChar*) returns a pointer which may not be valid later, so this is short term use only
+ wxGetApp().Contact->SetWhereClause(wxGetApp().Contact->whereStr);
+ }
+ else
+ wxGetApp().Contact->SetWhereClause(wxEmptyString);
+
+ // 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 (!wxGetApp().Contact->Query())
+ {
+ wxString tStr;
+ tStr = wxT("ODBC error during Query()\n\n");
+ wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
+ wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+ return false;
+ }
+
+ // Since Query succeeded, now get the row that was returned
+ if (!wxGetApp().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
+ wxGetApp().Contact->Initialize();
+/*
+ wxGetApp().Contact->GetDb()->RollbackTrans();
+*/
+ SetMode(mView);
+ PutData();
+
+ Show(true);
+
+ initialized = true;
+ return true;
+} // CeditorDlg::Initialize()
+
+#ifdef wxODBC_BLOB_SUPPORT
+
+void CeditorDlg::OnSelectPict()
+{
+ wxFileDialog dlg(this, wxT("Choose an image file less than 60K"), wxEmptyString, wxEmptyString, wxT("JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|BMP files (*.bmp)|*.bmp|All Files (*.*)|*.*"), wxOPEN);
+
+ if (dlg.ShowModal() == wxID_OK)
+ {
+ wxFile file(dlg.GetPath());
+
+ if (file.IsOpened())
+ {
+ off_t iSize = file.Length();
+
+ if ((iSize > 0) && (iSize < MAX_PICTURE_SIZE))
+ {
+ off_t iReadSize = 0;
+
+ wxGetApp().Contact->BlobSize = iSize;
+
+ memset(wxGetApp().Contact->Picture, 0, MAX_PICTURE_SIZE);
+
+ iReadSize = file.Read(wxGetApp().Contact->Picture, iSize);
+
+ if (iReadSize < iSize)
+ wxMessageBox(wxT("Something bad happened while reading..."), wxT("BLOB Loading Error"), wxOK | wxICON_EXCLAMATION);
+
+ wxString tStr;
+ tStr.Printf(wxT("%lu"),iSize);
+ pPictSizeTxt->SetValue(tStr);
+ }
+ else
+ wxMessageBox(wxT("Selected File is TOO BIG. 60k is the max image size"), wxT("BLOB Loading Error"), wxOK | wxICON_EXCLAMATION);
+ }
+ else
+ wxMessageBox(wxT("Unable to open the requested image file"), wxT("File Access Error"), wxOK | wxICON_EXCLAMATION);
+ }
+}
+
+void CeditorDlg::OnShowImage()
+{
+ if (wxGetApp().Contact->BlobSize > 0)
+ {
+ CimageDlg dlg(this, wxGetApp().Contact->Picture, wxGetApp().Contact->BlobSize);