Commit 41c61c8b by 李定达

1.打印实现界面可配置化;2.添加多个小票机同时打印支持;3.更丰富的打印模板支持

parent 6135bc46
......@@ -38,6 +38,28 @@ PrintLib::PrintLib()
}
}
void PrintLib::_PrintLabTest()
{
f_TSCInit();
f_TSCWinPrintln(10, 0, 28, 0, 2, 0, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "7 09/03 09:36 1/2", 0);
f_TSCWinPrintln(0, 0, 24, 0, 2, 2, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "------------------------------", 0.0266665);
f_TSCWinPrintln(10, 0, 32, 0, 2, 0, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "big tea", 0.0666665);
f_TSCWinPrintln(10, 0, 24, 0, 2, 2, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "add sweets, add milk", 0.0666665);
f_TSCWinPrintln(10, 0, 24, 0, 2, 2, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "test store", 0.0666665);
f_TSCWinPrintln(10, 0, 24, 0, 2, 2, 0, "\xE5\xAE\x8B\xE4\xBD\x93", "-----------------------------", 0.0266665);
f_TSCWinPrintln(0, 0, 24, 0, 2, 0, 0, "\xE5\xAE\x8B\xE4\xBD\x93", " freemudtest", 0);
f_TSCWinPrintPage("1","1");
}
void PrintLib::_PrintLab( OrderObject* order)
{
QString deliveryTime;
......@@ -160,6 +182,115 @@ bool PrintLib::DoPrint(const QString &content, OrderObject *orderObject, QString
}
}
bool PrintLib::OnlyDoPrint(const QString &content, OrderObject *orderObject, QString &error)
{
QByteArray iniData = _OnlyGetPrintIni().toLocal8Bit();
char inichar[2048]={0x0};
strcpy(inichar,iniData.data());
if(m_b_load_sucfl)
{
if(!f_LaodAddress())
{
return false;
}
f_InitPrinter(inichar);
if(!f_OpenPrinter())
{
f_ClosePrinter();
return false;
}
_order = orderObject;
bool result;
PrintDocument doc = PrintDocument::ParseToDocument(content, result,error);
if(!result)
{
f_ClosePrinter();
return false;
}
_PrintLineNode(doc,_order);
//_PrintLab(_order);
f_ClosePrinter();
return true;
}
else{
memset(inichar,0x0,sizeof(inichar));
return false;
}
}
bool PrintLib::DoTestPrint(QByteArray iniData, const QString &content, OrderObject *orderObject, QString &error)
{
//QByteArray iniData = _GetPrintIni().toLocal8Bit();
char inichar[2048]={0x0};
strcpy(inichar,iniData.data());
if(m_b_load_sucfl)
{
if(!f_LaodAddress())
{
return false;
}
f_InitPrinter(inichar);
if(!f_OpenPrinter())
{
f_ClosePrinter();
return false;
}
_order = orderObject;
bool result;
PrintDocument doc = PrintDocument::ParseToDocument(content, result,error);
if(!result)
{
f_ClosePrinter();
return false;
}
_PrintLineNode(doc,_order);
//_PrintLab(_order);
f_ClosePrinter();
return true;
}
else{
memset(inichar,0x0,sizeof(inichar));
return false;
}
}
bool PrintLib::DoTestLabelPrint(QByteArray iniData, OrderObject *orderObject)
{
//QByteArray iniData = _GetPrintIni().toLocal8Bit();
char inichar[2048]={0x0};
strcpy(inichar,iniData.data());
if(m_b_load_sucfl)
{
if(!f_LaodAddress())
{
return false;
}
f_InitPrinter(inichar);
// if(!f_OpenPrinter())
// {
// f_ClosePrinter();
// return false;
// }
_order = orderObject;
// bool result;
// PrintDocument doc = PrintDocument::ParseToDocument(content, result,error);
// if(!result)
// {
// f_ClosePrinter();
// return false;
// }
//_PrintLineNode(doc,_order);
_PrintLabTest();
//f_ClosePrinter();
return true;
}
else{
memset(inichar,0x0,sizeof(inichar));
return false;
}
}
//bool PrintLib::OpenPrinter()
//{
// QByteArray iniData = _GetPrintIni().toLocal8Bit();
......@@ -420,3 +551,54 @@ QString PrintLib::_GetPrintIni()
return ini;
}
QString PrintLib::_OnlyGetPrintIni()
{
QString path = QString("%1/printer.ini").arg(QCoreApplication::applicationDirPath());
QSettings config(path, QSettings::IniFormat);
QString ini;
ini.append(config.value("OtherPrinter/Name").toString());
ini.append("|");
ini.append(config.value("OtherPrinter/printType").toString());
ini.append("|");
ini.append(config.value("OtherPrinter/PaperWidth").toString());
ini.append("|");
ini.append(config.value("Printer/levlel").toString());
ini.append("|");
ini.append(config.value("Printer/parallel").toString());
ini.append("|");
ini.append(config.value("Printer/type").toString());
ini.append("|");
ini.append(config.value("Printer/usb").toString());
ini.append("|");
ini.append(config.value("OtherPrinter/IP").toString());
ini.append("|");
ini.append( config.value("Printer/Printlabel").toString());
ini.append("|");
ini.append( config.value("Printer/LogDays").toString());
ini.append("|");
//打印标签
ini.append(config.value("Printer/wigth","40").toString());
ini.append("|");
ini.append(config.value("Printer/high","30").toString());
ini.append("|");
ini.append( config.value("Printer/speed","3").toString());
ini.append("|");
ini.append( config.value("Printer/crow","1").toString());
ini.append("|");
//指令集选项
//标签打印机指令集0是TSC 适用佳博等;1PBAL 使用新北洋等;
ini.append(config.value("Printer/labeltype","0").toString());
ini.append("|");
ini.append(config.value("Printer/labelparall","LPT1").toString());
ini.append("|");
ini.append( config.value("Printer/labelusb","USB-0").toString());
ini.append("|");
ini.append( config.value("Printer/labelip","127.0.0.1").toString());
ini.append("|");
//标签打印机端口打开方式 3:Ip 4:驱动;
ini.append( config.value("Printer/labelprttype","4").toString());
ini.append("|");
return ini;
}
......@@ -30,6 +30,11 @@ public:
// bool PrintText(char data[], int fontType,int fontStyle ,int width,int height);
// bool FreeLine();
bool DoTestLabelPrint(QByteArray iniData, OrderObject *orderObject);
bool DoTestPrint(QByteArray iniData, const QString &content, OrderObject *orderObject, QString &error);
void _PrintLabTest();
QString _OnlyGetPrintIni();
bool OnlyDoPrint(const QString &content, OrderObject *orderObject, QString &error);
private:
typedef bool ( *OpenPrinter)( void);
......
#include <Windows.h>
#include <Winspool.h>
#include <QString>
#include <QStringList>
class GetPrinters {
public:
static BOOL HasPrintersName(QStringList &printerlist)
{
DWORD Flags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL; //local printers
DWORD cbBuf;
DWORD pcReturned;
DWORD Level = 2;
TCHAR Name[500] ;
LPPRINTER_INFO_2 pPrinterEnum = NULL;
memset(Name,0,sizeof(TCHAR)*500);
::EnumPrinters(Flags, Name, Level, NULL, 0, &cbBuf, &pcReturned);
pPrinterEnum = (LPPRINTER_INFO_2)LocalAlloc(LPTR, cbBuf+4);
if (NULL == pPrinterEnum)
{
return FALSE;
}
if (!EnumPrinters(
Flags, // DWORD Flags, printer object types
Name, // LPTSTR Name, name of printer object
Level, // DWORD Level, information level
(LPBYTE)pPrinterEnum, // LPBYTE pPrinterEnum, printer information buffer
cbBuf, // DWORD cbBuf, size of printer information buffer
&cbBuf, // LPDWORD pcbNeeded, bytes received or required
&pcReturned) // LPDWORD pcReturned number of printers enumerated
)
{
return FALSE;
}
LPPRINTER_INFO_2 p = pPrinterEnum;
for (int i=0; i<pcReturned;i++)
{
//wprintf( L"PrinterName: %s\n ", p->pPrinterName);
printerlist.append(QString::fromWCharArray(p->pPrinterName));
p++;
}
if (pcReturned > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
};
......@@ -15,6 +15,8 @@
#include <QFile>
#include <QByteArray>
#include <QSettings>
orderprintwork::orderprintwork(QObject *parent) : QObject(parent)
{
//订阅订单本地化事件
......@@ -39,7 +41,6 @@ bool orderprintwork::event(QEvent *e)
POSTEVENTTYPE(PosEvent::s_opt_status,smap,QVariantMap);
OrderObject order;
PrintLib print;
PosOrderPool::GetOrderObject(map[EVENT_KEY_ORDERID].toString(), order);
......@@ -51,14 +52,23 @@ bool orderprintwork::event(QEvent *e)
//QFile file(qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET);
QFile file;
QString prtinifile = qApp->applicationDirPath() + "/" + PREINTER_CONSS;
int prtwi = QSettings(prtinifile, QSettings::IniFormat).value("Printer/PaperWidth", 0).toInt();
if(order.order_type == 1 || order.order_type == 2)
{
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTTAKE_TEMPLET);
if(prtwi == 56)
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTTAKE_TEMPLET);
else
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTTAKE80_TEMPLET);
}
else
{
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET);
if(prtwi == 56)
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET);
else
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINT80_TEMPLET);
}
qDebug() << "+++++++++++++++++++++++++++" << file.fileName();
......@@ -80,39 +90,128 @@ bool orderprintwork::event(QEvent *e)
file.close();
qDebug() << content;
if(print.DoPrint(content, &order, error))
{
QLOG_INFO() << "print succcess";
PrintLib print;
QVariantMap tmpmap;
if(print.DoPrint(content, &order, error))
{
QLOG_INFO() << "print succcess";
tmpmap.insert(EVENT_KEY_STATUS, true);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit(" 打印成功")));
QVariantMap tmpmap;
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
tmpmap.insert(EVENT_KEY_STATUS, true);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit("打印成功")));
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
QVariantMap map;
map.insert(EVENT_KEY_ORDERID, order.order_id);
map.insert(EVENT_KEY_MSG, DEFAULT_LOCATION_PRINT);
map.insert(EVENT_KEY_STATUS, 1);
POSTEVENTTYPE(PosEvent::s_location_orderpool,map,QVariantMap);
}
else
{
QLOG_INFO() << "print failed : " << error;
QVariantMap tmpmap;
QVariantMap map;
tmpmap.insert(EVENT_KEY_STATUS, false);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit(" 打印失败")));
map.insert(EVENT_KEY_ORDERID, order.order_id);
map.insert(EVENT_KEY_MSG, DEFAULT_LOCATION_PRINT);
map.insert(EVENT_KEY_STATUS, 1);
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
POSTEVENTTYPE(PosEvent::s_location_orderpool,map,QVariantMap);
}
}
else
QString otherfile = qApp->applicationDirPath() + "/" + CONFIG_NAME;
int needptr = QSettings(otherfile, QSettings::IniFormat).value(INI_NEEDPTR, 0).toInt();
QEventLoop loop;
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(2*1000);
loop.exec();
if(needptr == 1)
{
QLOG_INFO() << "print failed : " << error;
PrintLib otherprint;
QVariantMap tmpmap;
QVariantMap smap;
smap.insert(EVENT_KEY_ORDERSTATUS, 0);
smap.insert(EVENT_KEY_MSG, QString::fromLocal8Bit("打印中..."));
POSTEVENTTYPE(PosEvent::s_opt_status,smap,QVariantMap);
tmpmap.insert(EVENT_KEY_STATUS, false);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit(" 打印失败")));
QString error;
QString contents;
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
//QFile file(qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET);
QFile file;
}
int othprtw = QSettings(prtinifile, QSettings::IniFormat).value("OtherPrinter/PaperWidth", 0).toInt();
if(order.order_type == 1 || order.order_type == 2)
{
if(othprtw == 56)
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTTAKE_TEMPLET);
else
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTTAKE80_TEMPLET);
}
else
{
if(othprtw == 56)
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET);
else
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINT80_TEMPLET);
}
qDebug() << "+++++++++++++++++++++++++++" << file.fileName();
if(!file.open(QFile::ReadOnly))
{
QVariantMap tmpmap;
tmpmap.insert(EVENT_KEY_STATUS, false);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit(" 打印失败")));
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
QLOG_ERROR() << "open " << qApp->applicationDirPath() + "/" + FILE_PRINT_TEMPLET << " failed";
return true;
}
contents = QString::fromUtf8(file.readAll());
file.close();
if(otherprint.OnlyDoPrint(contents, &order, error))
{
QLOG_INFO() << "print succcess";
QVariantMap tmpmap;
tmpmap.insert(EVENT_KEY_STATUS, true);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit("打印成功")));
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
}
else
{
QLOG_INFO() << "print failed : " << error;
QVariantMap tmpmap;
tmpmap.insert(EVENT_KEY_STATUS, false);
tmpmap.insert(EVENT_KEY_MSG, QString(order.order_id).append(QString::fromLocal8Bit(" 打印失败")));
POSTEVENTTYPE(PosEvent::s_opt_status,tmpmap,QVariantMap);
}
}
}
return true;
}
......
......@@ -35,6 +35,7 @@
#define CONFIG_NAME "config.ini"
#define STOREINFO_NAME "store.ini"
#define USERCONFIG_NAME "userConfig.ini"
#define PREINTER_CONSS "printer.ini"
#define UI_CASHIER "<font color='#ff0000'>未选择</font>"
#define UI_STOREID "<font color='#ff0000'>未登录</font>"
......@@ -59,6 +60,8 @@
#define INI_AUTOCONFIRM "info/autoconfirm"
#define INI_UIVISIBLE "Ui/visible"
#define INI_NEEDPTR "all/needotherprt"
#define INI_PUSHSERVER "info/pushserver"
#define INI_GETSERVER "info/getserver"
......@@ -246,5 +249,10 @@
//
#define FILE_PRINT_TEMPLET "printtemplet.txt"
#define FILE_PRINTTAKE_TEMPLET "printtemplettake.txt"
#define FILE_PRINT80_TEMPLET "printtemplet80.txt"
#define FILE_PRINTTAKE80_TEMPLET "printtemplettake80.txt"
#define DEFAULT_PRINTF_MAIN_SESSION "Printer"
#define DEFAULT_PRINTF_OTHER_SESSION "OtherPrinter"
#endif // PREDEFINE_H
......@@ -16,7 +16,7 @@ include("./base/Print/printlib.pri")
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/lib -llibeay32 -lssleay32
LIBS += -L$$PWD/lib -llibeay32 -lssleay32 -lwinspool
LIBS += -lWs2_32
LIBS += -lDbghelp
......@@ -57,7 +57,8 @@ SOURCES += main.cpp \
control/orderprintwork.cpp \
view/loginform.cpp \
model/discountObject.cpp \
control/workcontrol.cpp
control/workcontrol.cpp \
view/prtsettingform.cpp
HEADERS += \
event/fmapplication.h \
......@@ -93,7 +94,9 @@ HEADERS += \
control/orderprintwork.h \
view/loginform.h \
model/discountObject.h \
control/workcontrol.h
control/workcontrol.h \
view/prtsettingform.h \
base/System/GetPrinters.h
DISTFILES += takeout.rc
......@@ -106,4 +109,5 @@ FORMS += \
view/RejectForm.ui \
view/settingForm.ui \
view/detailForm.ui \
view/loginform.ui
view/loginform.ui \
view/prtsettingform.ui
......@@ -111,6 +111,8 @@ void MainForm::MyShow()
m_pickForm = new PickForm(this);
m_prtForm = new PrtSettingForm(this);
m_settingForm = new SettingForm(this);
m_rejectForm = new RejectForm(this);
......@@ -253,7 +255,7 @@ void MainForm::_Init()
// 显示托盘
m_tray.show();
ui->mainBtnDayReport->hide();
//ui->mainBtnDayReport->hide();
// 设置任务栏图标和标题
setWindowIcon(QIcon(":fm.ico"));
......@@ -748,5 +750,5 @@ void MainForm::onSetDailyReportData(QJsonObject json)
void MainForm::on_mainBtnDayReport_clicked()
{
emit getDayReport();
m_prtForm->show();
}
......@@ -14,6 +14,7 @@
#include <QListWidget>
#include "view/RejectForm.h"
#include "view/detailForm.h"
#include "view/prtsettingform.h"
namespace Ui {
class MainForm;
......@@ -54,6 +55,8 @@ private:
AlertForm *m_alertForm;
// 人员选择窗口
PickForm *m_pickForm;
//打印设置窗口
PrtSettingForm *m_prtForm;
// 设置窗口
SettingForm *m_settingForm;
// 订单详情窗口
......@@ -143,8 +146,6 @@ signals:
* 返回:NULL
* */
void getDayReport();
private slots:
/* 功能:初始化
* 参数:NULL
......
......@@ -492,7 +492,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>日结</string>
<string>打印</string>
</property>
</widget>
</item>
......
#ifndef PRTSETTINGFORM_H
#define PRTSETTINGFORM_H
#include <QDialog>
namespace Ui {
class PrtSettingForm;
}
class PrtSettingForm : public QDialog
{
Q_OBJECT
public:
explicit PrtSettingForm(QWidget *parent = 0);
~PrtSettingForm();
void GetData(char *data, QString type, QString ip, QString name, QString label_name, QString label_wigth, QString labe_high, QString label_type);
private slots:
void on_pushButton_test_clicked();
void on_btn_lab_test_clicked();
void on_pushButton_save_clicked();
void on_btn_lab_save_clicked();
private:
void Init();
private:
Ui::PrtSettingForm *ui;
};
#endif // PRTSETTINGFORM_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment