BOOL SQLW_ComboBoxFillTables (CComboBox* pCombo, CaLLQueryInfo* pInfo) { int idx = -1; CString strItem; CTypedPtrList<CObList, CaDBObject*> listObject; BOOL bOk = theApp.INGRESII_QueryObject (pInfo, listObject); if (!bOk) return FALSE; POSITION pos = listObject.GetHeadPosition(); while (pos != NULL) { CaDBObject* pObj = listObject.GetNext(pos); #if defined (_DISPLAY_OWNERxITEM) AfxFormatString2 (strItem, IDS_OWNERxITEM, (LPCTSTR)pObj->GetOwner(), (LPCTSTR)pObj->GetItem()); #else strItem = pObj->GetName(); #endif idx = pCombo->AddString (strItem); if (idx != CB_ERR) pCombo->SetItemData (idx, (DWORD)pObj); else delete pObj; } return TRUE; }
BOOL CuDlgPropertyPageSqlWizardUpdate2::GetListColumns (CaDBObject* pTable, CStringList& listColumn) { CxDlgPropertySheetSqlWizard* pParent = (CxDlgPropertySheetSqlWizard*)GetParent(); CTypedPtrList<CObList, CaDBObject*> listObject; ASSERT(pTable); if (!pTable) return FALSE; CaLLQueryInfo info(pParent->m_queryInfo); if (pTable->GetObjectID() == OBT_TABLE) info.SetObjectType(OBT_TABLECOLUMN); else info.SetObjectType(OBT_VIEWCOLUMN); info.SetItem2(pTable->GetName(), pTable->GetOwner()); BOOL bOk = theApp.INGRESII_QueryObject (&info, listObject); if (!bOk) return FALSE; CString strItem; POSITION pos = listObject.GetHeadPosition(); while (pos != NULL) { CaDBObject* pObj = listObject.GetNext(pos); strItem.Format ( _T("%s.%s.%s"), (LPCTSTR)INGRESII_llQuoteIfNeeded(pTable->GetOwner()), (LPCTSTR)INGRESII_llQuoteIfNeeded(pTable->GetName()), (LPCTSTR)INGRESII_llQuoteIfNeeded(pObj->GetName())); listColumn.AddTail(strItem); delete pObj; } return TRUE; }
// // Initialize the columns of Current Selected Object (Table or View): void CuDlgPropertyPageSqlWizardInsert1::OnSelchangeComboTable() { CWaitCursor doWaitCursor; CxDlgPropertySheetSqlWizard* pParent = (CxDlgPropertySheetSqlWizard*)GetParent(); int nSel = m_cComboTable.GetCurSel(); SQLW_CuCheckListBoxColumnsClean(&m_cCheckListBoxColumn); if (nSel == CB_ERR) return; try { CString strAll; if (m_strAll.IsEmpty()) { if (m_strAll.LoadString (IDS_SELECTALL) == 0) m_strAll = _T("<All Columns>"); } CaDBObject* pTable = (CaDBObject*)m_cComboTable.GetItemData(nSel); ASSERT(pTable); if (!pTable) return; CaLLQueryInfo info(pParent->m_queryInfo); if (pTable->GetObjectID() == OBT_TABLE) info.SetObjectType(OBT_TABLECOLUMN); else info.SetObjectType(OBT_VIEWCOLUMN); info.SetItem2(pTable->GetName(), pTable->GetOwner()); m_cCheckListBoxColumn.AddString (m_strAll); SQLW_CuCheckListBoxFillColumns (&m_cCheckListBoxColumn, &info); // // Select the previous selected columns if Any: // } catch (CMemoryException* e) { e->Delete(); theApp.OutOfMemoryMessage(); } catch (CeSqlException e) { AfxMessageBox (e.GetReason(), MB_ICONEXCLAMATION|MB_OK); } catch (...) { // _T("Cannot query the columns of the selected table"); AfxMessageBox (IDS_MSG_FAIL_2_QUERY_COLUMN, MB_ICONEXCLAMATION|MB_OK); } EnableWizardButtons(); }
void SQLW_SelectObject (CuListCtrlCheckBox& listCtrl, CaDBObject* pObj) { int i, nCount = listCtrl.GetItemCount(); for (i=0; i<nCount; i++) { CaDBObject* pItem = (CaDBObject*)listCtrl.GetItemData(i); if (pItem) { if (pObj->GetName().CompareNoCase (pItem->GetName()) == 0 && pObj->GetOwner().CompareNoCase (pItem->GetOwner()) == 0) { listCtrl.CheckItem (i, TRUE); } } } }
BOOL CuDlgPropertyPageSqlWizardUpdate3::OnInitDialog() { CWaitCursor doWaitCursor; CxDlgPropertySheetSqlWizard* pParent = (CxDlgPropertySheetSqlWizard*)GetParent(); CPropertyPage::OnInitDialog(); m_cListCtrl.m_queryInfo = pParent->m_queryInfo; int nSel = CB_ERR; CComboBox& comboTable = pParent->m_PageUpdate1.m_cComboTable; nSel = comboTable.GetCurSel(); if (nSel != CB_ERR) { CaDBObject* pObj = (CaDBObject*)comboTable.GetItemData (nSel); m_cListCtrl.m_queryInfo.SetItem2 (pObj->GetName(), pObj->GetOwner()); m_cListCtrl.m_queryInfo.SetObjectType(pObj->GetObjectID()); } VERIFY (m_cListCtrl.SubclassDlgItem (IDC_LIST1, this)); m_ImageList.Create(1, 20, TRUE, 1, 0); m_cListCtrl.SetImageList (&m_ImageList, LVSIL_SMALL); CString strItem; LVCOLUMN lvcolumn; LSCTRLHEADERPARAMS2 lsp[2] = { {IDS_HEADER_COLUMN, 100, LVCFMT_LEFT, FALSE}, {IDS_HEADER_VALUE, 300, LVCFMT_LEFT, FALSE} }; memset (&lvcolumn, 0, sizeof (LV_COLUMN)); lvcolumn.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH; for (int i=0; i<2; i++) { strItem.LoadString(lsp[i].m_nIDS); lvcolumn.fmt = lsp[i].m_fmt; lvcolumn.pszText = (LPTSTR)(LPCTSTR)strItem; lvcolumn.iSubItem = i; lvcolumn.cx = lsp[i].m_cxWidth; m_cListCtrl.InsertColumn (i, &lvcolumn); } m_cListCtrl.Invalidate(); EnableButtons(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
BOOL SQLW_CuCheckListBoxFillColumns (CuCheckListBox* pListBox, CaLLQueryInfo* pInfo) { int idx = -1; CTypedPtrList<CObList, CaDBObject*> listObject; BOOL bOk = theApp.INGRESII_QueryObject (pInfo, listObject); if (!bOk) return FALSE; POSITION pos = listObject.GetHeadPosition(); while (pos != NULL) { CaDBObject* pObj = listObject.GetNext(pos); idx = pListBox->AddString ((LPCTSTR)pObj->GetName()); if (idx != LB_ERR) pListBox->SetItemData (idx, (DWORD)pObj); else delete pObj; } return TRUE; }
BOOL SQLW_CuCheckListBoxFillTables (CuListCtrlCheckBox* pListBox, CaLLQueryInfo* pInfo) { int idx = -1; CString strItem; CTypedPtrList<CObList, CaDBObject*> listObject; BOOL bOk = theApp.INGRESII_QueryObject (pInfo, listObject); if (!bOk) return FALSE; LVITEM lvi; memset (&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE|LVIF_STATE; lvi.stateMask = LVIS_STATEIMAGEMASK; lvi.state = INDEXTOSTATEIMAGEMASK(1); lvi.iImage = 0; POSITION pos = listObject.GetHeadPosition(); while (pos != NULL) { CaDBObject* pObj = listObject.GetNext(pos); lvi.iItem = pListBox->GetItemCount(); lvi.iSubItem = 0; lvi.lParam = (LPARAM)pObj; lvi.pszText = (LPTSTR)(LPCTSTR)pObj->GetName(); idx = pListBox->InsertItem (&lvi); if (idx != -1) { pListBox->SetItemText (idx, 1, pObj->GetOwner()); } else { delete pObj; } } return TRUE; }
BOOL CuDlgPropertyPageSqlWizardUpdate3::OnWizardFinish() { CWaitCursor doWaitCursor; int i, idx, nCount1, nCount2; CString strStatement; CString strItem; CString strValue; m_cListCtrl.HideProperty (TRUE); CxDlgPropertySheetSqlWizard* pParent = (CxDlgPropertySheetSqlWizard*)GetParent(); CComboBox& comboTable = pParent->m_PageUpdate1.m_cComboTable; CuListCtrlCheckBox& listTable = pParent->m_PageUpdate2.m_cListTable; CuListCtrlCheckBox& listView = pParent->m_PageUpdate2.m_cListView; CEdit& editCriteria = pParent->m_PageUpdate2.m_cEditCriteria; idx = comboTable.GetCurSel(); if (idx == CB_ERR) { pParent->SetStatement (NULL); return TRUE; } // // Check Values: nCount1 = m_cListCtrl.GetItemCount(); for (i=0; i<nCount1; i++) { strValue = m_cListCtrl.GetItemText (i, CuEditableListCtrlSqlWizardUpdateValue::VALUE); strValue.TrimLeft(); strValue.TrimRight(); if (strValue.IsEmpty()) { // _T("Not all the columns have values.\nDo you want to continue ?"); //UK IDS_A_COLUMNS_VALUE if (AfxMessageBox (IDS_MSG_COLUMNS_VALUE, MB_ICONEXCLAMATION|MB_OKCANCEL) == IDOK) break; else { return FALSE; } } } // // Generate: UPDATE x strStatement.Format (_T(" %s "), cstrUpdate); CaDBObject* pTable = (CaDBObject*)comboTable.GetItemData(idx); ASSERT(pTable); if(!pTable) return FALSE; if (pTable->GetOwner().IsEmpty()) strStatement += INGRESII_llQuoteIfNeeded(pTable->GetName()); else { strStatement += INGRESII_llQuoteIfNeeded(pTable->GetOwner()); strStatement += _T("."); strStatement += INGRESII_llQuoteIfNeeded(pTable->GetName()); } // // Generate: FROM a, b, c: BOOL bOne = TRUE; CString strListItem = _T(""); nCount1 = listTable.GetItemCount(); nCount2 = listView.GetItemCount(); for (i=0; i<nCount1; i++) { if (listTable.GetItemChecked(i)) { CaDBObject* pTable =(CaDBObject*)listTable.GetItemData(i); ASSERT(pTable); if (!pTable) continue; if (!bOne) strListItem += _T(", "); bOne = FALSE; if (pTable->GetOwner().IsEmpty()) strListItem += INGRESII_llQuoteIfNeeded(pTable->GetName()); else { strListItem += INGRESII_llQuoteIfNeeded(pTable->GetOwner()); strListItem += _T("."); strListItem += INGRESII_llQuoteIfNeeded(pTable->GetName()); } } } for (i=0; i<nCount2; i++) { if (listView.GetItemChecked(i)) { CaDBObject* pView =(CaDBObject*)listView.GetItemData(i); ASSERT(pView); if (!pView) continue; if (!bOne) strListItem += _T(", "); bOne = FALSE; if (pView->GetOwner().IsEmpty()) strListItem += INGRESII_llQuoteIfNeeded(pView->GetName()); else { strListItem += INGRESII_llQuoteIfNeeded(pView->GetOwner()); strListItem += _T("."); strListItem += INGRESII_llQuoteIfNeeded(pView->GetName()); } } } if (!strListItem.IsEmpty()) { strStatement += _T(" "); strStatement += cstrFrom; strStatement += _T(" "); strStatement += strListItem; } // // SET column = expr ...: strListItem = _T(""); bOne = TRUE; nCount1 = m_cListCtrl.GetItemCount(); for (i=0; i<nCount1; i++) { strItem = m_cListCtrl.GetItemText (i, CuEditableListCtrlSqlWizardUpdateValue::COLUMN); strValue = m_cListCtrl.GetItemText (i, CuEditableListCtrlSqlWizardUpdateValue::VALUE); strValue.TrimLeft(); strValue.TrimRight(); if (strValue.IsEmpty()) continue; if (!bOne) strListItem += _T(", "); bOne = FALSE; if (strListItem.IsEmpty()) { strListItem += cstrSet; strListItem += _T(" "); } strListItem += INGRESII_llQuoteIfNeeded(strItem); strListItem += _T(" = "); strListItem += strValue; } if (strListItem.IsEmpty()) { pParent->SetStatement (NULL); return TRUE; } strStatement += _T(" "); strStatement += strListItem; // // Generate the WHERE ...: editCriteria.GetWindowText (strItem); strItem.TrimLeft(); strItem.TrimRight(); if (!strItem.IsEmpty()) { strStatement += _T(" "); strStatement += cstrWhere; strStatement += _T(" "); strStatement += strItem; } pParent->SetStatement (strStatement); return CPropertyPage::OnWizardFinish(); }
void CuDlgPropertyPageSqlWizardUpdate2::OnButtonCriteria() { CWaitCursor doWaitCursor; CxDlgPropertySheetSqlWizard* pParent = (CxDlgPropertySheetSqlWizard*)GetParent(); CxDlgPropertySheetSqlExpressionWizard wizdlg; wizdlg.m_queryInfo = pParent->m_queryInfo; wizdlg.m_nFamilyID = FF_PREDICATES; wizdlg.m_nAggType = IDC_RADIO1; wizdlg.m_nCompare = IDC_RADIO1; wizdlg.m_nIn_notIn = IDC_RADIO1; wizdlg.m_nSub_List = IDC_RADIO1; // // Initialize Tables or Views from the checked items: try { CString strItem; int i, nCount = m_cListTable.GetItemCount(); for (i=0; i<nCount; i++) { if (m_cListTable.GetItemChecked(i)) { CaDBObject* pObj = (CaDBObject*)m_cListTable.GetItemData (i); CaDBObject* pNewObject = new CaDBObject(*pObj); pNewObject->SetObjectID(OBT_TABLE); wizdlg.m_listObject.AddTail (pNewObject); } } nCount = m_cListView.GetItemCount(); for (i=0; i<nCount; i++) { if (m_cListView.GetItemChecked(i)) { CaDBObject* pObj = (CaDBObject*)m_cListView.GetItemData (i); CaDBObject* pNewObject = new CaDBObject(*pObj); pNewObject->SetObjectID(OBT_VIEW); wizdlg.m_listObject.AddTail (pNewObject); } } // // Append the current Table: CComboBox& comboTable = pParent->m_PageUpdate1.m_cComboTable; int nSel = comboTable.GetCurSel(); if (nSel != CB_ERR) { CaDBObject* pObj = (CaDBObject*)comboTable.GetItemData (nSel); // // Check to see if the current table has already been added: BOOL b2Add = TRUE; POSITION pf = wizdlg.m_listObject.GetHeadPosition(); while (pf != NULL) { CaDBObject* p = (CaDBObject*) wizdlg.m_listObject.GetNext (pf); if (p->GetName().CompareNoCase (pObj->GetName()) == 0 && p->GetOwner().CompareNoCase (pObj->GetOwner()) == 0) { b2Add = FALSE; break; } } if (b2Add) { CaDBObject* pNewObject = new CaDBObject(*pObj); if (pParent->m_PageUpdate1.IsDlgButtonChecked (IDC_RADIO1)) pNewObject->SetObjectID(OBT_TABLE); else pNewObject->SetObjectID(OBT_VIEW); wizdlg.m_listObject.AddTail (pNewObject); } } } catch (CMemoryException* e) { theApp.OutOfMemoryMessage(); e->Delete(); return; } catch (CeSqlException e) { AfxMessageBox (e.GetReason(), MB_ICONEXCLAMATION|MB_OK); } catch(...) { // _T("Cannot initialize the SQL assistant."); AfxMessageBox (IDS_MSG_SQL_ASSISTANT, MB_ICONEXCLAMATION|MB_OK); return; } int nResult = wizdlg.DoModal(); if (nResult == IDCANCEL) return; CString strStatement; wizdlg.GetStatement (strStatement); if (strStatement.IsEmpty()) return; m_cEditCriteria.ReplaceSel (strStatement); }