📄 homeresdlg.cpp
字号:
// HomeResDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HomeRes.h"
#include "HomeResDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CHomeResDlg dialog
CHomeResDlg::CHomeResDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHomeResDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHomeResDlg)
m_nHandler = -1;
m_strContent = _T("(无内容)");
m_fMoney = 0.0f;
m_nType = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pConnection = NULL;
m_lCurID = 0;
}
void CHomeResDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHomeResDlg)
DDX_Control(pDX, IDC_LIST_RESULT, m_ResList);
DDX_Control(pDX, IDC_TREE_BUDGET, m_Tree);
DDX_Control(pDX, IDC_DATETIMEPICKER_TO, m_DateTo);
DDX_Control(pDX, IDC_DATETIMEPICKER_FROM, m_DateFrom);
DDX_Control(pDX, IDC_COMBO_ANATYPE, m_cobAnaType);
DDX_Control(pDX, IDC_COMBO_ANAHANDLER, m_cobAnaHandler);
DDX_Control(pDX, IDC_DATETIMEPICKER_DATE, m_Date);
DDX_Control(pDX, IDC_COMBO_TYPE, m_cobType);
DDX_Control(pDX, IDC_COMBO_HANDLE, m_cobHandle);
DDX_CBIndex(pDX, IDC_COMBO_HANDLE, m_nHandler);
DDX_Text(pDX, IDC_EDIT_CONTENT, m_strContent);
DDX_Text(pDX, IDC_EDIT_MONEY, m_fMoney);
DDX_CBIndex(pDX, IDC_COMBO_TYPE, m_nType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHomeResDlg, CDialog)
//{{AFX_MSG_MAP(CHomeResDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BTN_MODIFY, OnBtnModify)
ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
ON_BN_CLICKED(IDC_BTN_ANA, OnBtnAna)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_BUDGET, OnSelchangedTreeBudget)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHomeResDlg message handlers
BOOL CHomeResDlg::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
//
m_cobAnaType.AddString("全部类型");
m_cobAnaHandler.AddString("全部人");
m_cobAnaType.SetCurSel(0);
m_cobAnaHandler.SetCurSel(0);
GetSystemTime(&m_CurTime);
m_CurTime.wDay = 1;
m_DateFrom.SetTime(&m_CurTime);
m_CurTime.wMonth += 1;
m_DateTo.SetTime(&m_CurTime);
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些意想不到的错误。jingzhou xu
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Home.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
return FALSE;
}
//从数据库中读入经手人名单和类型名单
_RecordsetPtr pHandlerRecordset;
pHandlerRecordset.CreateInstance(__uuidof(Recordset));
try
{
pHandlerRecordset->Open("SELECT * FROM Handler", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
_variant_t var;
CString strName;
while(!pHandlerRecordset->adoEOF)
{
var = pHandlerRecordset->GetCollect("Handler");
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
m_cobHandle.AddString(strName);
m_cobAnaHandler.AddString(strName);
pHandlerRecordset->MoveNext();
}
pHandlerRecordset->Close();
pHandlerRecordset.Release();
pHandlerRecordset = NULL;
//////////////////////////////////////////////////////////////////////////
CString strType;
_RecordsetPtr pTypeRecordset;
pTypeRecordset.CreateInstance(__uuidof(Recordset));
try
{
pTypeRecordset->Open("SELECT * FROM Type", // 查询DemoTable表中所有字段
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
while(!pTypeRecordset->adoEOF)
{
var = pTypeRecordset->GetCollect("Type");
if(var.vt != VT_NULL)
strType = (LPCSTR)_bstr_t(var);
m_cobType.AddString(strType);
m_cobAnaType.AddString(strType);
pTypeRecordset->MoveNext();
}
pTypeRecordset->Close();
pTypeRecordset.Release();
pTypeRecordset = NULL;
//读入当月的记录
//
CTime Today = CTime::GetCurrentTime();
Load(Today.GetMonth(),Today.GetMonth() + 1);
m_nHandler = 0;
m_nType = 0;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CHomeResDlg::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 CHomeResDlg::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 CHomeResDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -