📄 cit label printdlg.cpp
字号:
// CIT Label PrintDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CIT Label Print.h"
#include "CIT Label PrintDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CWnd * m_pWnd;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCITLabelPrintDlg dialog
CCITLabelPrintDlg::CCITLabelPrintDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCITLabelPrintDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCITLabelPrintDlg)
m_label = _T("");
m_bk_version = _T("");
m_hs_version = _T("");
m_mfgid = _T("");
m_model = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//
m_pDatabase = &m_Database;
}
void CCITLabelPrintDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCITLabelPrintDlg)
DDX_Text(pDX, IDC_LABEL, m_label);
DDV_MaxChars(pDX, m_label, 10);
DDX_Text(pDX, IDC_BOARD_KIT_VERSION, m_bk_version);
DDX_Text(pDX, IDC_HARDSOFT_VERSION, m_hs_version);
DDX_Text(pDX, IDC_MFGID2, m_mfgid);
DDX_Text(pDX, IDC_MODEL2, m_model);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCITLabelPrintDlg, CDialog)
//{{AFX_MSG_MAP(CCITLabelPrintDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnConfig)
// ON_MESSAGE(WM_SHOW_MESSAGE, OnGetMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCITLabelPrintDlg message handlers
BOOL CCITLabelPrintDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
CFont m_font;
m_font.CreateFont(-57,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH|FF_ROMAN,"Courier");
GetDlgItem(IDOK)->SetFont(&m_font,TRUE);
//
m_bk_version = AfxGetApp()->GetProfileString("Config","bk_version",NULL);
m_model = AfxGetApp()->GetProfileString("Config","model",NULL);
m_hs_version = AfxGetApp()->GetProfileString("Config","hs_version",NULL);
m_mfgid = AfxGetApp()->GetProfileString("Config","mfg_id",NULL);
//
char m_path_buf[1000] = "";
CString m_set_path;
GetCurrentDirectory(1000,m_path_buf);
m_set_path = m_path_buf;
m_set_path = m_set_path + "\\Setting.ini";
char m_product_buf[10] = "";
CString m_product;
GetPrivateProfileString("Setting","product","3",m_product_buf,10,m_set_path);
m_product = m_product_buf;
GetDlgItem(IDC_TITLE)->SetWindowText(m_product + " CIT Label Print");
//
UpdateData(FALSE);
m_pWnd = this;
return TRUE; // return TRUE unless you set the focus to a control
}
void CCITLabelPrintDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CCITLabelPrintDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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();
}
CFont m_font,m_font1;
m_font.CreateFont(-37,0,0,0,FW_NORMAL,false,true,false,
DEFAULT_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,
DEFAULT_QUALITY,VARIABLE_PITCH|FF_ROMAN,"Courier");
m_font1.CreateFont(-17,0,0,0,FW_NORMAL,false,true,false,
DEFAULT_CHARSET,OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,
DEFAULT_QUALITY,VARIABLE_PITCH|FF_ROMAN,"Courier");
GetDlgItem(IDC_TITLE)->SetFont(&m_font,TRUE);
GetDlgItem(IDC_SCAN)->SetFont(&m_font1,TRUE);
//
m_bk_version = AfxGetApp()->GetProfileString("Config","bk_version","0T50");
m_model = AfxGetApp()->GetProfileString("Config","model","CFUG1002AA");
m_hs_version = AfxGetApp()->GetProfileString("Config","hs_version","B214");
m_mfgid = AfxGetApp()->GetProfileString("Config","mfg_id","550");
UpdateData(FALSE);
//
GetDlgItem(IDC_LABEL)->SetFocus();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCITLabelPrintDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCITLabelPrintDlg::PrintBarcode(CString m_barcode)
{
CString m_week,m_day,m_hour;
CCalculateDayTime m_calculateTime;
m_calculateTime.GetWDH(m_week,m_day,m_hour);
//
char m_path_buf[1000] = "";
CString m_set_path;
GetCurrentDirectory(1000,m_path_buf);
m_set_path = m_path_buf;
m_set_path = m_set_path + "\\Setting.ini";
/////////////
char original_x_buf[10]="" ;
char original_y_buf[10]="" ;
char label_x_buf[10]="" ;
char label_y_buf[10] ="";
char serial_x_buf[10] ="";
char serial_y_buf[10] ="";
char mfg_x_buf[10] ="";
char mfg_y_buf[10] ="";
char time_x_buf[10] ="";
char time_y_buf[10] ="";
char area_x_buf[10] ="";
char area_y_buf[10] ="";
char product_area_info_buf[50] = "";
///
CString original_x ;
CString original_y ;
CString label_x ;
CString label_y ;
CString serial_x ;
CString serial_y ;
CString mfg_x ;
CString mfg_y ;
CString time_x ;
CString time_y ;
CString area_x,area_y;
CString product_area_info;
///
GetPrivateProfileString("Setting","original_x","3",original_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","original_y","3",original_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","label_x","3",label_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","label_y","3",label_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","serial_x","3",serial_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","serial_y","3",serial_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","mfg_x","3",mfg_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","mfg_y","3",mfg_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","time_x","3",time_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","time_y","3",time_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","area_x","3",area_x_buf,10,m_set_path);
GetPrivateProfileString("Setting","area_y","3",area_y_buf,10,m_set_path);
GetPrivateProfileString("Setting","product_area_info",NULL,product_area_info_buf,50,m_set_path);
///
original_x = original_x_buf;
original_y = original_y_buf ;
label_x = label_x_buf;
label_y = label_y_buf;
serial_x = serial_x_buf;
serial_y = serial_y_buf;
mfg_x = mfg_x_buf;
mfg_y = mfg_y_buf;
time_x = time_x_buf;
time_y = time_y_buf;
area_x = area_x_buf;
area_y = area_y_buf;
product_area_info = product_area_info_buf;
///
m_bk_version = AfxGetApp()->GetProfileString("Config","bk_version","0T50");
m_model = AfxGetApp()->GetProfileString("Config","model","CFUG1002AA");
m_hs_version = AfxGetApp()->GetProfileString("Config","hs_version","B214");
m_mfgid = AfxGetApp()->GetProfileString("Config","mfg_id","550");
/////////////////////
WriteData("^XA");
WriteData("^LH" + original_x + "," + original_y);
WriteData("^BY2,2.1");
WriteData("^FO"+label_x+","+label_y+"^BCN,16,N,N,N^fd" + m_barcode + "^Fs");//"^B3N,N,15,N,N^fd" + m_barcode + "^Fs");
WriteData("^FO" + serial_x + "," + serial_y + "^FWN^AD,18,10^fd" + m_barcode + "^Fs");
WriteData("^FO" + area_x + "," + area_y + "^FWN^AD,18,10^fd" + product_area_info + "^Fs");
WriteData("^FO" + time_x + "," + time_y + "^FWN^AD,18,10^fd" + "00" + m_week + m_day + m_hour + "^Fs");
WriteData("^FO" + mfg_x + "," + mfg_y + "^FWN^AD,18,10^fd" + m_model + "/" +m_mfgid + "/" + m_hs_version+ "^Fs");
WriteData("^XZ");
}
BOOL CCITLabelPrintDlg::OpenLPT()
{
COMMTIMEOUTS timeout;
h_LPT = CreateFile("d:\\a.txt",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(h_LPT == INVALID_HANDLE_VALUE)
return 0;
//////////////////////////////////////////////////////////////////////////
GetCommTimeouts(h_LPT,&timeout);
timeout.ReadIntervalTimeout = 0;
timeout.ReadTotalTimeoutConstant = 0;
timeout.ReadTotalTimeoutMultiplier = 0;
timeout.WriteTotalTimeoutConstant = 300;
timeout.WriteTotalTimeoutMultiplier = 500;
SetCommTimeouts(h_LPT,&timeout);
//////////////////////////////////////////////////////////////////////////
return true;
}
void CCITLabelPrintDlg::CloseLPT()
{
CloseHandle(h_LPT);
}
void CCITLabelPrintDlg::WriteData(CString m_data)
{
unsigned long i;
WriteFile(h_LPT,m_data.GetBuffer(m_data.GetLength()),m_data.GetLength(),&i,NULL);
}
void CCITLabelPrintDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
m_bk_version = AfxGetApp()->GetProfileString("Config","bk_version","0T50");
if((m_label.Left(1) == "G"&&m_label.GetLength() == 10&&m_label.Mid(2,4) == m_bk_version))
{
if(AfxGetApp()->GetProfileInt("Config","check_database",1))
{
if(!CheckLabelExist(m_label))
{
OpenLPT();
PrintBarcode(m_label);
CloseLPT();
}
else
{
AfxMessageBox("The Barcode is printed repeatedly!!!");
}
}
else
{
OpenLPT();
PrintBarcode(m_label);
CloseLPT();
}
}
else
{
AfxMessageBox("Barcode Wrong!!!");
}
m_label.Empty();
UpdateData(FALSE);
GetDlgItem(IDC_LABEL)->SetFocus();
}
void CCITLabelPrintDlg::OnConfig()
{
// TODO: Add your control notification handler code here
m_password.DoModal();
}
BOOL CCITLabelPrintDlg::CheckLabelExist(CString m_barcode)
{
bool m_dataexist = 1;
//
if(m_pDatabase->IsOpen())
{
m_pDatabase->Close();
}
m_pDatabase->Open();
//////////////////////////////////////////////////////////////////////////
if(m_pDatabase->IsBOF())
{
m_pDatabase->AddNew();
m_pDatabase->m_record = m_barcode;
if(m_pDatabase->CanUpdate())
m_pDatabase->Update();
m_dataexist = 0;
}
else
{
if(!m_pDatabase->IsBOF())
m_pDatabase->MoveFirst();
while (!m_pDatabase->IsEOF()) {
if(m_pDatabase->m_record == m_barcode)
{
m_dataexist = 1;
break;
}
m_pDatabase->MoveNext();
m_dataexist = 0;
}
if(!m_dataexist)
{
if(!m_pDatabase->IsEOF())
m_pDatabase->MoveLast();
m_pDatabase->AddNew();
m_pDatabase->m_record = m_barcode;
m_pDatabase->m_time = CTime::GetCurrentTime();
if(m_pDatabase->CanUpdate())
m_pDatabase->Update();
}
}
m_pDatabase->Close();
return m_dataexist;
}
void CCITLabelPrintDlg::OnGetMessage(WPARAM wParam,LPARAM lParam)
{
OnPaint();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -