UserDlg.cpp
上传用户:hddq88
上传日期:2010-01-15
资源大小:910k
文件大小:4k
- // UserDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "RMM.h"
- #include "UserDlg.h"
- #include <afxdao.h>
- #include <map>
- #include <string>
- using namespace std;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CUserDlg dialog
- CDaoDatabase db;
- CDaoRecordset RecSet(&db);
- typedef map<CString , int > INT2STRING;
- INT2STRING theMap;
- INT2STRING::iterator theIterator;
- extern CString result;
- CUserDlg::CUserDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CUserDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUserDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CUserDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUserDlg)
- DDX_Control(pDX, IDC_LIST2, m_ctrUserWordList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CUserDlg, CDialog)
- //{{AFX_MSG_MAP(CUserDlg)
- ON_BN_CLICKED(IDC_OK, OnOk)
- ON_BN_CLICKED(IDC_CANCEL, OnCancel)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUserDlg message handlers
- BOOL CUserDlg::OnInitDialog()
- {
- int nPos1=1,i=0;
- int len;
- CString rresult,tresult;
- CDialog::OnInitDialog();
- m_ctrUserWordList.SetExtendedStyle( m_ctrUserWordList.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
- m_ctrUserWordList.InsertColumn( 0, "词");
- m_ctrUserWordList.InsertColumn( 1, "次数");
-
- m_ctrUserWordList.SetColumnWidth( 0, 100);
- m_ctrUserWordList.SetColumnWidth( 1, 400);
-
- char buffer[10];
-
-
- // construct the map
- while(nPos1!=-1)
- {
- len=result.GetLength();
- nPos1=result.Find(" ");
- tresult=result;
- result=result.Left(nPos1);
- if(nPos1!=-1)
- {
- theIterator = theMap.find(result);
- if(theIterator == theMap.end() )
- theMap.insert(INT2STRING::value_type(result,1));
- else
- (*theIterator).second++;
- }
- result=tresult.Right(len-nPos1-1);
-
- }
- theIterator = theMap.find(result);
- if(theIterator == theMap.end() )
- theMap.insert(INT2STRING::value_type(result,1));
- else
- (*theIterator).second++;
-
- theIterator=theMap.begin();
- theIterator++;
- while(theIterator != theMap.end())
- {
- sprintf(buffer,"%d",(*theIterator).second);
- m_ctrUserWordList.InsertItem( i, (*theIterator).first);
- m_ctrUserWordList.SetItemText( i, 1,buffer);
- theIterator++;
- i++;
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CUserDlg::OnOk()
- {
- // TODO: Add your control notification handler code here
- CString sPath;
- GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
- sPath.ReleaseBuffer ();
- int nPos;
- char sword[1024];
- char scount[1024];
- nPos=sPath.ReverseFind ('\');
- sPath=sPath.Left (nPos);
- CString lpszFile = sPath + "\Demo.mdb";
- char szSql[1024];
- CFileFind fFind;
- BOOL bSuccess;
- bSuccess=fFind.FindFile(lpszFile);
- fFind.Close ();
- if(!bSuccess){
- db.Create(lpszFile);
- CString SqlCmd = "CREATE TABLE DemoTable(word VARCHAR(20),count VARCHAR(3));";
- db.Execute(SqlCmd);
-
- RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM DemoTable", 0);
- for ( int iCnt=0;iCnt<m_ctrUserWordList.GetItemCount();iCnt++ ){
- m_ctrUserWordList.GetItemText(iCnt,0,sword,1024);
- m_ctrUserWordList.GetItemText(iCnt,1,scount,1024);
- sprintf(szSql,"INSERT INTO DemoTable (word,count) VALUES ('%s','%s')",sword,scount);
- db.Execute(szSql);
- }
- }
- MessageBox("保存成功!");
- }
- void CUserDlg::OnCancel()
- {
- // TODO: Add your control notification handler code here
-
- }