
// MFCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MFC.h"
#include "MFCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCDlg dialog




CMFCDlg::CMFCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMFCDlg::IDD, pParent)
	, m_strMsg(_T(""))
	, m_strReceivedata(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO2, m_cb1);
	DDX_Control(pDX, IDC_COMBO1, m_portCtrl);
	DDX_Control(pDX, IDC_COMBO3, m_baudCtrl);
	DDX_Control(pDX, IDC_COMBO4, m_msrCtrl);
	DDX_Text(pDX, IDC_ANSWER, m_strMsg);
	DDX_Text(pDX, IDC_EDIT1, m_strReceivedata);
	DDX_Control(pDX, IDC_IPADDRESS1, m_ipCtrl);

}

BEGIN_MESSAGE_MAP(CMFCDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_CBN_SELCHANGE(IDC_COMBO2, &CMFCDlg::OnCbnSelchangeCombo2)
	ON_BN_CLICKED(IDC_BUTTON1, &CMFCDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CMFCDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CMFCDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CMFCDlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CMFCDlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CMFCDlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CMFCDlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON11, &CMFCDlg::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON8, &CMFCDlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON10, &CMFCDlg::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON12, &CMFCDlg::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON15, &CMFCDlg::OnBnClickedButton15)
	ON_BN_CLICKED(IDC_OK, &CMFCDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON9, &CMFCDlg::OnBnClickedButton9)
END_MESSAGE_MAP()


// CMFCDlg message handlers

BOOL CMFCDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	m_cb1.SetCurSel(0);
	OnCbnSelchangeCombo2();
	m_portCtrl.SetCurSel(0);
	m_baudCtrl.SetCurSel(3);
	m_msrCtrl.SetCurSel(1);
	
	GetDlgItem(IDC_STAtus)->GetFont()->GetLogFont(&Logfont);
	Logfont.lfWeight = 1000;
	Logfont.lfHeight = 20;
	m_font.CreateFontIndirect(&Logfont);
	GetDlgItem(IDC_STAtus)->SetFont(&m_font);
	GetDlgItem(IDC_STATIC_MSR)->SetFont(&m_font);

	GetDlgItem(IDC_ANSWER)->GetFont()->GetLogFont(&Logfont2);
	Logfont2.lfWeight = 0;
	Logfont2.lfHeight = 15;
	m_font2.CreateFontIndirect(&Logfont2);
	GetDlgItem(IDC_ANSWER)->SetFont(&m_font2);

	GetDlgItem(IDC_IPADDRESS1)->SetWindowText(_T("192.168.1.100"));
	GetDlgItem(IDC_iPort)->SetWindowText(_T("1470"));

	GetDlgItem(IDC_TEXT)->SetWindowText(_T("This mode only use \"WOOSIM\" printer\r\n"));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMFCDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMFCDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CMFCDlg::OnCbnSelchangeCombo2()
{
	// TODO: Add your control notification handler code here
	if(m_cb1.GetCurSel() == 0)	//Serial
	{
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO1)->ShowWindow(true);
		GetDlgItem(IDC_COMBO3)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(true);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(false);
		GetDlgItem(IDC_iPort)->ShowWindow(false);
	}
	else if(m_cb1.GetCurSel() == 1) // Wifi
	{	
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(true);
		GetDlgItem(IDC_COMBO1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO3)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(false);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(true);
		GetDlgItem(IDC_iPort)->ShowWindow(true);
	}
	else									// USB
	{	
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO3)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(false);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("USB Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("USB Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(false);
		GetDlgItem(IDC_iPort)->ShowWindow(false);
	}		
}
//Connection Open
void CMFCDlg::OnBnClickedButton1()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CString err = _T("");
	
	if(m_cb1.GetCurSel() == 0)	//Serial
	{
		int connectStatus = 0;
		CString CSportName,CSbaudRate;		
		m_portCtrl.GetLBText(m_portCtrl.GetCurSel(),CSportName);
		m_baudCtrl.GetLBText(m_baudCtrl.GetCurSel(),CSbaudRate);

		int size = strlen(CT2A(CSportName));
		char *portname = new char[size+1];
		strcpy(portname,CT2A(CSportName));

		int bautRate = _ttoi(CSbaudRate);
		connectStatus = woosim.ConnectSerialPrinter(portname,bautRate);

		switch(connectStatus)
		{
			case SUCCESS:
				m_strMsg = _T("SUCCESS");
				break;
			case ALREADY_OPENED : 
				m_strMsg = _T("ALREADY OPEND");
				break;
			case UNABLE_TO_OPEN_THE_PORT : 
				m_strMsg = _T("UNABLE TO OPEN THE PORT");
				break;
			case UNABLE_TO_CONFIGURE_THE_SERIAL_PORT : 
				m_strMsg = _T("UNABLE_TO_CONFIGURE_THE_SERIAL_PORT");
				break;
			case UNABLE_TO_SET_THE_TIMEOUT_PARAMETERS : 
				m_strMsg = _T("UNABLE_TO_SET_THE_TIMEOUT_PARAMETERS");
				break;
			case TIMEOUT:
				m_strMsg = _T("TIMEOUT");
				woosim.ClosePrinterConnection();
				break;
			default:
				err.Format(_T("%d"),connectStatus);
				AfxMessageBox(err);
				break;
		}
		delete [] portname;
	}
	if(m_cb1.GetCurSel() == 1) // Wifi
	{	
		BYTE IP_a, IP_b, IP_c, IP_d;
		int connectStatus = 0;
		CString ipaddr;
		CString CSiPortnum;
			
		m_ipCtrl.GetAddress(IP_a, IP_b, IP_c, IP_d);
		ipaddr.Format(_T("%d.%d.%d.%d"),IP_a, IP_b, IP_c, IP_d);		
		
		char* Wlan_buff = new char[strlen(CT2A(ipaddr))+1];
		strcpy(Wlan_buff, CT2A(ipaddr));

		GetDlgItem(IDC_iPort)->GetWindowText(CSiPortnum);
		int portnum = _ttoi(CSiPortnum);
	
		connectStatus = woosim.ConnectWirelessPrinter(Wlan_buff,portnum,2000);			
	
		switch(connectStatus)
		{
		case SUCCESS:
			m_strMsg = _T("SUCCESS");
			break;
		case SOCKET_ERROR:
			m_strMsg = _T("SOCKET ERROR");
			break;
		case CONNECT_FAIL:
			m_strMsg = _T("CONNECT FAIL");
			break;
		case ALREADY_OPENED:
			m_strMsg = _T("ALREADY CONNECTED");
			break;
		case TIMEOUT:
			m_strMsg = _T("TIMEOUT");
			woosim.ClosePrinterConnection();
			break;
		default:
			err.Format(_T("%d"),connectStatus);
			AfxMessageBox(err);
			break;
		}
	}
	if(m_cb1.GetCurSel() == 2)		// USB
	{	
		int connectStatus = 0;

		connectStatus = woosim.ConnectUSBPrinter(1000,FALSE);

		switch(connectStatus)
		{
			case SUCCESS:
				m_strMsg = _T("SUCCESS");
				break;
			case ALREADY_OPENED : 
				m_strMsg = _T("ALREADY OPEND");
				woosim.ClosePrinterConnection();
				break;
			case UNABLE_TO_MAKE_CONNECTION : 
				m_strMsg = _T("UNABLE_TO_MAKE_CONNECTION");
				woosim.ClosePrinterConnection();
				break;
			case UNABLE_TO_GET_INFOMATION : 
				m_strMsg = _T("UNABLE_TO_GET_INFOMATION");
				woosim.ClosePrinterConnection();
				break;
			case NOT_WOOSIM_PRINTER : 
				m_strMsg = _T("NOT_WOOSIM_PRINTER");
				woosim.ClosePrinterConnection();
				break;
			case TIMEOUT:
				m_strMsg = _T("TIMEOUT");
				woosim.ClosePrinterConnection();
				break;
			default:
				err.Format(_T("%d"),connectStatus);
				AfxMessageBox(err);
				break;

		}
	}
	UpdateData(false);
	Sleep(1000);
		//woosim.GetPrinterStatus(1000);

	BYTE getInternalSerial[3] = {0x1B, 0x6B, 0x01};
	woosim.ControlCommand(getInternalSerial,3);
	woosim.PrintSpool();
}

//Connection Close
void CMFCDlg::OnBnClickedButton2()
{
	// Close any connection (Serial, Wlan or USB)
	m_strMsg = _T("Connection closed");
	woosim.ClosePrinterConnection();
	UpdateData(FALSE);

}

//Button Box&Lines
void CMFCDlg::OnBnClickedButton3()
{
	//Initialization & make page
	woosim.InitPageMode(0,0,_2INCH,_3INCH);

	//Draw Black & long box
	woosim.Page_DrawBox(_2INCH-80,30,30,150,20);
	woosim.Page_DrawBox(_2INCH-80,200,30,_3INCH-200-30,1);
	
	//Contained text "TEXT"
	woosim.Page_DrawBox(214,224,50,258,1);
	
	//Boxes in Box
	woosim.Page_DrawBox(60,234,104,44,1);
	woosim.Page_DrawBox(60,312,28,150,1);
	woosim.Page_DrawBox(98,312,28,150,1);
	woosim.Page_DrawBox(136,312,28,150,1);
	woosim.Page_DrawBox(50,224,124,258,3);

	//Draw vertical lines
	woosim.Page_DrawBox(205,30,0,140,1);
	woosim.Page_DrawBox(235,30,0,140,1);
	woosim.Page_DrawBox(265,30,0,140,1);

	//Draw horizontal lines
	woosim.Page_DrawBox(185,55,100,0,1);
	woosim.Page_DrawBox(185,95,100,0,1);
	woosim.Page_DrawBox(185,135,100,0,1);

	//Draw outline-Box
	woosim.Page_DrawBox(30,0,_2INCH - 60, _3INCH, 1 );

	woosim.Page_SetDirection(3);// Clockwise rotation
	woosim.Page_SetPosition(214,30);//Y_pos, X_pos
	woosim.SetTextStyle(0,false,1,1,false);
	woosim.TextSaveSpool("Text");
	woosim.Page_SetPosition(270,70);
	woosim.QRCodeSaveSpool(0,'H',2,"www.woosim.com/english");

	woosim.SetTextStyle(0,true,1,0,false);
	woosim.Page_SetPosition(126,256); //Y_pos, X_pos
	woosim.TextSaveSpool("TEXT");
	//End of page mode.
	woosim.Page_Print_StandardMode();

	//Draw graph
	woosim.Page_SetDirection(0);
	//Starting new page mode.
	woosim.InitPageMode(0,0,_2INCH,_2INCH);
	
	woosim.Page_DrawBox(0,30,_2INCH,0,5);
	woosim.Page_DrawBox(30,0,0,_2INCH,5);
	woosim.Page_DrawLine(30,30,170,160,3);
	woosim.Page_DrawLine(170,160,130,190,3);
	woosim.Page_DrawLine(130,190,210,250,3);
	woosim.Page_DrawLine(210,250,190,270,3);
	woosim.Page_DrawLine(190,270,270,340,3);
	woosim.Page_DrawLine(270,340,210,370,3);
	woosim.Page_Newline();
	woosim.Page_Print();

	//Draw ellipse.
	woosim.Page_ClearCurrentData();
	woosim.Page_DrawBox(0,_1INCH,_2INCH,0,5);
	woosim.Page_DrawBox(_1INCH,0,0,_2INCH,5);
	woosim.Page_DrawBox(_1INCH/2,_1INCH,_1INCH,0,0);
	woosim.Page_DrawEllipse(_1INCH,_1INCH,_1INCH/2,_1INCH-20,3);
	woosim.Page_Print_StandardMode();

	woosim.PrintSpool();

}

//Button Text
void CMFCDlg::OnBnClickedButton4()
{
	woosim.InitPrinterStatus();

	// TODO: Add your control notification handler code here
	woosim.TextSaveSpool("   매 출 전 표\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n");
	
	//Company
	
	woosim.TextSaveSpool("상점명             Woosim Coffee\r\n");
	woosim.TextSaveSpool("사업자등록번호      119-81-36382\r\n");
	//Reg Number
	woosim.TextSaveSpool("대표자                  이 일 복\r\n");
	//Address
	woosim.TextSaveSpool("서울특별시 금천구 가산동 448번지\r\n대륭테크노타운 3차, 501호\r\n");
	//Tel
	woosim.TextSaveSpool("문의                02-2107-3709\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n\r\n");
	woosim.TextSaveSpool("    우심 비자 카드\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n");
	//Card number
	woosim.TextSaveSpool("카드번호     9445 4103 9533 2096\r\n");
	woosim.TextSaveSpool("유효 기간                2012/10\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n");
	woosim.TextSaveSpool("거 래 일 자           2011/04/11\r\n");
	woosim.TextSaveSpool("거 래 종 류       [신용거래승인]\r\n");
	woosim.TextSaveSpool("단 말 번 호            123456789\r\n");
	woosim.TextSaveSpool("승 인 번 호            987654321\r\n");
	woosim.TextSaveSpool("결 제 금 액             50,000원\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n");
	woosim.TextSaveSpool("서명: \r\n\r\n\r\n\r\n");
	woosim.TextSaveSpool("--------------------------------\r\n\r\n");
	
	/*
	woosim.TextSaveSpool("  SALES  SLIP\n");
	woosim.TextSaveSpool("--------------------------------\n");
	//Company
	woosim.TextSaveSpool("MERCHANT NAME      Woosim Coffee\n");
	//Reg Number
	woosim.TextSaveSpool("MASTER                LEE IL BOK\n");
	//Address
	woosim.TextSaveSpool("ADDRESS\n #501, DaerungTechnotown3th 448,\n  Gasan-dong, Geumchun-gu, Seoul\n  Korea\n");
	//Tel
	woosim.TextSaveSpool("HELP DESK       (+82-2)2107-3714\n");
	woosim.TextSaveSpool("--------------------------------\n\n");
	woosim.TextSaveSpool("        WOOSIM  CARD \n");
	woosim.TextSaveSpool("--------------------------------\n");
	woosim.TextSaveSpool("CARD NO.     4428-8819-0118-****\n");
	woosim.TextSaveSpool("EXPIRY                   2012/10\n");
	woosim.TextSaveSpool("--------------------------------\n");
	woosim.TextSaveSpool("TRANS. YEAR & DATE   2008/04/15\n");
	woosim.TextSaveSpool("TRANS CLASS             [Credit]\n");
	woosim.TextSaveSpool("TERMINAL ID.           123456789\n");
	woosim.TextSaveSpool("APPROVAL NO.           987654321\n");
	woosim.TextSaveSpool("AMOUNT                   500.00$\n");
	woosim.TextSaveSpool("--------------------------------\n");
	woosim.TextSaveSpool("SIGNATURE: \n\n");
	woosim.TextSaveSpool("--------------------------------\n\n");
	*/
			
    woosim.PrintSpool();
}

//Button Image
void CMFCDlg::OnBnClickedButton5()
{
	if(PathFileExists(_T("./woosim.bmp")))
	{
		woosim.InitPrinterStatus();

		//Normal BMP file print
		woosim.TextSaveSpool("Print Bmp file \"woosim.bmp\"");	woosim.PrintData();
		woosim.NormalBmpSaveSpool("./woosim.bmp");
		woosim.PrintLineFeed(2);

		//BMP file print using Compressed algorithm
		woosim.TextSaveSpool("Print Bmp file using compressed algorithm");	woosim.PrintData();
		woosim.CompressedBmpSaveSpool("./woosim.bmp");
		woosim.PrintLineFeed(2);

		//Print pre-download image.
		woosim.TextSaveSpool("Print pre-downloaded image file #0");	woosim.PrintData();
		woosim.LoadLogoSaveSpool(0);	woosim.PrintData();

		woosim.PrintSpool();
	}
	else
		AfxMessageBox(_T("\"woosim.bmp\" is not found!"));
}

//Button 1D barcode
void CMFCDlg::OnBnClickedButton6()
{
	woosim.InitPrinterStatus();
	woosim.TextSaveSpool("UPCA\r\n");
	woosim.OneDimensionBarcodeSaveSpool(UPCA, 2, 100, true, "012100000642"); woosim.PrintData();

	woosim.TextSaveSpool("UPCE\r\n");
	woosim.OneDimensionBarcodeSaveSpool(UPCE, 2, 100, true, "065100004328"); woosim.PrintData();

	woosim.TextSaveSpool("EAN13\r\n");
	woosim.OneDimensionBarcodeSaveSpool(EAN13, 2, 100, true, "123456478901"); woosim.PrintData();

	woosim.TextSaveSpool("EAN8\r\n");
	woosim.OneDimensionBarcodeSaveSpool(EAN8, 2, 100, true, "12345678"); woosim.PrintData();

	woosim.TextSaveSpool("CODE39\r\n");
	woosim.OneDimensionBarcodeSaveSpool(CODE39, 2, 100, true, "12345678901"); woosim.PrintData();

	woosim.TextSaveSpool("ITF\r\n");
	woosim.OneDimensionBarcodeSaveSpool(ITF, 2, 100, true, "123456"); woosim.PrintData();

	woosim.TextSaveSpool("CODABAR\r\n");
	woosim.OneDimensionBarcodeSaveSpool(CODABAR, 2, 100, true, "123456"); woosim.PrintData();

	woosim.TextSaveSpool("CODE93\r\n");
	woosim.OneDimensionBarcodeSaveSpool(CODE93, 2, 100, true, "12345678901");woosim.PrintData();

	woosim.TextSaveSpool("CODE128\r\n");
	woosim.OneDimensionBarcodeSaveSpool(CODE128, 2, 100, true, "12345678901"); woosim.PrintData();

	woosim.PrintSpool();
}

//Button 2D barcode
void CMFCDlg::OnBnClickedButton7()
{
	woosim.InitPrinterStatus();

	woosim.TextSaveSpool("PDF417");
	woosim.PrintData();
	woosim.PDF417SaveSpool(2,2,2,2,"0123456789",false);
	woosim.PrintData();

	woosim.TextSaveSpool("DataMatrix");
	woosim.PrintData();
	woosim.DataMatrixSaveSpool(36,36,2,"0123456789");
	woosim.PrintLineFeed(1);

	woosim.TextSaveSpool("QR Code");
	woosim.PrintData();
	woosim.QRCodeSaveSpool(0,'H',3,"0123456789");
	woosim.PrintDotFeed(30);
	
	woosim.TextSaveSpool("Micro PDF417");
	woosim.PrintData();
	woosim.MicroPDF417SaveSpool(2,1,0,2,"01234567",false);
	woosim.PrintDotFeed(30);

	woosim.TextSaveSpool("Truncated PDF417");
	woosim.PrintData();
	woosim.TruncatedPDF417SaveSpool(2,2,2,2,"0123456789",false);
	woosim.PrintData();

	woosim.TextSaveSpool("Maxicode");
	woosim.PrintData();
	woosim.MaxicodeSaveSpool(4,"0123456789");
	woosim.PrintData();

	woosim.PrintSpool();
}

//Button Get Printer status
void CMFCDlg::OnBnClickedButton11()
{
	woosim.GetPrinterStatus(1000);
	//woosim.GetPrinterStatus(1000);
}

//Button Get Printer model name & MCU ver.
void CMFCDlg::OnBnClickedButton8()
{
	woosim.GetPrinterModelName();
	woosim.GetFirmwareVersion();
}

//Button Print page mode with complex data
void CMFCDlg::OnBnClickedButton10()
{
	woosim.InitPageMode(0,0,_2INCH,700);
	woosim.SetTextStyle(false,true,1,1,false);
	woosim.TextSaveSpool("Woosim Cafe\r\n");

	woosim.SetTextStyle(false,false,0,0,false);
	woosim.TextSaveSpool("Coffee, tea and bread\r\n");
	woosim.Page_DotFeed(15);
	woosim.SetFontSize(1);
	woosim.Page_SetPosition(277,105);
	woosim.TextSaveSpool("2015-01-27\r\n");
	woosim.SetFontSize(0);

	woosim.Page_SetPosition(290,5);
	woosim.QRCodeSaveSpool(0,'H',2,"www.woosim.com/english");
	
	woosim.Page_DrawBox(0,130,_2INCH,0,2);
	woosim.Page_DotFeed(5);
	woosim.TextSaveSpool(" #      Item      Num    Charge\r\n");
	woosim.TextSaveSpool(" 1      Latte      1     $ 3.35");	woosim.Page_Newline();
	woosim.TextSaveSpool(" 2  House Coffee   2     $ 3.98");	woosim.Page_Newline();
	woosim.TextSaveSpool(" 3       Tea	       1     $ 1.95");	woosim.Page_DotFeed(10);
	woosim.Page_DrawBox(0,270,_2INCH,0,2);	woosim.Page_Newline();

	woosim.Page_DrawBox(0,310,115,0,2);woosim. Page_DrawBox(260,310,124,0,2); woosim.Page_DotFeed(15);
	woosim.Page_SetPosition(123,300);
	woosim.TextSaveSpool("Credit Card\r\n");

	woosim.TextSaveSpool("Number:         ");
	woosim.SetFontSize(1);
	woosim.TextSaveSpool("6688-9988-6644-3311");	woosim.Page_Newline();
	woosim.SetFontSize(0);
	woosim.TextSaveSpool("Payment:                $ 9.50 ");	woosim.Page_Newline();

	woosim.Page_DrawBox(0,400,120,0,2);	woosim.Page_DrawBox(250,400,134,0,2);woosim.Page_DotFeed(15);
	woosim.Page_SetPosition(145,390);
	woosim.TextSaveSpool("Payment\r\n");

	woosim.TextSaveSpool("Price:                  $ 9.28");	woosim.Page_Newline();
	woosim.TextSaveSpool("Tax:                    $ 0.22");	woosim.Page_Newline();

	woosim.Page_DrawBox(0,490,_2INCH,0,2);	woosim.Page_DotFeed(15);
	woosim.TextSaveSpool("Total:                  $ 9.50");	woosim.Page_Newline();
	woosim.TextSaveSpool("Credit Card:            $ 9.50");	woosim.Page_Newline();

	woosim.Page_SetPosition(40,580);
	woosim.OneDimensionBarcodeSaveSpool(CODE128,2,50,TRUE,"20150127123456789");
	woosim.Page_LineFeed(2);

	woosim.Page_Print_StandardMode();
	woosim.PrintSpool();
}

//Button Card read mode start
void CMFCDlg::OnBnClickedButton12()
{
	int modeSelect = 0;

	//MSR sample is based 12Track magnetic card
	switch(m_msrCtrl.GetCurSel())
	{
	case 0:
		modeSelect = 0;//Read 1T. If 23T card, read 2T.
		break;
	
	case 1:
		modeSelect = 1;//Read 2T. If 23T card, read 3T.
		break;
	
	case 2:
		modeSelect = 4;//Read 3T. It only use for 123T.
		break;
	
	case 3:
		modeSelect = 2;//Read 12T. If 23T card, read 23T.
		break;
	
	case 4:
		modeSelect = 3;//Read 123T. It only use for 123T.
		break;
	}

	woosim.EnterMSRMode(modeSelect);
}

//Button Card read mode cancel
void CMFCDlg::OnBnClickedButton15()
{
	woosim.CancelMSRMode();
}

void CMFCDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	OnBnClickedButton2();
	OnCancel();
}

LRESULT CMFCDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
	if(message == ::RegisterWindowMessage(MSG_RECEIVE_CHECK))
	{
		WPARAM chk;
		BYTE *tempBuf,*data;
		CString temp;
		UINT length;
		chk = HIWORD(wParam); // x86
		length = LOWORD(wParam);
		switch (chk)
		{

		case STATUS_ANSWER:
			
			tempBuf = (BYTE*)lParam;
			m_strMsg = _T("STATUS_ANSWER");
			m_strReceivedata.Format(_T("%02X"), tempBuf);
			break;

		case DATA:		
			
			temp = _T("");
			strDataHex =  _T("");
			data = (BYTE *)lParam;
			m_strMsg = _T("DATA");
			strDataHex.Format(_T("Receive %dbyte\r\n"), length ); 
			for(int i=0; i < length; i++)
			{
				if(i%32 == 0)
					strDataHex = strDataHex + _T("\r\n");
				temp.Format(_T("%c"),data[i]);
				strDataHex = strDataHex + temp;
			}

			m_strReceivedata = strDataHex;	

			break;
		}
		UpdateData(FALSE);
	}
	return CDialog::DefWindowProc(message, wParam, lParam);
}

void CMFCDlg::OnBnClickedButton9()
{
	// TODO: Add your control notification handler code here
	woosim.SetFontForTTF("WSTTFL.ttf");
	woosim.PrintSpoolForTTF("Woosim System Inc.",10,18);
	woosim.PrintSpool();
}
