従業員情報システム
11409 ワード
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class manager;
class employeeInfo;
manager *gMgr;
string strDept[]={"IT","Sales","H.R.","F.D.","Porduct","P.R.D.","Admin"};
string strTitle[]={"Chairman","Director","Manager","Secretary","staff","supervisor"};
class employeeInfo
{
public:
typedef struct
{
int id;
int department;
int salary;
int jobTitle;
int entryDate;
char name[40];
} data;
vector infoCollection;
public:
bool loadFile(string fname)
{
return true;
}
bool saveToFile()
{
return true;
}
friend class manager;
};
class manager
{
class functor
{
public:
int id;
functor(int a):id(a){
}
bool operator()(employeeInfo::data a)
{
if(id==a.id)return true;
return false;
}
};
class create
{
public:
int m_id;
bool check()
{
}
bool matchId(employeeInfo::data a)
{
if(m_id==a.id)return true;
return false;
}
bool addAnEmployee(employeeInfo::data& a,manager *p=gMgr)
{
m_id=a.id;
if(p->ee.infoCollection.size()==0){p->ee.infoCollection.push_back(a);return true;}
vector::iterator it=find_if(p->ee.infoCollection.begin(),p->ee.infoCollection.end(),functor(m_id));
if(it!=p->ee.infoCollection.end()){return false;}
p->ee.infoCollection.push_back(a);
return true;
}
};
class update
{
public:
int m_id;
bool matchId(employeeInfo::data a)
{
if(m_id==a.id)return true;
return false;
}
bool modify(vector& a,manager *p=gMgr)
{
vector::iterator it=a.begin();
while(it!=a.end())
{
m_id=it->id;
vector::iterator t=find_if(p->ee.infoCollection.begin(),p->ee.infoCollection.end(),[](employeeInfo::data a)->bool {if(a.id)return true;return false;});
if(t==p->ee.infoCollection.end()){++it;continue;}
(*t)=(*it);
++it;
}
return true;
}
};
class read
{
public:
int m_id;
int m_dept;
vector m_container;
bool matchId(employeeInfo::data a)
{
if(a.id==m_id)return true;
return false;
}
bool matchDept(employeeInfo::data a)
{
if(a.department==m_dept){m_container.push_back(a);return true;}
return false;
}
bool readById(int id,employeeInfo::data& a,manager *p=gMgr)
{
m_id=id;
vector::iterator it=find_if(p->ee.infoCollection.begin(), \
p->ee.infoCollection.end(),bind1st(mem_fun(&manager::read::matchId),this));
if(it==p->ee.infoCollection.end())return false;
a=*it;
return true;
}
vector readByDept(int dept,manager *p=gMgr)
{
m_dept=dept;
m_container.clear();
for_each(p->ee.infoCollection.begin(),p->ee.infoCollection.end(),bind1st(mem_fun(&manager::read::matchDept),this));
return m_container;
}
};
class del
{
public:
int m_id;
bool matchId(employeeInfo::data a)
{
if(m_id==a.id)return true;
return false;
}
bool delById(vector& a,manager *p=gMgr)
{
vector::iterator it=a.begin();
while(it!=a.end())
{
m_id=*it;
vector::iterator t=remove_if(p->ee.infoCollection.begin(),p->ee.infoCollection.end(), \
bind1st(mem_fun(&manager::del::matchId),this));
p->ee.infoCollection.resize(t-p->ee.infoCollection.begin());
++it;
}
return true;
}
};
public:
employeeInfo& ee;
manager(employeeInfo a):ee(a){}
public:
create creater;
update updater;
read reader;
del deler;
};
class shell
{
public:
manager& mgr;
shell(manager mgr):mgr(mgr){}
void start()
{
int selection;
cout<<"--------------------MainMenu-----------------------"<<endl;
cout<<"1.insertAnRecord 2.readByStaffId 3.readByDepartment"<<endl<<"4.delSomeRecords 5.modifyARecord 6.readAll 7.exit"<<endl;
cout<<"input:[operation code]+[content] or [conditions]"<<endl;
cout<<"---------------------------------------------------"<<endl;
next:cin>>selection;
switch(selection)
{
case 1:
insertAnRecord();
cin.clear();
cin.sync();
goto next;
case 2:
readByStaffId();
cin.clear();
cin.sync();
goto next;
case 3:
readByDept();
cin.clear();
cin.sync();
goto next;
case 4:
delSomeRecords();
cin.clear();
cin.sync();
goto next;
case 5:
updateARecord();
cin.clear();
cin.sync();
goto next;
case 7:
exit(1);
case 6:
readAll();
cin.clear();
cin.sync();
goto next;
default:
cout<<"Select a valid instruction No. please."<<endl;
cin.clear();
cin.sync();
goto next;
}
}
void insertAnRecord()
{
employeeInfo::data data;
cin>>data.id>>data.department>>data.jobTitle>>data.salary>>data.entryDate>>data.name;
bool flag=mgr.creater.addAnEmployee(data);
if(flag)cout<<"added."<<endl;
else cout<<"already exist."<<endl;
}
void readByStaffId()
{
int a;
cin>>a;
employeeInfo::data b;
cout<<setiosflags(ios::left);
cout<<"-----------------------------------------------------------"<<endl;
cout<<setw(10)<<"ID"<<setw(10)<<"DEPT."<<setw(10)<<"NAME"<<setw(10)<<"TITLE"<<setw(10)<<"WAGE"<<setw(10)<<"DOE"<<setw(10)<<endl;
cout<<"-----------------------------------------------------------"<<endl;
if(!mgr.reader.readById(a,b)){cout<<"search done."<<endl;return;}
cout<<setw(10)<<b.id<<setw(10)<<strDept[b.department].c_str()<<setw(10)<<b.name<<setw(10)<<strTitle[b.jobTitle].c_str()<<setw(10)<<b.salary<<setw(10)<<b.entryDate<<setw(10)<<endl;
cout<<"search done."<<endl;
}
void readByDept()
{
int a;
cin>>a;
vector b=mgr.reader.readByDept(a);
vector::iterator it=b.begin();
cout<<setiosflags(ios::left);
cout<<"-----------------------------------------------------------"<<endl;
cout<<setw(10)<<"ID"<<setw(10)<<"DEPT."<<setw(10)<<"NAME"<<setw(10)<<"Title"<<setw(10)<<"WAGE"<<setw(10)<<"DOE"<<setw(10)<<endl;
cout<<"-----------------------------------------------------------"<<endl;
while(it!=b.end())
{
cout<<setw(10)<id<<setw(10)<<strDept[it->department].c_str()<<setw(10)<name<<setw(10)<<strTitle[it->jobTitle].c_str()<<setw(10)<salary<<setw(10)<entryDate<<setw(10)<<endl;
++it;
}
cout<<"search done."<<endl;
}
void delSomeRecords()
{
vector a;
int b;
while(cin>>b)
{
a.push_back(b);
}
cout<<"deleted"<<endl;
mgr.deler.delById(a);
}
void updateARecord()
{
vector a;
employeeInfo::data b;
cin>>b.id>>b.department>>b.jobTitle>>b.salary>>b.entryDate>>b.name;
a.push_back(b);
mgr.updater.modify(a);
cout<<"updated."<<endl;
}
void readAll()
{
vector::iterator it=mgr.ee.infoCollection.begin();
cout<<setiosflags(ios::left);
cout<<"-----------------------------------------------------------"<<endl;
cout<<setw(10)<<"ID"<<setw(10)<<"DEPT."<<setw(10)<<"NAME"<<setw(10)<<"Title"<<setw(10)<<"WAGE"<<setw(10)<<"DOE"<<setw(10)<<endl;
cout<<"-----------------------------------------------------------"<<endl;
while(it!=mgr.ee.infoCollection.end())
{
cout<<setw(10)<id<<setw(10)<<strDept[it->department].c_str()<<setw(10)<name<<setw(10)<<strTitle[it->jobTitle].c_str()<<setw(10)<salary<<setw(10)<entryDate<<setw(10)<<endl;
++it;
}
cout<<"search done."<<endl;
}
};
int main()
{
employeeInfo ee;
ee.loadFile("1.txt");
manager mgr(ee);
gMgr=&mgr;
shell sh(mgr);
sh.start();
return 0;
}