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

📄 dialogrecord.cpp

📁 C++的课程设计
💻 CPP
字号:
// DialogRecord.cpp : implementation file
//

#include "stdafx.h"
#include "HomeFinanceManager.h"
#include "DialogRecord.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogRecord dialog


CDialogRecord::CDialogRecord(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogRecord::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogRecord)
	m_strUser = _T("");
	m_strClass = _T("");
	m_timeRecord = 0;
	m_strID = _T("");
	m_strRemark = _T("");
	m_strSum = _T("");
	//}}AFX_DATA_INIT
	m_bIsMoneyIn = false;
}


void CDialogRecord::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogRecord)
	DDX_Control(pDX, IDC_UPDATERECORD, m_btnUpdateRecord);
	DDX_Control(pDX, IDC_DELRECORD, m_btnDelRecord);
	DDX_Text(pDX, IDC_OPERATOR, m_strUser);
	DDX_CBString(pDX, IDC_RECORD_CLASS, m_strClass);
	DDX_DateTimeCtrl(pDX, IDC_RECORD_DATE, m_timeRecord);
	DDX_Text(pDX, IDC_RECORD_ID, m_strID);
	DDX_Text(pDX, IDC_RECORD_REMARK, m_strRemark);
	DDX_Text(pDX, IDC_RECORD_SUM, m_strSum);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogRecord, CDialog)
	//{{AFX_MSG_MAP(CDialogRecord)
	ON_BN_CLICKED(IDC_DELRECORD, OnDelrecord)
	ON_BN_CLICKED(IDC_UPDATERECORD, OnUpdaterecord)
	ON_WM_ERASEBKGND() 
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogRecord message handlers
BOOL CDialogRecord::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_RECORD_CLASS);
	pComboBox->Clear();
	for(int i = 0; i < m_ClassInfo.m_iClassNum; i++)
	{
		pComboBox->InsertString(-1, m_ClassInfo.m_Classes[i]);
	}
	
	if(m_bIsMoneyIn)
	{
		SetWindowText("收入记录窗口");
	}
	else
	{
		SetWindowText("支出记录窗口");
	}
	
	return TRUE;
}

//---------------------------------------------------------------------------

void	CDialogRecord::setRecordInfo(char* strID, 
									char* strSum, 
									char* strOperator, 
									char* strClass, 
									char* strDate,
									char* strRemark,
									CSysDataStruct::CClassInfo& ClassInfo)
{
	m_strClass = CString(strClass);
	m_strID = CString(strID);
	m_strUser= CString(strOperator);
	m_strRemark = CString(strRemark);
	m_strSum = CString(strSum);
	
	int iYear, iMonth, iDay;
	char strTemp[100];
	strcpy(strTemp, strDate);
	char* pChar = strTemp;
	while((*pChar++) != '-') {};
	*(--pChar) = '\0';
	iYear = atoi(strDate);
	
    char* pcMonth = ++pChar;
	while((*pChar++) != '-') {};
	*(--pChar) = '\0';
	iMonth = atoi(pcMonth);
	
	char* pcDay = ++pChar;
	iDay = atoi(pcDay);

	pChar = 0;
	
	CTime TempTime(iYear, iMonth, iDay, 0, 0, 0);
	m_timeRecord = TempTime;
	
	m_ClassInfo.m_iClassNum = ClassInfo.m_iClassNum;
	for(int i = 0; i < m_ClassInfo.m_iClassNum; i++)
	{
		m_ClassInfo.m_Classes[i] = ClassInfo.m_Classes[i];
	}

	
}

//---------------------------------------------------------------------------

void	CDialogRecord::IsMoneyIn(bool bValue)
{
	m_bIsMoneyIn = bValue;
}
//---------------------------------------------------------------------------

void CDialogRecord::OnDelrecord() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);	
	if(m_bIsMoneyIn)
	{
		int iID = atoi(m_strID);
		gDBOperator.DeleteFinanceIn(iID);		
	}
	else
	{
		int iID = atoi(m_strID);
		gDBOperator.DeleteFinanceOut(iID);		
	}	
}
//---------------------------------------------------------------------------

void CDialogRecord::OnUpdaterecord() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(TRUE);
	CString strDate;
	int iYear = m_timeRecord.GetYear();
	int iMonth = m_timeRecord.GetMonth();
	int iDay = m_timeRecord.GetDay();
	
	int iID = atoi(m_strID.GetBuffer(0));	
	
	strDate.Format("%d-%d-%d", iYear, iMonth, iDay);
	gDBOperator.UpdateRecord(iID, m_strSum, m_strClass, strDate, m_strRemark, !m_bIsMoneyIn);
	
}
//---------------------------------------------------------------------------

BOOL CDialogRecord::OnEraseBkgnd( CDC* pDC )
{
	RECT rcClient;
	this->GetClientRect(&rcClient);
	HBRUSH hOldBrush;
	HBRUSH hBrush = ::CreateSolidBrush(RGB(213, 247, 209));
	hOldBrush = (HBRUSH)pDC->SelectObject(hBrush);
	pDC->Rectangle(&rcClient);
	pDC->SelectObject(hOldBrush);
	
	::DeleteObject(hBrush);
	return TRUE;
}
//---------------------------------------------------------------------------

HBRUSH CDialogRecord::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	//改变控件的颜色
	if(nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0,0,0));
		
		LOGBRUSH  logBrush;
		logBrush.lbStyle = BS_HOLLOW;
		hbr = CreateBrushIndirect(&logBrush);
	}
	if(nCtlColor == CTLCOLOR_EDIT)
	{
		pDC->SetTextColor(RGB(255,0,0));//字体色
		//pDC->SetBkColor(RGB(170, 243, 162));
	}
	
	return hbr;
}

⌨️ 快捷键说明

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