📄 productview.cpp
字号:
#include "stdafx.h"
#include "DBSimpleUpdate.h"
#include "ProductView.h"
#include "ProductSet.h"
#include "viewconstants.h"
#include "MainFrm.h"
#include "DBSimpleUpdateDoc.h"
CProductView::CProductView()
: CRecordView(CProductView::IDD),
m_pSet(NULL)
, m_OrderID(0)
, m_CustomerName(_T(""))
, m_Quantity(0)
, m_Discount(0)
, m_OrderAdded(false)
{
}
CProductView::~CProductView()
{
if (m_pSet)
delete m_pSet;
}
void CProductView::DoDataExchange(CDataExchange* pDX)
{
// TODO: Add your specialized code here and/or call the base class
CRecordView::DoDataExchange(pDX);
DDX_FieldText(pDX, IDC_PRODUCTNAME, m_pSet->m_ProductName, m_pSet);
DDX_Text(pDX, IDC_NEWORDERID, m_OrderID);
DDX_Text(pDX, IDC_CUSTOMERNAME, m_CustomerName);
DDX_Text(pDX, IDC_ORDERQUANTITY, m_Quantity);
DDX_Text(pDX, IDC_ORDERSDISCOUNT, m_Discount);
}
void CProductView::OnInitialUpdate()
{
CRecordView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
}
CRecordset* CProductView::OnGetRecordset()
{
if(m_pSet == NULL) // If there is no recordset
{
m_pSet = new CProductSet(NULL); // create one
m_pSet->Open(); // then open it
}
return m_pSet; // Return the address of the recordset
}
CProductSet* CProductView::GetRecordset()
{
return static_cast<CProductSet*>(OnGetRecordset());
}
#ifdef _DEBUG
void CProductView::AssertValid() const
{
CRecordView::AssertValid();
}
void CProductView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
BEGIN_MESSAGE_MAP(CProductView, CRecordView)
ON_BN_CLICKED(IDC_SELECTPRODUCT, &CProductView::OnSelectproduct)
ON_BN_CLICKED(IDC_DONE, &CProductView::OnDone)
END_MESSAGE_MAP()
void CProductView::OnSelectproduct()
{
UpdateData(TRUE); // Transfer data from controls
// Get a pointer to the document
CDBSimpleUpdateDoc* pDoc = static_cast<CDBSimpleUpdateDoc*>(GetDocument());
if(!m_OrderAdded) // If order not added
m_OrderAdded = pDoc->AddOrder(); // then try to add it
if(m_OrderAdded)
{
pDoc->AddOrderDetails(m_pSet->m_ProductID,
m_pSet->m_UnitPrice,
m_Quantity,
m_Discount);
// Now reset the values in the quantity and discount controls
m_Quantity = 1;
m_Discount = 0;
UpdateData(FALSE); // Transfer data to controls
}
}
void CProductView::OnDone()
{
static_cast<CMainFrame*>(GetParentFrame())->SelectView(ORDER_DETAILS);
}
void CProductView::InitializeView(void)
{
// Get a pointer to the document
CDBSimpleUpdateDoc* pDoc = static_cast<CDBSimpleUpdateDoc*>(GetDocument());
m_OrderID = pDoc->m_Order.m_OrderID;
m_CustomerName = pDoc->m_Order.m_ShipName;
m_Quantity = 1; // Must order at least 1
m_Discount = 0; // No default discount
m_OrderAdded = false; // Order not added initially
UpdateData(FALSE); // Transfer data to controls
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -