2018-06-01 09:36:01 +00:00
|
|
|
|
#include "QRapidInputWidget.h"
|
|
|
|
|
#include "DataManipulation.h"
|
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QRapidInputWidget::QRapidInputWidget(QWidget* parent)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QRapidInputWidget::~QRapidInputWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::init()
|
|
|
|
|
{
|
|
|
|
|
initWidget();
|
|
|
|
|
initSignal();
|
|
|
|
|
initData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::initWidget()
|
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
setLayout(ui.pLayoutMain);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
setAcceptDrops(true);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::initSignal()
|
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
connect(ui.pButtonSave,SIGNAL(clicked()), this, SLOT(onSaveTelSalePolicy()));
|
|
|
|
|
connect(ui.pButtonClean,SIGNAL(clicked()), this, SLOT(onCleanTable()));
|
|
|
|
|
connect(ui.pButtonOpenFile,SIGNAL(clicked()), this, SLOT(onOpenFile()));
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::initData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
void QRapidInputWidget::dragEnterEvent(QDragEnterEvent* pEvent)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (pEvent->mimeData()->hasUrls())
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
|
|
|
|
pEvent->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
void QRapidInputWidget::dropEvent(QDropEvent* pEvent)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
|
|
|
|
QList<QUrl> listURL = pEvent->mimeData()->urls();
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QString strFilePath;
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//正则表达式判断文件类型
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QRegularExpression regXlsx(QString::fromLocal8Bit(".xlsx$"),
|
|
|
|
|
QRegularExpression::PatternOption::CaseInsensitiveOption);
|
|
|
|
|
QRegularExpression regXls(QString::fromLocal8Bit(".xls$"),
|
|
|
|
|
QRegularExpression::PatternOption::CaseInsensitiveOption);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
QRegularExpressionMatch match;
|
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (listURL.size() == 0)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strFilePath = listURL[0].toLocalFile();
|
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//是xlsx文件
|
2018-06-02 09:47:28 +00:00
|
|
|
|
match = regXlsx.match(strFilePath);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (match.hasMatch())
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
readTelsaleXlsxFile(strFilePath.toStdWString(),
|
|
|
|
|
m_vPolicy,
|
|
|
|
|
ui.pCheckBoxHasTitle->isChecked());
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//是xls文件
|
2018-06-02 09:47:28 +00:00
|
|
|
|
match = regXls.match(strFilePath);
|
|
|
|
|
|
|
|
|
|
if (match.hasMatch())
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
//readTelsaleXlsFile(strFilePath.toStdWString(), m_vPolicy, ui.pCheckBoxHasTitle->isChecked(), false);
|
|
|
|
|
QMessageBox::critical(this,
|
|
|
|
|
QString::fromLocal8Bit("文件类型错误!"),
|
|
|
|
|
QString::fromLocal8Bit("文件格式需为Excel 2007及以后!"));
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
2018-06-02 09:47:28 +00:00
|
|
|
|
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
|
|
|
|
showPolicy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::showPolicy()
|
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
int iRowCount = m_vPolicy.size();
|
|
|
|
|
QTableWidgetItem* pItem = NULL;
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setRowCount(iRowCount);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
for (int iRowIndex = 0; iRowIndex < iRowCount; iRowIndex++)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//保单号
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strPolicySerial.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 0, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//签单日期
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strSignDate.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 1, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//车牌号
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strPlateSerial.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 2, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//被保险人
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strCustomerName.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 3, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//车商代码
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strAutoTraderCode.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 4, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//经办人代码
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strSalerCode.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 5, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//经办人名称
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strSalerName.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 6, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//部门
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strSalerDeptName.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 7, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//科室
|
2018-06-02 09:47:28 +00:00
|
|
|
|
pItem = new QTableWidgetItem(QString::fromLocal8Bit(m_vPolicy[iRowIndex].strSalerOfficeName.c_str()));
|
|
|
|
|
pItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
pItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
ui.pTableWidgetPolicy->setItem(iRowIndex, 8, pItem);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.pTableWidgetPolicy->resizeColumnsToContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::onSaveTelSalePolicy()
|
|
|
|
|
{
|
|
|
|
|
vector<TelSalePolicyGift> vGifts;
|
|
|
|
|
|
|
|
|
|
m_vErrorPolicy.clear();
|
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
for (vector<SPolicyRecord>::iterator iter = m_vPolicy.begin(); iter != m_vPolicy.end(); ++iter)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
SaveTelSalePolicyInfo(*iter, vGifts);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
2018-06-02 09:47:28 +00:00
|
|
|
|
catch (runtime_error& excpt)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
m_vErrorPolicy.push_back(*iter);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QString strInfo = QString::fromLocal8Bit("保单") + QString::fromLocal8Bit((*iter).strPolicySerial.c_str()) + QString::
|
|
|
|
|
fromLocal8Bit("保存错误!\n") +
|
|
|
|
|
QString::fromLocal8Bit("错误信息:") + QString::fromLocal8Bit(excpt.what());
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QMessageBox::critical(this, QString::fromLocal8Bit("保存错误"), strInfo);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_vPolicy = m_vErrorPolicy;
|
|
|
|
|
|
|
|
|
|
showPolicy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::onCleanTable()
|
|
|
|
|
{
|
|
|
|
|
m_vErrorPolicy.clear();
|
|
|
|
|
m_vPolicy.clear();
|
|
|
|
|
|
|
|
|
|
ui.pTableWidgetPolicy->setRowCount(0);
|
|
|
|
|
ui.pTableWidgetPolicy->clearContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QRapidInputWidget::onOpenFile()
|
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QSettings reg("HKEY_CURRENT_USER\\Software\\TelsalePolicyInfoManager", QSettings::NativeFormat);
|
|
|
|
|
QString strPath = reg.value(QString::fromLocal8Bit("打开地址")).toString();
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QStringList listFileNames = QFileDialog::getOpenFileNames(this,
|
|
|
|
|
QString::fromLocal8Bit("打开Excel文件"),
|
|
|
|
|
strPath,
|
|
|
|
|
QString::fromLocal8Bit("Excel文件 (*.xls *.xlsx)"));
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//记录一下打开的路径
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (listFileNames.size() > 0)
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
strPath = listFileNames[0].left(listFileNames[0].lastIndexOf(QString::fromLocal8Bit("/")) + 1);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
reg.setValue(QString::fromLocal8Bit("打开地址"), strPath);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//正则表达式判断文件类型
|
2018-06-02 09:47:28 +00:00
|
|
|
|
QRegularExpression regXlsx(QString::fromLocal8Bit(".xlsx$"),
|
|
|
|
|
QRegularExpression::PatternOption::CaseInsensitiveOption);
|
|
|
|
|
QRegularExpression regXls(QString::fromLocal8Bit(".xls$"),
|
|
|
|
|
QRegularExpression::PatternOption::CaseInsensitiveOption);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
QRegularExpressionMatch match;
|
|
|
|
|
|
|
|
|
|
strPath = listFileNames[0];
|
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//是xlsx文件
|
2018-06-02 09:47:28 +00:00
|
|
|
|
match = regXlsx.match(strPath);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (match.hasMatch())
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
readTelsaleXlsxFile(strPath.toStdWString(), m_vPolicy, ui.pCheckBoxHasTitle->isChecked());
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 10:21:26 +00:00
|
|
|
|
//是xls文件
|
2018-06-02 09:47:28 +00:00
|
|
|
|
match = regXls.match(strPath);
|
2018-06-01 09:36:01 +00:00
|
|
|
|
|
2018-06-02 09:47:28 +00:00
|
|
|
|
if (match.hasMatch())
|
2018-06-01 09:36:01 +00:00
|
|
|
|
{
|
2018-06-02 09:47:28 +00:00
|
|
|
|
//readTelsaleXlsFile( strPath.toLocal8Bit().data(), m_vPolicy, ui.pCheckBoxHasTitle->isChecked(), false );
|
|
|
|
|
QMessageBox::critical(this,
|
|
|
|
|
QString::fromLocal8Bit("文件类型错误!"),
|
|
|
|
|
QString::fromLocal8Bit("文件格式需为Excel 2007及以后!"));
|
2018-06-01 09:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showPolicy();
|
|
|
|
|
}
|