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

📄 employsys.cpp

📁 这是一折员工管理系统
💻 CPP
字号:
// EmploySys.cpp: implementation of the CEmploySys class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Employ.h"
#include "EmploySys.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CEmploySys,CObject,1)
CEmploySys::CEmploySys()
{
	m_lMaxNum=0;
}

CEmploySys::~CEmploySys()
{
	POSITION pos=m_EmpList.GetHeadPosition();
	while(pos)
	{
		CEmploy * tp=m_EmpList.GetAt(pos);
		delete tp;
		m_EmpList.GetNext(pos);
	}
	m_EmpList.RemoveAll();
}

void CEmploySys::Serialize( CArchive& archive )
{
    // call base class function first
    // base class is CObject in this case
    CObject::Serialize( archive );
	// now do the stuff for our specific class
	if( archive.IsStoring() )
	{
		archive	<<	m_lMaxNum;
	}
    else
	{
		archive	>>	m_lMaxNum;
	}
	m_EmpList.Serialize(archive);
}


void CEmploySys::AddEmploy(const CEmploy &tp)
{
	CEmploy * temp=new CEmploy(tp);
	temp->m_lNum=m_lMaxNum;
	m_lMaxNum++;
	try
	{
		if(m_lMaxNum==LONG_MAX)
			throw(m_lMaxNum);
		else
			m_EmpList.AddTail(temp);
	}
	catch(long)
	{
		ProcExcept();
	}
}

void CEmploySys::ProcExcept()
{
	m_lMaxNum=m_EmpList.GetCount();
	POSITION pos=m_EmpList.GetHeadPosition();
	for(long i=0;i<m_lMaxNum;i++)
	{
		CEmploy * tp=m_EmpList.GetAt(pos);
		tp->m_lNum=i;
		m_EmpList.GetNext(pos);
	}
}

void CEmploySys::Del(long m)//m绰 m_IMaxNum狼 蔼阑 措钎茄促.
{
	POSITION pos=m_EmpList.GetHeadPosition();
	long lNumber=m_EmpList.GetCount();
	CEmploy * Aim=NULL;
	POSITION Aimpos=NULL;
	for(long i=0;i<lNumber;i++)
	{
		CEmploy * tp=m_EmpList.GetAt(pos);
		if(tp->m_lNum==m) {Aim=tp;Aimpos=pos;}
		m_EmpList.GetNext(pos);
	}
	try
	{
		if(Aim==NULL)
			throw(Aim);
		else
		{
			delete Aim;
			m_EmpList.RemoveAt(Aimpos);
		}
	}
	catch(CEmploy *)
	{
		int i=MessageBox(NULL,"昏力矫,郴何馒坷\n(扁废阑 茫瘤给窃)!!","摹疙利牢 馒坷!",MB_OK);
		CWnd * pWnd=AfxGetMainWnd( );
		pWnd->SendMessage(WM_DESTROY);
	}
}

BOOL CEmploySys::Search(const CEmploy &m, long &pos)
//m_EmpList俊辑 沥犬窍霸 茫绰促.
{
	POSITION ps=m_EmpList.GetHeadPosition();
	while(ps!=NULL)
	{
		CEmploy * tp=m_EmpList.GetAt(ps);
		if(*tp==m) 
		{
			pos=tp->m_lNum;
			return TRUE;
		}
		m_EmpList.GetNext(ps);
	}
	return FALSE;
}

BOOL CEmploySys::DelEmploy(const CEmploy &m)
{
	long tip=-1;
	if(Search(m,tip))
	{
		Del(tip);
		return TRUE;
	}
	else return FALSE;
}

void CEmploySys::SearchEmploy(const CEmploy & m,CList<CEmploy,CEmploy &> & ResultList)
{
	ResultList.RemoveAll();
	CList<CEmploy,CEmploy &> m_tpList1;
	POSITION pos1=m_EmpList.GetHeadPosition();
	while(pos1)
	{
		CEmploy * tp=m_EmpList.GetAt(pos1);
		if(tp->m_iSex==m.m_iSex||m.m_iSex==2)
		{
			m_tpList1.AddHead(*tp);
		}
		m_EmpList.GetNext(pos1);
	}
	CList<CEmploy,CEmploy &> m_tpList2;
	POSITION pos2=m_tpList1.GetHeadPosition();
	while(pos2)
	{
		CEmploy tp=m_tpList1.GetAt(pos2);
		if(tp.m_sAddress==m.m_sAddress||m.m_sAddress.IsEmpty())
			m_tpList2.AddHead(tp);
		m_tpList1.GetNext(pos2);
	}
	m_tpList1.RemoveAll();
	pos1=m_tpList2.GetHeadPosition();
	while(pos1)
	{
		CEmploy tp=m_tpList2.GetAt(pos1);
		if(tp.m_sDuty==m.m_sDuty||m.m_sDuty.IsEmpty())
			m_tpList1.AddHead(tp);
		m_tpList2.GetNext(pos1);
	}
	m_tpList2.RemoveAll();
	pos2=m_tpList1.GetHeadPosition();
	while(pos2)
	{
		CEmploy tp=m_tpList1.GetAt(pos2);
		if(tp.m_sEducate==m.m_sEducate||m.m_sEducate.IsEmpty())
			m_tpList2.AddHead(tp);
		m_tpList1.GetNext(pos2);
	}
	m_tpList1.RemoveAll();
	pos2=m_tpList2.GetHeadPosition();
	while(pos2)
	{
		CEmploy tp=m_tpList2.GetAt(pos2);
		if(tp.m_sMemo==m.m_sMemo||m.m_sMemo.IsEmpty())
			m_tpList1.AddHead(tp);
		m_tpList2.GetNext(pos2);
	}
	m_tpList2.RemoveAll();
	pos1=m_tpList1.GetHeadPosition();
	while(pos1)
	{
		CEmploy tp=m_tpList1.GetAt(pos1);
		if(tp.m_sPhone==m.m_sPhone||m.m_sPhone.IsEmpty())
			m_tpList2.AddHead(tp);
		m_tpList1.GetNext(pos1);
	}
	m_tpList1.RemoveAll();
	pos2=m_tpList2.GetHeadPosition();
	while(pos2)
	{
		CEmploy tp=m_tpList2.GetAt(pos2);
		if(tp.m_sName==m.m_sName||m.m_sName.IsEmpty())
			m_tpList1.AddHead(tp);
		m_tpList2.GetNext(pos2);
	}
	{
		pos1=m_tpList1.GetHeadPosition();
		while(pos1)
		{
			ResultList.AddHead(m_tpList1.GetAt(pos1));
			m_tpList1.GetNext(pos1);
		}
	}
}


void CEmploySys::SortEmploy(CEmploy ** & tp,int inwhich)
//inwhich绰 绢蠢 鉴辑 肺 硅凯且巴牢啊甫 措钎 茄促.
{
	long num=m_EmpList.GetCount();
	CEmploy ** ptToList=new CEmploy *[num];
	POSITION pos=m_EmpList.GetHeadPosition();
	for(long i=0;i<num;i++)
	{
		ptToList[i]=m_EmpList.GetAt(pos);
		m_EmpList.GetNext(pos);
	}
	int (*compare)(const void *elem1, const void *elem2 );
	switch(inwhich)
	{
	case 0:
		compare=CompareAddress;
		break;
	case 1:
		compare=CompareDuty;
		break;
	case 2:
		compare=CompareEducate;
		break;
	case 3:
		compare=CompareMemo;
		break;
	case 4:
		compare=CompareName;
		break;
	case 5:
		compare=ComparePhone;
		break;
	default:
		{
			try
			{
				throw(inwhich);
			}
			catch(int)
			{
				CWnd * pWnd=AfxGetMainWnd();
				pWnd->MessageBox("硅凯馒坷 。\n急琶惑亲格俊辑 馒坷惯积 !","摹疙利牢 馒坷 !");
				pWnd->SendMessage(WM_DESTROY,0,0);
			}
		}
	}
	qsort(ptToList,(unsigned int)num,sizeof(CEmploy *),compare);
	tp=ptToList;
}
//林家 厚背何盒 
int CEmploySys::CompareAddress(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sAddress,(*(CEmploy **)elem2)->m_sAddress);
}

int CEmploySys::CompareDuty(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sDuty,(*(CEmploy **)elem2)->m_sDuty);
}

int CEmploySys::CompareEducate(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sEducate,(*(CEmploy **)elem2)->m_sEducate);
}


int CEmploySys::CompareMemo(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sMemo,(*(CEmploy **)elem2)->m_sMemo);
}

int CEmploySys::CompareName(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sName,(*(CEmploy **)elem2)->m_sName);
}



int CEmploySys::ComparePhone(const void *elem1, const void *elem2)
{
	return lstrcmp((*(CEmploy **)elem1)->m_sPhone,(*(CEmploy **)elem2)->m_sPhone);
}

int CEmploySys::GetCount()
{
	return m_EmpList.GetCount();
}	

BOOL CEmploySys::GetEmploy(CEmploy & result,int pos)
{
	if(pos<0||pos>=GetCount()) return FALSE;
	POSITION ppos=m_EmpList.GetHeadPosition();
	for(int i=0;i<pos;i++)
	{
		m_EmpList.GetNext(ppos);
	}
	result=*m_EmpList.GetAt(ppos);
	return TRUE;
}

void CEmploySys::DeleteAll()
{
	POSITION pos=m_EmpList.GetHeadPosition();
	while(pos)
	{
		CEmploy * tp=m_EmpList.GetAt(pos);
		delete tp;
		m_EmpList.GetNext(pos);
	}
	m_EmpList.RemoveAll();
	m_lMaxNum=0L;
}

CEmploy & CEmploySys::Get(const CEmploy &m)
{
	long pos=-1L;
	Search(m,pos);
	POSITION ppos=m_EmpList.GetHeadPosition();
	while(ppos)
	{
		CEmploy * tp=m_EmpList.GetAt(ppos);
		if(tp->m_lNum==pos)
			break;
		m_EmpList.GetNext(ppos);
	}
	CEmploy * temp=m_EmpList.GetAt(ppos);
	return *temp;
}

void CEmploySys::DelPrtList()
{
	m_EmpList.RemoveAll();
}

void CEmploySys::InPutPtr(CEmploy **&tp)
{
	int Num=m_EmpList.GetCount();
	DelPrtList();
	for(int i=0;i<Num;i++)
		m_EmpList.AddHead(tp[i]);
	delete []tp;
}

⌨️ 快捷键说明

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