📄 cformprintstat.cpp
字号:
#include "link.h"
/***********************************************************************
报表界面类菜单函数
***********************************************************************/
void CFormPrintStat::load()
{
do{
CFormBase::load();
string title("Print Report");
int len=title.length();
GotoXY((80-len)/2,3);
cout<<title<<endl;
vector<string> menulist;
string s[]={"1.Print account list.","2.Print consume list.","3.Print add money list .","0.Return to menu."};
int n=4;
for(int i=0;i<n;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:";
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>'4')
{
CMessageBox::ShowMessage("Input must be in 0 to 3 !");
continue;
}
else
break;
}while(1);
cout<<choice;
switch(choice)
{
case '1':
do{
if(PrintAccount()==0)
break;
}while(1);//打印帐户列表
break;
case '2':
do{
if(PrintConsume()==0)//打印消费信息列表
break;
}while(1);
break;
case '3':
do
{
if(PrintAppMoney()==0)//打印充值信息列表
break;
} while (1);
break;
case '0':
//返回主菜单
return;
}
}while(1);
}
/***********************************************************************
账户信息打印函数
***********************************************************************/
int CFormPrintStat::PrintAccount()
{
CFormBase::load();
//遍历一次向量容器,将账户打印出来
CAccManager &accman=CAccManager::GetInstance();
int accsize;
accsize=accman.GetSize();
vector<CAccount> tempvec;
string _state;
for (int i=0;i<accsize;i++)
{
_state=accman.GetRec(i).GetStat();
if(_state=="Alive")
tempvec.push_back(accman.GetRec(i));
}
PrintAccountForm();
int x,y;
char temp[100]={0};
int maxpage,page=1;
int size=tempvec.size();
maxpage=size/PAGENUMBER;
if(size%PAGENUMBER)
maxpage++;
GotoXY(36,9+PAGENUMBER);cout<<size;
GotoXY(57,9+PAGENUMBER);WhereXY(&x,&y);
sprintf(temp,"%d/%d",page,maxpage);
cout<<temp<<ends;
CFormBase::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 )
{
if(ChangePage(ch,maxpage,page))
{
CFormBase::PrintPage(tempvec,maxpage,page);
GotoXY(57,9+PAGENUMBER);
sprintf(temp,"%d/%d",page,maxpage);
cout<<temp<<ends;
}
continue;
}
else if(isdigit(ch))
{
if(ch>'1')
{
CMessageBox::ShowMessage("Input must be in 0 to 2 !");
continue;
}
switch(ch)
{
case '0':return 0;
case '1':
GotoXY(22,22);
cout<<"Please input an account:";WhereXY(&x,&y);
break;
}
}
else if(ch==27)
{
return 0;
}
else
{
CMessageBox::ShowMessage("Press [Esc] to return....");
continue;
}
int num;
do{
GotoXY(x,y);
num=InputNum();
if(num==0)
{
CMessageBox::ShowMessage("There isnot the member.");
continue;
}
if(num==-1)
{
return 1;
}
for (int i=0;i<accsize;i++)
{
if (num==tempvec[i].GetID())
{
break;
}
}
if (i==accsize)
{
CMessageBox::ShowMessage("There is not this account !");
continue;
}
else
break;
}while(1);
//调用账户信息页面
accman.GetRec(num-1).ShowAccInfo();
CMessageBox::ShowMessage("Press any to return.");
getch();
return 1;
}while(1);
}
/***********************************************************************
消费记录打印函数
***********************************************************************/
int CFormPrintStat::PrintConsume()//日期限定范围,未zuo
{
CFormBase::load();
string title("Print consume list");
int len=title.length();
GotoXY((80-len)/2,3);
cout<<title<<endl;
//遍历一次向量容器,将账户打印出来
CConManager &conman=CConManager::GetInstance();
vector<CConsume>& veccon=conman.GetConsumeList();
int consize;
GotoXY(10,10);
cout<<"Input Date From :"<<ends;
GotoXY(10,11);
cout<<"Input Date To :"<<ends;
string fromdate;
string todate;
do
{
GotoXY(28,10);
fromdate=InputDate();
int len=fromdate.length();
if(fromdate[len-1]==27)
return 0;
cout<<fromdate<<ends;
GotoXY(28,11);
todate=InputDate();
len=todate.length();
if(todate[len-1]==27)
return 0;
cout<<fromdate<<ends;
if(CMyString::DateCompare(fromdate,todate)>0)
{
CMessageBox::ShowMessage("Your input is illegal,please input again.");
continue;
}
else
break;
}while(1);
consize=conman.GetSize();
vector<CConsume> tempvec;
for (int i=0;i<consize;i++)
{
string date1=conman.GetConsume(i).GetDate();
if(CMyString::DateCompare(date1,fromdate)>=0&&CMyString::DateCompare(date1,todate)<=0)
tempvec.push_back(conman.GetConsume(i));
}
int size=tempvec.size();
if(size==0)
{
char temp[100]={0};
sprintf(temp,"From %s to %s has not consume record !",fromdate.c_str,todate.c_str);
CMessageBox::ShowMessage(temp);
return 0;
}
//排序,按date降序
for(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(32,9+PAGENUMBER);cout<<size;
GotoXY(59,9+PAGENUMBER);WhereXY(&x,&y);
sprintf(temp,"%d/%d",page,maxpage);
cout<<temp<<ends;
PrintPage_2(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_2(tempvec,maxpage,page);
GotoXY(59,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);
}
/***********************************************************************
充值记录打印函数
***********************************************************************/
int CFormPrintStat::PrintAppMoney()
{
CFormBase::load();
//遍历一次向量容器,将账户打印出来
CAppMoneyManager &appman=CAppMoneyManager::GetInstance();
int appsize;
appsize=appman.GetSize();
vector<CAppMoney> tempvec;
for (int i=0;i<appsize;i++)
{
tempvec.push_back(appman.GetAppMoneyInfo(i));
}
int size=tempvec.size();
//排序,按money降序
for(i=0;i<tempvec.size();i++)
{
for(int j=i+1;j<tempvec.size();j++)
{
if(tempvec[i].GetMoney()<tempvec[j].GetMoney())
{
CAppMoney apptemp;
apptemp=tempvec[i];
tempvec[i]=tempvec[j];
tempvec[j]=apptemp;
}
}
}
PrintAppMoneyForm();
int x,y;
char temp[100]={0};
int maxpage,page=1;
maxpage=size/PAGENUMBER;
if(size%PAGENUMBER)
maxpage++;
GotoXY(32,9+PAGENUMBER);cout<<size;
GotoXY(55,9+PAGENUMBER);WhereXY(&x,&y);
sprintf(temp,"%d/%d",page,maxpage);
cout<<temp<<ends;
PrintPage_1(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 )
{
if(ChangePage(ch,maxpage,page))
{
PrintPage_1(tempvec,maxpage,page);
GotoXY(55,9+PAGENUMBER);
sprintf(temp,"%d/%d",page,maxpage);
cout<<temp<<ends;
}
continue;
}
else if(isdigit(ch))
{
if(ch>'1')
{
CMessageBox::ShowMessage("Input must be in 0 to 2 !");
continue;
}
switch(ch)
{
case '0':return 0;
case '1':
GotoXY(22,22);
cout<<"Please input an account:";WhereXY(&x,&y);
break;
}
break;
}
else if(ch==27)
{
return 0;
}
else
{
CMessageBox::ShowMessage("Press [Esc] to return.");
continue;
}
}while(1);
//调用账户冲值信息页面//要将所有账户充值信息打出
// appman.GetAppMoneyInfo(num-1).ShowAppMoneyInfo();
// CMessageBox::ShowMessage("Press any to return...");
// getch();
return 1;
}
/***********************************************************************
账户信息打印框架
***********************************************************************/
void CFormPrintStat::PrintAccountForm()
{
CFormBase::load();
string title("Print account list");
int len=title.length();
GotoXY((80-len)/2,3);
cout<<title<<endl;
char temp[100]={0};
GotoXY(22,5);
sprintf(temp,"---------------------------------------");
cout<<temp<<ends;
GotoXY(22,7);
cout<<temp<<ends;
GotoXY(22,8+PAGENUMBER);
cout<<temp<<ends;
GotoXY(22,6);
sprintf(temp,"%-4s%-21s%14s","ID","Name","Balance");
cout<<temp<<ends;
GotoXY(3,21);
sprintf(temp,"%s","[Esc]Return [Home]Firstpage [End]Lastpage [Left]PageUp [Right]PageDown");
cout<<temp<<ends;
GotoXY(22,9+PAGENUMBER);
sprintf(temp,"%s","Total Records:");
cout<<temp<<ends;
}
/***********************************************************************
消费记录打印框架
***********************************************************************/
void CFormPrintStat::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(18,5);
sprintf(temp,"-----------------------------------------------");
cout<<temp<<ends;
GotoXY(18,7);
cout<<temp<<ends;
GotoXY(18,8+PAGENUMBER);
cout<<temp<<ends;
GotoXY(18,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(18,9+PAGENUMBER);
sprintf(temp,"%s","Total Records:");
cout<<temp<<ends;
}
/***********************************************************************
充值记录打印框架
***********************************************************************/
void CFormPrintStat::PrintAppMoneyForm()
{
CFormBase::load();
string title("Print appmoney list");
int len=title.length();
GotoXY((80-len)/2,3);
cout<<title<<endl;
char temp[100]={0};
GotoXY(18,5);
sprintf(temp,"----------------------------------------------");
cout<<temp<<ends;
GotoXY(18,7);
cout<<temp<<ends;
GotoXY(18,8+PAGENUMBER);
cout<<temp<<ends;
GotoXY(18,6);
sprintf(temp,"%-4s%-21s%-12s%-7s","ID","Name","Date","Money");
cout<<temp<<ends;
GotoXY(3,21);
sprintf(temp,"%s","[Esc]Return [Home]Firstpage [End]Lastpage [Left]PageUp [Right]PageDown");
cout<<temp<<ends;
GotoXY(18,9+PAGENUMBER);
sprintf(temp,"%s","Total Records:");
cout<<temp<<ends;
}
/***********************************************************************
充值记录分页打印函数
***********************************************************************/
bool CFormPrintStat::PrintPage_1(vector<CAppMoney>&vecapp,int maxpage,int page)
{
char temp[50]={0};
int _id;
string _name;
string _date;
float _money;
int size=vecapp.size();
for(int k=0;k<PAGENUMBER;k++)
{
GotoXY(18,8+k);
CMessageBox::Clear(18,50);
}
for(int i=(page-1)*PAGENUMBER,j=0;i<page*PAGENUMBER&&i<size;i++)
{
_id=vecapp[i].GetID();
_name=vecapp[i].GetName();
_date=vecapp[i].GetDate();
_money=vecapp[i].GetMoney();
sprintf(temp,"%-4d%-21s%-12s%-7.2f",_id,_name.c_str(),_date.c_str(),_money);
GotoXY(18,8+j);j++;
cout<<temp<<ends;
}
return true;
}
/***********************************************************************
消费记录打印函数
***********************************************************************/
bool CFormPrintStat::PrintPage_2(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(18,8+k);
CMessageBox::Clear(18,50);
}
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(18,8+j);j++;
cout<<temp<<ends;
}
return true;
}
/***********************************************************************
编号输入函数
***********************************************************************/
int CFormPrintStat::InputNum()
{
int x,y;
WhereXY(&x,&y);
string strno;
int no,len;
do
{
GotoXY(x,y);
CMessageBox::Clear(x,3);
GetString(strno,3);
len=strno.length();
if(strno[len-1]==27)
{
// CMessageBox::Clear(22,30);
return -1;
}
if(!CMyString::CheckID(strno))
continue;
else
no=CMyString::StrToInt(strno);
return no;
} while (1);
}
/***********************************************************************
日期输入函数
***********************************************************************/
string CFormPrintStat::InputDate()
{
//日期输入
string date;
CDateTime datetime;
date=datetime.GetDateTime().substr(0,10);
int x,y;
WhereXY(&x,&y);
do
{
GotoXY(x,y);
CMessageBox::Clear(x,10);
GetString(date,10);
int len=date.length();
if(date[len-1]==27)
break;
if(len==0)
{
CMessageBox::ShowMessage("Date cannot be null ! Input again.");
continue;
}
if(date[len-1]==27)
break;
if(CMyString::CheckDate(date))
break;
else
continue;
}while(1);
GotoXY(x,y);
CMessageBox::Clear(x,10);
return date;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -