Commit ea9dbebc by NitefullWind

1. 实现充值打印功能。 2. 更新程序了程序图标。

parent df0cc34f
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += core gui network sql QT += core gui network sql printsupport
CONFIG += c++11 c++14 CONFIG += c++11 c++14
...@@ -38,7 +38,10 @@ SOURCES += main.cpp\ ...@@ -38,7 +38,10 @@ SOURCES += main.cpp\
windows/fmnumpad.cpp \ windows/fmnumpad.cpp \
task/coupon.cpp \ task/coupon.cpp \
windows/couponmodel.cpp \ windows/couponmodel.cpp \
windows/itemdelegate.cpp windows/itemdelegate.cpp \
fmprinter.cpp \
fmsetting.cpp \
windows/fmvipsetting.cpp
HEADERS += \ HEADERS += \
task/fmtask.h \ task/fmtask.h \
...@@ -68,7 +71,10 @@ HEADERS += \ ...@@ -68,7 +71,10 @@ HEADERS += \
windows/fmnumpad.h \ windows/fmnumpad.h \
task/coupon.h \ task/coupon.h \
windows/couponmodel.h \ windows/couponmodel.h \
windows/itemdelegate.h windows/itemdelegate.h \
fmprinter.h \
fmsetting.h \
windows/fmvipsetting.h
FORMS += \ FORMS += \
windows/forms/fmloading.ui \ windows/forms/fmloading.ui \
...@@ -77,7 +83,8 @@ FORMS += \ ...@@ -77,7 +83,8 @@ FORMS += \
windows/forms/fmviplogin.ui \ windows/forms/fmviplogin.ui \
windows/forms/fmviporder.ui \ windows/forms/fmviporder.ui \
windows/forms/fmvippanel.ui \ windows/forms/fmvippanel.ui \
windows/forms/fmnumpad.ui windows/forms/fmnumpad.ui \
windows/forms/fmvipsetting.ui
INCLUDEPATH += ../FMVipDC/ ./task ./windows ./backup INCLUDEPATH += ../FMVipDC/ ./task ./windows ./backup
...@@ -100,5 +107,6 @@ RESOURCES += \ ...@@ -100,5 +107,6 @@ RESOURCES += \
res/FMVip.qrc res/FMVip.qrc
win32 { win32 {
LIBS += -lws2_32 RC_FILE = res/FMVip.rc
LIBS += -lws2_32 -lWinspool
} }
#include "fmprinter.h"
#include "fmsetting.h"
#include <windows.h>
#include <winspool.h>
#include <QPrinterInfo>
#include <QMessageBox>
#include <QDebug>
#include "fmvipsetting.h"
FMPrinter::FMPrinter(QObject *parent) : QObject(parent)
{
}
bool FMPrinter::Print(QString data)
{
QString printerName = FMSetting::GetValue("Printer/name", "").toString();
if(printerName == "") {
printerName = FMSetting::GetPrinterList().first();
FMSetting::SetValue("Printer/name", printerName);
// FMVipSetting settingPrinterWnd;
// settingPrinterWnd.exec();
}
qDebug() << "打印机名称: " << printerName;
char *str = printerName.toLocal8Bit().data();
int length = strlen(str)+1;
wchar_t *wStr = (wchar_t*)malloc(sizeof(wchar_t)*length);
memset(wStr,0,length*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP,0,str,strlen(str),wStr,length);
LPTSTR szPrinterName = (LPTSTR)wStr;
QByteArray tmpData = data.toLocal8Bit();
LPBYTE lpData=(LPBYTE)tmpData.data();
DWORD dwCount = strlen((char*)lpData);
BOOL bStatus = FALSE;
HANDLE hPrinter = NULL;
DOC_INFO_1 DocInfo;
DWORD dwJob = 0L;
DWORD dwBytesWritten = 0L;
// Open a handle to the printer.
bStatus = OpenPrinter( szPrinterName, &hPrinter, NULL );
if (bStatus) {
// Fill in the structure with info about this "document."
DocInfo.pDocName = (LPTSTR)L"TakeawayDoc";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = (LPTSTR)L"RAW";
// Inform the spooler the document is beginning.
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );
if (dwJob > 0) {
// Start a page.
bStatus = StartPagePrinter( hPrinter );
if (bStatus) {
// Send the data to the printer.
bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten);
EndPagePrinter (hPrinter);
}
// Inform the spooler that the document is ending.
EndDocPrinter( hPrinter );
}
// Close the printer handle.
ClosePrinter( hPrinter );
}
// Check to see if correct number of bytes were written.
if (!bStatus || (dwBytesWritten != dwCount)) {
bStatus = FALSE;
qDebug() << "打印错误代码:" << GetLastError();
qDebug() << "打印数据" << data;
} else {
bStatus = TRUE;
}
return bStatus;
}
#ifndef FMPRINTER_H
#define FMPRINTER_H
#include <QObject>
class FMPrinter : public QObject
{
Q_OBJECT
public:
explicit FMPrinter(QObject *parent = 0);
static bool Print(QString data);
};
#endif // FMPRINTER_H
#include "fmsetting.h"
#include <QSettings>
#include <QApplication>
#include <QPrinterInfo>
#include <QDebug>
FMSetting::FMSetting()
{
_sets = new QSettings("FMVip.cfg", QSettings::IniFormat);
_sets->setIniCodec("GB18030");
}
FMSetting *FMSetting::Instance()
{
static FMSetting instance;
return &instance;
}
QVariant FMSetting::getValue(const QString &k, QVariant default_val)
{
return _sets->value(k, default_val);
}
bool FMSetting::setValue(const QString &k, QVariant v)
{
_sets->setValue(k, v);
return (_sets->value(k) == v);
}
QVariant FMSetting::GetValue(const QString &k, QVariant default_val)
{
return FMSetting::Instance()->getValue(k, default_val);
}
bool FMSetting::SetValue(const QString &k, QVariant v)
{
return FMSetting::Instance()->setValue(k, v);
}
QStringList FMSetting::GetPrinterList()
{
QStringList printerList = QPrinterInfo::availablePrinterNames();
qDebug() << "打印机列表:" << printerList;
if(FMSetting::GetValue("Printer/name", "") == "") {
FMSetting::SetValue("Printer/name", printerList.first());
}
return printerList;
}
#ifndef FMSETTING_H
#define FMSETTING_H
#include <QObject>
#include <QVariant>
class QSettings;
class FMSetting : public QObject
{
Q_OBJECT
public:
static FMSetting *Instance();
static QVariant GetValue(const QString &k, QVariant default_val);
static bool SetValue(const QString&k, QVariant v);
static QStringList GetPrinterList();
private:
explicit FMSetting();
QVariant getValue(const QString &k, QVariant default_val);
bool setValue(const QString&k, QVariant v);
QSettings *_sets;
signals:
public slots:
};
#endif // FMSETTING_H
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "fmvipdispatcher.h" #include "fmvipdispatcher.h"
#include "fmtask.h" #include "fmtask.h"
#include "taskfactory.h" #include "taskfactory.h"
#include "fmvipsetting.h"
FMVipDispatcher::FMVipDispatcher(QObject *parent) : FMVipDispatcher::FMVipDispatcher(QObject *parent) :
QObject(parent), QObject(parent),
...@@ -101,13 +102,16 @@ void FMVipDispatcher::onDisconnected() ...@@ -101,13 +102,16 @@ void FMVipDispatcher::onDisconnected()
void FMVipDispatcher::createSysIcon() void FMVipDispatcher::createSysIcon()
{ {
QIcon icon = QIcon(":/img_logo.png"); QIcon icon = QIcon(":/FreemudPOS.ico");
_sysIcon.setIcon(icon); _sysIcon.setIcon(icon);
_sysIcon.setToolTip("FMVIP"); _sysIcon.setToolTip("FMVIP");
auto menu = new QMenu(); auto menu = new QMenu();
auto action = new QAction("退出", this); auto settingAction = new QAction("设置", this);
connect(action, SIGNAL(triggered(bool)), this, SLOT(onQuit())); connect(settingAction, SIGNAL(triggered(bool)), this, SLOT(onSetting()));
menu->addAction(action); menu->addAction(settingAction);
auto quitAction = new QAction("退出", this);
connect(quitAction, SIGNAL(triggered(bool)), this, SLOT(onQuit()));
menu->addAction(quitAction);
_sysIcon.setContextMenu(menu); _sysIcon.setContextMenu(menu);
_sysIcon.show(); _sysIcon.show();
...@@ -126,3 +130,9 @@ void FMVipDispatcher::onQuit() ...@@ -126,3 +130,9 @@ void FMVipDispatcher::onQuit()
Transfer(data, data, a); Transfer(data, data, a);
qApp->quit(); qApp->quit();
} }
void FMVipDispatcher::onSetting()
{
FMVipSetting settingWnd;
settingWnd.exec();
}
#ifndef FMVIPDISPATCHER_H #ifndef FMVIPDISPATCHER_H
#define FMVIPDISPATCHER_H #define FMVIPDISPATCHER_H
#include <QObject> #include <QObject>
...@@ -40,6 +40,7 @@ signals: ...@@ -40,6 +40,7 @@ signals:
public slots: public slots:
void onDoTask(); void onDoTask();
void onQuit(); void onQuit();
void onSetting();
void onCheckSocket(); void onCheckSocket();
void onDisconnected(); void onDisconnected();
......
...@@ -15,5 +15,6 @@ ...@@ -15,5 +15,6 @@
<file>account.png</file> <file>account.png</file>
<file>num_del.png</file> <file>num_del.png</file>
<file>img_logo.png</file> <file>img_logo.png</file>
<file>FreemudPOS.ico</file>
</qresource> </qresource>
</RCC> </RCC>
IDI_ICON1 ICON "FMVip.ico" IDI_ICON1 ICON DISCARDABLE "FreemudPOS.ico"
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "fmvipfund.h" #include "fmvipfund.h"
#include "tasklogin.h" #include "tasklogin.h"
#include "taskothers.h" #include "taskothers.h"
#include "fmprinter.h"
#include <QDateTime> #include <QDateTime>
TaskFund::TaskFund(QJsonObject &jsonObj, Session* session, QObject *parent) TaskFund::TaskFund(QJsonObject &jsonObj, Session* session, QObject *parent)
...@@ -71,6 +72,8 @@ void TaskFund::onFund() ...@@ -71,6 +72,8 @@ void TaskFund::onFund()
QString msg = "充值失败:\n" + getServerJsonValue(PosProps.Msg).toString(); QString msg = "充值失败:\n" + getServerJsonValue(PosProps.Msg).toString();
FMMsgWnd::FailureWnd(msg); FMMsgWnd::FailureWnd(msg);
} else { } else {
QString print = getServerJsonValue(PosProps.Print).toString();
FMPrinter::Print(print);
int before_value = getServerJsonValue(PosProps.BeforeValue).toInt(); int before_value = getServerJsonValue(PosProps.BeforeValue).toInt();
int after_value = getServerJsonValue(PosProps.AfterValue).toInt(); int after_value = getServerJsonValue(PosProps.AfterValue).toInt();
QString before_value_str = DOUBLE_STR(before_value/100.0); QString before_value_str = DOUBLE_STR(before_value/100.0);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <QFile> #include <QFile>
#include <QMutex> #include <QMutex>
#include <QTimer> #include <QTimer>
#include <QTextStream>
#include "fmloading.h" #include "fmloading.h"
#include "fmnumpad.h" #include "fmnumpad.h"
...@@ -96,11 +97,12 @@ bool FMVipLogin::initWnd(Session *session) ...@@ -96,11 +97,12 @@ bool FMVipLogin::initWnd(Session *session)
QString FMVipLogin::getVersionInfo() QString FMVipLogin::getVersionInfo()
{ {
QByteArray versionInfo; QString versionInfo;
QFile versionFile(qApp->applicationDirPath() + "/version.dat"); QFile versionFile(qApp->applicationDirPath() + "/version.dat");
bool isOk = versionFile.open(QIODevice::ReadOnly); bool isOk = versionFile.open(QIODevice::ReadOnly);
if(isOk) { if(isOk) {
versionInfo = versionFile.readAll(); QTextStream in(&versionFile);
versionInfo = in.readLine();
} else { } else {
versionInfo = "未知"; versionInfo = "未知";
} }
......
#include "fmvipsetting.h"
#include "ui_fmvipsetting.h"
#include "fmsetting.h"
#include "fmprinter.h"
FMVipSetting::FMVipSetting(FMVipWnd *parent) :
FMVipWnd(parent),
ui(new Ui::FMVipSetting)
{
ui->setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
QStringList printerList = FMSetting::GetPrinterList();
ui->printer_box->addItems(printerList);
QString settingPrinterName = FMSetting::GetValue("Printer/name", "").toString();
if(printerList.contains(settingPrinterName)) {
ui->printer_box->setCurrentText(settingPrinterName);
}
}
FMVipSetting::~FMVipSetting()
{
delete ui;
}
void FMVipSetting::savePrinterName()
{
FMSetting::SetValue("Printer/name", ui->printer_box->currentText());
}
void FMVipSetting::on_printer_btn_clicked()
{
savePrinterName();
FMPrinter::Print("FMVip打印测试\n\n\n\n\n\n");
}
void FMVipSetting::on_ok_btn_clicked()
{
savePrinterName();
this->close();
}
#ifndef FMVIPSETTING_H
#define FMVIPSETTING_H
#include "fmvipwnd.h"
namespace Ui {
class FMVipSetting;
}
class FMVipSetting : public FMVipWnd
{
Q_OBJECT
public:
explicit FMVipSetting(FMVipWnd *parent = 0);
~FMVipSetting();
private slots:
void on_printer_btn_clicked();
void on_ok_btn_clicked();
private:
Ui::FMVipSetting *ui;
void savePrinterName();
};
#endif // FMVIPSETTING_H
...@@ -18,6 +18,7 @@ FMVipWnd::FMVipWnd(QDialog *parent) : ...@@ -18,6 +18,7 @@ FMVipWnd::FMVipWnd(QDialog *parent) :
setAttribute(Qt::WA_QuitOnClose, false); setAttribute(Qt::WA_QuitOnClose, false);
setAttribute(Qt::WA_DeleteOnClose, false); setAttribute(Qt::WA_DeleteOnClose, false);
setIsBusy(false); setIsBusy(false);
setWindowIcon(QIcon(":/FreemudPOS.ico"));
} }
FMVipWnd::~FMVipWnd() FMVipWnd::~FMVipWnd()
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FMVipSetting</class>
<widget class="QWidget" name="FMVipSetting">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="windowTitle">
<string>FMVipPanel</string>
</property>
<property name="styleSheet">
<string notr="true">#FMVipSetting {
background: rgba(100,100,100, 80);
}
#FMVipWnd {
background: rgb(255, 255, 255);
}
QWidget {
font: normal 22px &quot;Microsoft YaHei&quot;;
color: rgb(90,90,90);
}
/*
* 标题栏
*/
#title {
/*background: rgb(133, 194, 38);*/
background: #3f783c;
min-height: 48px; max-height: 48px;
border: 1 solid silver;
border-bottom: 0 solid silver;
}
#logo_label {
min-width: 110px; min-height: 48px;
border-image: url(&quot;:/img_logo_lxj.png&quot;);
margin-left: 12px;
}
#close_btn {
min-width: 50px; min-height: 50px;
border-image: url(&quot;:/btn_close.png&quot;);
margin-right: 12px;
}
#close_btn:hover{
min-width: 51px; min-height: 51px;
border-image: url(&quot;:/btn_alert_close.png&quot;);
}
#printer_label {
max-width: 70px;
font:18px;
}
#printer_btn, #ok_btn {
min-height: 56px;
background: rgb(122,172,101);
font: 400 23px &quot;Microsoft YaHei&quot;;
color: white;
border: 1 solid white;
border-right: 0 solid silver;
}
#printer_btn:hover, #ok_btn:hover {
padding: 2 0 0 2;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QWidget" name="FMVipWnd" native="true">
<property name="minimumSize">
<size>
<width>640</width>
<height>480</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>640</width>
<height>480</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="title" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="logo_label">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="close_btn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>50</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="user" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>44</number>
</property>
<property name="leftMargin">
<number>124</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>124</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="printer_label">
<property name="text">
<string>打印机:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="printer_box"/>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="printer_btn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>打印测试</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ok_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>确 定</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>50</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>close_btn</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
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