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

📄 administrator.cpp

📁 它是一个完整的工资管理系统
💻 CPP
字号:
#include "administrator.h"
#include "employee.h"
#include "menu.h"
#include <string>
#include <fstream>
#include <sstream>
#include "salary.h"

extern int iNumNode;
extern CEmployee *HeadEmployee;
CAdministrator::CAdministrator(string m_sPasswd, string m_sUser):
                CSalaryManager(m_sPasswd, m_sUser){}
//CAdministrator::~CAdministrator(){}
void CAdministrator::AddUser()///////////////////////////////////////wxw添加新用户入口
{
	string name="";/////////////////////////////////////////////////记录用户名
	string pword="";////////////////////////////////////////////////记录输入密码
	string identity="";////////////////////////////////////////////记录添加用户身份
    bool find=false;///////////////////////////////////////////////记录用户是否合法
    
	cout<<"\n\n\t\t\t\t请输入你要添加的用户名:";
	cin>>name;
	for(CEmployee *emp=HeadEmployee->next;emp!=NULL;emp=emp->next)//查找用户名是否合法
	{
		if(emp->m_sSalaryCardId==name)//////////////////////////////合法
		{
			find=true;
			break;
		}
	}
	if(find)////////////////////////////如果合法则要求输入密码及身份
	{
		cout<<"\n\n\t\t\t\t\t请输入密码:";
		CMenu menu;
		pword=menu.GetUserInputPassword();
        cout<<"\n\n\t\t\t\t\t请选择添加用户的身份:"<<endl
			<<"\n\t\t\t\t\t 1:一般用户"<<endl
			<<"\n\t\t\t\t\t 2:工资管理员"<<endl
			<<"\n\t\t\t\t\t 3:系统管理员"<<endl
			<<"\n\t\t\t\t\t:";
        cin>>identity;
		if(!menu.IsDigit(identity)||identity=="#")////////////判断是否是数字
		{
		  cout<<"错误的身份选择 !";
			return;
		}
		switch(identity[0])//////////////////////////////////根据身份打开不同的文件
		{
		case '1':	
			Open_Add("Secret\\SimpleUser.txt",name,pword);
			break;
		case '2':
			Open_Add("Secret\\SalaryManager.txt",name,pword);
			break;
		case '3':
			Open_Add("Secret\\Administrator.txt",name,pword);
			break;
		default:
			cout<<"\n\t\t\t\t错误的身份选择 !";
			break;
		}
	}
	else/////////////////////////////////////////////////////////////没有以输入用户名为工资卡号的员工
	{
		cout<<"\n\t\t\t\t添加用户名不合法。\n";
	}
}

void CAdministrator::Open_Add(char *filePath,string name,string pword)////wxw添加用户
{
	ifstream in(filePath);////////////////////////////////////////打开指定文件
	if(!in)
	{
		cout<<"\n\t\t\t\t\t文件打开出错\n\n";
		return;
	}
	for(string strLine;getline(in,strLine);)//////////////////////判断用户是否重复
	{
		istringstream sin(strLine);
		string strWord;
		sin>>strWord;
		if(strWord==name)
		{
			cout<<"\n\t\t\t\t\t用户已存在,请确认!";
			in.close();
			return;
		}
	}
	in.close();
    

	/////////////////////////////////////不重复则添加
	fstream io(filePath,ios::in|ios::out);
	io.seekg(0,ios::end);
	io<<name<<" "<<pword<<endl;
	io.close();
	cout<<"\n\t\t\t\t\t:添加用户成功。\n";
}

void CAdministrator::DelUser()////////////////////////删除用户
{
	string name="";
	string identity="";//////////////////////////////记录身份
    
	cout<<"\n\n\t\t\t\t请输入你要删除的用户名:";
	cin>>name;

	cout<<"\n\n\t\t\t\t\t请选择添加用户的身份:"<<endl
		<<"\n\t\t\t\t\t 1:一般用户"<<endl
		<<"\n\t\t\t\t\t 2:工资管理员"<<endl
		<<"\n\t\t\t\t\t 3:系统管理员"<<endl
		<<"\n\t\t\t\t\t:";
    cin>>identity;

	switch(identity[0])////////////////////////////按身份打开不同文件
	{
	case '1':	
		Open_Del("Secret\\SimpleUser.txt",name);
		break;
	case '2':
		Open_Del("Secret\\SalaryManager.txt",name);
		break;
	case '3':
		Open_Del("Secret\\Administrator.txt",name);
		break;
	default:
		cout<<"错误的身份选择 !";
		break;
	}
}

void CAdministrator::Open_Del(char *filePath,string name)//////////打开指定文件并删除
{
	string delStr="";
	bool find=false;

	fstream io(filePath,ios::in|ios::out);
	if(!io)
	{
		cout<<"\n\t\t\t\t\t文件打开出错\n\n";
		return;
	}
	for(string strLine;getline(io,strLine);)/////////查看是否存在,存在则删除,反之返回
	{
		istringstream sin(strLine);
		string strWord;
		sin>>strWord;
		if(strWord==name)
		{
			find=true;

			for(int i=0;i<strLine.length();i++)
			{
				delStr+=" ";
			}
			io.seekg(-(strLine.length()+2),ios::cur);
			io<<delStr;
			io.close();
			
		}
	}
	if(find)
	{
		cout<<"\n\t\t\t\t\t:删除用户成功。\n";
	}
	else
	{
		cout<<"\n\t\t\t\t\t:没有此用户登录信息,请确认!\n";
	}
}

void CAdministrator::AddEmp()/////////////////////////////////////////////////wxw
{
	string nameID="";/////////////////////////////////////////////////////////记录用户名
	CEmployee *emp=HeadEmployee;///////////////////////////////////////////记录查找记录

    cout<<"\n\t\t\t\t请输入用户名";
	cin>>nameID;
	for(;emp->next!=NULL;emp=emp->next)
	{
		if(emp->next->m_sSalaryCardId==nameID)
		{	
			break;
		}
	}
	if(emp->next!=NULL)
	{
		cout<<"\n\t\t\t\t该用户已经存在,请确认 。\n";
		return ;
	}
	else
	{
		CEmployee  *employee=new CEmployee();
		InputEmpInfo(nameID,*employee);//////////////////////////////////////添加员工
		emp->next=employee;
		iNumNode++;
		cout<<"\n\n\t\t\t\t添加成功\n";
	}
}

void  CAdministrator:: InputEmpInfo(string nameID,CEmployee &employee)////////////////wxw
{
	
    
	employee.m_sSalaryCardId=nameID;
	employee.m_cSalary.m_sSalaryCardId=nameID;

    cout<<"\n\t\t\t\t请输入员工姓名:";
	cin>>employee.m_sName;
	

    while(true)
	{
		cout<<"\n\n\t\t\t\t请选择员工性别:"
		<<"\n\n\t\t\t\t           1:男    2: 女"
		<<"\n\n\t\t\t\t  你的选择是:";
		string choice;
		cin>>choice;
		if(choice[0]=='1')
		{
			employee.m_cSex='M';
			break;
		}
		else
			if(choice[0]=='2')
			{
				employee.m_cSex='F';
				break;
			}
			else
			{
				cout<<"\n\n\t\t\t\t错误的选择:";
			}
	}
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入身份证号码:";
		string ID;
		cin>>ID;
		if(ID.length()!=8)
		{
			cout<<"\n\n\t\t\t\t长度错误";
		}
		else
		{
			employee.m_sIdentityId=ID;
			break;
		}
	}
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入年龄:";
		if( (cin>>employee.m_iAge) == 0 )
		{
			cout<<"\t\t\t\t输入年龄必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}

	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入工龄:";
		if( (cin>>employee.m_iWorkAge) == 0 )
		{
			cout<<"\t\t\t\t输入工龄必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
    
	while(true)
	{
		string sDep;
		cout<<"\n\n\t\t\t\t请输入部门:"
			<<"\n\n\t\t\t\t       1:公关部"
			<<"\n\n\t\t\t\t       2:调研部"
			<<"\n\n\t\t\t\t       3:开发部"
			<<"\n\n\t\t\t\t       4:测试部"
			<<"\n\n\t\t\t\t       5:人事部"
			<<"\n\n\t\t\t\t 你的选择是:";
		cin>>sDep;
		if(sDep[0]<'1'||sDep[0]>'5')
		{
			cout<<"\n\n\t\t\t\t错误的选择";
		}
		else
		{
			switch(sDep[0])
			{
			case '1':employee.m_sDepartment="公关";break;
			case '2':employee.m_sDepartment="调研";break;
			case '3':employee.m_sDepartment="开发";break;
			case '4':employee.m_sDepartment="测试";break;
			case '5':employee.m_sDepartment="人事";break;
			}
			break;
		}
	}

   while(true)
	{
		string sTch;
		cout<<"\n\n\t\t\t\t请输入职称:"
			<<"\n\n\t\t\t\t       001:经理"
			<<"\n\n\t\t\t\t       002:副经理"
			<<"\n\n\t\t\t\t       003:工程师"
			<<"\n\n\t\t\t\t       004:程序员"
			<<"\n\n\t\t\t\t       005:员工"
			<<"\n\n\t\t\t\t      :";
		cin>>sTch;
		if(sTch!="001"&&sTch!="002"&&sTch!="003"&&sTch!="004"&&sTch!="005")
		{
			cout<<"\n\n\t\t\t\t错误的选择";
		}
		else
		{
			switch(sTch[2])
			{
			case '1': employee.m_sTechPost="经理";
					  employee.m_sTechPostNum=sTch;
					  break;
			case '2': employee.m_sTechPost="副经理";
					  employee.m_sTechPostNum=sTch;
					  break;
			case '3': employee.m_sTechPost="工程师";
				      employee.m_sTechPostNum=sTch;
				      break;
			case '4': employee.m_sTechPost="程序员";
				      employee.m_sTechPostNum=sTch;
				      break;
			case '5': employee.m_sTechPost="员工";
				      employee.m_sTechPostNum=sTch;
				      break;
			}
			break;
		}
	}
    cout<<"\n\n\t\t\t\t请输入家庭电话:";
    cin>>employee.m_sHomePhone;
    
	cout<<"\n\n\t\t\t\t请输入移动电话:";
    cin>>employee.m_sMobilePhone;

//    cout<<"\n\n\t\t\t\t请输入基本工资:";
 //   cin>>employee.m_cSalary.m_fBasePay;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入基本工资:";
		if( (cin>>employee.m_cSalary.m_fBasePay) == 0 )
		{
			cout<<"\t\t\t\t输入基本工资必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}

//   cout<<"\n\n\t\t\t\t请输入职务工资:";
 //   cin>>employee.m_cSalary.m_fDutyPay;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入职务工资:";
		if( (cin>>employee.m_cSalary.m_fDutyPay) == 0 )
		{
			cout<<"\t\t\t\t输入职务工资必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
//    cout<<"\n\n\t\t\t\t请输入补助:";
//    cin>>employee.m_cSalary.m_fAssistance;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入补助:";
		if( (cin>>employee.m_cSalary.m_fAssistance) == 0 )
		{
			cout<<"\t\t\t\t输入补助金必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
//    cout<<"\n\n\t\t\t\t请输入水费:";
//    cin>>employee.m_cSalary.m_fWaterRate;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入水费:";
		if( (cin>>employee.m_cSalary.m_fWaterRate) == 0 )
		{
			cout<<"\t\t\t\t输入水费必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}	
//	cout<<"\n\n\t\t\t\t请输入电费:";
 //   cin>>employee.m_cSalary.m_fElecCost;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入电费:";
		if( (cin>>employee.m_cSalary.m_fElecCost) == 0 )
		{
			cout<<"\t\t\t\t输入电费必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
//	cout<<"\n\n\t\t\t\t请输入清洁费:";
 //   cin>>employee.m_cSalary.m_iCleanCost;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入清洁费:";
		if( (cin>>employee.m_cSalary.m_iCleanCost) == 0 )
		{
			cout<<"\t\t\t\t输入清洁费必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
//	cout<<"\n\n\t\t\t\t请输入闭路电视费:";
 //   cin>>employee.m_cSalary.m_iTVCost;
	while(true)
	{
		cout<<"\n\n\t\t\t\t请输入闭路电视费:";
		if( (cin>>employee.m_cSalary.m_iTVCost) == 0 )
		{
			cout<<"\t\t\t\t输入闭路电视费必须是数字"<<endl;
			cin.clear();
		    fflush(stdin);
			continue;
		}
		break;
	}
    employee.m_cSalary.AccountTax();
	employee.m_cSalary.AccountSalary();
    
}
void CAdministrator::DelEmp()//wxw
{
	string empID;
	cout<<"\n\n\t\t\t\t要删除的职工工资卡号:";
	cin>>empID;

	CEmployee *emp;

	for(emp=HeadEmployee;emp->next!=NULL;emp=emp->next)
	{
		if(emp->next->m_sSalaryCardId==empID)
		{
			break;
		}
	}

	if(emp->next==NULL)
	{
		cout<<"\n\n\t\t\t\t没有该员工的信息,请确认后再操作.\n";
		return;
	}
	else
	{
		CEmployee *delEmp=emp->next;
		emp->next=delEmp->next;
		delEmp->next=NULL;
		delete delEmp;
	}
	cout<<"\n\n\t\t\t\t删除"<<empID<<"号员工成功\n";
	iNumNode--;
	
}

void CAdministrator::ChangeSalarySys()
{
	CMenu menu;
	string sSalaryCardId;
    string sChoose;
    CEmployee *curNode = HeadEmployee->next;

	cout<<"\t\t\t\t请输入要修改的工资卡号";
	cin>> sSalaryCardId;

	while( curNode!=NULL && curNode->m_sSalaryCardId != sSalaryCardId )
	{
		curNode = curNode->next;
	}
	if( curNode == NULL )
	{
		cout<<"\t\t\t\t没有此人的信息!"<<endl;
		return;
	}
    	
	while( true )
	{
		cout<<"\n================================================================================"<<endl;
		cout<<"\n\t\t\t提示:你只能操作以下几项:"<<endl
			<<"\t\t\t\t[1]修改基本工资"<<endl
			<<"\t\t\t\t[2]修改奖金和补助"<<endl
			<<"\t\t\t\t[3]职务工资"<<endl
			<<"\t\t\t\t[#]返回上一层菜单"<<endl
			<<"\t\t\t\t[0]退出"<<endl;
		cout<<"\t\t\t\t你的选择是:";
		cin>>sChoose;

		if( !menu.IsDigit( sChoose ) )
		{
			cout<<"\t\t\t你的输入有错,请重新输入! "<<endl;
			continue;
		}
		switch( sChoose[0] )
		{
		case '1':
			cout<<"\t\t\t目前的基本工资是:"<<curNode->m_cSalary.m_fBasePay<<endl;
			cout<<"\t\t\t修改为:  ";
			cin>>curNode->m_cSalary.m_fBasePay;
			cout<<"\t\t提示:基本工资修改成功。"<<endl;
			break;
		case '2':
			cout<<"\t\t\t目前的奖金和补助是:"<<curNode->m_cSalary.m_fAssistance<<endl;
			cout<<"\t\t\t修改为:  ";
			cin>>curNode->m_cSalary.m_fAssistance;
			cout<<"\t\t提示:奖金和补助修改成功。"<<endl;
			break;
		case '3':
			cout<<"\t\t\t目前的职务工资是:"<<curNode->m_cSalary.m_fDutyPay<<endl;
			cout<<"\t\t\t修改为:  ";
			cin>>curNode->m_cSalary.m_fDutyPay;
			cout<<"\t\t提示:职务工资修改成功。"<<endl;
			break;
		case '#':
			return;
		case '0':
			menu.Exit();
		default:
			cout<<"\t\t\t你的输入有错,请重新输入! "<<endl;
			break;
		}
	}
}

⌨️ 快捷键说明

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