// MyVC81View.cpp : implementation of the CMyVC81View class
//#include "stdafx.h"
#include "MyVC81.h"#include "MyVC81Set.h"
#include "MyVC81Doc.h"
#include "MyVC81View.h"
#include "fltdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyVC81ViewIMPLEMENT_DYNCREATE(CMyVC81View, CRecordView)BEGIN_MESSAGE_MAP(CMyVC81View, CRecordView)
//{{AFX_MSG_MAP(CMyVC81View)
ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
ON_COMMAND(ID_SORT_ID, OnSortId)
ON_COMMAND(ID_SORT_LENGTH, OnSortLength)
ON_COMMAND(ID_FILTER_ID, OnFilterId)
ON_COMMAND(ID_FILTER_FACTORY, OnFilterFactory)
//}}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()/////////////////////////////////////////////////////////////////////////////
// CMyVC81View construction/destructionCMyVC81View::CMyVC81View()
: CRecordView(CMyVC81View::IDD)
{
//{{AFX_DATA_INIT(CMyVC81View)
m_pSet = NULL;
//}}AFX_DATA_INIT
         flag=FALSE;            ////////////////////////////出错误地方
}CMyVC81View::~CMyVC81View()
{
}void CMyVC81View::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyVC81View)
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_LENGTH, m_pSet->m_length, m_pSet);
DDX_FieldText(pDX, IDC_HEIGHT, m_pSet->m_height, m_pSet);
DDX_FieldText(pDX, IDC_FACTORY, m_pSet->m_factory, m_pSet);
DDX_FieldText(pDX, IDC_WIDTH, m_pSet->m_width, m_pSet);
DDX_FieldText(pDX, IDC_ID, m_pSet->m_column1, m_pSet);
//}}AFX_DATA_MAP
}BOOL CMyVC81View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CRecordView::PreCreateWindow(cs);
}void CMyVC81View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_myVC81Set;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();}/////////////////////////////////////////////////////////////////////////////
// CMyVC81View printingBOOL CMyVC81View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CMyVC81View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CMyVC81View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CMyVC81View diagnostics#ifdef _DEBUG
void CMyVC81View::AssertValid() const
{
CRecordView::AssertValid();
}void CMyVC81View::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}CMyVC81Doc* CMyVC81View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyVC81Doc)));
return (CMyVC81Doc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CMyVC81View database support
CRecordset* CMyVC81View::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CMyVC81View message handlersvoid CMyVC81View::OnRecordAdd() 
{
m_pSet->AddNew();
flag=TRUE;                     ////////////////////////////出错误地方CEdit*pCtrl=(CEdit*)GetDlgItem(IDC_ID);
pCtrl->SetReadOnly(FALSE);
UpdateData(FALSE);

}void CMyVC81View::OnRecordDelete() 
{
m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
  m_pSet->MoveLast();
if(m_pSet->IsBOF())
  m_pSet->SetFieldNull(NULL);
m_pSet->Requery();
UpdateData(FALSE);

}void CMyVC81View::OnSortId() 
{
m_pSet->Close();
m_pSet->m_strSort="ID";
m_pSet->Open();
UpdateData(FALSE);

}void CMyVC81View::OnSortLength() 
{
m_pSet->Close();
m_pSet->m_strSort="LENGTH";
m_pSet->Open();
UpdateData(FALSE);

}void CMyVC81View::OnFilterId() 
{
 Cfltdlg dlg;
 int index;
 if(dlg.DoModal()==IDOK)
 {
 sscanf(dlg.m_fltvalue,"%d",&index);
 m_pSet->Close();
 m_pSet->m_strFilter.Format("ID=%d",index);
      m_pSet->Open();
  int count=m_pSet->GetRecordCount();
  if(count==0)
  {
  MessageBox("无匹配记录!");
          m_pSet->Close();
          m_pSet->m_strFilter="";
  m_pSet->Open();
  }
  UpdateData(FALSE);
 }

}void CMyVC81View::OnFilterFactory() 
{
CString str,str1;
 str1="FACTORY";
 Cfltdlg dlg;
 if(dlg.DoModal()==IDOK)
 {
 str=str1+"="+dlg.m_fltvalue+"";
 m_pSet->Close();
 m_pSet->m_strFilter=str;
      m_pSet->Open();
  int count=m_pSet->GetRecordCount();
  if(count==0)
  {
  MessageBox("无匹配记录!");
          m_pSet->Close();
          m_pSet->m_strFilter="";
  m_pSet->Open();
  }
  UpdateData(FALSE);
 }
}BOOL CMyVC81View::OnMove(UINT nIDMoveCommand) 
{
if(flag)                          ////////////////////////////出错误地方{
UpdateData(TRUE);
if(m_pSet->CanUpdate())
{m_pSet->Update();}
else
{MessageBox("数据源不能完成更新!");}
flag=FALSE;                            ////////////////////////////出错误地方m_pSet->Requery();
UpdateData(FALSE);
CEdit*pCtrl=(CEdit*)GetDlgItem(IDC_ID);
pCtrl->SetReadOnly(TRUE);
return TRUE;
}
else
return CRecordView::OnMove(nIDMoveCommand);
}BOOL CMyVC81View::flag()
{}