?? productdlg.cpp
字號(hào):
// ProductDLG.cpp : implementation file
//
#include "stdafx.h"
#include "trade_mis.h"
#include "ProductDLG.h"
#include "Trade_MISView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProductDLG dialog
CProductDLG::CProductDLG(CWnd* pParent /*=NULL*/)
: CDialog(CProductDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CProductDLG)
m_sMemo = _T("");
m_sName = _T("");
m_sSpec = _T("");
m_sUnit = _T("");
//}}AFX_DATA_INIT
}
void CProductDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProductDLG)
DDX_Text(pDX, IDD_PRODUCT_MEMO, m_sMemo);
DDX_Text(pDX, IDD_PRODUCT_NAME, m_sName);
DDX_Text(pDX, IDD_PRODUCT_SPEC, m_sSpec);
DDX_Text(pDX, IDD_PRODUCT_UNIT, m_sUnit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProductDLG, CDialog)
//{{AFX_MSG_MAP(CProductDLG)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProductDLG message handlers
BOOL CProductDLG::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// Set Windows Text
if (m_bAppend) SetWindowText(_T("添加商品信息"));
else SetWindowText(_T("修改商品信息"));
m_sOldName = m_sName;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CProductDLG::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
m_sName.TrimRight(" ");
m_sSpec.TrimRight(" ");
m_sUnit.TrimRight(" ");
m_sMemo.TrimRight(" ");
// Make sure all needed info is available
CString sWarning="";
if ( ""==m_sName ) sWarning=_T("商品名稱");
else if ( ""==m_sSpec ) sWarning=_T("商品規(guī)格");
else if ( ""==m_sUnit ) sWarning=_T("計(jì)量單位");
if ( ""!=sWarning )
{
sWarning += _T("不能為空");
AfxMessageBox(sWarning, MB_ICONEXCLAMATION);
return;
}
_variant_t strQuery;
if ( m_bAppend || m_sName!=m_sOldName )
{
// Judge Product is unique
strQuery = "select * from products where ProductName='"+m_sName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0!=iCount )
{
AfxMessageBox(_T("已經(jīng)存在此商品記錄!"), MB_ICONEXCLAMATION);
return;
}
}
if ( !m_bAppend ) // Not Append, delete old record first
{
strQuery = "delete from products where ProductName='"+m_sOldName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
}
// Insert Record
strQuery = "insert products (ProductName, Spec, Unit, Productmemo) \
values ('"+m_sName+"', '"+m_sSpec+"', '"+m_sUnit+"', '"+m_sMemo+"')";
if ( theApp.ADOExecute(theApp.m_pADOSet, strQuery) )
{
if (m_bAppend)
{
AfxMessageBox(_T("添加商品信息成功!"), MB_ICONINFORMATION);
// Clear all input
m_sName=m_sSpec=m_sUnit=m_sMemo="";
UpdateData(false);
}
else AfxMessageBox(_T("修改商品信息成功!"), MB_ICONINFORMATION);
}
else
{
if (m_bAppend) AfxMessageBox(_T("添加商品信息失敗!"), MB_ICONEXCLAMATION);
else AfxMessageBox(_T("修改商品信息失敗!"), MB_ICONEXCLAMATION);
}
strQuery = "select * from products";
CTrade_MISView* p = (CTrade_MISView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
p->RefreshProduct(strQuery);
if (!m_bAppend) CDialog::OnOK();
//CDialog::OnOK();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -