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

📄 manage.cpp

📁 这是一个用VC++编写的银行定期储蓄管理系统
💻 CPP
字号:
// MANAGE.cpp: implementation of the MANAGE class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "银行系统.h"
#include "MANAGE.h"

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

#include <fstream.h>
#include <iomanip.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//序列化宏定义
IMPLEMENT_SERIAL(MANAGE,CObject,1)

//////////////////////////////////////////////////////////////////////
//构造函数,析构函数
//////////////////////////////////////////////////////////////////////
//——————————————————————————————————
MANAGE::MANAGE()
{
	waiter[0].name = "李桂兰        0001";
	waiter[1].name = "高倩        0002";
	waiter[2].name = "张三          0003";
	waiter[3].name = "周周            0004";
	waiter[4].name = "李斯     0005";
	isfirstload=true;
	isfirstsave=true;
}

//——————————————————————————————————
MANAGE::~MANAGE()
{
    CUSTOMER::DelAll();
}

//////////////////////////////////////////////////////////////////////
//用户操作
//////////////////////////////////////////////////////////////////////
//——————————————————————————————————
CUSTOMER *MANAGE::CreateCustomer(CString nname,long npassword,CString naddress,
								 int ntype,double nbase,time_t nindate)
{
	CUSTOMER *pivort;
	POSITION position;
	pivort = new CUSTOMER(nname,npassword,naddress,ntype,nbase,nindate);
	if(!pivort) return NULL;
	position = MyDoc->customerlist.AddTail(*pivort);
	return pivort;
}//如果返回NULL表示未能分配到对内存。
 //返回的指针指向刚刚创建的结点。

//——————————————————————————————————
ISEXIST *MANAGE::CreateIsexist(/*long account*/)
{
	ISEXIST *pivort;
	POSITION position;
	pivort = new ISEXIST(/*account*/);
	if(!pivort) return NULL;
	position = MyDoc->isexistlist.AddTail(*pivort);
	return pivort;
}//如果返回NULL表示未能分配到对内存。
 //返回的指针指向刚刚创建结点的ISEXIST指针。

//////////////////////////////////////////////////////////////////////
//文件操作
//////////////////////////////////////////////////////////////////////
//——————————————————————————————————
void MANAGE::CreateSaveDoc()
{
	ofstream out("SAVE.fac",ios::trunc);
	out <<setiosflags(ios::left);
	out <<setw(5) <<"账号" <<setw(15) <<"储户姓名" <<setw(7) <<"密码"
		<<setw(30) <<"储户地址" <<setw(6) <<"储种" <<setw(10) <<"本金"
		<<setw(16) <<"收储日期" <<setw(5) <<"挂失" <<setw(16) <<"挂失日期"
		<<setw(15) <<"收银员" <<setw(5) <<"工号" <<endl;
	out.close();
}

//——————————————————————————————————
void MANAGE::CreateLoadDoc()
{
	ofstream out("LOAD.fac");
	out <<setiosflags(ios::left);
	out <<setw(5) <<"账号" <<setw(15) <<"储户姓名" <<setw(7) <<"密码"
		<<setw(30) <<"储户地址" <<setw(6) <<"储种" <<setw(10) <<"本金"
		<<setw(16) <<"收储日期" <<setw(5) <<"挂失" <<setw(16) <<"挂失日期"
		<<setw(10) <<"取款金额" <<setw(16) <<"取款日期" 
		<<setw(15) <<"收银员" <<setw(5) <<"工号" <<endl;
	out.close();
}

//——————————————————————————————————
void MANAGE::WriteSaveDoc(CUSTOMER c,CString wname)
{
    ofstream out("SAVE.fac",ios::ate);
    out <<setiosflags(ios::left) <<setprecision(2) <<setiosflags(ios::fixed);
	CTime a = c.GetIndate();
	CTime b = c.GetMissdate();
	out <<setw(5) <<c.GetAccount()/*四位*/ <<setw(15) <<c.GetName()/*小于14个字符*/
		<<setw(7) <<c.Getpassword()/*6位*/ <<setw(30) <<c.GetAddress()/*小于29个字节*/
		<<setw(2) <<c.GetType() <<"年期"
		<<setw(10) <<c.GetBase(); /*小于9位*/
	out <<setw(6) <<a.GetYear() <<"年" <<setw(2) <<a.GetMonth() <<"月"
		<<setw(2) <<a.GetDay() <<"日" <<setfill(' ');
	if(c.GetIsmiss() != 0) 
	{
		out <<setw(5) <<"yes";
	    out <<"  " <<b.GetYear() <<"年"
		    <<setw(2) <<b.GetMonth() <<"月" <<setw(2) <<b.GetDay() <<"日";
	}
	else 
	{
		out <<setw(5) <<"no";
		out <<setw(16) <<' ';
	}
	out <<setw(20) <<wname/*小于14字节*/ <<endl; 
		//<<setiosflags(ios::left) <<setw(4) <<w.ID <<endl;
	out.close();
}

//——————————————————————————————————
void MANAGE::WriteLoadDoc(CUSTOMER c,CString wname,double total,CTime stime)
{
	ofstream out("LOAD.fac",ios::ate);
	out <<setiosflags(ios::left) <<setprecision(2) <<setiosflags(ios::fixed);
	CTime a = c.GetIndate();
	CTime b = c.GetMissdate();
	out <<setw(5) <<c.GetAccount()/*四位*/ <<setw(15) <<c.GetName()/*小于14个字符*/
		<<setw(8) <<c.Getpassword()/*七位*/ <<setw(30) <<c.GetAddress()/*小于29个字节*/
		<<setw(2) <<c.GetType() <<"年期"
		<<setw(10) <<c.GetBase(); /*小于9位*/
	out <<setw(6) <<a.GetYear() <<"年" <<setw(2) <<a.GetMonth() <<"月"
		<<setw(2) <<a.GetDay() <<"日" <<setfill(' ');
	if(c.GetIsmiss() != 0) 
	{
		out <<setw(5) <<"yes";
	    out <<"  " <<b.GetYear() <<"年"
		    <<setw(2) <<b.GetMonth() <<"月" <<setw(2) <<b.GetDay() <<"日";
	}
	else 
	{
		out <<setw(5) <<"no";
		out <<setw(16) <<' ';
	}
	out <<setw(10) <<total ;
	out <<"  " <<stime.GetYear() <<"年" <<setw(2) <<stime.GetMonth()
		<<"月" <<setw(2) <<stime.GetDay() <<"日";
	out	<<setw(20) <<wname/*小于14字节*/ <<endl;//<<' ' <<setw(4) <<ID <<endl;
	out.close();
}

//——————————————————————————————————
void MANAGE::PrintBeniList(CUSTOMER &a,double interest)
{
	ofstream out("Interest.fac",ios::trunc);
	out <<"账号:" <<a.GetAccount() <<endl;
	out <<"姓名:" <<a.GetName() <<endl;
	out <<"储种:" <<a.GetType() <<"年期"<<endl;
	out <<"本金:" <<a.GetBase() <<"元" <<endl;
	time_t nindate = a.GetIndate().GetTime();
	out <<"收储日期:" <<ctime(&nindate) <<endl;
	out <<"取款额:" <<a.GetBase() + interest <<"元" <<endl;
	time_t noutdate = a.GetOutdate().GetTime();
	out <<"取款日期:" <<ctime(&noutdate) <<endl;
    out.close();
}

//——————————————————————————————————
void MANAGE::WriteMiss(CUSTOMER *missc)
{
	ofstream out("SAVE.fac",ios::ate);
	long psize = 133;
	out.seekp((missc->GetAccount()-1000) * psize + 87);
    out <<setw(5) <<"yes";
   	CTime misst = missc->GetMissdate();
	out <<"  " <<misst.GetYear() <<"年" <<setfill('0') <<setw(2) <<misst.GetMonth() <<"月"
		<<setw(2) <<misst.GetDay() <<"日" <<setfill(' ');
	out.close();
}

//////////////////////////////////////////////////////////////////////
//功能函数
//////////////////////////////////////////////////////////////////////
//——————————————————————————————————
int MANAGE::DoSave(CString nname,long npassword,CString naddress,
				   int ntype,double nbase,time_t nindate,CString wname)
{
	CUSTOMER *isc = NULL;//有无成功创建客户结点的标示符
	ISEXIST *ise = NULL;//有无成功创建存在结点的标示符
	int nntype;
	switch(ntype)
	{
	case 0:nntype = 1;break;
	case 1:nntype = 3;break;
	case 2:nntype = 5;break;
	}
	isc = CreateCustomer(nname,npassword,naddress,nntype,nbase,nindate);
	if(isc == NULL) return 1;
	ise = CreateIsexist();
	if(ise == NULL) return 2;
	if(isfirstsave) //第一次存款时创建存款文件
	{
		CreateSaveDoc();
		isfirstsave = false;
	}
	
    WriteSaveDoc(*isc,wname);//写存款文件
	return 0;
}//返回1表示创建客户结点失败
 //返回2表示创建存在结点失败
 //返回0表示创建成功

//——————————————————————————————————
int MANAGE::DoMiss(long naccount,CString nname,long npassword,CString naddress,
				   int ntype,double nbase,time_t nmissdate)
{
	if(CUSTOMER *c = CUSTOMER::Find(naccount)) 
	{
		if(npassword != c->Getpassword()) return 1;
		if(nname != c->GetName()) return 2;
		if(naddress != c->GetAddress()) return 3;
		if(ntype != c->GetType()) return 4;
		if(nbase != c->GetBase()) return 5;
		c->Miss();
		c->MissDate(nmissdate);
		WriteMiss(c);
		CUSTOMER::DelP(c);
		return 0;
	}
	if(MyDoc->isexistlist.FindIndex(naccount-1001)) return 10;
	return 20;
}//返回0表示挂失成功,1表示密码不对,2表示名字不对,3表示地址不对,4表示储种不对,5表示本金不对。
 //返回10表示有过此项存款但已被取走。
 //返回20表示未有过此项存款。		

//——————————————————————————————————
int MANAGE::DoLoad(long naccount,CString nname,int ntype,long npassword,
				   double nbase,double &interest,time_t systime,CString wname)
{
	if(isfirstload)
	{
		CreateLoadDoc();
		isfirstload = false;
	}
	
	CUSTOMER *c = CUSTOMER::Find(naccount);
	if(!c) return 0;
	if(npassword != c->Getpassword()) return 1;
	if(c->GetIsmiss()) return 2;
	if(c->GetBase() != nbase) return 5;
    CTime stime(systime);

	if(c->GetOutdate() > stime)
	{
		CTimeSpan span1(stime - c->GetIndate());
		interest = 0.0005 * span1.GetDays() * c->GetBase();
		WriteLoadDoc(*c,wname,interest+c->GetBase(),CTime(time(NULL)));
		PrintBeniList(*c,interest);
		CUSTOMER::DelP(c);
		return 3;
	}
    
	CTimeSpan span2(stime - c->GetOutdate());
	interest = 0.0005 * span2.GetDays() * c->GetBase();
	switch(c->GetType()){
	case 1: interest += 0.07 * c->GetBase();break;
	case 3: interest += 0.08 * 3 * c->GetBase();break;
	case 5: interest += 0.09 * 5 * c->GetBase();break;
	}
	
	WriteLoadDoc(*c,wname,interest,stime);
	PrintBeniList(*c,interest);
	CUSTOMER::DelP(c);
	return 4;
}//返回0表示未找到此客户。
 //返回1表示密码错误。
 //返回2表示以挂失。
 //返回3表示未到期取款。
 //返回4表示正常取款。
 //返回5表示款项错误。
		
//——————————————————————————————————
int MANAGE::DoConsult(double &d1,double &d2,double &d3,time_t systime)
{
	d1 = 0;d2 = 0;d3 = 0;
	if(MyDoc->customerlist.IsEmpty()) return 2;
	CUSTOMER s = MyDoc->customerlist.GetHead();
	CUSTOMER *ps = &s;
	POSITION position = MyDoc->customerlist.GetHeadPosition();
	while(!ps)
	{
		if(ps->GetOutdate().GetYear() == CTime(systime).GetYear() &&
		   ps->GetOutdate().GetMonth() == CTime(systime).GetMonth() &&
		   ps->GetOutdate().GetDay() == CTime(systime).GetDay())
		{
			switch(ps->GetType()){
			case 1: d1 += ps->GetBase() * 1 * 0.07;break;
			case 3: d1 += ps->GetBase() * 3 * 0.08;break;
			case 5: d1 += ps->GetBase() * 5 * 0.09;break;
			}
		}
        if(s == MyDoc->customerlist.GetTail()) break;
		s = MyDoc->customerlist.GetNext(position);
		ps = &s;
	}

	s = MyDoc->customerlist.GetHead();
	ps = &s;
    position = MyDoc->customerlist.GetHeadPosition();
	while(!ps)
	{
		if(ps->GetOutdate().GetYear() == CTime(systime).GetYear() &&
		   ps->GetOutdate().GetMonth() == CTime(systime).GetMonth() &&
	       ps->GetOutdate().GetDay() == CTime(systime).GetDay()+1)
		{
		   switch(ps->GetType()){
		   case 1: d1 += ps->GetBase() * 1 * 0.07;break;
		   case 3: d1 += ps->GetBase() * 3 * 0.08;break;
		   case 5: d1 += ps->GetBase() * 5 * 0.09;break;
		   }
		}
        if(s == MyDoc->customerlist.GetTail()) break;
		s = MyDoc->customerlist.GetNext(position);
		ps = &s;
	}

	s = MyDoc->customerlist.GetHead();
	ps = &s;
	position = MyDoc->customerlist.GetHeadPosition();
	while(!ps)
	{
		if(ps->GetOutdate().GetYear() == CTime(systime).GetYear() &&
		   ps->GetOutdate().GetMonth() == CTime(systime).GetMonth() &&
	       ps->GetOutdate().GetDay() == CTime(systime).GetDay()+2)
		{
		   switch(ps->GetType()){
			case 1: d1 += ps->GetBase() * 1 * 0.07;break;
			case 3: d1 += ps->GetBase() * 3 * 0.08;break;
			case 5: d1 += ps->GetBase() * 5 * 0.09;break;
		   }
		}
		if(s == MyDoc->customerlist.GetTail()) break;
		s = MyDoc->customerlist.GetNext(position);
		ps = &s;
	}
    return 1;
}//返回1表示查询成功。
 //返回2表示尚无存款。


//////////////////////////////////////////////////////////////////////
//序列化函数
//////////////////////////////////////////////////////////////////////
//——————————————————————————————————
void MANAGE::Serialize(CArchive &ar)
{
	CObject::Serialize(ar);
	if(ar.IsStoring())
	{
		ar <<isfirstload <<isfirstsave;
	    /*ar <<MANAGE::isfirstload <<MANAGE::isfirstsave <<CUSTOMER::numofclass <<ISEXIST::numofclass;
	    if(!MyDoc->customerlist.IsEmpty())//序列化CUSTOMER类。
		{
		    POSITION cposition = MyDoc->customerlist.GetHeadPosition();
	        MyDoc->customerlist.GetAt(cposition).Serialize(ar);
			for(int j=CUSTOMER::numofclass;j>0;j--){MyDoc->customerlist.GetNext(cposition).Serialize(ar);}
		}
	
	    if(!MyDoc->isexistlist.IsEmpty())//序列化ISEXIST类。
		{
		    POSITION iposition = MyDoc->isexistlist.GetHeadPosition();
	        MyDoc->isexistlist.GetAt(iposition).Serialize(ar);
			for(int k=ISEXIST::numofclass;k>0;k--){MyDoc->isexistlist.GetNext(iposition).Serialize(ar);}
		}*/
	}
	else
	{
		ar >>isfirstload >>isfirstsave;
		/*ar >>MANAGE::isfirstload >>MANAGE::isfirstsave >>CUSTOMER::numofclass >>ISEXIST::numofclass;
		CUSTOMER *cpoint;//序列化CUSTOMER类。
		for(int j = CUSTOMER::numofclass;j>0;j--)
		{
			if(!(cpoint = new CUSTOMER)) return;
			cpoint->Serialize(ar);
			MyDoc->customerlist.AddTail(*cpoint);
		}
		ISEXIST *ipoint;
		for(int k = ISEXIST::numofclass;k>0;k--)
		{
			if(!(ipoint = new ISEXIST)) return;
			ipoint->Serialize(ar);
			MyDoc->isexistlist.AddTail(*ipoint);
		}*/
	}
	//for(int i=0;i<5;i++){waiter[i].Serialize(ar);}//序列化waiter.
}

⌨️ 快捷键说明

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