// barcode.cpp : 实现文件
//

#include "stdafx.h"
#include "MFC_TSPL.h"
#include "barcode.h"
#include "afxdialogex.h"
#include "tspl_printer_base.h"


// barcode 对话框

IMPLEMENT_DYNAMIC(barcode, CDialogEx)

barcode::barcode(CWnd* pParent /*=NULL*/)
	: CDialogEx(barcode::IDD, pParent)
{

}

barcode::~barcode()
{
}

void barcode::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, xstart);
	DDX_Control(pDX, IDC_EDIT2, ystart);
	DDX_Control(pDX, IDC_EDIT3, codetype);
	DDX_Control(pDX, IDC_EDIT9, height);
	DDX_Control(pDX, IDC_EDIT4, readable);
	DDX_Control(pDX, IDC_EDIT10, rotation);
	DDX_Control(pDX, IDC_EDIT5, narrow);
	DDX_Control(pDX, IDC_EDIT11, wide);
	DDX_Control(pDX, IDC_EDIT6, data);


	xstart.SetWindowText(_T("50"));
	ystart.SetWindowText(_T("50"));
	codetype.SetWindowText(_T("0"));
	height.SetWindowText(_T("80"));
	readable.SetWindowText(_T("1"));
	rotation.SetWindowText(_T("0"));
	narrow.SetWindowText(_T("2"));
	wide.SetWindowText(_T("4"));
	data.SetWindowText(_T("123456"));
	
}


BEGIN_MESSAGE_MAP(barcode, CDialogEx)
	ON_BN_CLICKED(IDOK, &barcode::OnBnClickedOk)
END_MESSAGE_MAP()


// barcode 消息处理程序


void barcode::OnBnClickedOk()
{
	// TODO:  在此添加控件通知处理程序代码
	CString x, y, type, barheight, barread, barrotation, barnarrow, barwide, bardata;
	int result=-10;
	GetDlgItemText(IDC_EDIT1, x);
	if (!(x != ""))
		AfxMessageBox(_T("横坐标起始位置不能为空！"));

	GetDlgItemText(IDC_EDIT2, y);
	if (!(y != ""))
		AfxMessageBox(_T("纵坐标起始位置不能为空！"));

	GetDlgItemText(IDC_EDIT3, type);
	if (!(type != ""))
		AfxMessageBox(_T("类型选择不能为空！"));

	GetDlgItemText(IDC_EDIT9, barheight);
	if (!(barheight != ""))
		AfxMessageBox(_T("条形码高不能为空！"));

	GetDlgItemText(IDC_EDIT4, barread);
	if (!(barread != ""))
		AfxMessageBox(_T("代码可读不能为空！"));

	GetDlgItemText(IDC_EDIT10, barrotation);
	if (!(barrotation != ""))
		AfxMessageBox(_T("旋转选择不能为空！"));

	GetDlgItemText(IDC_EDIT5, barnarrow);
	if (!(barnarrow != ""))
		AfxMessageBox(_T("窄条型宽不能为空！"));

	GetDlgItemText(IDC_EDIT11, barwide);
	if (!(barwide != ""))
		AfxMessageBox(_T("宽条型宽不能为空！"));

	GetDlgItemText(IDC_EDIT6, bardata);
	if (!(bardata != ""))
		AfxMessageBox(_T("文本内容不能为空！"));


	DemClearBuffer(hprinter);
	DemSetup(hprinter, 100, 80, 2, 6, 1, 2, 0);
	result = DemBarCode(hprinter, _ttoi(x), _ttoi(y), _ttoi(type), _ttoi(barheight), _ttoi(barread), _ttoi(barrotation), _ttoi(barnarrow), _ttoi(barwide), cstringtocharstring(bardata));
	DemPrint(hprinter,1,1);
}
