Data1View.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:6k
源码类别:
GIS编程
开发平台:
Visual C++
- // Data1View.cpp : implementation of the CData1View class
- //
- #include "stdafx.h"
- #include "Data1.h"
- #include "Data1Set.h"
- #include "Data1Doc.h"
- #include "Data1View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CData1View
- IMPLEMENT_DYNCREATE(CData1View, CRecordView)
- BEGIN_MESSAGE_MAP(CData1View, CRecordView)
- //{{AFX_MSG_MAP(CData1View)
- ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
- ON_COMMAND(ID_RECORD_MODIFY, OnRecordModify)
- ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
- ON_COMMAND(ID_RECORD_FILTER, OnRecordFilter)
- ON_COMMAND(ID_RECORD_SORT, OnRecordSort)
- ON_COMMAND(ID_RECORD_SAVE, OnRecordSave)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CData1View construction/destruction
- CData1View::CData1View()
- : CRecordView(CData1View::IDD)
- {
- //{{AFX_DATA_INIT(CData1View)
- m_pSet = NULL;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- }
- CData1View::~CData1View()
- {
- }
- void CData1View::DoDataExchange(CDataExchange* pDX)
- {
- CRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CData1View)
- DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_only_id, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_city_name, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_population, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT4, m_pSet->m_area, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT5, m_pSet->m_industry, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT6, m_pSet->m_translate, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT7, m_pSet->m_enviroment, m_pSet);
- //}}AFX_DATA_MAP
- }
- BOOL CData1View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CRecordView::PreCreateWindow(cs);
- }
- void CData1View::OnInitialUpdate()
- {
- m_pSet = &GetDocument()->m_data1Set;
- CRecordView::OnInitialUpdate();
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CData1View printing
- BOOL CData1View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CData1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CData1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CData1View diagnostics
- #ifdef _DEBUG
- void CData1View::AssertValid() const
- {
- CRecordView::AssertValid();
- }
- void CData1View::Dump(CDumpContext& dc) const
- {
- CRecordView::Dump(dc);
- }
- CData1Doc* CData1View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CData1Doc)));
- return (CData1Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CData1View database support
- CRecordset* CData1View::OnGetRecordset()
- {
- return m_pSet;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CData1View message handlers
- void CData1View::OnRecordAdd()
- {
- // TODO: Add your command handler code here
- m_pSet->AddNew(); //在记录集合中增加一条记录
- m_bAdding=TRUE; //标识正在进行增加记录操作
- UpdateData(FALSE);//将新增空记录的内容转移到视图的控制中
- }
- void CData1View::OnRecordModify()
- {
- // TODO: Add your command handler code here
- m_pSet->Edit(); //使当前记录处于编辑状态
- UpdateData(TRUE); //在视图中对话框控制的内容修改记录集合的当前记录
- if(m_pSet->CanUpdate()) //如果能够对数据源进行更新
- m_pSet->Update(); //更新数据源
- m_pSet->Requery(); //重新产生数据源
- UpdateData(FALSE); //以记录集合中当前记录的内容修改视图中的对话框控制
- }
- void CData1View::OnRecordDelete()
- {
- // TODO: Add your command handler code here
- m_pSet->Delete(); //删除记录集合的当前记录
- m_pSet->MoveNext();
- if(m_pSet->IsEOF()) //如果超出记录集合的范围
- m_pSet->MoveLast();
- if(m_pSet->IsBOF()) //如果记录指针在第一条记录前,即记录集合中无任何记录
- m_pSet->SetFieldNull(NULL); //将记录设置为空
- UpdateData(FALSE); //以记录集合当前记录的内容修改视图中的控制
- }
- void CData1View::OnRecordFilter()
- {
- // TODO: Add your command handler code here
- if(m_pSet->IsOpen())//如果记录集合对象处于打开状态,则关闭记录集合对象
- m_pSet->Close();
- m_pSet->m_strFilter="population>600";
- m_pSet->Open();
- }
- void CData1View::OnRecordSort()
- {
- // TODO: Add your command handler code here
- if(m_pSet->IsOpen())//如果记录集合对象处于打开状态,则关闭记录集合对象
- m_pSet->Close();
- m_pSet->m_strSort="population DESC";//设置排序子式
- // m_pSet->m_strSort="enviroment,population DESC";//设置排序子式enviroment升序,后者降序
- m_pSet->Open();
- }
- int CData1View::OnRecordSave()
- {
- // TODO: Add your command handler code here
- if(m_bAdding)
- {
- m_bAdding=FALSE;
- UpdateData(TRUE);
- if(m_pSet->CanUpdate())
- m_pSet->Update();
- m_pSet->Requery();
- UpdateData(FALSE);
- return TRUE;
- }
- return FALSE;
- }
- BOOL CData1View::OnMove(UINT nIDMoveCommand)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(m_bAdding)
- {
- m_bAdding=FALSE;
- UpdateData(TRUE);
- if(m_pSet->CanUpdate())
- m_pSet->Update();
- m_pSet->Requery();
- UpdateData(FALSE);
- return TRUE;
- }
- else
- return CRecordView::OnMove(nIDMoveCommand);
- }