MFC人事信息管理实验报告_第1页
MFC人事信息管理实验报告_第2页
MFC人事信息管理实验报告_第3页
MFC人事信息管理实验报告_第4页
MFC人事信息管理实验报告_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

基于MFC对话框的人事信息管理实验报告题目:人事信息管理系统系别:计算机科学与技术专业班级:201X级指导教师:XXXXXX小组成员:XXXXXXXXXXXXXXXX目录1摘要……………….32关键词……………33.编写目的………..34.功能列表………..35.程序框图………..46.UML类图………57.详细设计………..88.总结………….…319.参考资料……………………...321.摘要有公司就有员工,公司的员工信息的管理也成了重要的一部分,为了更好地管理员工信息,我们小组设计人事信息管理系统,并在程序中设置了权限管理,防止信息被非法修改,同时对信息统一使用数据库管理,提高效率。本次实验历时4周,使用的操作系统为Windows8,开发环境为vs2008;并在windowsXP和windows7上做了程序测试,经测试未发现程序在运行时发生访问内存的冲突。2.关键词人事信息管理,程序设计3.编写目的本款软件面向广大公司,但不适合公开发行,其中的数据库是使用的Access的数据库,并且数据没有加密,密码也没有加密,容易导致员工信息泄露。本程序只能作为一家小型公司的使用,本程序不能出色的管理大型数据,很多数据管理的功能没又加入。4.功能列表注册产品用户登录增加用户更改密码删除用户冻结用户解冻用户设置管理员退出登录修改信息增加信息统计结果备份文件获得帮助5.程序框图退出开始注册信息正确退出开始注册信息正确?显示主程序根据用户选择执行相应的功能用户信息合法?是注册否是否CReg+m_number:CString+m_user:CString+m_key:CString+regname:CString+Check():CString+ReadFile():boolClogin-m_loguser:CComboBox-m_pRecordset:_RecordsetPtr-var:_variant_t-Strpass:CString-m_brush:CBrush-m_font:CFont+m_user:CString+m_passwd:CString+m_userid:int+m_isman:int+OnStnClickedForget():void+OnInitDialog():BOOL+OnOK():void+OnPaint():void+OnCtlColor(pDC:CDC*,pWnd:CWnd*,nCtlColor:UINT):HBRUSHCUser-DoDataExchange(pDX:CDataExchange*):void-m_mode:int-m_userid:int-IsMan:bool-m_pRecordset:_RecordsetPtr-var:_variant_t+CUser(mode:int,userid:int,pParent:CWnd*)+OnInitDialog():BOOL+OnOK():voidCInfoManagerDlg-m_hIcon:HICON-m_rect:CRect-m_StatusBar:CStatusBar-m_choose:int-avrage:int+isman:bool+userid:int+data:CData+m_list:CListCtrl+OnInitDialog():BOOL+OnSysCommand(nID:UINT,lParam:LPARAM):void+OnPaint():void+OnQueryDragIcon():HCURSOR+OnAboutbox():void+OnExit():void+OnAdduser():void+OnDeluser():void+OnStopuser():void+OnResuser():void+OnSetmanger():void+OnRelogin():void+ReInit():void+OnSize(nType:UINT,cx:int,cy:int):void+ReSize(intnID,intcx,intcy):void+OnNewdata():void+OnBakdata():void+OnRestore():void+OnChang():void+ShowList():void+OnTimer(nIDEvent:UINT_PTR):void+OnMenuSelect(nItemID:UINT,nFlags:UINT,hSysMenuHMenu):void+OnGai():void+OnError():void+OnAll():void+OnReg():void+OnGethelp():void+OnReturn():void+OnZhuang():void+OnTable():void+OnUpdateZhuang(pCmdUI:CCmdUI*):void+OnUpdateTable(pCmdUI:CCmdUI*);+OnInitMenuPopup(pPopupMenu:CMenu,nIndex:UINT,bSysMenu:BOOL):void+OnMouseMove(nFlags:UINT,point:CPoint):voidCInfoManagerApp+m_pConnection:_ConnectionPtr+reg:CReg+login:Clogin+GetSetting(void):bool+virtualBOOLInitInstance();+OnNewData():voidDataEdit-m_name:CString-m_birthday:CString-m_sex:CString-m_phone:CString-m_xueli:CString-m_zhengzi:CString-m_address:CString-m_indate:CString-m_money:int-m_other:CString-m_pRecordset:RecordsetPtr-var:_variant_t-m_id:int-m_isman:bool+OnOK():void+OnAddData():void+OnDelData():void+OnInitDialog():BOOL+OnEnChangeEdit1():void+Sort():voidPersonid:CStringname:CStringbirthday:CStringsex:CStringphone:CStringxueli:CStringzhengzi:CStringaddress:CStringindate:CStringmoney:CStringother:CStringoperator[](index:constint):CString&CData+person:Person*+count:int-m_pRecordset:_RecordsetPtr-var:_variant_t+CData()+~CData()+boolReadFile():bool+boolWriteFile():bool+Add(intindex=-1):bool+Del(intindex=-1):bool+Init():boool+Changle(intx,inty,CStringstr):bool+operator[](constintindex):Person&+CStringAll()7.详细设计本程序是基于对话框设计,考虑到基于单文档的程序加入了没有用的View类和Doc类,同时自动加入了文件保存操作以及不必要的菜单,我们最终选择了基于对话框。由于对话框没有菜单和状态栏,于是我们又自己添加了菜单和状态栏,同时加入了菜单提示,状态栏的时间信息显示,本来想显示当前选中的行列信息,最终没有实现,采用了对mousemove消息的响应显示坐标信息。为了保证程序先运行CReg,同时优先读取文件,如果成功就不在显示注册对话框,然后显示用户登陆窗口,对用户名和密码的判断放在重载的OnOk()中,根据是否调用基类的OnOk()来决定是否销毁窗口。以下是在BOOLCInfoManagerApp::InitInstance()中增减的内容:free((void*)m_pszAppName);m_pszAppName=_tcsdup(_T("人事信息管理系统"));afxCurrentAppName=m_pszAppName;if(!reg.ReadFile()){ if(IDYES==AfxMessageBox(_T("是否注册?"),MB_YESNO)) { reg.DoModal(); }}AfxOleInit();HRESULThr;try{ hr=m_pConnection.CreateInstance(__uuidof(Connection)); m_pConnection->Open(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=sourse.dat"),"","",adModeUnknown);}catch(_com_errore){ AfxMessageBox(_T("这可能是你第一次使用该软件,\n我们将为你准备必要的文件,请关闭后重试!\n初始用户为:manager,密码为:123456,\n登陆后请尽快修改密码"),0,MB_YESNO); OnNewData(); returnfalse;}if(IDOK!=login.DoModal()) returnfalse;CInfoManagerDlgdlg;m_pMainWnd=&dlg;dlg.isman=login.m_isman;dlg.userid=login.m_userid;同时增加函数OnNewData()用于用户第一次使用的复制初始文件voidCInfoManagerApp::OnNewData(){ CStringstr=_T(".//bak/sourse.dat"); CopyFile(str,_T("sourse.dat"),false);}用户的登陆窗口是新建了一个CLogin的类,该类的基类是CDialog,对这个类的主要修改在于关联了成员变量,对OnInitDialog()进行修改用于读数据库,重载了OnOk()函数,以下是修改的主要代码://单击忘记密码voidClogin::OnStnClickedForget(){ //TODO:在此添加控件通知处理程序代码 MessageBox(_T("请联系管理员改密码!"));}BOOLClogin::OnInitDialog(){ CDialog::OnInitDialog(); //TODO:在此添加额外的初始化 m_pRecordset.CreateInstance(__uuidof(Recordset)); try { m_pRecordset->Open("SELECT*FROMusers", theApp.m_pConnection.GetInterfacePtr(),//获取库接库的IDispatch指针 adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_errore) { AfxMessageBox(e.ErrorMessage()); } CStringstrName; try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { MessageBox(_T("无用户信息")); returnfalse; } while(!m_pRecordset->adoEOF) { var=m_pRecordset->GetCollect("username"); if(var.vt!=VT_NULL) strName=(LPCSTR)_bstr_t(var); var=m_pRecordset->GetCollect("isstop"); if((bool)var.boolVal==true) {m_pRecordset->MoveNext();continue;} m_loguser.AddString(strName); m_pRecordset->MoveNext(); } } catch(_com_errore) { MessageBox(e.ErrorMessage()); } m_loguser.SetCurSel(0); //m_loguser.AddString(); //m_font.CreatePointFont(150,_T("华文行楷")); //m_brush.CreateSolidBrush(RGB(0,255,0)); LOGFONTlf; GetFont()->GetObject(sizeof(lf),&lf);//对忘记密码添加下划线 lf.lfUnderline=TRUE;//具有下划线的文字 m_font.CreateFontIndirect(&lf); returnTRUE;//returnTRUEunlessyousetthefocustoacontrol //异常:OCX属性页应返回FALSE}//用于判断密码正确与否voidClogin::OnOK(){ //TODO:在此添加专用代码和/或调用基类 UpdateData(); if(m_user==_T("")) {MessageBox(_T("用户名不能为空!"));return;} if(m_passwd==_T("")) {MessageBox(_T("密码不能为空!"));return;} try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { MessageBox(_T("无用户信息")); return; } while(!m_pRecordset->adoEOF) { var=m_pRecordset->GetCollect("username"); if(var.vt!=VT_NULL) if(m_user==(LPCSTR)_bstr_t(var)) { var=m_pRecordset->GetCollect("ID"); if(var.vt!=VT_NULL) m_userid=Val; var=m_pRecordset->GetCollect("isman"); if(var.vt!=VT_NULL) m_isman=var.boolVal; var=m_pRecordset->GetCollect("isstop"); if(true==(bool)var.boolVal) {MessageBox(_T("该用户已冻结,请联系管理员解冻!"));return;} var=m_pRecordset->GetCollect("passwd"); if(var.vt!=VT_NULL) if(m_passwd==(LPCSTR)_bstr_t(var)) {CDialog::OnOK();return;} else {MessageBox(_T("密码错误!"));m_passwd="";UpdateData(false);return;} } m_pRecordset->MoveNext(); } } catch(_com_errore) { MessageBox(e.ErrorMessage()); } MessageBox(_T("无此用户!")); return;}voidClogin::OnPaint(){ CPaintDCdc(this);//devicecontextforpainting}//对“忘记密码”添加下划线HBRUSHClogin::OnCtlColor(CDC*pDC,CWnd*pWnd,UINTnCtlColor){ HBRUSHhbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor); if(GetDlgItem(IDC_FORGET)->m_hWnd==pWnd->m_hWnd) { pDC->SetBkMode(TRANSPARENT); pDC->SelectObject(&m_font); returnm_brush; } returnhbr;}其中CReg主要是对序列号和用户名加密后与检验码判断是否相等,这里不展示源代码,CData类和Person类在一个文件中实现,CData类中用到了Person指针动态分配大小用于显示表格,由于实现上的原因中间很多函数运行时发生访问内存错误,我们通过直接修改数据库然后重建CData类显示表格,这里是本程序的缺陷,内存占用多,而且没有必要。整个程序中花的时间最多的是CUser类的设计和在CInfoManagerDlg类中对菜单消息的响应、计时器的响应、鼠标移动消息的响应和菜单选择的响应。下面是CInfoManagerDlg类中添加的代码://CInfoManagerDlg对话框CInfoManagerDlg::CInfoManagerDlg(CWnd*pParent/*=NULL*/):CDialog(CInfoManagerDlg::IDD,pParent){ m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); isman=false; userid=0; m_choose=0;}voidCInfoManagerDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); DDX_Control(pDX,IDC_LIST1,m_list);}BEGIN_MESSAGE_MAP(CInfoManagerDlg,CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_COMMAND(IDM_ABOUTBOX,&CInfoManagerDlg::OnAboutbox) ON_COMMAND(IDM_EXIT,&CInfoManagerDlg::OnExit) ON_COMMAND(IDM_ADDUSER,&CInfoManagerDlg::OnAdduser) ON_COMMAND(IDM_DELUSER,&CInfoManagerDlg::OnDeluser) ON_COMMAND(IDM_STOPUSER,&CInfoManagerDlg::OnStopuser) ON_COMMAND(IDM_RESUSER,&CInfoManagerDlg::OnResuser) ON_COMMAND(IDM_SETMANGER,&CInfoManagerDlg::OnSetmanger) ON_COMMAND(ID_32791,&CInfoManagerDlg::OnRelogin) ON_WM_SIZE() ON_COMMAND(IDM_NEWDATA,&CInfoManagerDlg::OnNewdata) ON_COMMAND(IDM_BAKDATA,&CInfoManagerDlg::OnBakdata) ON_COMMAND(IDM_RESTORE,&CInfoManagerDlg::OnRestore) ON_COMMAND(IDM_CHANG,&CInfoManagerDlg::OnChang) ON_WM_TIMER() ON_WM_MENUSELECT() ON_COMMAND(IDM_GAI,&CInfoManagerDlg::OnGai) ON_COMMAND(IDM_ERROR,&CInfoManagerDlg::OnError) ON_COMMAND(IDM_ALL,&CInfoManagerDlg::OnAll) ON_COMMAND(IDM_SORTA,&CInfoManagerDlg::OnSorta) ON_COMMAND(IDM_SORTB,&CInfoManagerDlg::OnSortb) ON_COMMAND(IDM_SORTC,&CInfoManagerDlg::OnSortc) ON_COMMAND(IDM_SORTD,&CInfoManagerDlg::OnSortd) ON_COMMAND(IDM_REG,&CInfoManagerDlg::OnReg) ON_COMMAND(IDM_GETHELP,&CInfoManagerDlg::OnGethelp) ON_COMMAND(IDM_RETURN,&CInfoManagerDlg::OnReturn) ON_COMMAND(IDM_ZHUANG,&CInfoManagerDlg::OnZhuang) ON_COMMAND(IDM_TABLE,&CInfoManagerDlg::OnTable) ON_UPDATE_COMMAND_UI(IDM_ZHUANG,&CInfoManagerDlg::OnUpdateZhuang) ON_UPDATE_COMMAND_UI(IDM_TABLE,&CInfoManagerDlg::OnUpdateTable) ON_WM_INITMENUPOPUP() ON_WM_MOUSEMOVE()END_MESSAGE_MAP()//CInfoManagerDlg消息处理程序BOOLCInfoManagerDlg::OnInitDialog(){ CDialog::OnInitDialog(); //将“关于...”菜单项添加到系统菜单中。 //IDM_ABOUTBOX必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX<0xF000); CMenu*pSysMenu=GetSystemMenu(FALSE); if(pSysMenu!=NULL) { CStringstrAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if(!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu); } } //设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 staticUINTindicators[]=//状态栏的显示 { ID_SEPARATOR,//状态 ID_SEPARATOR,//坐标 ID_SEPARATOR,//时间 ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; if(!m_StatusBar.Create(this,CBRS_BOTTOM|WS_CHILD|WS_VISIBLE)|| !m_StatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT))) { TRACE0("Failedtocreatestatusbar/n"); returnfalse; } SetTimer(1,1000,NULL); //执行此操作 SetIcon(m_hIcon,TRUE); //设置大图标 SetIcon(m_hIcon,FALSE); //设置小图标 //TODO:在此添加额外的初始化代码 m_list.ModifyStyle(0,LVS_REPORT);//报表模式 m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB); m_list.InsertColumn(0,_T("员工号")); m_list.InsertColumn(1,_T("姓名")); m_list.InsertColumn(2,_T("出生年月")); m_list.InsertColumn(3,_T("性别")); m_list.InsertColumn(4,_T("联系方式")); m_list.InsertColumn(5,_T("学历")); m_list.InsertColumn(6,_T("政治面貌")); m_list.InsertColumn(7,_T("家庭住址")); m_list.InsertColumn(8,_T("入职时间")); m_list.InsertColumn(9,_T("工资")); m_list.InsertColumn(10,_T("备注")); GetClientRect(&m_rect); ReInit(); ReSize(IDC_LIST1,0,0); returnTRUE;//除非将焦点设置到控件,否则返回TRUE}voidCInfoManagerDlg::OnSysCommand(UINTnID,LPARAMlParam){ if((nID&0xFFF0)==IDM_ABOUTBOX) { CAboutDlgdlgAbout(theApp.reg.regname); dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID,lParam); }}//如果向对话框添加最小化按钮,则需要下面的代码//来绘制该图标。对于使用文档/视图模型的MFC应用程序,//这将由框架自动完成。voidCInfoManagerDlg::OnPaint(){ if(IsIconic()) { CPaintDCdc(this);//用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND,reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0); //使图标在工作区矩形中居中 intcxIcon=GetSystemMetrics(SM_CXICON); intcyIcon=GetSystemMetrics(SM_CYICON); CRectrect; GetClientRect(&rect); intx=(rect.Width()-cxIcon+1)/2; inty=(rect.Height()-cyIcon+1)/2; //绘制图标 dc.DrawIcon(x,y,m_hIcon); } else { CDialog::OnPaint(); } CRectrect; m_list.GetClientRect(rect);//获得当前客户区信息 avrage=rect.Width()/11+1; floataw[11]={0.851351,0.851351,1.175676,0.513514,1.243243,0.635135,0.878378, 1.445946,0.905405,0.851351,1.540541}; for(inti=0;i<11;i++) m_list.SetColumnWidth(i,avrage*aw[i]); GetWindowRect(&rect);//显示状态栏 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); if(rect.Width()-330>0) { m_StatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_NORMAL,rect.Width()-330); m_StatusBar.SetPaneInfo(1,ID_SEPARATOR,SBPS_NORMAL,80); m_StatusBar.SetPaneInfo(2,ID_SEPARATOR,SBPS_NORMAL,80); m_StatusBar.SetPaneInfo(3,ID_SEPARATOR,SBPS_NORMAL,30); m_StatusBar.SetPaneInfo(4,ID_SEPARATOR,SBPS_NORMAL,30); m_StatusBar.SetPaneInfo(5,ID_SEPARATOR,SBPS_NORMAL,30); m_StatusBar.SetPaneText(0,_T("就绪"),TRUE); m_StatusBar.SetPaneText(1,_T("坐标"),true); m_StatusBar.SetPaneText(2,_T("时间"),true); OnTimer(1); } }//当用户拖动最小化窗口时系统调用此函数取得光标//显示。HCURSORCInfoManagerDlg::OnQueryDragIcon(){ returnstatic_cast<HCURSOR>(m_hIcon);}voidCInfoManagerDlg::OnAboutbox(){ //TODO:在此添加命令处理程序代码 //m_list.SetColumnWidth(10,avrage); /*floattemp; CStringstr=_T(""); CStringstrtemp=_T(""); for(inti=0;i<11;i++) { temp=m_list.GetColumnWidth(i); temp=temp/avrage; strtemp.Format(_T("Width%d=%f,"),i,temp); str+=strtemp; } MessageBox(str);*/ CAboutDlgdlgAbout(theApp.reg.regname); dlgAbout.DoModal();}voidCInfoManagerDlg::OnExit(){ //TODO:在此添加命令处理程序代码 SendMessage(WM_CLOSE);}voidCInfoManagerDlg::OnAdduser(){ //TODO:在此添加命令处理程序代码 CUserdd(ADDUSER,userid); dd.DoModal();}voidCInfoManagerDlg::OnDeluser(){ //TODO:在此添加命令处理程序代码 CUserdd(DELUSER,userid); dd.DoModal();}voidCInfoManagerDlg::OnStopuser(){ //TODO:在此添加命令处理程序代码 CUserdd(STOPUSER,userid); dd.DoModal();}voidCInfoManagerDlg::OnResuser(){ //TODO:在此添加命令处理程序代码 CUserdd(RESUSER,userid); dd.DoModal();}voidCInfoManagerDlg::OnSetmanger(){ //TODO:在此添加命令处理程序代码 CUserdd(ASMAN,userid); dd.DoModal();}voidCInfoManagerDlg::OnChang(){ //TODO:在此添加命令处理程序代码 CUserdd(CHANG,userid); dd.DoModal();}voidCInfoManagerDlg::OnRelogin(){ //TODO:在此添加命令处理程序代码 ShowWindow(SW_HIDE); Clogindd; if(IDOK!=dd.DoModal()) SendMessage(WM_CLOSE); ShowWindow(SW_SHOW); userid=dd.m_userid; isman=dd.m_isman; ReInit();}voidCInfoManagerDlg::ReInit(){ data.Init(); data.ReadFile(); m_list.DeleteAllItems(); for(inti=0;i<data.count;i++) m_list.InsertItem(i,_T("")); if(isman) { GetMenu()->EnableMenuItem(IDM_ADDUSER,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_DELUSER,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_RESUSER,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_SETMANGER,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_NEWDATA,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_BAKDATA,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_RESTORE,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_GAI,MF_ENABLED); GetMenu()->EnableMenuItem(IDM_ERROR,MF_GRAYED); } else { GetMenu()->EnableMenuItem(IDM_ADDUSER,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_DELUSER,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_RESUSER,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_SETMANGER,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_NEWDATA,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_BAKDATA,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_RESTORE,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_GAI,MF_GRAYED); GetMenu()->EnableMenuItem(IDM_ERROR,MF_ENABLED); } ShowList();}voidCInfoManagerDlg::OnSize(UINTnType,intcx,intcy){ CDialog::OnSize(nType,cx,cy); if(nType!=SIZE_MINIMIZED)//判断是否为最小化 { ReSize(IDC_LIST1,cx,cy); GetClientRect(&m_rect); } //TODO:在此处添加消息处理程序代码}voidCInfoManagerDlg::ReSize(intnID,intcx,intcy){ CWnd*pWnd; pWnd=GetDlgItem(nID);//获取控件句柄 if(pWnd) { CRectrect;//获取控件变化前大小 CRectwin_rect; GetClientRect(&win_rect); pWnd->GetWindowRect(&rect); ScreenToClient(&rect);//将控件大小转换为在对话框中的区域坐标 rect.bottom=win_rect.bottom-20; rect.right=win_rect.right-(m_rect.right-rect.right); pWnd->MoveWindow(rect);//设置控件位置 }}voidCInfoManagerDlg::OnNewdata(){ //TODO:在此添加命令处理程序代码 if(IDYES==MessageBox(_T("这样会删除所有数据,你真的要继续吗?"),_T("警告"),MB_YESNO)) {theApp.OnNewData(); MessageBox(_T("请重新登陆,初始用户为:manager,\n密码为:123456,登陆后请尽快修改密码")); SendMessage(WM_CLOSE);}}voidCInfoManagerDlg::OnBakdata(){ //TODO:在此添加命令处理程序代码 CFileDialogfile(false,_T("bak"),0,0,_T("数据备份文件(*.bak)|*.bak|所有文件(*.*)|*||")); if(file.DoModal()==IDOK) { CStringstr=file.GetFolderPath()+"\\"+file.GetFileName(); if(!CopyFile(_T("sourse.dat"),str,true)) MessageBox(_T("文件已存在!")); }}voidCInfoManagerDlg::OnRestore(){ //TODO:在此添加命令处理程序代码 CFileDialogfile(true,_T("bak"),0,0,_T("数据备份文件(*.bak)|*.bak|所有文件(*.*)|*||")); if(IDOK==file.DoModal()) { CStringstr=file.GetFolderPath()+"\\"+file.GetFileName(); CopyFile(str,_T("sourse.dat"),false); MessageBox(_T("请重新登陆!")); SendMessage(WM_CLOSE); }}voidCInfoManagerDlg::ShowList(){ if(data.count!=0) { for(inti=0;i<data.count;i++) for(intj=0;j<11;j++) m_list.SetItemText(i,j,data[i][j]); }}voidCInfoManagerDlg::OnTimer(UINT_PTRnIDEvent){ //TODO:在此添加消息处理程序代码和/或调用默认值 if(nIDEvent==1) { CStringstr; CTimetm; tm=CTime::GetCurrentTime(); str=tm.Format(_T("%H:%M:%S")); m_StatusBar.SetPaneText(2,str,true); return; } CDialog::OnTimer(nIDEvent);}voidCInfoManagerDlg::OnMenuSelect(UINTnItemID,UINTnFlags,HMENUhSysMenu){ CDialog::OnMenuSelect(nItemID,nFlags,hSysMenu); //TODO:在此处添加消息处理程序代码 CStringstrStatusText; strStatusText.LoadString(nItemID);//SetStringatID if(strStatusText!=_T("")) m_StatusBar.SetPaneText(0,strStatusText); else m_StatusBar.SetPaneText(0,_T("就绪"));}voidCInfoManagerDlg::OnGai(){ //TODO:在此添加命令处理程序代码 DataEditdd; dd.DoModal(); ReInit(); }voidCInfoManagerDlg::OnError(){ //TODO:在此添加命令处理程序代码 DataEditdd(false); dd.DoModal(); ReInit();}voidCInfoManagerDlg::OnAll(){ //TODO:在此添加命令处理程序代码 MessageBox(data.All());}voidCInfoManagerDlg::OnSorta(){ //TODO:在此添加命令处理程序代码 DataEditdd; dd.Sort();}voidCInfoManagerDlg::OnSortb(){ //TODO:在此添加命令处理程序代码}voidCInfoManagerDlg::OnSortc(){ //TODO:在此添加命令处理程序代码 }voidCInfoManagerDlg::OnSortd(){ //TODO:在此添加命令处理程序代码}voidCInfoManagerDlg::OnReg(){ //TODO:在此添加命令处理程序代码 if(theApp.reg.ReadFile()) { if(MessageBox(_T("你已成功注册该产品,是否更改密钥?"),0,MB_YESNO)!=IDYES) return; } theApp.reg.DoModal();}voidCInfoManagerDlg::OnGethelp(){ //TODO:在此添加命令处理程序代码 ShellExecute(NULL,_T("open"),_T("notepad.exe"),_T(".\\help\\help.txt"),NULL,SW_SHOWNORMAL);}voidCInfoManagerDlg::OnReturn(){ //TODO:在此添加命令处理程序代码 MessageBox(_T("你可以通过邮件发送至a53133@163.com"),_T("未实现的功能"));}voidCInfoManagerDlg::OnZhuang(){ //TODO:在此添加命令处理程序代码 if(m_StatusBar.IsWindowVisible()) m_StatusBar.ShowWindow(SW_HIDE); else m_StatusBar.ShowWindow(SW_SHOW);}voidCInfoManagerDlg::OnTable(){ //TODO:在此添加命令处理程序代码 if(GetDlgItem(IDC_LIST1)->IsWindowVisible()) GetDlgItem(IDC_LIST1)->ShowWindow(SW_HIDE); else GetDlgItem(IDC_LIST1)->ShowWindow(SW_SHOW);}voidCInfoManagerDlg::OnUpdateZhuang(CCmdUI*pCmdUI){ //TODO:在此添加命令更新用户界面处理程序代码 if(m_StatusBar.IsWindowVisible()) pCmdUI->SetCheck(1); else pCmdUI->SetCheck(0);}voidCInfoManagerDlg::OnUpdateTable(CCmdUI*pCmdUI){ //TODO:在此添加命令更新用户界面处理程序代码 if(GetDlgItem(IDC_LIST1)->IsWindowVisible()) pCmdUI->SetCheck(1); else pCmdUI->SetCheck(0);}voidCInfoManagerDlg::OnInitMenuPopup(CMenu*pPopupMenu,UINTnIndex,BOOLbSysMenu){ASSERT(pPopupMenu!=NULL);//Checktheenabledstateofvariousmenuitems.CCmdUIstate;state.m_pMenu=pPopupMenu;ASSERT(state.m_pOther==NULL);ASSERT(state.m_pParentMenu==NULL);//Determineifmenuispopupintop-levelmenuandsetm_pOtherto//itifso(m_pParentMenu==NULLindicatesthatitissecondarypopup).HMENUhParentMenu;if(AfxGetThreadState()->m_hTrackingMenu==pPopupMenu->m_hMenu)state.m_pParentMenu=pPopupMenu;//Parent==childfortrackingpopup.elseif((hParentMenu=::GetMenu(m_hWnd))!=NULL){CWnd*pParent=this;//Childwindowsdon'thavemenus--needtogotothetop!if(pParent!=NULL&&(hParentMenu=::GetMenu(pParent->m_hWnd))!=NULL){intnIndexMax=::GetMenuItemCount(hParentMenu);for(intnIndex=0;nIndex<nIndexMax;nIndex++){if(::GetSubMenu(hParentMenu,nIndex)==pPopupMenu->m_hMenu){//Whenpopupisfound,m_pParentMenuiscontainingmenu.state.m_pParentMenu=CMenu::FromHandle(hParentMenu);break;}}}}state.m_nIndexMax=pPopupMenu->GetMenuItemCount();for(state.m_nIndex=0;state.m_nIndex<state.m_nIndexMax;state.m_nIndex++){state.m_nID=pPopupMenu->GetMenuItemID(state.m_nIndex);if(state.m_nID==0)continue;//Menuseparatororinvalidcmd-ignoreit.ASSERT(state.m_pOther==NULL);ASSERT(state.m_pMenu!=NULL);if(state.m_nID==(UINT)-1){//Possiblyapopupmenu,routetofirstitemofthatpopup.state.m_pSubMenu=pPopupMenu->GetSubMenu(state.m_nIndex);if(state.m_pSubMenu==NULL||(state.m_nID=state.m_pSubMenu->GetMenuItemID(0))==0||state.m_nID==(UINT)-1){continue;//Firstitemofpopupcan'tberoutedto.}state.DoUpdate(this,TRUE);//Popupsareneverautodisabled.}else{//Normalmenuitem.//Autoenable/disableifframewindowhasm_bAutoMenuEnable//setandcommandis_not_asystemcommand.state.m_pSubMenu=NULL;state.DoUpdate(this,FALSE);}//Adjustformenudeletionsandadditions.UINTnCount=pPopupMenu->GetMenuItemCount();if(nCount<state.m_nIndexMax){state.m_nIndex-=(state.m_nIndexMax-nCount);while(state.m_nIndex<nCount&&pPopupMenu->GetMenuItemID(state.m_nIndex)==state.m_nID){state.m_nIndex++;}}state.m_nIndexMax=nCount;}}voidCInfoManagerDlg::OnMouseMove(UINTnFlags,CPointpoint){ //TODO:在此添加消息处理程序代码和/或调用默认值 CStringstr; str.Format(_T("x=%d,y=%d"),point.x,point.y); m_StatusBar.SetPaneText(1,str,true); CDialog::OnMouseMove(nFlags,point);}在CUser类中实现了修改密码增加用户等功能,同时采用了同一个对话框,最初可能是尽可能的节省内存,减小程序大小,事实上这最多是看起来更加清楚,这给我们变成带来了很大的困难,因为我们在设计是必须考虑周全。以下是CUser类的源代码:CUser::CUser(CWnd*pParent/*=NULL*/) :CDialog(CUser::IDD,pParent),m_mode(-1){ IsMan=false;}CUser::CUser(intmode,intuserid,CWnd*pParent/*NULL*/):CDialog(CUser::IDD,pParent),m_mode(mode),m_userid(userid){ IsMan=false;}CUser::~CUser(){}voidCUser::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CUser,CDialog) END_MESSAGE_MAP()//CUser消息处理程序BOOLCUser::OnInitDialog(){ CDialog::OnInitDialog(); //TODO:在此添加额外的初始化 m_pRecordset.CreateInstance(__uuidof(Recordset)); CListBox*a=(CListBox*)GetDlgItem(IDC_USERLIST); CStringstrName; try { m_pRecordset->Open("SELECT*FROMusers", theApp.m_pConnection.GetInterfacePtr(),//获取库接库的IDispatch指针 adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_errore) { AfxMessageBox(e.ErrorMessage()); } ////////// try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { MessageBox(_T("无用户信息")); returnfalse; } while(!m_pRecordset->adoEOF) { var=m_pRecordset->GetCollect("ID"); if(var.vt!=VT_NULL) if(m_userid==Val) {var=m_pRecordset->GetCollect("isman"); IsMan=var.boolVal; } m_pRecordset->MoveNext(); } } catch(_com_errore) { MessageBox(e.ErrorMessage()); } if(IsMan) switch(m_mode) { caseADDUSER: GetDlgItem(IDC_USERLIST)->ShowWindow(false); ((CButton*)GetDlgItem(IDC_NOTMAN))->SetCheck(true); break; caseDELUSER: GetDlgItem(IDC_AUSER)->ShowWindow(false); GetDlgItem(IDC_APASS)->ShowWindow(false); GetDlgItem(IDC_APASS2)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); GetDlgItem(IDC_STATIC2)->ShowWindow(false); GetDlgItem(IDC_STATIC3)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); break; caseSTOPUSER: GetDlgItem(IDC_AUSER)->ShowWindow(false); GetDlgItem(IDC_APASS)->ShowWindow(false); GetDlgItem(IDC_APASS2)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); GetDlgItem(IDC_STATIC2)->ShowWindow(false); GetDlgItem(IDC_STATIC3)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); //SetDlgItemText(IDC_STATIC4,_T("是否冻结:")); break; caseRESUSER: GetDlgItem(IDC_AUSER)->ShowWindow(false); GetDlgItem(IDC_APASS)->ShowWindow(false); GetDlgItem(IDC_APASS2)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); GetDlgItem(IDC_STATIC2)->ShowWindow(false); GetDlgItem(IDC_STATIC3)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); //SetDlgItemText(IDC_STATIC4,_T("是否冻结:")); break; caseASMAN: GetDlgItem(IDC_AUSER)->ShowWindow(false); GetDlgItem(IDC_APASS)->ShowWindow(false); GetDlgItem(IDC_APASS2)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); GetDlgItem(IDC_STATIC2)->ShowWindow(false); GetDlgItem(IDC_STATIC3)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); break; caseCHANG: GetDlgItem(IDC_USERLIST)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); SetDlgItemText(IDC_STATIC1,_T("旧密码:")); SetDlgItemText(IDC_STATIC2,_T("新密码:"));#ifdefWindowsVista ((CEdit*)GetDlgItem(IDC_AUSER))->SetPasswordChar(L'●');#else ((CEdit*)GetDlgItem(IDC_AUSER))->SetPasswordChar(L'*');#endif break; default: break; } else { switch(m_mode) { caseSTOPUSER: GetDlgItem(IDC_USERLIST)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->EnableWindow(false); GetDlgItem(IDC_ISMAN)->EnableWindow(false); GetDlgItem(IDC_NOTMAN)->EnableWindow(false); GetDlgItem(IDC_STATIC3)->EnableWindow(false); GetDlgItem(IDC_APASS2)->EnableWindow(false); GetDlgItem(IDC_STATIC1)->EnableWindow(false); GetDlgItem(IDC_AUSER)->EnableWindow(false); break; caseCHANG: GetDlgItem(IDC_USERLIST)->ShowWindow(false); GetDlgItem(IDC_STATIC4)->ShowWindow(false); GetDlgItem(IDC_ISMAN)->ShowWindow(false); GetDlgItem(IDC_NOTMAN)->ShowWindow(false); SetDlgItemText(IDC_STATIC1,_T("旧密码:")); SetDlgItemText(IDC_STATIC2,_T("新密码:")); break; default: break; } } switch(m_mode) { caseASMAN: try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { MessageBox(_T("无用户信息")); returnfalse; } while(!m_pRecordset->adoEOF) { var=m_pRecordset->GetCollect("username"); if(var.vt!=VT_NULL) strName=(LPCSTR)_bstr_t(var); var=m_pRecordset->GetCollect("isman"); if((bool)var.boolVal) strName+=_T("管理员"); a->AddString(strName); m_pRecordset->MoveNext(); } } catch(_com_errore) { MessageBox(e.ErrorMessage()); } break; caseSTOPUSER: caseRESUSER: try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { MessageBox(_T("无用户信息"));

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论