📄 lhpdlg.cpp
字号:
// lhpDlg.cpp : implementation file
//
#include "stdafx.h"
#include "lhp.h"
#include "lhpDlg.h"
#include "icrsint.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SAFE_CALL( expression ) { HRESULT hr; if ( FAILED(hr=expression) ) \
_com_issue_error( hr ); }
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// ClhpDlg dialog
ClhpDlg::ClhpDlg(CWnd* pParent /*=NULL*/)
: CDialog(ClhpDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(ClhpDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void ClhpDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ClhpDlg)
DDX_Control(pDX, IDC_LIST_SHOW, m_CtrListShow);
DDX_Control(pDX, IDC_LIST_RESULT, m_CtrListResult);
DDX_Control(pDX, IDC_COMBO_SEL, m_ComSel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ClhpDlg, CDialog)
//{{AFX_MSG_MAP(ClhpDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_COMBO_SEL, OnSelchangeComboSel)
ON_CBN_SELENDOK(IDC_COMBO_SEL, OnSelendokComboSel)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ClhpDlg message handlers
BOOL ClhpDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
_variant_t l_vaIndex,l_vaIndex1;
CString str,str1;
LPCSTR strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=lhp.mdb";
//创建 Connection 对象---------------------------
HRESULT hr = pConnection.CreateInstance("ADODB.Connection");
//设置连接时间-----------------------------------
pConnection->put_ConnectionTimeout(long(5));
if (SUCCEEDED(hr))
{
// 连接数据库---------------------------------------------
pConnection->Open(strConnect, "", "", adConnectUnspecified);
}
LPCSTR strSQL = "select * from FDb";
pRecordset.CreateInstance("ADODB.Recordset");
pRecordset->Open(_bstr_t(strSQL),
_variant_t((IDispatch*)pConnection, true),
adOpenStatic,
adLockReadOnly,
adCmdText);
strSQL = "select * from Rule";
pSetRule.CreateInstance("ADODB.Recordset");
pSetRule->Open(_bstr_t(strSQL),
_variant_t((IDispatch*)pConnection, true),
adOpenStatic,
adLockReadOnly,
adCmdText);
strSQL = "select * from MDb";
pSetMedium.CreateInstance("ADODB.Recordset");
pSetMedium->Open(_bstr_t(strSQL),
_variant_t((IDispatch*)pConnection, true),
adOpenStatic,
adLockReadOnly,
adCmdText);
pSetRule->MoveFirst();
l_vaIndex.vt = VT_I2;
l_vaIndex1.vt=VT_I2;
while (!pRecordset->adoEOF)
{
l_vaIndex1=pRecordset->GetCollect("Name");
str=(char*)_bstr_t(l_vaIndex1);
m_ComSel.AddString(str);
pRecordset->MoveNext();
}
strSQL="Delete * from MDb";
pConnection->Execute(_bstr_t(strSQL),NULL,1);
strSQL="Insert into MDb(premise,conclude,name) select premise,conclude,name from Rule";
pConnection->Execute(_bstr_t(strSQL),NULL,1);
// 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 ClhpDlg::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 ClhpDlg::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 ClhpDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void ClhpDlg::OnSelchangeComboSel()
{
// TODO: Add your control notification handler code here
}
void ClhpDlg::OnSelendokComboSel()
{
// TODO: Add your control notification handler code here
}
void ClhpDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
int n=m_CtrListResult.GetCount();
for(int i=n-1;i>=0;i--)
{
m_CtrListResult.DeleteString(i);
}
CString str;
CString strSQL;
_variant_t l_vaIndex;
_variant_t rec_affected;
// str="Delete from MDb";
// pConnection->Execute(_bstr_t(str),NULL,1);
m_ComSel.GetWindowText(str);
if(str.IsEmpty())
{
return;
}
m_CtrListShow.AddString(str);
strSQL.Format("select * from FDb where Name='%s'",str);
// AfxMessageBox(strSQL);
pRecordset=pConnection->Execute(bstr_t(strSQL),&rec_affected,0);
pRecordset->MoveFirst();
while (!pRecordset->adoEOF)
{
l_vaIndex=pRecordset->GetCollect("Ff");
str=(char*)_bstr_t(l_vaIndex);
// AfxMessageBox(str);
pRecordset->MoveNext();
//其实应该只有一个记录。这里也就这么处理了。
}
strSQL.Format("delete * from MDb where premise not like '%%%s%%'",str);
// pSetMedium->Filter=_bstr_t(strSQL);
// pSetMedium->Requery(0);
// AfxMessageBox(strSQL);
pConnection->Execute(_bstr_t(strSQL),NULL,1);
pSetMedium->Requery(1);
if(pSetMedium->adoEOF&&pSetMedium->BOF)
{
AfxMessageBox("条件相悖,不存在这样的动物!");
}
else
{
pSetMedium->MoveFirst();
while (!pSetMedium->adoEOF)
{
l_vaIndex=pSetMedium->GetCollect("premise");
str=(char*)_bstr_t(l_vaIndex);
// AfxMessageBox(str);
l_vaIndex=pSetMedium->GetCollect("Name");
str=(char*)_bstr_t(l_vaIndex);
m_CtrListResult.AddString(str);
// AfxMessageBox("s");
pSetMedium->MoveNext();
}
}
}
void ClhpDlg::OnButtonDel()
{
// TODO: Add your control notification handler code here
CString strSQL;
int n=m_CtrListShow.GetCount();
CString str;
for(int i=n-1;i>=0;i--)
{
str.Format("%d",i);
m_CtrListShow.DeleteString(i);
}
n=m_CtrListResult.GetCount();
for(i=n-1;i>=0;i--)
{
str.Format("%d",i);
m_CtrListResult.DeleteString(i);
}
strSQL="Delete * from MDb";
pConnection->Execute(_bstr_t(strSQL),NULL,1);
strSQL="Insert into MDb(premise,conclude,name) select premise,conclude,name from Rule";
pConnection->Execute(_bstr_t(strSQL),NULL,1);
}
void ClhpDlg::OnCancel()
{
// TODO: Add extra cleanup here
CString strSQL;
strSQL="Delete * from MDb";
pConnection->Execute(_bstr_t(strSQL),NULL,1);
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -