- pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
- pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
-
- widgetPtrsSet = TRUE;
-
- // Query the lookup table and display the result set
- if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
- {
- wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
- Close();
- return;
- }
-
- if (!lookup2->Open())
- {
- wxString tStr;
- tStr.Printf("Unable to open the table '%s'.",tableName);
- tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
- wxMessageBox(tStr,"ODBC Error...");
- Close();
- return;
- }
-
- // If displaying 2 columns, determine the maximum length of column1
- int maxColLen;
- if (maxLenCol1)
- maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
- else
- {
- maxColLen = LOOKUP_COL_LEN;
- if (strlen(dispCol2))
- {
- wxString q = "SELECT MAX({fn LENGTH(";
- q += dispCol1;
- q += ")}), NULL";
- q += " FROM ";
- q += tableName;
- if (strlen(where))
- {
- q += " WHERE ";
- q += where;
- }
- if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
- {
- wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
- Close();
- return;
- }
- if (lookup2->GetNext())
- maxColLen = col1Len = atoi(lookup2->lookupCol1);
- else
- wxMessageBox("ODBC error during GetNext()","ODBC Error...");
- }
- }
-
- // Query the actual record set
- if (selectStmt && strlen(selectStmt)) // Query by sql stmt passed in
- {
- if (!lookup2->QueryBySqlStmt(selectStmt))
- {
- wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
- Close();
- return;
- }
- }
- else // Query using where and order by clauses
- {
- lookup2->orderBy = orderBy;
- lookup2->where = where;
- if (!lookup2->Query(FALSE, distinctValues))
- {
- wxMessageBox("ODBC error during Query()","ODBC Error...");
- Close();
- return;
- }
- }
-
- // Fill in the list box from the query result set
- wxString s;
- while (lookup2->GetNext())
- {
- s = lookup2->lookupCol1;
- if (strlen(dispCol2)) // Append the optional column 2
- {
- s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - strlen(lookup2->lookupCol1)));
- s.Append(lookup2->lookupCol2);
- }
- pLookUpSelectList->Append(s);
- }
-
- // Highlight the first list item
- pLookUpSelectList->SetSelection(0);
-
- // Make the OK activate by pressing Enter
- if (pLookUpSelectList->Number())
- pLookUpOkBtn->SetDefault();
- else
- {
- pLookUpCancelBtn->SetDefault();
- pLookUpOkBtn->Enable(FALSE);
- }
-
- pLookUpOkBtn->Enable(allowOk);
-
- // Display the dialog window
- SetTitle(windowTitle);
- Centre(wxBOTH);
- wxEndBusyCursor();
- ShowModal();
+ pLookUpOkBtn = new wxButton(this, LOOKUP_DIALOG_OK, "&Ok", wxPoint(113, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpOkBtn");
+ pLookUpCancelBtn = new wxButton(this, LOOKUP_DIALOG_CANCEL, "C&ancel", wxPoint(212, 222), wxSize(70, 35), 0, wxDefaultValidator, "LookUpCancelBtn");
+
+ widgetPtrsSet = TRUE;
+
+ // Query the lookup table and display the result set
+ if (!(lookup2 = new Clookup2(tableName, dispCol1, dispCol2, pDb)))
+ {
+ wxMessageBox("Error allocating memory for 'Clookup2'object.","Error...");
+ Close();
+ return;
+ }
+
+ if (!lookup2->Open())
+ {
+ wxString tStr;
+ tStr.Printf("Unable to open the table '%s'.",tableName);
+ tStr += GetExtendedDBErrorMsg2(__FILE__,__LINE__);
+ wxMessageBox(tStr,"ODBC Error...");
+ Close();
+ return;
+ }
+
+ // If displaying 2 columns, determine the maximum length of column1
+ int maxColLen;
+ if (maxLenCol1)
+ maxColLen = col1Len = maxLenCol1; // user passed in max col length for column 1
+ else
+ {
+ maxColLen = LOOKUP_COL_LEN;
+ if (wxStrlen(dispCol2))
+ {
+ wxString q = "SELECT MAX({fn LENGTH(";
+ q += dispCol1;
+ q += ")}), NULL";
+ q += " FROM ";
+ q += tableName;
+ if (wxStrlen(where))
+ {
+ q += " WHERE ";
+ q += where;
+ }
+ if (!lookup2->QueryBySqlStmt((char*) (const char*) q))
+ {
+ wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
+ Close();
+ return;
+ }
+ if (lookup2->GetNext())
+ maxColLen = col1Len = atoi(lookup2->lookupCol1);
+ else
+ wxMessageBox("ODBC error during GetNext()","ODBC Error...");
+ }
+ }
+
+ // Query the actual record set
+ if (selectStmt && wxStrlen(selectStmt)) // Query by sql stmt passed in
+ {
+ if (!lookup2->QueryBySqlStmt(selectStmt))
+ {
+ wxMessageBox("ODBC error during QueryBySqlStmt()","ODBC Error...");
+ Close();
+ return;
+ }
+ }
+ else // Query using where and order by clauses
+ {
+ lookup2->SetOrderByClause(orderBy);
+ lookup2->SetWhereClause(where);
+ if (!lookup2->Query(FALSE, distinctValues))
+ {
+ wxMessageBox("ODBC error during Query()","ODBC Error...");
+ Close();
+ return;
+ }
+ }
+
+ // Fill in the list box from the query result set
+ wxString s;
+ while (lookup2->GetNext())
+ {
+ s = lookup2->lookupCol1;
+ if (wxStrlen(dispCol2)) // Append the optional column 2
+ {
+ s.Append(' ', (maxColLen + LISTDB_NO_SPACES_BETWEEN_COLS - wxStrlen(lookup2->lookupCol1)));
+ s.Append(lookup2->lookupCol2);
+ }
+ pLookUpSelectList->Append(s);
+ }
+
+ // Highlight the first list item
+ pLookUpSelectList->SetSelection(0);
+
+ // Make the OK activate by pressing Enter
+ if (pLookUpSelectList->Number())
+ pLookUpOkBtn->SetDefault();
+ else
+ {
+ pLookUpCancelBtn->SetDefault();
+ pLookUpOkBtn->Enable(FALSE);
+ }
+
+ pLookUpOkBtn->Enable(allowOk);
+
+ // Display the dialog window
+ SetTitle(windowTitle);
+ Centre(wxBOTH);
+ wxEndBusyCursor();
+ ShowModal();