完成表格模板验证

This commit is contained in:
2020-12-09 10:46:16 +08:00
parent 96bd16a290
commit aff4ec48f6
3 changed files with 105 additions and 40 deletions

View File

@@ -8,6 +8,28 @@
using namespace std;
using namespace libxl;
//车商方案表
const unsigned int CARDEALER_SCHEMA_CAPTION_COUNT = 9;
const wchar_t * pwszSchema[] = {L"年度", L"月份", L"车商代码", L"车商名称", L"工时标准", L"配件价格", L"其他理赔支持", L"营销活动方案", L"是否达成预期"};
//车商业绩表
const unsigned int CARDEALER_ACHIEVEMENT_CAPTION_COUNT = 10;
const wchar_t* pwszAchievement[] = { L"年度", L"月份", L"车商代码", L"车商名称", L"店内双签产值(万元)", L"店内新车开票数", L"我司新车签单台次", L"人保新车签单台次", L"平安新车签单台次", L"其他保险公司新车签单台次" };
/************************************************
* \brief
* \param pBook
* \param sheetIndex
* \param captionRowIndex
* \param pszCaptionFormat
* \param captionCount
* \return
************************************************/
bool checkExcelFileFormat( Book * pBook,
int sheetIndex,
int captionRowIndex,
const wchar_t * pszCaptionFormat[],
int captionCount );
/************************************************
* \brief 从Excel文件读取车商方案表
@@ -37,6 +59,19 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
throw runtime_error( errorMessage );
}
//验证表格内容是否相符
bool isEqual = checkExcelFileFormat( pBook, sheetIndex, startRowIndex - 1, pwszSchema, CARDEALER_SCHEMA_CAPTION_COUNT );
if ( isEqual == false )
{
//内容不相符,抛出异常
string errorMessage = "Excel文件内容不符\n请核对后再导入!";
pBook->release();
throw runtime_error( errorMessage );
}
pSheet = pBook->getSheet( sheetIndex );
if ( pSheet == nullptr )
@@ -54,7 +89,7 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex;
//车商名称表
//车商名称表,用于验证表格中的车商代码
auto * pCarDealerMap = GetCarDealerMap();
while ( rowIndex <= lastRowIndex )
@@ -132,6 +167,19 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
throw runtime_error( errorMessage );
}
//验证表格内容是否相符
bool isEqual = checkExcelFileFormat(pBook, sheetIndex, startRowIndex - 1, pwszAchievement, CARDEALER_ACHIEVEMENT_CAPTION_COUNT);
if (isEqual == false)
{
//内容不相符,抛出异常
string errorMessage = "Excel文件内容不符\n请核对后再导入!";
pBook->release();
throw runtime_error(errorMessage);
}
pSheet = pBook->getSheet( sheetIndex );
if ( pSheet == nullptr )
@@ -149,6 +197,7 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex;
//车商名称表
unordered_map<wstring, CarDealer> * pCarDealerMap = GetCarDealerMap();
while ( rowIndex <= lastRowIndex )
@@ -158,7 +207,7 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
const wstring && theYear = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true );
const wstring && theMonth = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 1, true );
const wstring && carDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 2, true );
const wstring && carDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 3, true );
//const wstring && carDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 3, true );
long double checkedAchievement = 0;
int policyAmount = 0;
int cpicAmount = 0;
@@ -366,7 +415,7 @@ void LoadRepairOrderFromXlsx( const std::wstring & filePath,
const wstring && isSuccess = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
const wstring && recommandDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
const wstring && recommandDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
const wstring && recommandDealerCodeInNotify = L""; // ReadCellStringFromXlsx(pBook, sheetIndex, rowIndex, colunmIndex, true);
const wstring && recommandDealerCodeInNotify = L""; //表格中没有报案推荐车商代码
const wstring && recommandDealerNameInNotify = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
const wstring && recommandDealerNameInSurvey = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
const wstring && agentName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
@@ -726,18 +775,35 @@ void LoadNewRepairMonitorReportFromXlsx( const std::wstring &
* \param pszCaptionFormat
* \return
************************************************/
bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, wchar_t * pszCaptionFormat[], int captionCount )
bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, const wchar_t * pszCaptionFormat[], int captionCount )
{
if ( pBook == nullptr )
{
throw logic_error( "Excel文件指针为空" );
}
if ( sheetIndex < 0 || captionRowIndex < 0 )
{
throw logic_error( "标题行参数错误!" );
}
Sheet * pSheet = pBook->getSheet( sheetIndex );
int captionIndex = 0;
bool isEqual = true;
while ( captionIndex < captionCount )
{
const wchar_t * pwszCaption = pSheet->readStr( captionRowIndex, captionIndex );
if ( wcscmp( pwszCaption, pszCaptionFormat[captionIndex] ) != 0 )
{
isEqual = false;
break;
}
captionIndex++;
}
return isEqual;
}

View File

@@ -1,11 +1,8 @@
#include <QFileDialog>
#include "QCarDealerAchievementWidget.h"
#include <QMessageBox>
#include <stdexcept>
#include "QCarDealerAchievementWidget.h"
#include "../../Data/Datastructure/CarDealer/CarDealerMap.h"
#include "../../../data/DataManipulation/oracle/ImportToOracle.h"
#include "../../Data/DataManipulation/Excel/LoadFromExcel.h"
#include "../../../util/qt/qt_util.h"
@@ -98,6 +95,8 @@ void QCarDealerAchievementWidget::showCarDealerAchievement()
ui.pTableWidgetAchievement->setItem( rowIndex, columnIndex++, pItem );
//车商名称
QString carDealerName = QString::fromStdWString(GetCarDealerName(iter->getCarDealerCode()));
pItem = new QTableWidgetItem( QString::fromStdWString( iter->getCarDealerCode() ) );
pItem->setTextAlignment( Qt::AlignVCenter | Qt::AlignHCenter );