⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paymanagedlg.cpp

📁 家庭财务管理系统
💻 CPP
字号:
// PayManageDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Money.h"
#include "PayManageDlg.h"
#include "COMDEF.H"
#include "Column.h"
#include "Columns.h"
#include "PayOut.h"
#include "_recordset.h"
#include "LoginDlg.h"
#include "Users.h"
#include "PayModiDlg.h"
#include "PayAddDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPayManageDlg dialog


CPayManageDlg::CPayManageDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPayManageDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPayManageDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPayManageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPayManageDlg)
	DDX_Control(pDX, IDC_ADODC1, m_adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPayManageDlg, CDialog)
	//{{AFX_MSG_MAP(CPayManageDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
	ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPayManageDlg message handlers

void CPayManageDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	OnOK();
	CDialog::OnCancel();
}

//刷新数据
void CPayManageDlg::RefreshData()
{
	//设置记录源
	CString cSource;
	cSource = "SELECT PayIndex AS 代码,UserName AS 用户名,DateTime AS 时间,UserMoney AS 金额,MoneyType AS 说明"
		" FROM PayOut "
		" ORDER BY UserName,DateTime";

	m_adodc.SetRecordSource(cSource);
	m_adodc.Refresh();
	//设置表格列宽度
	_variant_t vIndex;
	vIndex = long(0);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(30);
	vIndex = long(1);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(3);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(4);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(300);

}

void CPayManageDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	CPayAddDlg dlg;
	dlg.DoModal();
	RefreshData();
}

void CPayManageDlg::OnDelButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if (m_adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要修改的记录");
		return;
	}
	if (MessageBox("是否删除当前记录","请确认!", MB_YESNO) == IDYES)
	{
		CPayOut pay;
		pay.sql_delete(m_datagrid.GetItem(0));
		RefreshData();
	}
}

void CPayManageDlg::OnModiButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CPayModiDlg dlg;
	CPayOut pay;
	dlg.m_PayIndex = atoi(Index);
	dlg.m_UserName = Name;
	dlg.m_DateTime = Date;
	dlg.m_UserMoney = atoi(Money);
	dlg.m_MoneyType = Type;
	if (dlg.DoModal() == IDOK)
		RefreshData();
}

BEGIN_EVENTSINK_MAP(CPayManageDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CPayManageDlg)
	ON_EVENT(CPayManageDlg, IDC_DATAGRID1, -601 /* DblClick */, OnDblClickDatagrid1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

BOOL CPayManageDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	RefreshData();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPayManageDlg::OnDblClickDatagrid1() 
{
	// TODO: Add your control notification handler code here
	if(m_adodc.GetRecordset().GetEof())
	{
		MessageBox("请选择数据行!");
		return;
	}
	
	Index=m_datagrid.GetItem(0);
	Name=m_datagrid.GetItem(1);
	Date=m_datagrid.GetItem(2);
	Money=m_datagrid.GetItem(3);
	Type=m_datagrid.GetItem(4);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -