📄 cformaddconsume.cpp
字号:
#include "link.h"
/***********************************************************************
添加消费界面菜单函数
***********************************************************************/
void CFormAddConsume::load()
{
int _ID;
string _IDList;
string _date;
string _smoney;
float _money;
string _scount;
int _mancount=0;
string _comment;
CConsume tempcon;
CAccManager& accman=CAccManager::GetInstance();
CConManager& conman=CConManager::GetInstance();
do
{
addconsumeform();
GotoXY(45,10);
_date=InputDate();
int len;
len=_date.length();
if(_date[len-1]==27)
return;
cout<<_date<<ends;
GotoXY(45,11);
_smoney=InputMoney();
len=_smoney.length();
if(_smoney[len-1]==27)
return;
cout<<_smoney<<ends;
GotoXY(45,12);
_comment=InputComment();
len=_comment.length();
if(_comment[len-1]==27)
return;
cout<<_comment<<ends;
CDateTime::DelayTime(1);
int k;
k=tempcon.ActCon();
//IDList输入确定
int tage=0;//标签:用来返回判断
switch(k)
{
case 0:
{
_IDList=accman.GetAllID();//IDList=所有未停用账户的id
bool b=CMyString::CheckIDList(_IDList,_mancount);
if(!b)
continue;
break;
}
case 1:
GotoXY(22,17);CMessageBox::Clear(22,50);
GotoXY(22,18);CMessageBox::Clear(22,50);
GotoXY(22,19);CMessageBox::Clear(22,50);
GotoXY(22,21);CMessageBox::Clear(22,50);
//IDList=输入在席的账户id
do{
CMessageBox::ShowMessage("");
GotoXY(45,14);CMessageBox::Clear(45,30);
GotoXY(10,13);
cout<<"Input people count<1-100> : ";cout.flush();
GotoXY(10,14);
cout<<"Input IDList : ";cout.flush();
GotoXY(45,13);
_scount=InputManCount();
len=_scount.length();
if(_scount[len-1]==27)
{
tage=1;
break;
}
_mancount=CMyString::StrToInt(_scount);
cout<<_mancount<<ends;
GotoXY(45,14);
_IDList=InputIDList();
len=_IDList.length();
if(_IDList[len-1]==27)
{
tage=1;
break;
}
// CMessageBox::Clear(40,len);
cout<<_IDList;
bool ft=CMyString::CheckIDList(_IDList,_mancount);
// cout<<_IDList;
if(!ft)
{
tage=1;
continue;
}
else
break;
}while(1);
break;
case 2:
GotoXY(22,17);CMessageBox::Clear(22,50);
GotoXY(22,18);CMessageBox::Clear(22,50);
GotoXY(22,19);CMessageBox::Clear(22,50);
GotoXY(22,21);CMessageBox::Clear(22,50);
//IDList=输入缺席的账户id
do{
GotoXY(10,13);
cout<<"Input people count<1-100> : ";cout.flush();
GotoXY(10,14);
cout<<"Input IDList : ";cout.flush();
GotoXY(45,13);
_scount=InputManCount();
len=_scount.length();
if(_scount[len-1]==27)
{
tage=1;
break;
}
_mancount=CMyString::StrToInt(_scount);
cout<<_mancount<<ends;
GotoXY(45,14);
_IDList=InputIDList();
string all_IDList=accman.GetAllID();//IDList=所有未停用账户的id
int all_mancount=0;
for(int i=0;i<all_IDList.length();i++)
{
if(all_IDList[i]=='/')
all_mancount++;
}
cout<<_IDList;
// bool b=CMyString::CheckIDList(all_IDList,all_mancount);
//用所有正常账户除去缺席账户
int x[100]={0},y[100]={0};
int j,x_size=0,y_size=0;
for(i=0,j=0;i<_IDList.length();i++)
{
char ch=_IDList[i];
if(isdigit(ch))
x[j++]=CMyString::CharToInt(_IDList[i]);
}
x_size=j;
for(i=0,j=0;i<all_IDList.length();i++)
{
char ch=all_IDList[i];
if(isdigit(all_IDList[i]))
y[j++]=CMyString::CharToInt(all_IDList[i]);
}
y_size=j;
for(i=0;i<x_size;i++)
{
for(j=0;j<y_size;j++)
{
if(x[i]==y[j])
y[j]=0;
}
}
_IDList="";
for(i=0;i<all_mancount;i++)
{
if(y[i]!=0)
_IDList+=CMyString::IntToStr(y[i]);
_IDList+="/";
}
len=_IDList.length();_mancount=all_mancount-_mancount;
if(_IDList[len-1]==27)
{
tage=1;
break;
}
if(!CMyString::CheckIDList(_IDList,_mancount))
continue;
else
break;
}while(1);
break;
}
if(tage==1)
continue;
//将IdList中的id分离出来
// char temp[200];
// len=strlen(temp)+1;temp[len]='\0';
// _IDList=temp;
int a[100]={0};
char str[200],*result;
for (int i=0;i<_IDList.length();i++)
{
str[i]=_IDList[i];
}
str[i]='\0';
result=strtok(str,"/");
i=0;
while(result!=NULL)
{
a[i]=atoi(result);i++;
result=strtok(NULL,"/");
}
//将消费记录存放到临时容器中
CConsume tempcon;
vector<CConsume> tempvec;
_money=CMyString::StrToFloat(_smoney)/_mancount;
tempcon.SetIDList(_IDList);
tempcon.SetDate(_date);
tempcon.SetMoney(_money);
tempcon.SetComment(_comment);
tempcon.SetManCount(_mancount);
for(i=0;a[i]>0;i++)
{
_ID=a[i];
tempcon.SetID(_ID);
tempvec.push_back(tempcon);
}
//打印消费信息:消费日期,消费账户列表,消费金额及备注。
//询问是否保存
k=tempcon.AddConsume();
if(k==2)
{
//保存消费记录,扣除消费账户余额,成功后打印提示,后返回菜单
for(i=0;i<tempvec.size();i++)
{
conman.AddNewCon(tempvec[i]);
accman.GetVecAccount()[i].SetBalance(accman.GetVecAccount()[i].GetBalance()-_money);
accman.SaveData();
}
conman.SaveConsumeData();
conman.GetConsumeList().clear();
conman.RestoreConsumeData();
CMessageBox::ShowMessage("Save success !");
CDateTime::DelayTime(1);
return;
}
if(k==1)
return;
if(k==0)
continue;
}while(1);
}
/***********************************************************************
添加消费类框架
***********************************************************************/
void CFormAddConsume::addconsumeform()
{
//界面
CFormBase addcon;
addcon.load();
string acctitle="Add consume report";
int len=acctitle.length();
addcon.GotoXY((80-len)/2,3);
cout<<acctitle;cout.flush();
addcon.GotoXY(15,5);
//填写日期
CDateTime _date;
string date=_date.GetDateTime().substr(0,10);
addcon.GotoXY(10,10);
cout<<"Input the date<1900-2010> : ";cout.flush();
addcon.GotoXY(10,11);
cout<<"Input consume money<0.00-999.99> : ";cout.flush();
addcon.GotoXY(10,12);
cout<<"Input comment<length:0-200> : ";cout.flush();
}
/***********************************************************************
日期输入
***********************************************************************/
string CFormAddConsume::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;
}
/***********************************************************************
金钱输入
***********************************************************************/
string CFormAddConsume::InputMoney()
{
//金额输入
string _conmoney;
float money;
int x,y,len;
WhereXY(&x,&y);
do
{
GotoXY(x,y);
CMessageBox::Clear(x,5);//列数,个数
GetString(_conmoney,5);//需要验证
len=_conmoney.length();
if(_conmoney[len-1]==27)
break;
if(CMyString::CheckMoney(_conmoney))
{
money=CMyString::StrToFloat(_conmoney);
if(money>=0&&money<=999)
{
GotoXY(x,y);
CMessageBox::Clear(x,5);
_conmoney=CMyString::FloatToStr(money);
cout<<_conmoney;
break;
}
else
{
CMessageBox::ShowMessage("Input money must be in 0.00 to 999.00 !");
_conmoney="";//置空
continue;
}
}
else
{
int len=_conmoney.length();
if(len==0)
{
CMessageBox::ShowMessage("Money cannot be null ! Input again.");
continue;
}
continue;
}
}while(1);
GotoXY(x,y);
CMessageBox::Clear(x,5);
return _conmoney;
}
/***********************************************************************
备注输入
***********************************************************************/
string CFormAddConsume::InputComment()
{
//备注输入
string comment;
int x,y,len;
WhereXY(&x,&y);
GetString(comment,200);
CMyString::RemoveLeftBlank(comment);
CMyString::RemoveRightBlank(comment);
CMyString::RemoveMiddleBlank(comment);
len=comment.length();
if(comment[len-1]==27)
return comment;
if(len==0)
comment="Null";
GotoXY(x,y);
CMessageBox::Clear(x,comment.length());
return comment;
}
/***********************************************************************
消费人数输入
***********************************************************************/
string CFormAddConsume::InputManCount()
{
string smancount;
int x,y,len;
WhereXY(&x,&y);
do
{ CMessageBox::Clear(x,3);
GetString(smancount,3);
CMyString::RemoveLeftBlank(smancount);
CMyString::RemoveRightBlank(smancount);
len=smancount.length();
if(smancount[len-1]==27)
return smancount;
for(int i=0;i<len;i++)
{
if(!isdigit(smancount[i]))
break;
}
if(i<len)
continue;
else
break;
}while(1);
GotoXY(x,y);
CMessageBox::Clear(x,3);
return smancount;
}
/***********************************************************************
id列表输入
***********************************************************************/
string CFormAddConsume::InputIDList()
{
//IDList=输入在席的账户id
string IDList;
int x,y;
WhereXY(&x,&y);
CMessageBox::Clear(x,25);
CFormBase::GetString(IDList,25);
GotoXY(x,y);
CMessageBox::Clear(x,25);
return IDList;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -