中山大学2018年软件工程专业初级实训

以下为实训代码,只到AgendaService类,因为我的UI还有问题,不过已经通过了我就没有再搞

以下代码亲测在2018年的软件工程初级实训中可以通过Matrix的机器测试,希望造福大家

User类

#include<iostream>
#include"User.hpp"
using namespace std;

User::User(const std::string &t_userName, const std::string &t_userPassword,const std::string &t_userEmail, const std::string &t_userPhone){
	this->m_name=t_userName;
	this->m_password=t_userPassword;
	this->m_email=t_userEmail;
	this->m_phone=t_userPhone;
}
User::User(const User &t_user){
	this->m_name=t_user.m_name;
	this->m_password=t_user.m_password;
	this->m_email=t_user.m_email;
	this->m_phone=t_user.m_phone;
}
std::string User::getName()const{
	return this->m_name;
}
void User::setName(const std::string &t_name){
	this->m_name=t_name;
}
std::string User::getPassword() const{
	return this->m_password;
}
void User::setPassword(const std::string &t_password){
	this->m_password=t_password;
}
std::string User::getEmail() const{
	return this->m_email;
}
void User::setEmail(const std::string &t_email){
	this->m_email=t_email;
}
std::string User::getPhone() const{
	return this->m_phone;
}
void User::setPhone(const std::string &t_phone){
	this->m_phone=t_phone;
}

Date类

#include<iostream>
#include"Date.hpp"
using namespace std;
Date::Date(){
	this->m_year=0;
	this->m_month=0;
	this->m_day=0;
	this->m_hour=0;
	this->m_minute=0;
}
Date::Date(int t_year, int t_month, int t_day, int t_hour, int t_minute){
	this->m_year=t_year;
	this->m_month=t_month;
	this->m_day=t_day;
	this->m_hour=t_hour;
	this->m_minute=t_minute;
}
Date::Date(const std::string &dateString){
	int year=0;
	int month=0;
	int day=0;
	int hour=0;
	int minute=0;
	bool v=true;
	if(dateString.size()!=16){
		this->m_year=0;
		this->m_month=0;
		this->m_day=0;
		this->m_hour=0;
		this->m_minute=0;
		v=false;
	}
	if(dateString[4]!='-'||dateString[7]!='-'||dateString[10]!='/'||dateString[13]!=':'){
		this->m_year=0;
		this->m_month=0;
		this->m_day=0;
		this->m_hour=0;
		this->m_minute=0;
		v=false;
	}
	for(int i=0;i<16;i++){
  		if(i==4||i==7||i==10||i==13){
  			
		}	
		else{
			if(dateString[i]<'0'||dateString[i]>'9'){
				this->m_year=0;
				this->m_month=0;
				this->m_day=0;
				this->m_hour=0;
				this->m_minute=0;
				v=false;
			}
		}
	}
	if(v){
		for(int i=0;i<4;i++){
			year=year*10+dateString[i]-'0';
		}
		for(int i=5;i<=6;i++){
			month=month*10+dateString[i]-'0';
		}
		for(int i=8;i<=9;i++){
			day=day*10+dateString[i]-'0';
		}
		for(int i=11;i<=12;i++){
			hour=hour*10+dateString[i]-'0';
		}
		for(int i=14;i<=15;i++){
			minute=minute*10+dateString[i]-'0';
		}
		this->m_year=year;
		this->m_month=month;
		this->m_day=day;
		this->m_hour=hour;
		this->m_minute=minute;
	}
}
int Date::getYear(void) const{
	return this->m_year;
}
void Date::setYear(const int t_year){
	this->m_year=t_year;
}
int Date::getMonth(void) const{
	return this->m_month;
}
void Date::setMonth(const int t_month){
	this->m_month=t_month;
}
int Date::getDay(void) const{
	return this->m_day;
}
void Date::setDay(const int t_day){
	this->m_day=t_day;
}
int Date::getHour(void) const{
	return this->m_hour;
}
void Date::setHour(const int t_hour){
	this->m_hour=t_hour;
}
int Date::getMinute(void) const{
	return this->m_minute;
}
void Date::setMinute(const int t_minute){
	this->m_minute=t_minute;
}
bool Date::isValid(const Date &t_date){
	if(t_date.getYear()<1000||t_date.getYear()>9999){
		return false;
	}
	if(t_date.getMonth()<1||t_date.getMonth()>12){
		return false;
	}
	if(t_date.getMonth()==1||t_date.getMonth()==3||t_date.getMonth()==5||t_date.getMonth()==7||t_date.getMonth()==8||t_date.getMonth()==10||t_date.getMonth()==12){
		if(t_date.getDay()<1||t_date.getDay()>31){
			return false;
		}
	}
	if(t_date.getMonth()==4||t_date.getMonth()==6||t_date.getMonth()==9||t_date.getMonth()==11){
		if(t_date.getDay()<1||t_date.getDay()>30){
			return false;
		}
	}
	if(t_date.getMonth()==2){
		if(t_date.getYear()%400==0||(t_date.getYear()%4==0&&t_date.getYear()%100!=0)){
			if(t_date.getDay()<1||t_date.getDay()>29){
				return false;
			}
		}
		else{
			if(t_date.getDay()<1||t_date.getDay()>28){
				return false;
			}
		}
	}
	if(t_date.getHour()<0||t_date.getHour()>23){
		return false;
	}
	if(t_date.getMinute()<0||t_date.getMinute()>59){
		return false;
	}
	return true;
}
 Date Date::stringToDate(const std::string &t_dateString){
	Date d=Date(0,0,0,0,0);
	int year=0;
	int month=0;
	int day=0;
	int hour=0;
	int minute=0;
	if(t_dateString.size()!=16){
		return d;
	}
	if(t_dateString[4]!='-'||t_dateString[7]!='-'||t_dateString[10]!='/'||t_dateString[13]!=':'){
		return d;
	}
	for(int i=0;i<16;i++){
		if(i==4||i==7||i==10||i==13){
			
		}
		else{
			if(t_dateString[i]<'0'||t_dateString[i]>'9'){
				return d;
			}
		}
	}
	Date d1(t_dateString);
	return d1;
}
string Date::dateToString(const Date& t_date){ 
	if(t_date.isValid(t_date) ==false){
    	string str1 = "0000-00-00/00:00";
    	return str1;
  	}
  	int year;
  	int month;
  	int day;
  	int hour;
  	int minute;
  	year=t_date.m_year;
  	month=t_date.m_month;
  	day=t_date.m_day;
  	hour=t_date.m_hour;
  	minute=t_date.m_minute;
  	string str;
  	str.push_back(year/1000+'0');
  	int three=year-(year/1000)*1000;
  	str.push_back(three/100+'0');
  	int two=three-(three/100)*100;
  	str.push_back(two/10+'0');
  	str.push_back(two%10+'0');
  	str.push_back('-');
  	str.push_back(month/10+'0');
  	str.push_back(month%10+'0');
  	str.push_back('-');
  	str.push_back(day/10+'0');
  	str.push_back(day%10+'0');
  	str.push_back('/');
  	str.push_back(hour/10+'0');
  	str.push_back(hour%10+'0');
  	str.push_back(':');
  	str.push_back(minute/10+'0');
 	str.push_back(minute%10+'0');
  	return str;
}
Date & Date::operator=(const Date &t_date){
	this->m_year=t_date.m_year;
	this->m_month=t_date.m_month;
	this->m_day=t_date.m_day;
	this->m_hour=t_date.m_hour;
	this->m_minute=t_date.m_minute;
	return (*this);
}
bool Date::operator==(const Date &t_date) const{
	if(this->m_year==t_date.m_year&&this->m_month==t_date.m_month&&this->m_day==t_date.m_day&&this->m_hour==t_date.m_hour&&this->m_minute==t_date.m_minute){
		return true;
	}
	else{
		return false;
	}
}
bool Date::operator>(const Date &t_date) const{
	if(this->m_year>t_date.m_year){
		return true;
	}
	else if(this->m_year<t_date.m_year){
		return false;
	}
	else{
		if(this->m_month>t_date.m_month){
			return true;
		}
		else if(this->m_month<t_date.m_month){
			return false;
		}
		else{
			if(this->m_day>t_date.m_day){
				return true;
			}
			else if(this->m_day<t_date.m_day){
				return false;
			}
			else{
				if(this->m_hour>t_date.m_hour){
					return true;
				}
				else if(this->m_hour<t_date.m_hour){
					return false;
				}
				else{
					if(this->m_minute>t_date.m_minute){
						return true;
					}
					else if(this->m_minute<=t_date.m_minute){
						return false;
					}
				}
			}
		}
	}
}
bool Date::operator<(const Date &t_date) const{
		if(this->m_year<t_date.m_year){
		return true;
	}
	else if(this->m_year>t_date.m_year){
		return false;
	}
	else{
		if(this->m_month<t_date.m_month){
			return true;
		}
		else if(this->m_month>t_date.m_month){
			return false;
		}
		else{
			if(this->m_day<t_date.m_day){
				return true;
			}
			else if(this->m_day>t_date.m_day){
				return false;
			}
			else{
				if(this->m_hour<t_date.m_hour){
					return true;
				}
				else if(this->m_hour>t_date.m_hour){
					return false;
				}
				else{
					if(this->m_minute<t_date.m_minute){
						return true;
					}
					else if(this->m_minute>=t_date.m_minute){
						return false;
					}
				}
			}
		}
	}
}

bool Date::operator>=(const Date &t_date) const{
	if((*this)>t_date||(*this)==t_date){
		return true;
	}
	else{
		return false;
	}
}
bool Date::operator<=(const Date &t_date) const{
	if((*this)<t_date||(*this)==t_date){
		return true;
	}
	else{
		return false;
	}
}

Meeting类

#include"Meeting.hpp"
using namespace std;
  Meeting::Meeting(const std::string &t_sponsor,const std::vector<std::string> &t_participator, const Date &t_startTime,const Date &t_endTime, const std::string &t_title){
  	this->m_sponsor=t_sponsor;
  	this->m_participators=t_participator;
  	this->m_startDate=t_startTime;
  	this->m_endDate=t_endTime;
  	this->m_title=t_title;
  }
  Meeting::Meeting(const Meeting &t_meeting){
	this->m_sponsor=t_meeting.getSponsor();
  	this->m_participators=t_meeting.getParticipator();
  	this->m_startDate=t_meeting.getStartDate();
  	this->m_endDate=t_meeting.getEndDate();
  	this->m_title=t_meeting.getTitle();
  }
  std::string Meeting::getSponsor(void) const{
  		return this->m_sponsor;
  }
  void Meeting::setSponsor(const std::string &t_sponsor){
		this->m_sponsor=t_sponsor;
  }
  std::vector<std::string> Meeting::getParticipator(void) const{
		return this->m_participators;
  }
  void Meeting::setParticipator(const std::vector<std::string> &t_participators){
	  	this->m_participators=t_participators;
  }
  Date Meeting::getStartDate(void) const{
		return this->m_startDate;
  }
  void Meeting::setStartDate(const Date &t_startTime){
  		this->m_startDate=t_startTime;
  }
  Date Meeting::getEndDate(void) const{
		return this->m_endDate;
  }
  void Meeting::setEndDate(const Date &t_endTime){
		this->m_endDate=t_endTime;
  }
  std::string Meeting::getTitle(void) const{
		return this->m_title;
  }
  void Meeting::setTitle(const std::string &t_title){
  		this->m_title=t_title;
  }
  bool Meeting::isParticipator(const std::string &t_username) const{
  		int size=this->m_participators.size();
  		for(int i=0;i<size;i++){
  			if(t_username==this->m_participators[i]){
  				return true;
  			}
  		}
  		return false;
  }
  void Meeting::addParticipator(const std::string &t_participator){
     m_participators.push_back(t_participator);
  }

  void Meeting::removeParticipator(const std::string &t_participator){
    std::vector<std::string> temp;
    int size=m_participators.size();
    for(int i=0;i<size;i++){
      if(m_participators[i]!=t_participator){
        temp.push_back(m_participators[i]);
      }
    }
    size=temp.size();
    m_participators.clear();
    for(int i=0;i<size;i++){
      m_participators.push_back(temp[i]);
    }
  }

Storage类

#include "Storage.hpp"
#include "Path.hpp"
#include <fstream>
using namespace std;
std::shared_ptr<Storage> Storage::m_instance = nullptr;
Storage::Storage() {
	m_dirty = false;
	readFromFile();
};
bool Storage::readFromFile(void) {
	ifstream fusers(Path::userPath);
	ifstream fmeetings(Path::meetingPath);
	if (!(fusers.is_open() && fmeetings.is_open())){
		return false;
	}
	string str1;
	while (getline(fusers, str1)) {
		string name, password, email, phone;
		if(str1.size() == 0) {
            continue;
        }
        int len=str1.size();
        vector<int>pos;
		for(int i = 0; i < len ; i++){
    		if(str1[i] == '"')
    		pos.push_back(i);
  		}
		for(int i = pos[0]+1 ; i < pos[1] ; i++){
			name.push_back(str1[i]);
		}	
   		for(int i = pos[2]+1 ; i < pos[3] ; i++){
   			password.push_back(str1[i]);
		}
   		for(int i = pos[4]+1 ; i < pos[5] ; i++){
   			email.push_back(str1[i]);
		}
   		for(int i = pos[6]+1 ; i < pos[7] ; i++){
   			phone.push_back(str1[i]);
		}
		User u(name, password, email, phone);
		m_userList.push_back(u);
	}
	fusers.close();
	string str2;
	while (getline(fmeetings, str2)) {
		string sponsor, participators, startDate, endDate, title;
		if(str2.size() == 0) {
                continue;
        }
		int len=str2.size();
		vector<int> pos;
		for(int i = 0; i < len ; i++){
    		if(str2[i] == '"')
    		pos.push_back(i);
  		}
  			for(int i = pos[0]+1 ; i < pos[1] ; i++){
				sponsor.push_back(str2[i]);
			}
			for(int i = pos[2]+1 ; i < pos[3] ; i++){
				participators.push_back(str2[i]);
			}
    		for(int i = pos[4]+1 ; i < pos[5] ; i++){
				startDate.push_back(str2[i]);
			}	
    		for(int i = pos[6]+1 ; i < pos[7] ; i++){
				endDate.push_back(str2[i]);
			}
    		for(int i = pos[8]+1 ; i < pos[9] ; i++){
				title.push_back(str2[i]);
			}
		vector<string> v_participators;
		int len2=participators.size();
		string parti;
		for(int i=0;i<len2;i++){
			if(participators[i]!='&'){
				parti.push_back(participators[i]);
			}
			else{
				string temp=parti;
				v_participators.push_back(temp);
				parti.clear();
			}
		}
		v_participators.push_back(parti);
		Date start(startDate);
		Date end(endDate);
		Meeting meeting(sponsor, v_participators, start, end, title);
		m_meetingList.push_back(meeting);
	}
	fmeetings.close();
	return true;
};
bool Storage::writeToFile(void) {
	ofstream fusers(Path::userPath);
	ofstream fmeetings(Path::meetingPath);
	if (!(fusers.is_open() && fmeetings.is_open())){
		return false;
	}
	for (auto it = m_userList.begin();it != m_userList.end();it++) {
		fusers<<'"'<<(*it).getName()<<'"'<<','<<'"'<<(*it).getPassword()<<'"'<<','<<'"'<<(*it).getEmail()<<'"'<<','<<'"'<<(*it).getPhone()<<'"';
		fusers<<"\n";
	}
	fusers.close();
   	for(auto it = m_meetingList.begin();it != m_meetingList.end();it++)  {
       fmeetings<<'"'<<(*it).getSponsor()<<'"'<<','<<'"';
       vector<string> par = (*it).getParticipator();
       int len = par.size();
       for(int i = 0 ; i < len-1 ; i++){
         	fmeetings<<par[i]<<'&';
       }
       fmeetings<<par[len-1];
       fmeetings<<'"'<<','<<'"'<<(*it).getStartDate().dateToString((*it).getStartDate())<<'"'<<','<<'"'<<(*it).getEndDate().dateToString((*it).getEndDate())<<'"'<<','<<'"'<<(*it).getTitle()<<'"';
         fmeetings<<"\n";
     }
	fmeetings.close();
	return true;
};
std::shared_ptr<Storage> Storage::getInstance(void) {
	if (m_instance == nullptr) {
		m_instance = shared_ptr<Storage>(new Storage());
	}
	return m_instance;
};
Storage::~Storage() {
	sync();
};
void Storage::createUser(const User &t_user) {
	m_userList.push_back(t_user);
	m_dirty = true;
};
std::list<User> Storage::queryUser(std::function<bool(const User &)> filter) const {
	std::list<User> result;
	for (auto it = m_userList.begin();it != m_userList.end();it++) {
		if (filter(*it)){
			result.push_back(*it);
		}
	}
	return result;
};
int Storage::updateUser(std::function<bool(const User &)> filter,
             std::function<void(User &)> switcher) {
	int num = 0;
	for (auto it = m_userList.begin();it != m_userList.end();it++) {
		if (filter(*it)) {
			switcher(*it);
			num++;
		}
	}
	if(num > 0){
		m_dirty = true;
	}
	return num;
};
int Storage::deleteUser(std::function<bool(const User &)> filter) {
	int num = 0;
	for (auto it = m_userList.begin();it != m_userList.end();) {
		if (filter(*it)) {
			it = m_userList.erase(it);
			num++;
		}
		else{
			it++;
		}
	}
	if (num > 0){
		m_dirty = true;
	}
	return num;
};
void Storage::createMeeting(const Meeting &t_meeting) {
	m_meetingList.push_back(t_meeting);
	m_dirty = true;
};
std::list<Meeting> Storage::queryMeeting(
  std::function<bool(const Meeting &)> filter) const {
	list<Meeting> meeting;
	for (auto it = m_meetingList.begin();it != m_meetingList.end();it++) {
		if (filter(*it))
			meeting.push_back(*it);
	}
	return meeting;
};
int Storage::updateMeeting(std::function<bool(const Meeting &)> filter,
                std::function<void(Meeting &)> switcher) {
	int num = 0;
	for (auto it = m_meetingList.begin();it != m_meetingList.end();it++) {
		if (filter(*it)) {
			switcher(*it);
			num++;
		}
	}
	if (num > 0){
		m_dirty = true;
	}
	return num;
};
int Storage::deleteMeeting(std::function<bool(const Meeting &)> filter) {
	int num = 0;
	for (auto it = m_meetingList.begin();it != m_meetingList.end();) {
		if (filter(*it)) {
			it = m_meetingList.erase(it);
			num++;
		}
		else
			it++;
	}
	if (num > 0){
		m_dirty = true;
	}
	return num;
};
bool Storage::sync(void) {
	m_dirty = false;
	return writeToFile();
};

AgendaService类

#include<iostream>
#include<string>
#include<list>
#include<vector>
#include"User.hpp"
#include"Date.hpp"
#include"Meeting.hpp"
#include"Storage.hpp"
#include"AgendaService.hpp" 
using namespace std;
AgendaService::AgendaService(){
	startAgenda();
}
AgendaService::~AgendaService(){
	quitAgenda();
}
bool AgendaService::userLogIn(const std::string &userName, const std::string &password){
	auto filter=[userName, password](const User &user) {//
        if(userName==user.getName()&&password==user.getPassword()){
        	return true;
		}
		else{
			return false;
		}
    };
    list<User>temp=m_storage->queryUser(filter);
    int size=temp.size();
    if(size>0){
    	return true;
	}
	else{
		return false;
	}
}
bool AgendaService::userRegister(const std::string &userName, const std::string &password,const std::string &email, const std::string &phone){
	User U(userName, password, email, phone);
	auto filter=[userName](const User &user) {
       if(user.getName()==userName){
       		return true;
	   }
	   else{
	   	return false;
	   }
    };
    list<User> temp=m_storage->queryUser(filter);
    if(temp.empty()){
    	m_storage->createUser(U);
    	return true;
	}
	else{
		return false;
	}
}
bool AgendaService::deleteUser(const std::string &userName, const std::string &password){
	auto filter=[userName, password](const User &user) {
        if(userName==user.getName()&&password==user.getPassword()){
        	return true;
		}
		else{
			return false;
		}
    };
    deleteAllMeetings(userName);
     auto parlist=listAllParticipateMeetings(userName);
     for(auto it=parlist.begin();it!=parlist.end();it++){
     	quitMeeting(userName, it->getTitle());
	 }
    int num=m_storage->deleteUser(filter);
   	if(num>0){
   		return true;
	}
	else{
		return false;
	} 
}
std::list<User> AgendaService::listAllUsers(void) const{
	auto filter=[](const User &user) {return true;};
	list<User>temp=m_storage->queryUser(filter);
    return temp;
}
bool AgendaService::addMeetingParticipator(const std::string &userName,const std::string &title,const std::string &participator){
    auto filter = [participator](const User& user) {
        if(user.getName()==participator){
           return true;
        }
        return false;
    };
    std::list<User>U=m_storage->queryUser(filter);
    if(U.size()!=1){
   		return false;
    }
    auto filter1=[&](const Meeting & meeting){
        if(meeting.getSponsor()==userName&&meeting.getTitle()==title){
			std::list<Meeting>l=m_storage->queryMeeting( [&](const Meeting&meeting1){
        	if(meeting1.getSponsor()==participator||meeting1.isParticipator(participator)){
        		if(meeting.getStartDate()>=meeting1.getEndDate()||meeting.getEndDate()<=meeting1.getStartDate()){
        	   		return false;
       			}
       			else{
       				return true;
				}
      	  	}
      		return false;
        	});
			if(l.empty()){
        	   return true;
       		}
       		return false;
        }
        return false;
    };
    auto switcher=[participator](Meeting &meeting) {
        meeting.addParticipator(participator);	
    };
    int num=m_storage->updateMeeting(filter1, switcher);
    if(num>0){
     	return true;
	}
	else{
	 	return false;
	}
}
bool AgendaService::createMeeting(const std::string &userName, const std::string &title,const std::string &startDate, const std::string &endDate,const std::vector<std::string> &participator){
	Date start(startDate);
	Date end(endDate);
	Meeting meeting(userName,participator,start,end,title);
	if (participator.empty()){
		return false;
	}
	if(start.isValid(start)==false||end.isValid(end)==false||start>=end){//
		return false;
	}
    bool have=false;
    list<User>temp=listAllUsers();
    for(auto it=temp.begin();it!=temp.end();it++){
    	if(userName==it->getName()){
    		have=true;
    		break;
		}
	}
	if(have==false){
		return false;
	}
	if (participator.empty()){
		return false;
	}
    auto filter=[title](const Meeting &meeting) {
        if(meeting.getTitle()==title){
        	return true;
		}
		else{
			return false;
		}
    };
    list<Meeting>temp1=m_storage->queryMeeting(filter);
    if(temp1.empty()==false){
    	return false;
	}
    auto filter1=[userName](const Meeting &meeting) {
        if(userName==meeting.getSponsor()){
        	return true;
		}
		else{
			return false;
		}
    };
    list<Meeting>m=listAllMeetings(userName);
    for(auto it=m.begin();it!=m.end();it++){
		if(!(it->getEndDate()<=start||it->getStartDate()>= end)){
			 return false;
		}
	}
	vector<string>par;
    Meeting meet(userName,par,start,end,title);
    m_storage->createMeeting(meet);
	for (auto it=participator.begin();it!=participator.end();it++){
		bool suc;
		suc=addMeetingParticipator(userName, title, *it);
    	if(suc==true){
    		par.push_back(*it);
		}
		else{
			m_storage->deleteMeeting(filter);
			return false;
		}
	}
	return true;
}
bool AgendaService::removeMeetingParticipator(const std::string &userName,const std::string &title,const std::string &participator){
	 if(userName==participator){
    	return false;
	} 
	auto filter=[userName](const User &u){
		if(u.getName()==userName){
			return true;
		}
		else{
			return false;
		}
	};
	auto filter1=[participator](const User &u){
		if(u.getName()==participator){
			return true;
		}
		else{
			return false;
		}
	};
	list<User>u1=m_storage->queryUser(filter);
	list<User>u2=m_storage->queryUser(filter1);
	if(u1.empty()||u2.empty()){
		return false;
	}
	auto filter2 = [userName, title](const Meeting &meeting) {
        if (meeting.getSponsor()==userName&&meeting.getTitle()==title){
        	return true;
		}
        else{
        	return false;
		}
    };
    list<Meeting>l=m_storage->queryMeeting(filter2);
    if(l.size()!=1){
    	return false;
	}
	Meeting m=*(l.begin());
	if(!m.isParticipator(participator)){
		return false;
	}
    auto switcher=[participator](Meeting &meeting) {
    	meeting.removeParticipator(participator);
    };
    
    int num=m_storage->updateMeeting(filter2, switcher);
    m_storage->deleteMeeting([](const Meeting &meeting){
    	return meeting.getParticipator().empty();
	});
    if(num>0){
   		return true;
    }
    else{
   		return false;
    }
}
bool AgendaService::quitMeeting(const std::string &userName, const std::string &title){
	auto filter=[userName, title](const Meeting &meeting){
     	if(meeting.isParticipator(userName)&&meeting.getTitle()==title){
     		return true;
	 	}
	 	else{
	 		return false;
	 	}
	};
	auto switcher=[userName](Meeting &meeting) {
        meeting.removeParticipator(userName);
    };
    int num=m_storage->updateMeeting(filter, switcher);
    auto filter1=[](const Meeting &meeting) {
        if(meeting.getParticipator().empty()){
        	return true;
		}
		else{
			return false;
		}
    };
    m_storage->deleteMeeting(filter1);
    if(num>0){
    	return true;
	}
	else{
		return false;
	}
}
std::list<Meeting> AgendaService::meetingQuery(const std::string &userName,const std::string &title) const{
	list<Meeting>l;
	list<User>U=m_storage->queryUser([userName](const User&u){
		if(u.getName()==userName){
			return true;
		}
		else{
			return false;
		}
	});
	if(U.empty()){
		return l;
	}
	auto filter=[userName, title](const Meeting &meeting){
    	if((userName==meeting.getSponsor()||meeting.isParticipator(userName))&&title==meeting.getTitle()){
    		return true;
		}
		else{
			return false;
		}
	};
	list<Meeting>temp=m_storage->queryMeeting(filter);
	return temp;
}
std::list<Meeting> AgendaService::meetingQuery(const std::string &userName,const std::string &startDate,const std::string &endDate) const{
	Date start(startDate);
	Date end(endDate);
	list<Meeting> temp;
	list<Meeting>l;
	if(start.isValid(start)==false||end.isValid(end)==false||start>end){//
		return temp;
	}
	list<User>U=m_storage->queryUser([userName](const User&u){
		if(u.getName()==userName){
			return true;
		}
		else{
			return false;
		}
	});
	if(U.empty()){
		return l;
	}
	auto filter=[userName, start, end](const Meeting &meeting){
		if((meeting.getSponsor()==userName||meeting.isParticipator(userName))&&meeting.getEndDate()>=start&&meeting.getStartDate()<=end){
			return true;
		}
	 	else{
	 		return false;
	 	}
	};
	temp=m_storage->queryMeeting(filter);
	return temp;
}
std::list<Meeting> AgendaService::listAllMeetings(const std::string &userName) const{
	auto filter = [userName](const Meeting &meeting) {
        if(userName==meeting.getSponsor()||meeting.isParticipator(userName)){
        	return true;
		}
		else{
			return false;
		}
    };
    list<Meeting>temp=m_storage->queryMeeting(filter);
    return temp;
}
std::list<Meeting> AgendaService::listAllSponsorMeetings(const std::string &userName) const{
 	auto filter=[userName](const Meeting &meeting) {
 			if(userName==meeting.getSponsor()){
 				return true;
			}
			else{
			 	return false;
			}
    };
    list<Meeting>temp=m_storage->queryMeeting(filter);
    return temp;
}
std::list<Meeting> AgendaService::listAllParticipateMeetings(const std::string &userName) const{
	auto filter=[userName](const Meeting &meeting){
		if(meeting.isParticipator(userName)){
			return true;
		}
		else{
			return false;
		}
	};
	list<Meeting>temp=m_storage->queryMeeting(filter);
    return temp;
}
bool AgendaService::deleteMeeting(const std::string &userName, const std::string &title){
	auto filter=[userName, title](const Meeting &meeting) {
       if(userName==meeting.getSponsor()&&title==meeting.getTitle()){
       		return true;
	   	}
	   	else{
	   		return false;	
		}
    };
    int num=m_storage->deleteMeeting(filter);
    if(num>0){
    	return true;
	}
	else{
		return false;
	}
}
bool AgendaService::deleteAllMeetings(const std::string &userName){
	auto filter=[userName](const Meeting &meeting) {
        if(userName==meeting.getSponsor()){
        	return true;
		}
		else{
			return false;
		}
    };
    int num=m_storage->deleteMeeting(filter);
    if(num>0){
    	return true;
	}
	else{
		return false;
	}
}
void AgendaService::startAgenda(void){
	m_storage=Storage::getInstance();
}
void AgendaService::quitAgenda(void){
	m_storage->sync();
}

猜你喜欢

转载自blog.csdn.net/dcy19991116/article/details/84633885
今日推荐