📄 systemview.cpp
字号:
// systemView.cpp : implementation of the CSystemView class
//
#include "stdafx.h"
#include "system.h"
#include "systemDoc.h"
#include "systemView.h"
#include "AddNew.h"
#include "Find.h"
#include "RWrite.h"
#include "Delete.h"
#include "DelView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSystemView
IMPLEMENT_DYNCREATE(CSystemView, CView)
BEGIN_MESSAGE_MAP(CSystemView, CView)
//{{AFX_MSG_MAP(CSystemView)
ON_COMMAND(ID_ADDNEW, OnAddnew)
ON_COMMAND(ID_FIND, OnFind)
ON_COMMAND(ID_REWRITE, OnRewrite)
ON_COMMAND(ID_DELETE, OnDelete)
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_MENUITEM32776, OnLBDraw)
ON_COMMAND(ID_MENUITEM32779, OnCLEARDRAW)
ON_WM_DESTROY()
ON_WM_CANCELMODE()
ON_WM_CREATE()
ON_COMMAND(ID_SEThong, OnSEThong)
ON_COMMAND(ID_SETbai, OnSETbai)
ON_COMMAND(ID_SEThuang, OnSEThuang)
ON_COMMAND(ID_SETlan, OnSETlan)
ON_COMMAND(ID_SETlv, OnSETlv)
ON_COMMAND(ID_SETzi, OnSETzi)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSystemView construction/destruction
CSystemView::CSystemView()
{
// TODO: add construction code here
findout=deletetrue=false;
cpoint=0;
m_RBD=false;
m_lbdraw=false;
totalnumber=0;
C1=255;
C2=255;
C3=0;
}
CSystemView::~CSystemView()
{
}
BOOL CSystemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass=AfxRegisterWndClass(0,LoadCursor(NULL,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0);
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView drawing
void CSystemView::OnDraw(CDC* pDC)
{
CSystemDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->SetTextColor(RGB(C1,C2,C3));
//pDC->GetTextColor();
pDC->SetBkColor(NULL);
CFont Font;
Font.CreatePointFont(250,"华文行楷"/*微软雅黑*/);
CFont *oldfont;
oldfont=pDC->SelectObject(&Font);
CString str="人员管理系统";
pDC->TextOut(400,0,str);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
pDC->SelectObject(oldfont);
CFont Font2;
Font2.CreatePointFont(150,"幼圆");
CFont *oldfont2;
oldfont2=pDC->SelectObject(&Font2);
str.Format("当前系统存档人数:%d",totalnumber);
pDC->TextOut(0,tm.tmHeight,str);
CClientDC dc(this);
dc.Draw3dRect(5,95,1200,400,RGB(255,0,0),RGB(0,0,255));
HICON hIcon=LoadIcon(NULL,IDI_INFORMATION);//MAKEINTRESOURCE(IDI_ICON1));
dc.DrawIcon(0,60,hIcon);
hIcon=LoadIcon(NULL,IDI_EXCLAMATION);
dc.DrawIcon(900,200,hIcon);
CFont cfont,*oldcfont;
cfont.CreatePointFont(100,"微软雅黑");
oldcfont=dc.SelectObject(&cfont);
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,255));
dc.TextOut(940,210,"请保护隐私,防止个人信息的泄露!");
dc.SelectObject(oldcfont);
str.Format("档案信息:");
pDC->TextOut(33,tm.tmHeight*2,str);
pDC->SelectObject(oldfont2);
////////////////////////////////////////////////////////////////////////////////////////
CFont cfontHDU,*oldHDU;//画公司的名称
cfontHDU.CreatePointFont(150,"微软雅黑");
oldHDU=dc.SelectObject(&cfontHDU);
dc.SetBkColor(RGB(0,0,0));
dc.SetTextColor(RGB(255,0,255));
dc.TextOut(950,600,"山东鲁能石化公司");
dc.SelectObject(oldHDU);
//////////////////////////////////////////////////////////////////////////////////////////
//RECT rct = {100,600,700,630};//定义方法
CFont fonttext;
fonttext.CreatePointFont(150,"幼圆");
oldfont=pDC->SelectObject(&fonttext);
TEXTMETRIC tm2;
pDC->GetTextMetrics(&tm2);
////////////////////在屏幕显示///////////////////////////////////////////////
str.Format(" 姓名:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*2.5,str+name);
str.Format(" 性别:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*3.5,str+sex);
str.Format(" 民族:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*4.5,str+minzu);
str.Format(" 出生日期:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*5.5,str+birth);
str.Format(" 身份证号码:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*6.5,str+shenfenzheng);
str.Format(" 籍贯:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*7.5,str+jiguan);
str.Format(" 家庭住址:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*8.5,str+address);
str.Format(" 毕业院校:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*9.5,str+college);
str.Format(" 专业:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*10.5,str+zhuanye);
str.Format(" 学位:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*11.5,str+xuewei);
str.Format(" 外语语种:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*12.5,str+waiyuyuzhong);
str.Format(" 外语等级:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*13.5,str+waiyudengji);
str.Format(" 进入时间:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*14.5,str+jinrushijian);
str.Format(" 所在部门:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*15.5,str+bumen);
str.Format(" 职位:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*16.5,str+zhiwei);
str.Format(" 邮箱:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*17.5,str+xinshui);
str.Format(" 联系电话号码:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*18.5,str+lianxihaoma);
str.Format(" 备注:");
pDC->TextOut(0,tm.tmHeight*1.5+tm2.tmHeight*19.5,str+beizhu);
////////////////////////////////////////////////////////////////////////////////////
pDC->SelectObject(oldfont);
if(deletetrue)
{
HICON m_dhicon=LoadIcon(NULL,IDI_ERROR);//显示图标,美观
pDC->DrawIcon(500,300,m_dhicon);
CFont cft,*oldcft;//调整字体
cft.CreatePointFont(150,"幼圆",NULL);
oldcft=pDC->SelectObject(&cft);
pDC->TextOut(540,310,"该档案已删除!");
dc.SelectObject(oldcft);
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView diagnostics
#ifdef _DEBUG
void CSystemView::AssertValid() const
{
CView::AssertValid();
}
void CSystemView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSystemDoc* CSystemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSystemDoc)));
return (CSystemDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSystemView message handlers
void CSystemView::OnAddnew()
{
// TODO: Add your command handler code here
CAddNew can;
if(IDOK==can.DoModal())
{
//判断是否都正确填写了
/////////////////////////////////////////////////////////////////////////////////////////////////////////
if(can.changename && (can.changenan || can.changenv) && can.changeid && \
can.changeaddress && can.changecollege && can.changeday && \
can.changedepartment && can.changejiguan && can.changelianxihaoma \
&& can.changeminzu && can.changeyear && can.changemonth && \
can.changeday && can.changewaiyu && can.changewaiyudengji && \
can.changexinshui && can.changezhuanye && can.changezhiwei && can.changedate)
/////////////////////////////共19个,其中不包括对备注的判断//////////////////////////////////////////////
{
//MessageBox("all information right");
char ch[10];//字符以及类型转化辅助
name=can.m_name;
if(can.changenan)
sex="男";
else if(can.changenv)
sex="女";
minzu=can.m_minzu;
///////////////////时间要经过特殊转换,注意在内部,每一个列表框里的项对应的值分别是1,2,3……的值////
itoa(can.m_year+1966,ch,10);
birth=ch; //MessageBox(birth);
birth+=can.m_month; //MessageBox(birth);
birth+=can.m_day; //MessageBox(birth);
//////////////////////////////////////////////////////////
shenfenzheng=can.m_id;
jiguan=can.m_jiguan;
address=can.m_address;
college=can.m_college;
zhuanye=can.m_zhuanye;
xuewei=can.m_xuewei;
waiyuyuzhong=can.m_waiyu;
waiyudengji=can.m_waiyudengji;
jinrushijian=can.m_time; //MessageBox(jinrushijian);
bumen=can.m_department;
zhiwei=can.m_zhiwei;
xinshui=can.m_xinshui;
lianxihaoma=can.m_lianxihaoma;
beizhu=can.m_beizhu;
WriteFile();
totalnumber++;
}
deletetrue=false;//让删除成功的指挥量为假,不再显示错误符号以及“该档案已删除”
}
}
void CSystemView::OnFind()
{
// TODO: Add your command handler code here
CFind cf;
if(IDOK==cf.DoModal())
{
if(cf.changebirth)
{
if(strlen(cf.m_birth)==8)
FindFile(cf.m_findname,cf.m_findname,cf.m_birth);
else
MessageBox("出生日期格式错误,请检查!");
}
FindFile(cf.m_findname,cf.m_findname,cf.m_birth);
//MessageBox(bumen); MessageBox(zhiwei);
deletetrue=false;//让删除成功的指挥量为假,不再显示错误符号以及“该档案已删除”
}
}
void CSystemView::OnRewrite()
{
// TODO: Add your command handler code here
CRWrite cw;
if(IDOK==cw.DoModal())
{
FindFile(cw.m_name,cw.m_name,cw.m_birth);
if(findout){
CAddNew can;
char chhelp1[20],chhelp2[10];
/////////////////填充删除预览对话框/////////////////
can.m_name=name;
//can.m_sex=sex;
if(sex=="男")
can.changenan=true;
else if(sex=="女")
can.changenv=true;
can.m_minzu=minzu;
can.m_jiguan=jiguan;
can.m_address=address;
//can.m_birth=birth;
///////////////////////////出生日期需要特殊处理///////////////////////
strcpy(chhelp1,birth);
chhelp2[0]=chhelp1[0]; chhelp2[1]=chhelp1[1];
chhelp2[2]=chhelp1[2]; chhelp2[3]=chhelp1[3]; chhelp2[4]=0;
can.m_year=atoi(chhelp2)-1966;
chhelp2[0]=chhelp1[4]; chhelp2[1]=chhelp1[5]; chhelp2[2]=0;
can.m_month=chhelp2;
chhelp2[0]=chhelp1[6]; chhelp2[1]=chhelp1[7]; chhelp2[2]=0;
can.m_day=chhelp2;
//////////////////////////////////////////////////////////////////////////
//GetDlgItem(IDC_TIME)->SetWindowText(jinrushijian);
can.m_college=college;
can.m_beizhu=beizhu;
can.m_department=bumen;
can.m_waiyudengji=waiyudengji;
can.m_id=shenfenzheng;
can.m_lianxihaoma=lianxihaoma;
//can.m_time=jinrushijian;
can.m_zhuanye=zhuanye;
can.m_xinshui=xinshui;
can.m_xuewei=xuewei;
can.m_waiyu=waiyuyuzhong;
can.m_zhiwei=zhiwei;
////////////////设置状态量表示已经输入了/////////////////////////////////////////////////
can.changeaddress=can.changecollege=can.changeid=can.changejiguan= \
can.changelianxihaoma=can.changename=can.changewaiyu= \
can.changewaiyudengji=can.changezhuanye=can.changexinshui= \
can.changeyear=can.changemonth=can.changeday=can.changeminzu= \
can.changedepartment=can.changezhiwei=can.changexuewei= \
can.changenan=can.changenv=true;
/////////////////////////////////////////////////////////////////////////////////////
if(IDOK==can.DoModal())
{
char ch[10];//字符以及类型转化辅助
name=can.m_name;
if(can.changenan)
sex="男";
else if(can.changenv)
sex="女";
minzu=can.m_minzu;
///////////////////时间要经过特殊转换,注意在内部,每一个列表框里的项对应的值分别是1,2,3……的值////
itoa(can.m_year+1966,ch,10);
birth=ch; //MessageBox(birth);
birth+=can.m_month; //MessageBox(birth);
birth+=can.m_day; //MessageBox(birth);
//////////////////////////////////////////////////////////
shenfenzheng=can.m_id;
jiguan=can.m_jiguan;
address=can.m_address;
college=can.m_college;
zhuanye=can.m_zhuanye;
xuewei=can.m_xuewei;
waiyuyuzhong=can.m_waiyu;
waiyudengji=can.m_waiyudengji;
jinrushijian=can.m_time; //MessageBox(jinrushijian);
bumen=can.m_department;
zhiwei=can.m_zhiwei;
xinshui=can.m_xinshui;
lianxihaoma=can.m_lianxihaoma;
beizhu=can.m_beizhu;
/////////刷新系统值并删除原来的档案并且重新创建新的档案//////////
char *fname=new char[10];
strcpy(fname,can.m_name);
CFile::Remove(fname);
free(fname);
WriteFile();
FindFile(cw.m_name,cw.m_name,cw.m_birth);
/////////////////////////////////////////////////////////////////
}
deletetrue=false;//让删除成功的指挥量为假,不再显示错误符号以及“该档案已删除”
Invalidate();
}
findout=false;
}
}
void CSystemView::OnDelete()
{
// TODO: Add your command handler code here
CDelete cd;
bool success=false;
if(IDOK==cd.DoModal())
{
FindFile(cd.m_name,cd.m_name,cd.m_birth);
if(findout)
{
CDelView cdv;
/////////////////填充删除预览对话框/////////////////
cdv.m_name=name;
cdv.m_sex=sex;
cdv.m_minzu=minzu;
cdv.m_jiguan=jiguan;
cdv.m_address=address;
cdv.m_birth=birth;
cdv.m_college=college;
cdv.m_beizhu=beizhu;
cdv.m_birth=birth;
cdv.m_bumen=bumen;
cdv.m_dengji=waiyudengji;
cdv.m_shenfenzheng=shenfenzheng;
cdv.m_haoma=lianxihaoma;
cdv.m_time=jinrushijian;
cdv.m_zhuanye=zhuanye;
cdv.m_xinshui=xinshui;
cdv.m_xuewei=xuewei;
cdv.m_yuzhong=waiyuyuzhong;
cdv.m_zhiwu=zhiwei;
CFile cfile;
try{
cfile.Open(cd.m_name,CFile::modeRead|CFile::modeWrite,NULL);
}
catch(CFileException e)
{
if(CFileException::fileNotFound)
cfile.Abort();
}
cdv.m_wenjianweizhi=cfile.GetFilePath();
cfile.Close();
/////////////////////////////////////////////////////////////////////////////////////
if(IDOK==cdv.DoModal())
{
if(cdv.okdelete)
{
char fname[10];
strcpy(fname,name);
CFile::Remove(fname);
success=true;
}
}
if(success)
{
totalnumber--;
deletetrue=true;
MessageBox("档案删除成功!");
}
}
findout=false;
}
// CDelete *cdl=new CDelete;
// cdl->Create(IDD_DELETE);
// cdl->ShowWindow(SW_SHOWNORMAL);
Invalidate();
}
//DEL void CSystemView::FindFile(CFile cfile)
//DEL {
//DEL
//DEL
//DEL }
void CSystemView::FindFile(CString filename, CString dlgname, CString dlgbirth)
{
CFile cfile;
bool haveone=false;//指示是否有该档案
bool find=false;//指示是否匹配,如果输入了生日,则精确匹配后为真,如果没有输入生日进行模糊匹配,则自动为真
int num,lenth=0;
char chnum[3],chmain[20];//用来存储读出的字符,以致得到出生日期比较是否是该人
/*try
{
cfile.Open(filename,CFile::modeRead,NULL);
}
catch(CFileException*e)
{
switch(e->m_cause)
{
case CFileException::fileNotFound:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -