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

📄 adddlg.cpp

📁 Family Financial Management System是一个特别方便的理财系统。功能方便实用。
💻 CPP
字号:
// AddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FFManage.h"
#include "AddDlg.h"
#include "TypeDlg.h"
#include "ListDlg.h"

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

extern CRecordset g_Recordset;	
extern CDatabase  g_Database;
extern int        g_iType;


extern int Encrypt(const CString passwd, const char key, CString & resPasswd);
extern int Decrypt(const CString passwd, const char key, CString & resPasswd);



/////////////////////////////////////////////////////////////////////////////
// CAddDlg dialog


CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddDlg)
	m_iRadSel = 0;
	m_strCmbType = _T("");
	m_fMoney = 0.0f;
	m_strDescribe = _T("");
	m_oleDate = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	m_strSQL = _T("");
	m_strFID = _T("");
	m_strDateLimit = _T("");
}


void CAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddDlg)
	DDX_Control(pDX, IDC_CMB_Type, m_ctlCmbType);
	DDX_Control(pDX, IDC_BTN_Type, m_btnType);
	DDX_Radio(pDX, IDC_RAD0, m_iRadSel);
	DDX_CBString(pDX, IDC_CMB_Type, m_strCmbType);
	DDV_MaxChars(pDX, m_strCmbType, 100);
	DDX_Text(pDX, IDC_EDIT_Money, m_fMoney);
	DDV_MinMaxFloat(pDX, m_fMoney, 0.f, 65535.f);
	DDX_Text(pDX, IDC_EDIT_Describe, m_strDescribe);
	DDX_DateTimeCtrl(pDX, IDC_DatePicker, m_oleDate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddDlg, CDialog)
	//{{AFX_MSG_MAP(CAddDlg)
	ON_BN_CLICKED(IDC_BTN_Type, OnBTNType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddDlg message handlers

BOOL CAddDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	GetDlgItem(IDC_RAD0)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_RAD1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_RAD2)->ShowWindow(SW_HIDE);

	switch(g_iType)
	{
	case TYPE_Out:
		if(m_strFID.IsEmpty())
		{
			SetWindowText("增加 “开支” 记录");
		}
		else
		{
			SetWindowText("修改 “开支” 记录");
		}		
		break;
	case TYPE_Event:
		if(m_strFID.IsEmpty())
		{
			SetWindowText("增加 “记事” 记录");	
		}
		else
		{
			SetWindowText("修改 “记事” 记录");	
		}
		m_fMoney = 1;
		GetDlgItem(IDC_STA_Money)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_EDIT_Money)->ShowWindow(SW_HIDE);	
		break;
	case TYPE_In:
		if(m_strFID.IsEmpty())
		{
			SetWindowText("增加 “收入” 记录");
		}
		else
		{
			SetWindowText("修改 “收入” 记录");
		}
		break;
	case TYPE_Save:
		SetWindowText("增加 “储蓄” 记录");	
				
		GetDlgItem(IDC_RAD0)->ShowWindow(SW_SHOW);
		GetDlgItem(IDC_RAD1)->ShowWindow(SW_SHOW);

		GetDlgItem(IDC_RAD0)->SetWindowText("支取");
		GetDlgItem(IDC_RAD1)->SetWindowText("存入");
		m_strCmbType = "储蓄记录";
	//	dStyle =  m_ctlCmbType.GetStyle();	
	//	m_ctlCmbType.ModifyStyle(CBS_DROPDOWN,CBS_DROPDOWNLIST,1); 
	
		GetDlgItem(IDC_BTN_Type)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_CMB_Type)->ShowWindow(SW_HIDE);	
	
		break;
	case TYPE_Dac:
		if(m_strFID.IsEmpty())
		{
			SetWindowText("增加 “借贷” 记录");
		}
		else
		{
			SetWindowText("修改 “借贷” 记录");
		}
		GetDlgItem(IDC_RAD0)->ShowWindow(SW_SHOW);
		GetDlgItem(IDC_RAD1)->ShowWindow(SW_SHOW);
		if(!m_strFID.IsEmpty())
		{
			GetDlgItem(IDC_RAD2)->ShowWindow(SW_SHOW);
		}		
		GetDlgItem(IDC_RAD0)->SetWindowText("借");
		GetDlgItem(IDC_RAD1)->SetWindowText("贷");
		GetDlgItem(IDC_RAD2)->SetWindowText("清");
		SetDlgItemText(IDC_BTN_Kind, "对方:");			
		break;
	default:
		break;
	}

	InitListCmb();
	
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}



void CAddDlg::InitListCmb(void)
{
	
	while(m_ctlCmbType.DeleteString(0) != CB_ERR );
	CString strTemp;
	m_strSQL.Format("select FValue from TListCmb where FType = %d Order by FValue",g_iType);
	if(g_Recordset.IsOpen())g_Recordset.Close();
	g_Recordset.Open(CRecordset::forwardOnly, m_strSQL, CRecordset::readOnly);
	while( !g_Recordset.IsEOF())
	{
		g_Recordset.GetFieldValue((short)0,strTemp);		
		m_ctlCmbType.AddString(strTemp);
    	g_Recordset.MoveNext();			
	}
	g_Recordset.Close();  
}

void CAddDlg::OnBTNType() 
{
	CTypeDlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		InitListCmb();	
		m_ctlCmbType.SelectString(-1, dlg.m_strSel);	
	}	
}

void CAddDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	if(m_fMoney < 0.001)
	{
		AfxMessageBox("请输入金额数字! ");
		GetDlgItem(IDC_EDIT_Money)->SetFocus();
		return;
	}
	if(m_strCmbType.IsEmpty())
	{
		if(g_iType == TYPE_Dac)
		{
			AfxMessageBox("请输入或选择借贷对方! ");
		}
		else
		{
			AfxMessageBox("请输入或选择种类! ");
		}
		
		GetDlgItem(IDC_CMB_Type)->SetFocus();
		return;
	}
	
	CString strTemp;
	CString strDate = m_oleDate.Format("%Y年%m月%d日");
	if(!m_strDateLimit.IsEmpty())
	{
		if(strDate < m_strDateLimit)
		{
			strTemp.Format("选择的时间不能小于 %s",m_strDateLimit);			
			AfxMessageBox(strTemp);
			return;
		}
	}

	switch(g_iType)
	{
	case TYPE_Out:
		if(m_strFID.IsEmpty())
		{
			m_strSQL.Format("Insert into TOut(FDate, FTypeValue, FMoney,FDescribe) values ('%s','%s', %.2f,'%s')",strDate,m_strCmbType,m_fMoney,m_strDescribe);	
		}
		else
		{
			m_strSQL.Format("Update TOut Set FDate='%s',FTypeValue='%s',FMoney=%.2f,FDescribe='%s' where FID=%s",strDate,m_strCmbType,m_fMoney,m_strDescribe,m_strFID);	
		}		
		break;
	case TYPE_Event:
		if(m_strFID.IsEmpty())
		{
			m_strSQL.Format("Insert into TEvent(FDate, FTypeValue,FDescribe) values ('%s','%s','%s')",strDate,m_strCmbType,m_strDescribe);	
		}
		else
		{
			m_strSQL.Format("Update TEvent Set FDate='%s',FTypeValue='%s',FDescribe='%s' where FID=%s",strDate,m_strCmbType,m_strDescribe,m_strFID);	
		}		
		break;
	case TYPE_In:
		if(m_strFID.IsEmpty())
		{
			m_strSQL.Format("Insert into TIn(FDate, FTypeValue, FMoney,FDescribe) values ('%s','%s', %.2f,'%s')",strDate,m_strCmbType,m_fMoney,m_strDescribe);	
		}
		else
		{
			m_strSQL.Format("Update TIn Set FDate='%s',FTypeValue='%s',FMoney=%.2f,FDescribe='%s' where FID=%s",strDate,m_strCmbType,m_fMoney,m_strDescribe,m_strFID);	
		}
		break;
	case TYPE_Save:
		{
			if(m_strFID.IsEmpty())
			{
				AfxMessageBox("错误!m_strFID 为空!");
				return;
			}
			float  fOldMoney = 0;
			float  fOutMoney = 0;
			float  fInMoney  = 0;
			float  fBalance  = 0;
			CString strMoney;
			m_strSQL.Format("Select FMoney from TBankBook Where FID = %s",m_strFID);
			if(g_Recordset.IsOpen())g_Recordset.Close();
			g_Recordset.Open(CRecordset::forwardOnly,m_strSQL,CRecordset::readOnly);
			if( !g_Recordset.IsEOF() )
			{
				g_Recordset.GetFieldValue((short)0,strTemp);
				Decrypt(strTemp,PWDKEY,strMoney);
				fOldMoney = (float)atof(strMoney);
			}
			g_Recordset.Close();
		
			if(m_iRadSel == 0)  //支取
			{
				fOutMoney = m_fMoney;
				fBalance  = fOldMoney - fOutMoney;
			}
			else if(m_iRadSel == 1)  //存入
			{
				fInMoney  = m_fMoney;
				fBalance  = fOldMoney + fInMoney;
			}
			strTemp.Format("%.2f",fBalance);
			Encrypt(strTemp,PWDKEY,strMoney);
			m_strSQL.Format("Update TBankBook Set FMoney='%s' where FID=%s ",strMoney,m_strFID);	
			g_Database.ExecuteSQL(m_strSQL);
			m_strSQL.Format("Insert into TSave(FBankBookID, FDate,FOutMoney,FInMoney,FBalance,FDescribe) values (%s,'%s', %.2f,%.2f,%.2f,'%s')",m_strFID,strDate,fOutMoney,fInMoney, fBalance,m_strDescribe);	
		}
		break;
	case TYPE_Dac:
		if(m_iRadSel == 0)
		{
			strTemp = "借";
		}
		else if(m_iRadSel == 1)
		{
			strTemp = "贷";
		}
		else if(m_iRadSel == 2)
		{
			strTemp = "清";
		}
		if(m_strFID.IsEmpty())
		{
			m_strSQL.Format("Insert into TDac(FDate, FTypeValue, FDac,FMoney,FDescribe) values ('%s','%s', '%s',%.2f,'%s')",strDate,m_strCmbType,strTemp, m_fMoney,m_strDescribe);	
		}
		else
		{
			m_strSQL.Format("Update TDac Set FDate='%s',FTypeValue='%s',FDac= '%s',FMoney=%.2f,FDescribe='%s' where FID=%s",strDate,m_strCmbType,strTemp,m_fMoney,m_strDescribe,m_strFID);	
		}
		break;
	default:
		CDialog::OnOK();
		return;
		break;
	}
//	AfxMessageBox(m_strSQL);
	if(!m_strSQL.IsEmpty())
	{
		try
		{
			g_Database.ExecuteSQL(m_strSQL);
		}
		catch(...)
		{
			AfxMessageBox("错误! " + m_strSQL);			
		}
	}
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

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