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

📄 project.cpp

📁 标准C++编写的小小CRM软件,无任何平台依赖.采用标准XML作为数据库.只需重新纺译,可在任何平台上运行.目前测试过在GCC和VC下都可以编译通过
💻 CPP
字号:
#include "Project.h"

Project::Project(void)
{
	initProj();
}

Project::~Project(void)
{	save();				}

bool Project::save()		
/* storage memory date back to project file.	*
 * success return true, else return fasle.		*/
{
	ofstream projFile( "project.xml" );
	multimap <string, int> ::const_iterator map_Iter;

	if( projFile.fail() ){	// can't open project file
		cerr<<"open project define file error."<<endl;
		return false;
	}
	else{
		projFile << "<?xml version=\"1.0\" encoding=\"gb2312\"?>" << endl;
		projFile << "<Project_File>" << endl;
		for( map_Iter = projMap.begin(); map_Iter != projMap.end(); map_Iter++ ){
			projFile << '<' << map_Iter->first << '>' << map_Iter->second
				<< "</" << map_Iter->first << '>' <<endl;
		}
		projFile << "</Project_File>" << endl;
		return true;
	}
}

bool Project::initProj()
{
	ifstream projFile( "project.xml" );
	string buf;
	string first;
	typedef pair <string, int> map_Pair;

	if( projFile.fail() ){	// can't open project file
		cerr<<"open project define file error."<<endl;
		return false;
	}

	while( getline( projFile,buf,'>' ) ){
		if( buf.substr( buf.find( '<' ) ) == "<Project_File"  ){
			while( getline( projFile, buf, '>' ) ){
				first = buf.substr( buf.find( '<' ) + 1 );
				if( first == "/Project_File" )		// reading complete.
				{	return true;	}
				else{
					if( getline( projFile, buf, '<' ) )	
					{	projMap.insert( map_Pair( first,toInt( buf ) ) );	}
					else
					{	cerr<<"unmatch format."<<endl;	}
				}
				getline( projFile, buf, '<' );
			}
		}
	}
	
	return false;
}

bool Project::add( const string& proj )
/* create a project. if success return true, else return false.		*/
{
	int id;
	int i=0;
	multimap <string, int> :: const_iterator map_Iter;
	typedef pair <string, int> map_Pair;

	map_Iter = projMap.find( proj );
	if ( map_Iter != projMap.end( ) ){
		cerr<<"Sorry, but this project have been exist"<<endl;
		return false;
	}
	else{
		cout<<"Please input users' id, input 0 end input: ";
		while( cin>>id ){
			if( id==0 )
			{	break;	}
			else
			{	projMap.insert( map_Pair( proj, id ) );	}
		}
	}

	return true;
}

bool Project::joinCustomer( const string& proj, int id )
/* join a customer to a project, success return true, else return false. */
{
	multimap <string, int> :: const_iterator map_Iter;
	Customer::Iterator c_Iter;
	typedef pair <string, int> map_Pair;

	map_Iter = projMap.find( proj );
	c_Iter = customer.find( id );
	if ( map_Iter == projMap.end( )  ){
		cerr<<"Sorry, but this project not exist"<<endl;
		return false;
	}
	if( c_Iter == customer.end() ){
		cout << " Sorry, but this customer's id in used. "<<endl;
		return false;
	}
	else{	
		projMap.insert( map_Pair( proj, id ) );	
		return true;
	}
}


bool Project::chg( const string& proj, const string& newProj )
/* change a project's name. success return true, else return false	*/
{
	multimap <string, int> :: iterator map_Iter;
	typedef pair<string, int> si_Pair;
	bool   findSign = false;
	int    id;

	while( (map_Iter = projMap.find( proj )) != projMap.end() ){
		findSign = true;
		id = map_Iter->second;
		map_Iter = projMap.erase( map_Iter );
		projMap.insert( si_Pair( newProj, id ) );
	}

	if ( !findSign ){
		cerr<<"Sorry, but your project not exist"<<endl;
		return false;
	}
	else{
		return true;
	}
}

bool Project::del( const string& proj )
/* delete a project. if success return true, else return false.		*/
{
	multimap <string, int> :: iterator map_Iter;
	bool findSign = false;

	while( (map_Iter = projMap.find( proj )) != projMap.end() )	{
		findSign = true;
		projMap.erase( map_Iter );
	}
	if( !findSign )
	{	cout << " Sorry, but I really can't find you project. "<<endl;	}

	return findSign;
}


bool Project::remCustomer( const string& proj, int id )
/* remove a customer from project. success return true,	else return false	*/
{
	multimap <string, int> :: iterator map_Iter;
	Customer::Iterator c_Iter;
	typedef pair <string, int> map_Pair;

	for( map_Iter = projMap.begin(); map_Iter != projMap.end(); map_Iter++ ){
		if( map_Iter->first == proj && map_Iter->second == id ){
			projMap.erase( map_Iter );
			return true;
		}
	}

	cout << "Sorry, but I can't find such customer in such project." <<endl;
	return false;
}
bool Project::display( const string& proj )
/* dispaly all customers in ther project. success return true,	*
 * else return false.											*/
{			
	multimap <string, int> :: const_iterator map_Iter;

	if( projMap.find( proj ) == projMap.end() ){
		cout<<" Sorry, but I can't find your project. "<<endl;
		return false;
	}
	else{
		for( map_Iter = projMap.begin(); map_Iter!= projMap.end(); map_Iter++ ){
			if( map_Iter->first == proj )
			{	customer.display( map_Iter->second );	}
		}
		return true;
	}
}

bool Project::display()
/* display all customers have been join to projects	*/
{
	multimap <string, int> :: const_iterator map_Iter;

	for( map_Iter = projMap.begin(); map_Iter!= projMap.end(); map_Iter++ ){
		cout << "Project: " << map_Iter->first << endl;
		customer.display( map_Iter->second );	
	}

	return true;
}

⌨️ 快捷键说明

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