MapFormView.cpp
上传用户:jc6688
上传日期:2013-05-06
资源大小:344k
文件大小:5k
源码类别:

GPS编程

开发平台:

Visual C++

  1. // MapFormView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MapDemo.h"
  5. #include "MapDemoDoc.h"
  6. #include "MapView.h"
  7. #include "MapFormView.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMapFormView
  16. IMPLEMENT_DYNCREATE(CMapFormView, CFormView)
  17. CMapFormView::CMapFormView()
  18. : CFormView(CMapFormView::IDD)
  19. {
  20. //{{AFX_DATA_INIT(CMapFormView)
  21. // NOTE: the ClassWizard will add member initialization here
  22. //}}AFX_DATA_INIT
  23. m_pCtrlMapX=NULL;
  24. }
  25. CMapFormView::~CMapFormView()
  26. {
  27. }
  28. void CMapFormView::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CFormView::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CMapFormView)
  32. DDX_Control(pDX, IDC_MSFLEXGRID1, m_ctrlGrid);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CMapFormView, CFormView)
  36. //{{AFX_MSG_MAP(CMapFormView)
  37. ON_WM_SIZE()
  38. ON_WM_DESTROY()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CMapFormView diagnostics
  43. #ifdef _DEBUG
  44. void CMapFormView::AssertValid() const
  45. {
  46. CFormView::AssertValid();
  47. }
  48. void CMapFormView::Dump(CDumpContext& dc) const
  49. {
  50. CFormView::Dump(dc);
  51. }
  52. #endif //_DEBUG
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CMapFormView message handlers
  55. void CMapFormView::OnInitialUpdate() 
  56. {
  57. CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
  58. m_pMapView=pFrame->m_pMapView;
  59. if(m_pMapView!=NULL) 
  60. m_pCtrlMapX=&(m_pMapView->m_ctrlMapX);
  61.    m_strEditLayer=m_pMapView->m_strEditLayer;
  62. if(m_strEditLayer=="")
  63. {
  64. m_pMapView->SendMessage(WM_COMMAND,ID_MAPEDIT_SELETTABLE);
  65. m_strEditLayer=m_pMapView->m_strEditLayer;
  66. }
  67. CFormView::OnInitialUpdate();
  68. pFrame->m_pFormView=this;
  69. AddFormData();
  70. }
  71. void CMapFormView::OnSize(UINT nType, int cx, int cy) 
  72. {
  73. CFormView::OnSize(nType, cx, cy);
  74. if(m_ctrlGrid.m_hWnd !=NULL) 
  75. m_ctrlGrid.MoveWindow(0,0,cx,cy,FALSE);
  76. }
  77. void CMapFormView::OnDestroy() 
  78. {
  79. CFormView::OnDestroy();
  80. CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
  81. pFrame->m_pFormView=NULL;
  82. }
  83. void CMapFormView::AddFormData()
  84. {
  85.     CMapXLayer layer;
  86. m_strEditLayer=m_pMapView->m_strEditLayer;
  87. if(m_pCtrlMapX==NULL) return;
  88.     
  89.     
  90.     if(m_strEditLayer!="")
  91. layer=m_pCtrlMapX->GetLayers().Item(m_strEditLayer);
  92. else return;
  93. try {
  94. COleVariant vtLayer;
  95. vtLayer.vt = VT_DISPATCH;
  96. vtLayer.pdispVal = layer.m_lpDispatch;
  97. vtLayer.pdispVal->AddRef();
  98.           
  99.     CString str1=m_strEditLayer; 
  100. CMapXDataset dataSet;
  101. if(!IsInDataSet(m_strEditLayer))
  102.  dataSet=m_pCtrlMapX->GetDatasets().Add(miDataSetLayer, vtLayer, str1);
  103.         else 
  104. dataSet=m_pCtrlMapX->GetDatasets().Item(str1);
  105. CMapXFields mapField= dataSet.GetFields();
  106.         int cols,rows; 
  107. cols=mapField.GetCount();
  108. rows=dataSet.GetRowCount(); 
  109. m_ctrlGrid.SetCols(cols+1);
  110. m_ctrlGrid.SetRows(rows+1); 
  111.          
  112.         m_ctrlGrid.SetCol(0);
  113. m_ctrlGrid.SetRow(0); 
  114. m_ctrlGrid.SetText("ͼԪID");
  115. for(int i=0;i<cols;i++)
  116. {
  117. CMapXField field=mapField.Item(i+1);
  118. CString str=field.GetName();
  119. m_ctrlGrid.SetCol(i+1);
  120. m_ctrlGrid.SetText(str);
  121. int nType=field.GetType();
  122.          
  123.    }//end if i
  124. CString str;
  125. //dataSet.GetLayer().BeginAccess(miAccessRead);
  126.         for(int j=0;j<rows;j++)
  127. {
  128.  str.Format("ID %d",j);
  129.  
  130.  WriteRows(-1,j,cols+1,str);  
  131.  for(i=0;i<cols;i++)
  132.  {
  133. VARIANT var=dataSet.GetValue(j+1, i+1);
  134. COleVariant vVal(var);
  135. vVal.ChangeType(VT_BSTR);
  136. str= vVal.bstrVal;
  137. WriteRows(i,j,cols+1,str);  
  138.  }
  139. /*switch(nType)
  140. {
  141. case miTypeString:
  142. {
  143. str= vVal.bstrVal;
  144. }
  145. break;
  146. case miTypeNumeric:
  147. {
  148. vVal.ChangeType(VT_BSTR);
  149. str= vVal.bstrVal;
  150. }
  151. break;*/
  152. //}//end swithch   
  153.   
  154.   
  155.         
  156.   
  157.   }//end if j 
  158. //miAccessEnd;
  159. // VARIANT vv=COleVariant((long)1);
  160. // dataSet.GetLayer().EndAccess(vv);
  161.     //end try
  162. catch (COleDispatchException *e) {
  163. e->ReportError();
  164. e->Delete();
  165. } catch (COleException *e) {
  166. e->ReportError();
  167. e->Delete();
  168. }
  169. // MessageBox("test");
  170. }
  171. void CMapFormView::WriteRows(int x, int y, int cols,CString str)
  172. {
  173.   //m_ctrlGrid.SetCol(x+1);
  174.   //m_ctrlGrid.SetRow(y+1); 
  175.       //m_ctrlGrid.SetText(str);
  176.   int index=(y+1)*cols+x+1;
  177.   m_ctrlGrid.SetTextArray(index, str);
  178. }
  179. BOOL CMapFormView::IsInDataSet(CString strName)
  180. {
  181. CMapXDatasets datasets=m_pCtrlMapX->GetDatasets();
  182. for(int i=1;i<=datasets.GetCount();i++)
  183. {
  184. if(datasets.Item(i).GetName()==strName) return TRUE;
  185. }
  186.    return FALSE;
  187. }