UserDlg.cpp
上传用户:hddq88
上传日期:2010-01-15
资源大小:910k
文件大小:4k
源码类别:

多国语言处理

开发平台:

C/C++

  1. // UserDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "RMM.h"
  5. #include "UserDlg.h"
  6. #include <afxdao.h>
  7. #include <map>
  8. #include <string>
  9. using namespace std;
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CUserDlg dialog
  17. CDaoDatabase db;
  18. CDaoRecordset RecSet(&db);
  19. typedef  map<CString , int > INT2STRING;
  20. INT2STRING theMap;
  21. INT2STRING::iterator theIterator;
  22. extern CString result;
  23. CUserDlg::CUserDlg(CWnd* pParent /*=NULL*/)
  24. : CDialog(CUserDlg::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CUserDlg)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. }
  30. void CUserDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CUserDlg)
  34. DDX_Control(pDX, IDC_LIST2, m_ctrUserWordList);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(CUserDlg, CDialog)
  38. //{{AFX_MSG_MAP(CUserDlg)
  39. ON_BN_CLICKED(IDC_OK, OnOk)
  40. ON_BN_CLICKED(IDC_CANCEL, OnCancel)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CUserDlg message handlers
  45. BOOL CUserDlg::OnInitDialog() 
  46. {
  47.  int nPos1=1,i=0;
  48.  int len;
  49.      CString rresult,tresult;
  50. CDialog::OnInitDialog();
  51. m_ctrUserWordList.SetExtendedStyle( m_ctrUserWordList.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
  52. m_ctrUserWordList.InsertColumn( 0, "词");
  53. m_ctrUserWordList.InsertColumn( 1, "次数");
  54.    
  55. m_ctrUserWordList.SetColumnWidth( 0, 100);
  56. m_ctrUserWordList.SetColumnWidth( 1, 400);
  57. char buffer[10];
  58.    
  59.   
  60.    // construct the map
  61.   while(nPos1!=-1)
  62. {
  63.   len=result.GetLength();
  64.   nPos1=result.Find(" ");
  65.   tresult=result;
  66.   result=result.Left(nPos1);
  67.   if(nPos1!=-1)
  68.   {
  69.   theIterator = theMap.find(result);
  70.               if(theIterator == theMap.end() )
  71.     theMap.insert(INT2STRING::value_type(result,1));  
  72.       else
  73. (*theIterator).second++; 
  74.   }
  75.   result=tresult.Right(len-nPos1-1);
  76.   
  77. }    
  78.       theIterator = theMap.find(result);
  79.               if(theIterator == theMap.end() )
  80.     theMap.insert(INT2STRING::value_type(result,1));  
  81.       else
  82. (*theIterator).second++; 
  83.  
  84. theIterator=theMap.begin();
  85. theIterator++;
  86. while(theIterator != theMap.end())
  87. {
  88.         sprintf(buffer,"%d",(*theIterator).second);
  89. m_ctrUserWordList.InsertItem( i, (*theIterator).first);
  90. m_ctrUserWordList.SetItemText( i, 1,buffer);
  91. theIterator++;
  92. i++;
  93. }
  94. return TRUE;  // return TRUE unless you set the focus to a control
  95.               // EXCEPTION: OCX Property Pages should return FALSE
  96. }
  97. void CUserDlg::OnOk() 
  98. {
  99. // TODO: Add your control notification handler code here
  100. CString sPath;
  101. GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
  102. sPath.ReleaseBuffer ();
  103. int nPos;
  104. char sword[1024];
  105. char scount[1024];
  106. nPos=sPath.ReverseFind ('\');
  107. sPath=sPath.Left (nPos);
  108. CString lpszFile = sPath + "\Demo.mdb";
  109. char szSql[1024];
  110. CFileFind  fFind;
  111. BOOL bSuccess;
  112. bSuccess=fFind.FindFile(lpszFile);
  113. fFind.Close ();
  114. if(!bSuccess){
  115. db.Create(lpszFile);
  116. CString SqlCmd = "CREATE TABLE DemoTable(word VARCHAR(20),count VARCHAR(3));";
  117. db.Execute(SqlCmd);
  118. RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM DemoTable", 0);
  119.         for ( int iCnt=0;iCnt<m_ctrUserWordList.GetItemCount();iCnt++ ){
  120.          m_ctrUserWordList.GetItemText(iCnt,0,sword,1024);
  121.          m_ctrUserWordList.GetItemText(iCnt,1,scount,1024);
  122.          sprintf(szSql,"INSERT INTO DemoTable (word,count) VALUES ('%s','%s')",sword,scount);
  123.  db.Execute(szSql);
  124. }
  125. }
  126. MessageBox("保存成功!");
  127. }
  128. void CUserDlg::OnCancel() 
  129. {
  130. // TODO: Add your control notification handler code here
  131. }