C + + Course Design -- family financial management system (MFC)

Lesson title

Family financial management system

Class setting requirements

  1. user management
  2. Member management
  3. Input, modification and deletion of daily income information
  4. Entry, modification and deletion of daily expenditure information
  5. Browse and query revenue and expense information of members
  6. Statistics of members' income and expenditure by month, quarter and year
  7. Data import and export

Program operation interface





Core code

Financial management pay.cpp

// pay.cpp : implementation file
//

#include "stdafx.h"
#include "family management system. h"
#include "pay.h"
#include"Cai.h"

#include <vector>
#include <ostream>
#include<fstream>
#include "iostream.h"
#include <string>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// pay dialog
class Studentx{
public:
	CString phone;
	CString name;

};

vector <Studentx>stu;
int m=-1;
pay::pay(CWnd* pParent /*=NULL*/)
	: CDialog(pay::IDD, pParent)
{
	//{{AFX_DATA_INIT(pay)
	//}}AFX_DATA_INIT
}


void pay::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(pay)
	DDX_Control(pDX, IDC_COMBO3, m_flag);
	DDX_Control(pDX, IDC_COMBO1, m_name);
	DDX_Control(pDX, IDC_LIST1, m_pay);
	//}}AFX_DATA_MAP
}
BOOL pay::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_pay.InsertColumn(0,"number",LVCFMT_CENTER,100);
	m_pay.InsertColumn(1,"Name",LVCFMT_CENTER,100);
	m_pay.InsertColumn(2,"category",LVCFMT_CENTER,100);
	m_pay.InsertColumn(3,"Price",LVCFMT_CENTER,100);
   	m_pay.InsertColumn(4,"income or expenditure",LVCFMT_CENTER,100);
	m_pay.InsertColumn(5,"Month",LVCFMT_CENTER,100);
	m_pay.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

 
	showname();
	ShowCai();

	m_name.SetCurSel(0);
    m_flag.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void pay::showname()
{
	
//	m_list.DeleteAllItems(); // Empty all 	
	ifstream fin("members.txt",ios_base::in); 
	string a,b;
	fin>>a>>b;
	for(int i=0;!fin.fail();++i){

		m_name.AddString(_T(a.data()));
       	rname=a.data();
	
		Studentx s1;
		
		s1.phone=a.data();
		s1.name=b.data();
		stu.reserve(stu.size()+1);//Increase capacity to prevent overflow

	stu.push_back(s1);
	fin>>a>>b;
	}
	fin.close();
}
void pay::ShowCai()
{
	m_pay.DeleteAllItems();
	int num=ReadCai();
	for(int i=0;i<num;i++)
	{
		m_pay.InsertItem(i,0);
		m_pay.SetItemText(i,0,cai[i].id);
		m_pay.SetItemText(i,1,cai[i].name);
		m_pay.SetItemText(i,2,cai[i].type);
		m_pay.SetItemText(i,3,cai[i].price);
		m_pay.SetItemText(i,4,cai[i].flag);
		m_pay.SetItemText(i,5,cai[i].time);
	}
}

int pay::ReadCai()
{
	CString txt_name;// Temporary file name
	txt_name=rname+".txt";
		MessageBox(txt_name);
	FILE *file=fopen(txt_name,"r");
	int a=0;
	while(!feof(file))
	{
		fscanf(file,"%s%s%s%s%s%s",&cai[a].id,&cai[a].name,&cai[a].type,&cai[a].price,&cai[a].flag,&cai[a].time);
		a++;
	}
	fclose(file);
	a--;
	return a;
}


BEGIN_MESSAGE_MAP(pay, CDialog)
	//{{AFX_MSG_MAP(pay)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// pay message handlers

void pay::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CString txt_name;// Temporary file name
	txt_name=rname+".txt";
	CString time; //get SysTime
	CTime tm; tm=CTime::GetCurrentTime();
	//time=tm.Format("%Y-%m-%d");

	time=tm.Format("%m");

		CString id,name,type,price,flag;// flag is input or expenditure
	GetDlgItem(IDC_EDIT1)->GetWindowText(id);
	GetDlgItem(IDC_EDIT3)->GetWindowText(name);
	GetDlgItem(IDC_EDIT2)->GetWindowText(price);
	GetDlgItem(IDC_COMBO2)->GetWindowText(type);
    GetDlgItem(IDC_COMBO3)->GetWindowText(flag);

	if(id==""||name==""||price==""||type=="")
	{
		MessageBox("Add information cannot be empty");
		return;
	}
	
	FILE *file=fopen(txt_name,"a+");
	fprintf(file,"%s   %s   %s   %s   %s   %s\r\n",id,name,type,price,flag,time);
	fclose(file);	
	MessageBox("Add success");
	ShowCai();
}

void pay::OnButton5() 
{
		CString txt_name;// Temporary file name
	txt_name=rname+".txt";

	// TODO: Add your control notification handler code here
		CString id,name,type,price,flag;
	GetDlgItem(IDC_EDIT1)->GetWindowText(id);
	GetDlgItem(IDC_EDIT3)->GetWindowText(name);
	GetDlgItem(IDC_EDIT2)->GetWindowText(price);
	GetDlgItem(IDC_COMBO2)->GetWindowText(type);
GetDlgItem(IDC_COMBO3)->GetWindowText(flag);

	if(id==""||name==""||price==""||type=="")
	{
		MessageBox("Modification information cannot be empty");
		return;
	}
	int num=ReadCai();
	FILE *file=fopen(txt_name,"w");	
	for(int i=0;i<num;i++)
	{
		if(strcmp(id,cai[i].id)==0)
		{
			strcpy(cai[i].name,name);
			strcpy(cai[i].type,type);
			strcpy(cai[i].price,price);
            	strcpy(cai[i].flag,flag);

		}
		fprintf(file,"%s   %s   %s   %s   %s   %s\r\n",cai[i].id,cai[i].name\
			,cai[i].type,cai[i].price,cai[i].flag,cai[i].time);
	}
	fclose(file);

	MessageBox("Modified success");
	ShowCai();
}

void pay::OnButton6() 
{	CString txt_name;// Temporary file name
	txt_name=rname+".txt";

	// TODO: Add your control notification handler code here
	int sel = m_pay.GetSelectionMark();
	if(sel ==-1)
	{
		MessageBox("Please select the dish information to be deleted first");
	}

	CString id=	m_pay.GetItemText(sel,0);
	int num=ReadCai();
	FILE *file=fopen(txt_name,"w+");

	for(int i=0;i<num;i++)
	{
		if(strcmp(id,cai[i].id)==0)  
			continue;
		fprintf(file,"%s   %s   %s   %s   %s   %s\r\n",cai[i].id,cai[i].name\
			,cai[i].type,cai[i].price,cai[i].flag,cai[i].time);
	}
	fclose(file);
	MessageBox("Delete successful","Tips");
	ShowCai();
}

void pay::OnButton7() 
{
	m_pay.DeleteAllItems();

	int index = m_name.GetCurSel();
 CString str_name;  
  CString strI;  
   m_name.GetLBText(index,str_name); 
   rname=str_name;
 	MessageBox(rname);
    	ShowCai();
	
}

void pay::OnButton8() 
{
	// TODO: Add your control notification handler code here
	if(MessageBox("Please save the information and exit!",NULL,MB_YESNO)==IDNO);
	else	CDialog::OnCancel();
}

155 original articles published, praised 103, visited 50000+
Private letter follow

Posted by ntroycondo on Sat, 08 Feb 2020 06:41:46 -0800