版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
基于MFC對話框的人事信息管理實驗報告題目:人事信息管理系統(tǒng)系別:計算機(jī)科學(xué)與技術(shù)專業(yè)班級:201X級指導(dǎo)教師:XXXXXX小組成員:XXXXXXXXXXXXXXXX目錄1摘要……………….32關(guān)鍵詞……………33.編寫目的………..34.功能列表………..35.程序框圖………..46.UML類圖………57.詳細(xì)設(shè)計………..88.總結(jié)………….…319.參考資料……………………...321.摘要有公司就有員工,公司的員工信息的管理也成了重要的一部分,為了更好地管理員工信息,我們小組設(shè)計人事信息管理系統(tǒng),并在程序中設(shè)置了權(quán)限管理,防止信息被非法修改,同時對信息統(tǒng)一使用數(shù)據(jù)庫管理,提高效率。本次實驗歷時4周,使用的操作系統(tǒng)為Windows8,開發(fā)環(huán)境為vs2008;并在windowsXP和windows7上做了程序測試,經(jīng)測試未發(fā)現(xiàn)程序在運(yùn)行時發(fā)生訪問內(nèi)存的沖突。2.關(guān)鍵詞人事信息管理,程序設(shè)計3.編寫目的本款軟件面向廣大公司,但不適合公開發(fā)行,其中的數(shù)據(jù)庫是使用的Access的數(shù)據(jù)庫,并且數(shù)據(jù)沒有加密,密碼也沒有加密,容易導(dǎo)致員工信息泄露。本程序只能作為一家小型公司的使用,本程序不能出色的管理大型數(shù)據(jù),很多數(shù)據(jù)管理的功能沒又加入。4.功能列表注冊產(chǎn)品用戶登錄增加用戶更改密碼刪除用戶凍結(jié)用戶解凍用戶設(shè)置管理員退出登錄修改信息增加信息統(tǒng)計結(jié)果備份文件獲得幫助5.程序框圖退出開始注冊信息正確退出開始注冊信息正確?顯示主程序根據(jù)用戶選擇執(zhí)行相應(yīng)的功能用戶信息合法?是注冊否是否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.詳細(xì)設(shè)計本程序是基于對話框設(shè)計,考慮到基于單文檔的程序加入了沒有用的View類和Doc類,同時自動加入了文件保存操作以及不必要的菜單,我們最終選擇了基于對話框。由于對話框沒有菜單和狀態(tài)欄,于是我們又自己添加了菜單和狀態(tài)欄,同時加入了菜單提示,狀態(tài)欄的時間信息顯示,本來想顯示當(dāng)前選中的行列信息,最終沒有實現(xiàn),采用了對mousemove消息的響應(yīng)顯示坐標(biāo)信息。為了保證程序先運(yùn)行CReg,同時優(yōu)先讀取文件,如果成功就不在顯示注冊對話框,然后顯示用戶登陸窗口,對用戶名和密碼的判斷放在重載的OnOk()中,根據(jù)是否調(diào)用基類的OnOk()來決定是否銷毀窗口。以下是在BOOLCInfoManagerApp::InitInstance()中增減的內(nèi)容:free((void*)m_pszAppName);m_pszAppName=_tcsdup(_T("人事信息管理系統(tǒng)"));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我們將為你準(zhǔn)備必要的文件,請關(guā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;同時增加函數(shù)OnNewData()用于用戶第一次使用的復(fù)制初始文件voidCInfoManagerApp::OnNewData(){ CStringstr=_T(".//bak/sourse.dat"); CopyFile(str,_T("sourse.dat"),false);}用戶的登陸窗口是新建了一個CLogin的類,該類的基類是CDialog,對這個類的主要修改在于關(guān)聯(lián)了成員變量,對OnInitDialog()進(jìn)行修改用于讀數(shù)據(jù)庫,重載了OnOk()函數(shù),以下是修改的主要代碼://單擊忘記密碼voidClogin::OnStnClickedForget(){ //TODO:在此添加控件通知處理程序代碼 MessageBox(_T("請聯(lián)系管理員改密碼!"));}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屬性頁應(yīng)返回FALSE}//用于判斷密碼正確與否voidClogin::OnOK(){ //TODO:在此添加專用代碼和/或調(diào)用基類 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("該用戶已凍結(jié),請聯(lián)系管理員解凍!"));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類在一個文件中實現(xiàn),CData類中用到了Person指針動態(tài)分配大小用于顯示表格,由于實現(xiàn)上的原因中間很多函數(shù)運(yùn)行時發(fā)生訪問內(nèi)存錯誤,我們通過直接修改數(shù)據(jù)庫然后重建CData類顯示表格,這里是本程序的缺陷,內(nèi)存占用多,而且沒有必要。整個程序中花的時間最多的是CUser類的設(shè)計和在CInfoManagerDlg類中對菜單消息的響應(yīng)、計時器的響應(yīng)、鼠標(biāo)移動消息的響應(yīng)和菜單選擇的響應(yīng)。下面是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(); //將“關(guān)于...”菜單項添加到系統(tǒng)菜單中。 //IDM_ABOUTBOX必須在系統(tǒng)命令范圍內(nèi)。 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); } } //設(shè)置此對話框的圖標(biāo)。當(dāng)應(yīng)用程序主窗口不是對話框時,框架將自動 staticUINTindicators[]=//狀態(tài)欄的顯示 { ID_SEPARATOR,//狀態(tài) ID_SEPARATOR,//坐標(biāo) 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); //執(zhí)行此操作 SetIcon(m_hIcon,TRUE); //設(shè)置大圖標(biāo) SetIcon(m_hIcon,FALSE); //設(shè)置小圖標(biāo) //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("聯(lián)系方式")); m_list.InsertColumn(5,_T("學(xué)歷")); 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;//除非將焦點(diǎn)設(shè)置到控件,否則返回TRUE}voidCInfoManagerDlg::OnSysCommand(UINTnID,LPARAMlParam){ if((nID&0xFFF0)==IDM_ABOUTBOX) { CAboutDlgdlgAbout(theApp.reg.regname); dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID,lParam); }}//如果向?qū)υ捒蛱砑幼钚』粹o,則需要下面的代碼//來繪制該圖標(biāo)。對于使用文檔/視圖模型的MFC應(yīng)用程序,//這將由框架自動完成。voidCInfoManagerDlg::OnPaint(){ if(IsIconic()) { CPaintDCdc(this);//用于繪制的設(shè)備上下文 SendMessage(WM_ICONERASEBKGND,reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0); //使圖標(biāo)在工作區(qū)矩形中居中 intcxIcon=GetSystemMetrics(SM_CXICON); intcyIcon=GetSystemMetrics(SM_CYICON); CRectrect; GetClientRect(&rect); intx=(rect.Width()-cxIcon+1)/2; inty=(rect.Height()-cyIcon+1)/2; //繪制圖標(biāo) dc.DrawIcon(x,y,m_hIcon); } else { CDialog::OnPaint(); } CRectrect; m_list.GetClientRect(rect);//獲得當(dāng)前客戶區(qū)信息 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);//顯示狀態(tài)欄 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("坐標(biāo)"),true); m_StatusBar.SetPaneText(2,_T("時間"),true); OnTimer(1); } }//當(dāng)用戶拖動最小化窗口時系統(tǒng)調(diào)用此函數(shù)取得光標(biāo)//顯示。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);//將控件大小轉(zhuǎn)換為在對話框中的區(qū)域坐標(biāo) rect.bottom=win_rect.bottom-20; rect.right=win_rect.right-(m_rect.right-rect.right); pWnd->MoveWindow(rect);//設(shè)置控件位置 }}voidCInfoManagerDlg::OnNewdata(){ //TODO:在此添加命令處理程序代碼 if(IDYES==MessageBox(_T("這樣會刪除所有數(shù)據(jù),你真的要繼續(xù)嗎?"),_T("警告"),MB_YESNO)) {theApp.OnNewData(); MessageBox(_T("請重新登陸,初始用戶為:manager,\n密碼為:123456,登陸后請盡快修改密碼")); SendMessage(WM_CLOSE);}}voidCInfoManagerDlg::OnBakdata(){ //TODO:在此添加命令處理程序代碼 CFileDialogfile(false,_T("bak"),0,0,_T("數(shù)據(jù)備份文件(*.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("數(shù)據(jù)備份文件(*.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:在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值 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("你已成功注冊該產(chǎn)品,是否更改密鑰?"),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("你可以通過郵件發(fā)送至a53133@163.com"),_T("未實現(xiàn)的功能"));}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:在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值 CStringstr; str.Format(_T("x=%d,y=%d"),point.x,point.y); m_StatusBar.SetPaneText(1,str,true); CDialog::OnMouseMove(nFlags,point);}在CUser類中實現(xiàn)了修改密碼增加用戶等功能,同時采用了同一個對話框,最初可能是盡可能的節(jié)省內(nèi)存,減小程序大小,事實上這最多是看起來更加清楚,這給我們變成帶來了很大的困難,因為我們在設(shè)計是必須考慮周全。以下是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("是否凍結(jié):")); 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("是否凍結(jié):")); 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年滬科新版八年級地理上冊階段測試試卷
- 2025中國鐵路北京局集團(tuán)限公司招聘普通高校畢業(yè)生868人(二)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國聯(lián)通廣西分公司招聘97人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國神華系統(tǒng)內(nèi)招聘擬錄取人員高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國電信福建公司春季招聘148人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 動物炭黑、動物膠及其衍生物相關(guān)行業(yè)投資方案范本
- 2025中國旅游集團(tuán)戰(zhàn)略發(fā)展部副總經(jīng)理公開招聘1人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國南水北調(diào)集團(tuán)新能源投資限公司下屬經(jīng)營區(qū)域招聘5人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國人民財產(chǎn)保險股份限公司自貢市分公司招聘5人(四川)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中共聊城市委組織部所屬事業(yè)單位公開招聘(2025年)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 導(dǎo)尿管相關(guān)尿路感染防控措施實施情況督查表
- 三甲醫(yī)院評審護(hù)理院感組專家現(xiàn)場訪談問題梳理(護(hù)士)
- 家庭、私有制和國家的起源
- 中職《數(shù)學(xué)》課程思政教學(xué)案例(一等獎)
- 水庫移民安置檔案分類大綱與編號方案
- GA 1802.2-2022生物安全領(lǐng)域反恐怖防范要求第2部分:病原微生物菌(毒)種保藏中心
- 企業(yè)EHS風(fēng)險管理基礎(chǔ)智慧樹知到答案章節(jié)測試2023年華東理工大學(xué)
- 《解放戰(zhàn)爭》(共48張PPT)
- 借調(diào)人員年終總結(jié)模板【5篇】
- GB 1886.342-2021食品安全國家標(biāo)準(zhǔn)食品添加劑硫酸鋁銨
- 期末復(fù)習(xí)必背作文 魯教版八年級上冊英語全冊
評論
0/150
提交評論