www.pudn.com > duanxinfangwei.rar > Dialog_MakeCodeSet.cpp


// Dialog_MakeCodeSet.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "smspreventforgery.h" 
#include "Dialog_MakeCodeSet.h" 
#include "DbInterface.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDialog_MakeCodeSet dialog 
 
 
CDialog_MakeCodeSet::CDialog_MakeCodeSet(CWnd* pParent /*=NULL*/) 
	: CDialog(CDialog_MakeCodeSet::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDialog_MakeCodeSet) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CDialog_MakeCodeSet::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDialog_MakeCodeSet) 
	DDX_Control(pDX, IDC_EDIT_CODENUM, m_edit_codenum); 
	DDX_Control(pDX, IDC_EDIT_FILE, m_edit_file); 
	DDX_Control(pDX, IDC_EDIT_CODELEN, m_edit_codelen); 
	DDX_Control(pDX, IDC_COMBO_PRODUCT, m_combo_product); 
	DDX_Control(pDX, IDC_CHECK_CODEMEM_NUM, m_check_codemem_num); 
	DDX_Control(pDX, IDC_CHECK_CODEMEM_LETTER, m_check_codemem_letter); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CDialog_MakeCodeSet, CDialog) 
	//{{AFX_MSG_MAP(CDialog_MakeCodeSet) 
	ON_BN_CLICKED(IDC_BUTTON_FILE, OnButtonFile) 
	ON_EN_CHANGE(IDC_EDIT_CODELEN, OnChangeEditCodelen) 
	ON_EN_CHANGE(IDC_EDIT_CODENUM, OnChangeEditCodenum) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDialog_MakeCodeSet message handlers 
 
void CDialog_MakeCodeSet::OnOK()  
{ 
	/* 取得设定值 */ 
	//使用数字 
	if(m_check_codemem_num.GetCheck() == BST_CHECKED) 
	{ 
		m_out_useNum = true; 
	} 
	else 
	{ 
		m_out_useNum = false; 
	} 
	//使用字母 
	if(m_check_codemem_letter.GetCheck() == BST_CHECKED) 
	{ 
		m_out_useLetter = true; 
	} 
	else 
	{ 
		m_out_useLetter = false; 
	} 
	//号码长度 
	CString strCodeLen; 
	m_edit_codelen.GetWindowText(strCodeLen); 
	if(!strCodeLen.IsEmpty()) 
	{ 
		m_out_codeLen = atoi(strCodeLen); 
	} 
	//生成号码数 
	CString strCodeNum; 
	m_edit_codenum.GetWindowText(strCodeNum); 
	if(!strCodeNum.IsEmpty()) 
	{ 
		m_out_codenum = atoi(strCodeNum); 
	} 
	//关联产品 
	CString productName; 
	m_combo_product.GetWindowText(productName); 
	if(!productName.IsEmpty()) 
	{ 
		CDbInterface db; 
		PRODUCTINFO productInfo; 
		if(db.GetProductInfo(productName, productInfo)) 
		{ 
			m_out_productId = productInfo.productId; 
		} 
		else 
		{ 
			MessageBox("取得产品信息失败!", "错误", MB_OK | MB_ICONERROR); 
			return; 
		} 
	} 
	//输出文件位置 
	m_edit_file.GetWindowText(m_out_file); 
 
	/* 检查参数设定 */ 
	//防伪码组成 
	if(!m_out_useNum && !m_out_useLetter) 
	{ 
		MessageBox("请选择防伪码组成字符!", "提示", MB_OK | MB_ICONWARNING); 
		return; 
	} 
	//号码长度 
	if(strCodeLen.GetLength() == 0 || m_out_codeLen < 6 || m_out_codeLen > 50) 
	{ 
		MessageBox("防伪码长度非法!", "提示", MB_OK | MB_ICONWARNING); 
		return; 
	} 
	//生成号码数 
	if(strCodeNum.IsEmpty()) 
	{ 
		MessageBox("请指定要生成的号码数量!", "提示", MB_OK | MB_ICONWARNING); 
		return; 
	} 
	//关联产品 
	if(productName.IsEmpty()) 
	{ 
		MessageBox("请指定生成防伪码关联的产品!", "提示", MB_OK | MB_ICONWARNING); 
		return; 
	} 
	//输出文件位置 
	if(m_out_file.IsEmpty()) 
	{ 
		MessageBox("请指定输出文件!", "提示", MB_OK | MB_ICONWARNING); 
		return; 
	} 
 
 
	CDialog::OnOK(); 
} 
 
BOOL CDialog_MakeCodeSet::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	/* 取得产品列表 */	 
	CDbInterface db; 
	std::list productList; 
	if(db.GetProductList(productList)) 
	{ 
		if(productList.size() == 0) 
		{ 
			MessageBox("请先设定产品信息!", "警告", MB_OK | MB_ICONWARNING); 
			PostMessage(WM_CLOSE); 
		} 
		while(productList.size() > 0) 
		{ 
			PRODUCTINFO productinfo; 
			productinfo = productList.front(); 
			productList.pop_front(); 
 
			m_combo_product.InsertString(0, productinfo.productName); 
		} 
		m_combo_product.SetCurSel(0); 
	} 
	else 
	{ 
		MessageBox("取得产品信息失败!", "错误", MB_OK | MB_ICONERROR); 
		PostMessage(WM_CLOSE); 
	} 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
/********************************************************************** 
 * 函数名:	OnButtonFile 
 * 功  能:  显示文件选择框 
 * 参  数:  void 
 * 返回值:  void 
 *********************************************************************/ 
void CDialog_MakeCodeSet::OnButtonFile()  
{ 
	CString filepath; 
 
	CFileDialog dlgFile(FALSE, "txt", NULL, OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST, 
						"Text File(*.txt)|*.txt||",	NULL); 
	if(dlgFile.DoModal() == IDOK) 
	{ 
		filepath = dlgFile.GetPathName(); 
		if(filepath.IsEmpty()) 
		{ 
			MessageBox("请选定文件!", "提示", MB_OK | MB_ICONWARNING); 
			return; 
		} 
		m_edit_file.SetWindowText(filepath); 
	}				 
} 
 
/********************************************************************** 
 * 函数名:	OnChangeEditCodelen 
 * 功  能:  用户输入防伪码长度变化 
 * 参  数:  void 
 * 返回值:  void 
 *********************************************************************/ 
void CDialog_MakeCodeSet::OnChangeEditCodelen()  
{ 
	CString srtCodeLen; 
	int		lCodeLen; 
 
	m_edit_codelen.GetWindowText(srtCodeLen); 
	lCodeLen = atoi(srtCodeLen); 
 
	if(lCodeLen > 50) 
	{ 
		MessageBox("防伪码最长不能超过50位!", "提示", MB_OK | MB_ICONWARNING); 
		m_edit_codelen.SetWindowText("50"); 
	}	 
} 
 
/********************************************************************** 
 * 函数名:	OnChangeEditCodenum 
 * 功  能:  用户输入要生成的防伪码个数变化 
 * 参  数:  void 
 * 返回值:  void 
 *********************************************************************/ 
void CDialog_MakeCodeSet::OnChangeEditCodenum()  
{ 
	 
	 
}