SELECTTABLE.CPP
上传用户:sygkzy
上传日期:2013-03-13
资源大小:150k
文件大小:3k
- // SelectTable.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ole_database.h"
- #include "SelectTable.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSelectTable dialog
- CSelectTable::CSelectTable(CWnd* pParent /*=NULL*/)
- : CDialog(CSelectTable::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSelectTable)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CSelectTable::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSelectTable)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSelectTable, CDialog)
- //{{AFX_MSG_MAP(CSelectTable)
- ON_LBN_SELCHANGE(IDC_TABLE, OnSelchangeTable)
- ON_EN_CHANGE(IDC_TABLENAME, OnChangeTablename)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSelectTable message handlers
- BOOL CSelectTable::OnInitDialog()
- {
- CDialog::OnInitDialog();
- OValue ovalue;
- CListBox *m_listbox=(CListBox*)GetDlgItem(IDC_TABLE);
- odyn.Open(odb," select table_name from user_tables");
- while(!odyn.IsEOF())
- {
- odyn.GetFieldValue("table_name",&ovalue);
- m_listbox->AddString(&(*ovalue));
- odyn.MoveNext();
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- CString CSelectTable::GetSql(CString m_tablename)
- {
- CString m_tmp,m_tmp2=" ";
- OValue ovalue;
- m_tmp="select column_name from user_tab_columns where table_name='"+m_tablename+"'";
- m_tablename=" ";
- odyn.Open(odb,m_tmp);
- while(!odyn.IsEOF())
- {
- odyn.GetFieldValue("column_name",&ovalue);
- m_tablename=m_tablename+m_tmp2+&(*ovalue);
- m_tmp2=" , ";
- odyn.MoveNext();
- }
- return m_tablename;
- }
- void CSelectTable::OnOK()
- {
- CString m_tablename,m_tmp;
- CEdit *m_edit=(CEdit*)GetDlgItem(IDC_TABLENAME);
- CListBox *m_listbox=(CListBox*)GetDlgItem(IDC_TABLE);
- if(m_listbox->GetCurSel()>0)
- {
- m_listbox->GetText(m_listbox->GetCurSel(),m_tmp);
- m_edit->SetWindowText(m_tmp);
- }
- m_edit->GetWindowText(m_tablename);
- if(m_tablename.IsEmpty())
- {
- this->MessageBox("请选择表","提示",MB_OK);
- return;
- }
- m_sSql="SELECT"+GetSql(m_tablename)+" FROM "+m_tablename;
- CDialog::OnOK();
- }
- void CSelectTable::OnSelchangeTable()
- {
- CString m_tmp;
- CEdit *m_edit=(CEdit*)GetDlgItem(IDC_TABLENAME);
- CListBox *m_listbox=(CListBox*)GetDlgItem(IDC_TABLE);
- if(m_listbox->GetCurSel()>0)
- {
- m_listbox->GetText(m_listbox->GetCurSel(),m_tmp);
- m_edit->SetWindowText(m_tmp);
- }
- }
- void CSelectTable::OnChangeTablename()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function and call CRichEditCtrl().SetEventMask()
- // with the ENM_CHANGE flag ORed into the mask.
- CString m_tmp;
- int m_i;
- CEdit *m_edit=(CEdit*)GetDlgItem(IDC_TABLENAME);
- CListBox *m_listbox=(CListBox*)GetDlgItem(IDC_TABLE);
- m_edit->GetWindowText(m_tmp);
- m_i=m_listbox->FindString(0,m_tmp);
- if(m_i>0)
- m_listbox->SetCurSel(m_i);
- }