You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
489 lines
9.7 KiB
C++
489 lines
9.7 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QLibrary>
|
|
#include <stdio.h>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QJsonParseError>
|
|
|
|
#include <QVariant>
|
|
#include <QJsonValue>
|
|
#include <QString>
|
|
#include <QDateTime>
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
InitStr();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::InitStr()
|
|
{
|
|
ui->textEditPrintLine->setText("18");
|
|
|
|
ui->textEditPrtColum->setText("42");
|
|
|
|
ui->textEditStatesAddr->setText("4096");
|
|
|
|
ui->textEditInportLine->setText("10");
|
|
|
|
ui->textEditInportColum->setText("10");
|
|
|
|
ui->textEditoutportLine->setText("10");
|
|
ui->textEditoutportColum->setText("28");
|
|
|
|
ui->textEditMannoLine->setText("14");
|
|
|
|
ui->textEditMannoColum->setText("28");
|
|
|
|
ui->textEditVehtypeLine->setText("9");
|
|
|
|
ui->textEditVehTypeColum->setText("27");
|
|
|
|
ui->textEditTimeLine->setText("12");
|
|
|
|
ui->textEditTimeColum->setText("10");
|
|
|
|
ui->textEditMoneyLine->setText("13");
|
|
|
|
ui->textEditMoneyColum->setText("10");
|
|
|
|
|
|
ui->textEditInPort->setText("呼和浩特东");
|
|
ui->textEditOutPort->setText("赤峰西");
|
|
ui->textEditMoney->setText("119.76");
|
|
|
|
ui->textEditManno->setText("1201202");
|
|
|
|
ui->textEditVehtype->setText("一型车");
|
|
|
|
m_Handle = NULL;
|
|
// QLibrary mylib;
|
|
// mylib.setFileName("WinIo32.dll");
|
|
|
|
// m_Handle = NULL:
|
|
|
|
// if(mylib.load())
|
|
// {
|
|
// int i=0;
|
|
// i++;
|
|
// }
|
|
|
|
}
|
|
|
|
void MainWindow::on_pushButtonCreate_clicked()
|
|
{
|
|
QString qtemp;
|
|
QString qFormat;
|
|
|
|
QString qLine;
|
|
QString qcol;
|
|
|
|
char printName[64];
|
|
int iCol;
|
|
int iLine;
|
|
char portAddr[64];
|
|
char printFomat[512];
|
|
int iRet;
|
|
bool ok;
|
|
|
|
int tmpcol;
|
|
int tmpline;
|
|
char cutbuf[126];
|
|
|
|
memset(portAddr,0,sizeof(portAddr));
|
|
|
|
qtemp = ui->comboBoxPtrName->currentText();
|
|
iRet = QStringToChar(printName,qtemp,63,2);
|
|
if(iRet<0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qtemp = ui->textEditPrintLine->toPlainText();
|
|
iLine = qtemp.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qtemp = ui->textEditPrtColum->toPlainText();
|
|
iCol = qtemp.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qtemp = ui->textEditStatesAddr->toPlainText();
|
|
iRet = QStringToChar(portAddr,qtemp,63,2);
|
|
if(iRet<0)
|
|
{
|
|
// return;
|
|
}
|
|
|
|
qLine = ui->textEditInportLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditInportColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat = "[{\"NAME\":\"INPORT\",\"COL\":";
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
qFormat += "},";
|
|
|
|
qLine = ui->textEditoutportLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditoutportColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat += "{\"NAME\":\"OUTPORT\",\"COL\":";;
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
qFormat += "},";
|
|
|
|
qLine = ui->textEditMannoLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditMannoColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat += "{\"NAME\":\"MANNO\",\"COL\":";
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
qFormat += "},";
|
|
|
|
qLine = ui->textEditVehtypeLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditVehTypeColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat += "{\"NAME\":\"VEHTYPE\",\"COL\":";
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
qFormat += "},";
|
|
|
|
qLine = ui->textEditTimeLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditTimeColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat += "{\"NAME\":\"TIME\",\"COL\":";
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
qFormat += "},";
|
|
|
|
qLine = ui->textEditMoneyLine->toPlainText();
|
|
tmpline = qLine.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qcol = ui->textEditMoneyColum->toPlainText();
|
|
tmpcol = qcol.toInt(&ok);
|
|
if(! ok)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qFormat += "{\"NAME\":\"MONEY\",\"COL\":";
|
|
qFormat += qcol;
|
|
|
|
qFormat +=",\"ROW\":";
|
|
qFormat += qLine;
|
|
|
|
qFormat += "}]";
|
|
|
|
// qFormat = "[{\"NAME\":\"INPORT\",\"COL\":6,\"ROW\":8},{\"NAME\":\"MANNO\",\"COL\":6,\"ROW\":10},{\"NAME\":\"VEHTYPE\",\"COL\":20,\"ROW\":8}]";
|
|
memset(printFomat,0,sizeof(qFormat));
|
|
iRet = QStringToChar(printFomat,qFormat,511,2);
|
|
if(iRet<0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
strcpy(cutbuf,"{\"CUTPAPER\":0,\"CMDLF\":0,\"CUTCMD\":1}");
|
|
m_Handle = PRN_CreatePrinter(1,printName,iCol,iLine,12,portAddr,printFomat,cutbuf);
|
|
if(m_Handle)
|
|
{
|
|
ui->textEditPrintStates->setText("创建打印机成功");
|
|
}
|
|
else{
|
|
ui->textEditPrintStates->setText("创建打印机失败");
|
|
}
|
|
}
|
|
|
|
|
|
int MainWindow::QStringToChar(char * dest,QString & Qsource, int iLen,int isChange)
|
|
{
|
|
QByteArray ba2;
|
|
char * ptr;
|
|
int nextlen;
|
|
|
|
if(Qsource.length() == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if( 0 == isChange)
|
|
{
|
|
ba2 =Qsource.toLocal8Bit();
|
|
}
|
|
else if(1 == isChange)
|
|
{
|
|
ba2 = Qsource.toUtf8();
|
|
}
|
|
else
|
|
{
|
|
ba2 =Qsource.toLatin1();
|
|
}
|
|
|
|
ptr=ba2.data();
|
|
|
|
nextlen =strlen(ptr);
|
|
if(iLen < nextlen)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
strcpy(dest, ptr);
|
|
return 0;
|
|
}
|
|
|
|
//
|
|
|
|
|
|
void MainWindow::on_pushButtonPrint_clicked()
|
|
{
|
|
char prtInfo[256];
|
|
QString qtemp;
|
|
QString qInfostr;
|
|
int iRet;
|
|
|
|
if(NULL == m_Handle)
|
|
{
|
|
return;
|
|
}
|
|
|
|
qInfostr="[";
|
|
qtemp = ui->textEditInPort->toPlainText();
|
|
if( ! (qtemp.isEmpty()))
|
|
{
|
|
qInfostr += "{\"NAME\":\"INPORT\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"},";
|
|
}
|
|
|
|
qtemp = ui->textEditOutPort->toPlainText();
|
|
if( ! (qtemp.isEmpty()))
|
|
{
|
|
qInfostr += "{\"NAME\":\"OUTPORT\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"},";
|
|
}
|
|
|
|
qtemp = ui->textEditManno->toPlainText();
|
|
if( ! (qtemp.isEmpty()))
|
|
{
|
|
qInfostr += "{\"NAME\":\"MANNO\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"},";
|
|
}
|
|
|
|
qtemp = ui->textEditVehtype->toPlainText();
|
|
if( ! (qtemp.isEmpty()))
|
|
{
|
|
qInfostr += "{\"NAME\":\"VEHTYPE\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"},";
|
|
}
|
|
|
|
qtemp = ui->textEditMoney->toPlainText();
|
|
if( ! (qtemp.isEmpty()))
|
|
{
|
|
qInfostr += "{\"NAME\":\"MONEY\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"},";
|
|
}
|
|
|
|
QDateTime current_date_time =QDateTime::currentDateTime();
|
|
qtemp =current_date_time.toString("yyyy.MM.dd hh:mm:ss");
|
|
|
|
qInfostr += "{\"NAME\":\"TIME\",\"VALUE\":\"";
|
|
qInfostr += qtemp;
|
|
qInfostr += "\"}]";
|
|
|
|
// qInfostr += "\"]";
|
|
|
|
memset(prtInfo,0,sizeof(prtInfo));
|
|
// int iRet = QStringToChar(prtInfo, qInfostr,255);
|
|
// if(iRet<0)
|
|
//{
|
|
// return;
|
|
//}
|
|
|
|
// strcpy(prtInfo,"[{\"NAME\":\"INPORT\",\"VALUE\":\"呼和浩特东\"},{\"NAME\":\"MANNO\",\"VALUE\":\"1201202\"},{\"NAME\":\"VEHTYPE\",\"VALUE\":\"一型车\"}]");
|
|
// char prtinfo2[256];
|
|
//strcpy(prtinfo2,"[{\"NAME\":\"INPORT\",\"VALUE\":\"zgbeijing\"},{\"NAME\":\"MANNO\",\"VALUE\":\"1201202\"},{\"NAME\":\"VEHTYPE\",\"VALUE\":\"zxcvb\"}]");
|
|
|
|
// iRet = strcmp(prtInfo,prtinfo2);
|
|
//qtemp = prtInfo;
|
|
|
|
//iRet = qtemp.compare(qInfostr);
|
|
if(qInfostr.size() >255)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// QByteArray byteFileName = qInfostr.toUtf8();
|
|
|
|
// strcpy(prtInfo, byteFileName.data());
|
|
|
|
|
|
iRet = QStringToChar(prtInfo, qInfostr,255,0);
|
|
|
|
// iRet = QStringToChar(prtInfo, qtemp,255);
|
|
//if(iRet<0)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
// Jsontest(prtInfo);
|
|
|
|
PRN_Print(m_Handle,prtInfo);
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButtonStates_clicked()
|
|
{
|
|
INT32 iStates;
|
|
int iRet =0;
|
|
|
|
if(NULL == m_Handle)
|
|
{
|
|
return;
|
|
}
|
|
|
|
iRet = PRN_CheckPrinter(m_Handle,iStates);
|
|
if(iRet <0)
|
|
{
|
|
ui->textEditPrintStates->setText("获取打印机状态失败");
|
|
return;
|
|
}
|
|
|
|
switch(iStates)
|
|
{
|
|
case 0:
|
|
ui->textEditPrintStates->setText("打印机正常");
|
|
break;
|
|
|
|
case 1:
|
|
ui->textEditPrintStates->setText("打印机缺纸");
|
|
break;
|
|
|
|
case 2:
|
|
ui->textEditPrintStates->setText("打印机未联机");
|
|
break;
|
|
default:
|
|
ui->textEditPrintStates->setText("打印机故障");
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButtonCut_clicked()
|
|
{
|
|
INT32 iStates;
|
|
int iRet;
|
|
|
|
/* if(NULL == m_Handle)
|
|
{
|
|
return;
|
|
}
|
|
|
|
iRet = PRN_PaperCut(m_Handle);
|
|
if(iRet <0)
|
|
{
|
|
ui->textEditPrintStates->setText("打印机切纸失败");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ui->textEditPrintStates->setText("打印机切纸成功");
|
|
}
|
|
*/
|
|
}
|
|
|
|
void MainWindow::on_pushButtonClose_clicked()
|
|
{
|
|
PRN_Close(m_Handle);
|
|
m_Handle =NULL;
|
|
}
|