⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productdlg.cpp

📁 一个用vc写的贸易公司管理系统
💻 CPP
字号:
// 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("商品规格");
	else if ( ""==m_sUnit ) sWarning=_T("计量单位");
		    
	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("已经存在此商品记录!"), 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();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -