ProceduresDlg.cpp
资源名称:ISQL_src.zip [点击查看]
上传用户:jsxglz
上传日期:2007-01-03
资源大小:117k
文件大小:7k
源码类别:
SQL Server
开发平台:
Visual C++
- // ProceduresDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "interactivesql.h"
- #include "ProceduresDlg.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CProceduresDlg dialog
- CProceduresDlg::CProceduresDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CProceduresDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CProceduresDlg)
- m_strSearch = _T("");
- //}}AFX_DATA_INIT
- m_nSelectedItem = 0;
- m_bSort = true;
- }
- void CProceduresDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CProceduresDlg)
- DDX_Control(pDX, IDC_LIST1, m_ctrlList);
- DDX_Text(pDX, IDC_SEARCH, m_strSearch);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CProceduresDlg, CDialog)
- //{{AFX_MSG_MAP(CProceduresDlg)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
- ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
- ON_EN_CHANGE(IDC_SEARCH, OnChangeSearch)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CProceduresDlg message handlers
- BOOL CProceduresDlg::OnInitDialog()
- {
- CWaitCursor wait;
- CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
- ASSERT(pFrame);
- pFrame->m_wndStatusBar.SetPaneText(pFrame->m_nResultSetPaneNo, "Executing...");
- CDialog::OnInitDialog();
- LV_COLUMN lvcColumn;
- lvcColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
- lvcColumn.fmt = LVCFMT_LEFT;
- CRect rect;
- m_ctrlList.GetClientRect(&rect);
- lvcColumn.cx = rect.Size().cx;
- lvcColumn.pszText = "Name";
- lvcColumn.iSubItem = 0;
- m_ctrlList.InsertColumn(0, &lvcColumn);
- BOOL bNativeWay = pFrame->m_bIsTSQLSupported ||
- !pFrame->m_strDBMS.CompareNoCase(pFrame->m_strOracle);
- BOOL bPopulated = TRUE;
- if(!bNativeWay)
- bPopulated = PopulateList();
- else
- {
- CString sSQL;
- if(pFrame->m_bIsTSQLSupported)
- sSQL = "select name from sysobjects where type = 'P'";
- if(!pFrame->m_strDBMS.CompareNoCase(pFrame->m_strOracle))
- sSQL = "select distinct NAME from ALL_SOURCE where type = 'PROCEDURE'";
- // Efficient when compared to ::SQLProcedures
- bPopulated = PopulateListTheNativeWay(sSQL);
- }
- if(!bPopulated)
- SendMessage(WM_CLOSE);
- else
- {
- m_ctrlList.SetFullRowSel(TRUE);
- UpdateData(FALSE);
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BOOL CProceduresDlg::PopulateList()
- {
- CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
- ASSERT(pFrame);
- BOOL bRet = FALSE;
- try
- {
- CStoredProcedures set(&pFrame->m_database);
- bRet = set.Open();
- if(bRet)
- {
- CString sBuff;
- int nPos = -1;
- while(!set.IsEOF())
- {
- nPos = set.m_strProcedureName.Find(';');
- if(nPos != -1)
- set.m_strProcedureName = set.m_strProcedureName.Left(nPos);
- sBuff = set.m_strProcedureName;
- if(!pFrame->m_bIsJetDriver &&
- set.m_strProcedureName.Find(' ') != -1) // MS SQL Server scenario
- sBuff = "[" + set.m_strProcedureName + "]";
- CHelpers::Insert(&m_ctrlList, sBuff+"|");
- set.MoveNext();
- }
- m_ctrlList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED,
- LVIS_SELECTED | LVIS_FOCUSED);
- }
- }
- catch(CDBException* e)
- {
- if(e)
- {
- CString sMsg;
- if(!e->m_strError.IsEmpty())
- sMsg.Format("%s%s", (LPCTSTR)e->m_strError, (LPCTSTR)e->m_strStateNativeOrigin);
- else
- sMsg = e->m_strStateNativeOrigin;
- e->Delete();
- pFrame->m_strStatusText.Format("CDBException::m_nRetCode: %dn", e->m_nRetCode);
- pFrame->OnExceptionClear(sMsg);
- }
- }
- catch(CMemoryException* e)
- {
- pFrame->m_strStatusText = "Out-of-memory.";
- pFrame->OnExceptionClear(pFrame->m_strStatusText);
- if(e)
- e->Delete();
- }
- catch(const char* e)
- {
- pFrame->m_strStatusText.Format("DSN: %s", (const char*)pFrame->m_strODBCDSN);
- pFrame->OnExceptionClear(e);
- }
- if(!m_ctrlList.GetItemCount())
- {
- GetDlgItem(IDOK)->EnableWindow(FALSE);
- GetDlgItem(IDCANCEL)->SetWindowText(_T("&Close"));
- }
- return bRet;
- }
- void CProceduresDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CWaitCursor wait;
- if(GetDlgItem(IDOK)->IsWindowEnabled())
- OnOK();
- *pResult = 0;
- }
- void CProceduresDlg::OnOK()
- {
- CWaitCursor wait;
- m_strProcedureName = m_ctrlList.GetItemText(m_nSelectedItem, 0);
- CDialog::OnOK();
- }
- void CProceduresDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- if(pNMListView->uNewState)
- m_nSelectedItem = pNMListView->iItem;
- *pResult = 0;
- }
- void CProceduresDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CWaitCursor wait;
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- CSortColumn sort(&m_ctrlList, pNMListView->iSubItem, false);
- sort.Sort(m_bSort = !m_bSort);
- m_nSelectedItem = m_ctrlList.GetNextItem(-1, LVNI_SELECTED);
- *pResult = 0;
- }
- BOOL CProceduresDlg::PopulateListTheNativeWay(const CString& sSQL)
- {
- CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
- ASSERT(pFrame);
- BOOL bRet = FALSE;
- try
- {
- CRecordsetEx set(&pFrame->m_database);
- bRet = set.ExecDirect(sSQL);
- if(bRet)
- {
- CString sBuff;
- while(!set.IsEOF())
- {
- set.GetFieldValue((short)0, sBuff);
- if(sBuff.Find(' ') != -1)
- sBuff = "[" + sBuff + "]";
- CHelpers::Insert(&m_ctrlList, sBuff+"|");
- set.MoveNext();
- }
- m_ctrlList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED,
- LVIS_SELECTED | LVIS_FOCUSED);
- }
- }
- catch(CDBException* e)
- {
- if(e)
- {
- CString sMsg;
- if(!e->m_strError.IsEmpty())
- sMsg.Format("%s%s", (LPCTSTR)e->m_strError, (LPCTSTR)e->m_strStateNativeOrigin);
- else
- sMsg = e->m_strStateNativeOrigin;
- e->Delete();
- pFrame->m_strStatusText.Format("CDBException::m_nRetCode: %dn", e->m_nRetCode);
- pFrame->OnExceptionClear(sMsg);
- }
- }
- catch(CMemoryException* e)
- {
- pFrame->m_strStatusText = "Out-of-memory.";
- pFrame->OnExceptionClear(pFrame->m_strStatusText);
- if(e)
- e->Delete();
- }
- if(!m_ctrlList.GetItemCount())
- {
- GetDlgItem(IDOK)->EnableWindow(FALSE);
- GetDlgItem(IDCANCEL)->SetWindowText(_T("&Close"));
- }
- return bRet;
- }
- void CProceduresDlg::OnChangeSearch()
- {
- UpdateData(TRUE);
- LVFINDINFO findInfo;
- findInfo.flags = LVFI_PARTIAL | LVFI_STRING;
- findInfo.psz = (LPCTSTR)m_strSearch;
- int nItem = m_ctrlList.FindItem(&findInfo);
- m_ctrlList.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
- m_ctrlList.EnsureVisible(nItem, TRUE);
- }