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

📄 cformsearchconsume.cpp

📁 AA制消费管理系统(简易型) 实现账户信息
💻 CPP
字号:
#include "link.h"
/***********************************************************************
查询界面
***********************************************************************/
void CFormSearchConsume::load()
{
	do{
		SearchForm();	
		char choice;
		int x,y;
		WhereXY(&x,&y);
		do
		{
			GotoXY(x,y);
			choice=getch();
			if(!isdigit(choice))
			{
				CMessageBox::ShowMessage("Input must be digit !");
				continue;
			}
			else if(choice>'2')
			{
				CMessageBox::ShowMessage("Input must be in 0 to 2 !");
				continue;
			}
			else
				break;
		}while(1);
		cout<<choice;
		switch(choice)
		{
		case '1':
			//按姓名查找
			do{
				if(SearchConsumeByName()==0)
					break;
				else
					PrintConsume();
			}while(1);
				break;
		case '2':
			//按日期查找
			do{
				if(SearchConsumeByDate()==0)
					break;
				else
					PrintConsume();
			}while(1);
				break;
		case '0':
			//返回主菜单
			return;
		}
	}while(1);
}
/***********************************************************************
按姓名查询
***********************************************************************/
int CFormSearchConsume::SearchConsumeByName()
{
	SearchByNameForm();
	int x,y;
	WhereXY(&x,&y);
	string searchname;
	searchname=InputName();
	int len=searchname.length();
	if(searchname[len-1]==27)
		return 0;//返回主菜单
	CConManager& conman=CConManager::GetInstance();
	vector<CConsume>& veccon=conman.GetConsumeList();
	CAccManager& accman=CAccManager::GetInstance();
	vector<CAccount>& vecacc=accman.GetVecAccount();
	vector<int> vecid;
	int size=vecacc.size();
	if(size==0)
	{
		CMessageBox::ShowMessage("No consume record.Press anykey to return.");
		getch();
		return 0;//无数据
	}
	vecid.clear();
	for(int i=0;i<size;i++)
	{
		int tempid=vecacc[i].GetID();
		string tempname=vecacc[i].GetName();
		strupr((char *)tempname.c_str());
		strupr((char *)searchname.c_str());
		if(strstr(tempname.c_str(),searchname.c_str())!=NULL)//模糊查询
			vecid.push_back(tempid);
		else
			continue;
	}
	if(vecid.size()==0)
	{
		CMessageBox::ShowMessage("No record this man.Press anykey to return.");
		getch();
		return -1;//无数据
	}
	size=veccon.size();
	tempvec.clear();
	for(i=0;i<size;i++)
	{
		int tempid=veccon[i].GetID();
		for(int j=0;j<vecid.size();j++)
		{
			if(vecid[j]==tempid)
				tempvec.push_back(veccon[i]);
		}
	}
	if(tempvec.size()==0)
		return 0;//无数据
	return 1;
}
/***********************************************************************
按日期查询
***********************************************************************/
int CFormSearchConsume::SearchConsumeByDate()
{
	SearchByDateForm();
	int x,y;
	WhereXY(&x,&y);
	string searchdate;
	searchdate=InputDate();
	int len=searchdate.length();
	if(searchdate[len-1]==27)
		return 0;//返回主菜单
	CConManager& conman=CConManager::GetInstance();
	vector<CConsume>& veccon=conman.GetConsumeList();
	int size=veccon.size();
	if(size==0)
	{
		CMessageBox::ShowMessage("No consume record.Press anykey to return.");
		getch();
		return 0;//无数据
	}
	tempvec.clear();
	for(int i=0;i<size;i++)
	{
		string tempdate=veccon[i].GetDate();
		if(CMyString::DateCompare(searchdate,tempdate)==0)
			tempvec.push_back(veccon[i]);
	}
	if(tempvec.size()==0)
	{
		CMessageBox::ShowMessage("No record this day.Press anykey to return.");
		getch();
		return -1;//无数据
	}
	return 1;
}
/***********************************************************************
查询函数菜单函数
***********************************************************************/
void CFormSearchConsume::SearchForm()
{
	CFormBase::load();
	string title("Search Consume");
	int len=title.length();
	GotoXY((80-len)/2,3);
	cout<<title<<endl;
	vector<string> menulist;
	string s[]={"1.Search consume by name.","2.Search consume by date.","0.Return to menu."};
	int n=3;
	for(int i=0;i<3;i++)
		menulist.push_back(s[i]);
	vector<string>::iterator VecStr;
	for (i =0,VecStr=menulist.begin();i<n;VecStr++,i++)
	{
		GotoXY(28,7+i);
		cout<<*VecStr<<endl;
	}
	GotoXY(28,7+n+1);
	cout<<"Please make your choice:";
}
/***********************************************************************
按姓名查询框架
***********************************************************************/
void CFormSearchConsume::SearchByNameForm()
{
	CFormBase::load();
	string title("Search by name");
	int len=title.length();
	GotoXY((80-len)/2,3);
	cout<<title<<endl;
	
	GotoXY(10,10);
	cout<<"Please input name :"<<ends;
}
/***********************************************************************
按日期查询框架
***********************************************************************/
void CFormSearchConsume::SearchByDateForm()
{
	CFormBase::load();
	string title("Search by date");
	int len=title.length();
	GotoXY((80-len)/2,3);
	cout<<title<<endl;
	GotoXY(10,10);
	cout<<"Please input date :"<<ends;
}
/***********************************************************************
姓名输入
***********************************************************************/
string CFormSearchConsume::InputName()
{
	string _name;
	int x,y,len;
	WhereXY(&x,&y);
	do 
	{
		GotoXY(x,y);
		CMessageBox::Clear(x,21);
		GetString(_name,21);
		len=_name.length();
		if(_name[len-1]==27)
			break;
		if (CMyString::CheckName(_name))
			break;
	} while (1);
	GotoXY(x,y);
	CMessageBox::Clear(x,21);
	return _name;
}
/***********************************************************************
日期输入
***********************************************************************/
string CFormSearchConsume::InputDate()
{
	string _date;
	int x,y,len;
	WhereXY(&x,&y);
	do 
	{
		GotoXY(x,y);
		CMessageBox::Clear(x,10);
		GetString(_date,10);
		len=_date.length();
		if(_date[len-1]==27)
			break;
		if (CMyString::CheckDate(_date))
			break;
	} while (1);
	GotoXY(x,y);
	CMessageBox::Clear(x,10);
	return _date;
}
/***********************************************************************
消费打印
***********************************************************************/
int CFormSearchConsume::PrintConsume()
{
	CFormBase::load();
	string title("Search by date");
	int len=title.length();
	GotoXY((80-len)/2,3);
	cout<<title<<endl;
	//遍历一次向量容器,将账户打印出来
	CConManager &conman=CConManager::GetInstance();
	int consize;
	consize=conman.GetSize();
//	vector<CConsume> tempvec;
	int size=tempvec.size();
	//排序,按date降序
	for(int i=0;i<tempvec.size();i++)
	{
		for(int j=i+1;j<tempvec.size();j++)
		{
			string date1=tempvec[i].GetDate();
			string date2=tempvec[j].GetDate();
			
			if(CMyString::DateCompare(date1,date2)<0)
			{
				CConsume contemp;
				contemp=tempvec[i];
				tempvec[i]=tempvec[j];
				tempvec[j]=contemp;
			}
		}
	}
	PrintConsumeForm();
	int x,y;
	char temp[100]={0};
	int maxpage,page=1;
	maxpage=size/PAGENUMBER;
	if(size%PAGENUMBER)
		maxpage++;
	GotoXY(24,9+PAGENUMBER);cout<<size;
	GotoXY(51,9+PAGENUMBER);WhereXY(&x,&y);
	sprintf(temp,"%d/%d",page,maxpage);
	cout<<temp<<ends;
	PrintPage(tempvec,maxpage,page);
	char ch;
	do{
		GotoXY(x,y);
		ch=getch();
		if(ch==-32||ch==0)
			ch=getch();
		CMessageBox::ShowMessage("");
		if((ch==75 || ch==73 ||ch==72) || (ch==77||ch==80||ch==81)||ch==71 || ch==79 ||isdigit(ch))
		{
			if(ChangePage(ch,maxpage,page))
			{
				PrintPage(tempvec,maxpage,page);
				GotoXY(51,9+PAGENUMBER);
				sprintf(temp,"%d/%d",page,maxpage);
				cout<<temp<<ends;
			}
			continue;
		}
		else if(ch==27)
		{
			return 0;
		}
		else
		{
			CMessageBox::ShowMessage("Press [Esc] to return.");
			continue;
		}
	}while(1);
}
/***********************************************************************
消费记录打印框架
***********************************************************************/
void CFormSearchConsume::PrintConsumeForm()
{
//	CFormBase::load();
//	string title("Print consume list");
//	int len=title.length();
//	GotoXY((80-len)/2,3);
//	cout<<title<<endl;
	char temp[100]={0};
	GotoXY(10,5);
	sprintf(temp,"-----------------------------------------------");
	cout<<temp<<ends;
	GotoXY(10,7);
	cout<<temp<<ends;
	GotoXY(10,8+PAGENUMBER);
	cout<<temp<<ends;
	GotoXY(10,6);
	sprintf(temp,"%-12s%-7s%-8s%20s","Date","Money","ManCount","IDList");
	cout<<temp<<ends;
	GotoXY(3,21);
	sprintf(temp,"%s","[Esc]Return [Home]Firstpage [End]Lastpage [Left]PageUp [Right]PageDown");
	cout<<temp<<ends;
	GotoXY(10,9+PAGENUMBER);
	sprintf(temp,"%s","Total Records:");
	cout<<temp<<ends;
	
}
/***********************************************************************
消费记录按页打印函数
***********************************************************************/
bool CFormSearchConsume::PrintPage(vector<CConsume>&veccon,int maxpage,int page)
{
	char temp[50]={0};
	string _date;
	float _money;
	int _mancount;
	string _IDList;
	int size=veccon.size();
	for(int k=0;k<PAGENUMBER;k++)
	{
		GotoXY(20,8+k);
		CMessageBox::Clear(20,40);
	}
	for(int i=(page-1)*PAGENUMBER,j=0;i<page*PAGENUMBER&&i<size;i++)
	{
		_IDList=veccon[i].GetIDList();
		_mancount=veccon[i].GetManCount();
		_date=veccon[i].GetDate();
		_money=veccon[i].GetMoney();
		sprintf(temp,"%-12s%-7.2f%-8d%20s",_date.c_str(),_money,_mancount,_IDList.c_str());
		GotoXY(10,8+j);j++;
		cout<<temp<<ends;
	}
	return true;
}

⌨️ 快捷键说明

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