📄 ydata11dlg.cpp
字号:
// Ydata11Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Ydata11.h"
#include "Ydata11Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYdata11Dlg dialog
CYdata11Dlg::CYdata11Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CYdata11Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CYdata11Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
bS=0;
}
void CYdata11Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CYdata11Dlg)
DDX_Control(pDX, IDC_COMBO1, m_list2);
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CYdata11Dlg, CDialog)
//{{AFX_MSG_MAP(CYdata11Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_READ, OnRead)
ON_BN_CLICKED(IDC_WRITE, OnWrite)
ON_BN_CLICKED(IDC_READOBDC, OnReadobdc)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_CBN_SELENDOK(IDC_COMBO1, OnSelendokCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYdata11Dlg message handlers
BOOL CYdata11Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CYdata11Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CYdata11Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CYdata11Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CYdata11Dlg::OnRead()
{ CFileDialog dlg(1,".mdb","*.mdb");
if(dlg.DoModal()!=IDOK)return;
if(m_db.IsOpen())
{m_db.Close(); m_set->Close();
}
m_list.ResetContent();
m_list2.ResetContent();
m_db.Open(dlg.GetPathName());
/* CFileFind file;
CString strFile=dlg.GetPathName();
if(file.FindFile(strFile)) {m_db.Open(strFile);}
else {m_db.Create(strFile);
m_db.Execute("CREATE TABLE YZC(Name VARCHAR(20),AGE VARCHAR(2))",0);
m_set=new CDaoRecordset(&m_db);
m_set->Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM YZC",NULL);
m_db.Execute("INSERT INTO YZC(NAME,AGE) VALUES('XX','20')");
this->OnWrite();
}*/
//CDaoTableDef m_tb(&m_db);
//CDaoIndexInfo m_info;
CDaoTableDefInfo m_info;
CString str;
m_list2.ResetContent();
int num=m_db.GetTableDefCount();
int x=0;
for(int j=4;j<num;j++)
{m_db.GetTableDefInfo(j,m_info);
str=m_info.m_strName ;
m_list2.InsertString(x,str);
x++;
}
m_list2.SetCurSel(0);
bS=1;
}
void CYdata11Dlg::OnCancel()
{ if(m_db.IsOpen())
{
m_db.Close();
m_set->Close();
delete m_set;}
CDialog::OnCancel();
}
void CYdata11Dlg::OnWrite()
{ if(!m_db.IsOpen())return;
m_set->AddNew();
m_set->SetFieldValue(0,"测试");
//m_set->SetFieldValue(,"写入");
m_set->Update();
}
void CYdata11Dlg::OnReadobdc()
{this->BeginWaitCursor();
if(m_db.IsOpen())
{m_db.Close(); m_set->Close();
}
m_list.ResetContent();
m_db.Open("",FALSE,FALSE,_T("ODBC;"));
CDaoTableDefInfo m_info;
CString str;
m_list2.ResetContent();
int num=m_db.GetTableDefCount();
for(int j=0;j<num;j++)
{m_db.GetTableDefInfo(j,m_info);
str=m_info.m_strName ;
m_list2.InsertString(j,str);
}
m_list2.SetCurSel(0);
this->EndWaitCursor();
bS=1;
}
void CYdata11Dlg::OnSelchangeCombo1()
{
}
void CYdata11Dlg::OnSelendokCombo1()
{if(!bS) return;
if(!m_db.IsOpen()) return;
CString strSql="SELECT * FROM ";
CString str1,str;
m_list2.GetWindowText(str1);
if(str1.IsEmpty()) return;
strSql+=str1;
try{
m_set=new CDaoRecordset(&m_db);
m_set->Open(AFX_DAO_USE_DEFAULT_TYPE,strSql,NULL);
m_list.ResetContent();
COleVariant var;
int i=0;
while(!m_set->IsEOF())
{ m_set->GetFieldValue(0,var);
switch(var.vt)
{ case VT_BSTR:
str=(LPCSTR)var.bstrVal;
break;
case VT_I2:
str.Format("%d",(int)var.iVal);
break;
case VT_I4:
str.Format("%d",(int)var.lVal) ;
break;
}
m_list.InsertString(i,str);
i++;
m_set->MoveNext();
}
}
catch(CDaoException *e)
{e->ReportError();
delete e;
bS=0;
return;
}
bS=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -