?? employsys.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 + -