提交信息!

This commit is contained in:
Kane Wang 2020-11-23 15:48:50 +08:00
parent 6572379132
commit 1e628ccc30
5 changed files with 102 additions and 48 deletions

View File

@ -2,6 +2,7 @@
#include <stdexcept> #include <stdexcept>
#include "LoadFromExcel.h" #include "LoadFromExcel.h"
#include "../../excel/excel.h" #include "../../excel/excel.h"
#include "../../Data/Datastructure/CarDealer/CarDealerMap.h"
using namespace std; using namespace std;
using namespace libxl; using namespace libxl;
@ -52,6 +53,9 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
int firstColumnIndex = pSheet->firstCol(); int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex; int rowIndex = firstRowIndex + startRowIndex;
//车商名称表
auto * pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex ) while ( rowIndex <= lastRowIndex )
{ {
int colunmIndex = firstRowIndex; int colunmIndex = firstRowIndex;
@ -59,7 +63,7 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
const wstring && theYear = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true ); const wstring && theYear = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true );
const wstring && theMonth = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 1, true ); const wstring && theMonth = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 1, true );
const wstring && carDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 2, 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 );
const wstring && manHourPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 4, true ); const wstring && manHourPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 4, true );
const wstring && partPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 5, true ); const wstring && partPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 5, true );
const wstring && claimSupport = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 6, true ); const wstring && claimSupport = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 6, true );
@ -74,6 +78,19 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
continue; continue;
} }
//核对车商代码
auto iterCarDealer = pCarDealerMap->find(carDealerCode);
if ( iterCarDealer == pCarDealerMap->end() )
{
//没查到这个车商,清除掉已经读取的数据
schemeVector.clear();
QString rowIndexString = QString::number(rowIndex, 'g', -1);
QString errorMessage = QString("") + rowIndexString + QString("行车商代码错误!");
throw runtime_error(errorMessage.toStdString());
}
CarDealerScheme carDealerScheme( theYear, CarDealerScheme carDealerScheme( theYear,
theMonth, theMonth,
carDealerCode, carDealerCode,
@ -131,6 +148,8 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
int firstColumnIndex = pSheet->firstCol(); int firstColumnIndex = pSheet->firstCol();
int rowIndex = firstRowIndex + startRowIndex; int rowIndex = firstRowIndex + startRowIndex;
unordered_map<wstring, CarDealer>* pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex ) while ( rowIndex <= lastRowIndex )
{ {
int colunmIndex = firstRowIndex; int colunmIndex = firstRowIndex;
@ -154,6 +173,19 @@ void LoadCarDealerAchievementFromXlsx( const std::wstring & fileP
continue; continue;
} }
//核对车商代码
auto iterCarDealer = pCarDealerMap->find(carDealerCode);
if (iterCarDealer == pCarDealerMap->end())
{
//没查到这个车商,清除掉已经读取的数据
achievementVector.clear();
QString rowIndexString = QString::number(rowIndex, 'g', -1);
QString errorMessage = QString("") + rowIndexString + QString("行车商代码错误!");
throw runtime_error(errorMessage.toStdString());
}
//每个字段都要先判断数据类型再读写,防止填写表格的人填错内容。 //每个字段都要先判断数据类型再读写,防止填写表格的人填错内容。
CellType type = pSheet->cellType( rowIndex, firstColumnIndex + 4 ); CellType type = pSheet->cellType( rowIndex, firstColumnIndex + 4 );
char errorMessage[1000]; char errorMessage[1000];
@ -309,6 +341,8 @@ void LoadRepairOrderFromXlsx( const std::wstring & filePath,
int firstRowIndex = pSheet->firstRow(); int firstRowIndex = pSheet->firstRow();
int rowIndex = firstRowIndex + startRowIndex; int rowIndex = firstRowIndex + startRowIndex;
auto* pCarDealerMap = getCarDealerMap();
while ( rowIndex <= lastRowIndex ) while ( rowIndex <= lastRowIndex )
{ {
int colunmIndex = pSheet->firstCol(); int colunmIndex = pSheet->firstCol();

View File

@ -18,7 +18,7 @@
using namespace std; using namespace std;
using namespace ocilib; using namespace ocilib;
unordered_map<string, CarDealer> * pCarDealerMap = nullptr; unordered_map<wstring, CarDealer> * pCarDealerMap = nullptr;
void initCarDealerMap() void initCarDealerMap()
{ {
@ -78,17 +78,17 @@ void initCarDealerMap()
OCI_ExecuteStmt( pStatement, sql.c_str() ); OCI_ExecuteStmt( pStatement, sql.c_str() );
pResult = OCI_GetResultset( pStatement ); pResult = OCI_GetResultset( pStatement );
pCarDealerMap = new unordered_map<string, CarDealer>; pCarDealerMap = new unordered_map<wstring, CarDealer>;
while ( OCI_FetchNext( pResult ) == true ) while ( OCI_FetchNext( pResult ) == true )
{ {
string carDealerCodeIndex = OCI_GetString( pResult, 1 ); wstring carDealerCodeIndex = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) ).toStdWString();
QString carDealerCode = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) ); QString carDealerCode = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) );
QString carDealerName = QString::fromLocal8Bit( OCI_GetString( pResult, 2 ) ); QString carDealerName = QString::fromLocal8Bit( OCI_GetString( pResult, 2 ) );
CarDealer dealer( carDealerCode, carDealerName ); CarDealer dealer( carDealerCode, carDealerName );
pCarDealerMap->insert( pair<string, CarDealer>( carDealerCodeIndex, dealer ) ); pCarDealerMap->insert( pair<wstring, CarDealer>( carDealerCodeIndex, dealer ) );
} }
} }
catch ( runtime_error & error ) catch ( runtime_error & error )
@ -187,7 +187,12 @@ void initCarDealerMapCpp()
Environment::Cleanup(); Environment::Cleanup();
} }
std::unordered_map<string, CarDealer> * getCarDealerMap() std::unordered_map<wstring, CarDealer> * getCarDealerMap()
{ {
if ( pCarDealerMap != nullptr )
{
initCarDealerMap();
}
return pCarDealerMap; return pCarDealerMap;
} }

View File

@ -22,4 +22,4 @@ void initCarDealerMap();
* \brief * \brief
* \return * \return
************************************************/ ************************************************/
std::unordered_map<std::string, CarDealer> * getCarDealerMap(); std::unordered_map<std::wstring, CarDealer> * getCarDealerMap();

View File

@ -3,6 +3,7 @@
#include <stdexcept> #include <stdexcept>
#include "Widgets/MainFrame/QMainFrame.h" #include "Widgets/MainFrame/QMainFrame.h"
#include "QLoginDialog.h" #include "QLoginDialog.h"
#include "Data/Datastructure/CarDealer/CarDealerMap.h"
#include "test/test.h" #include "test/test.h"
using namespace std; using namespace std;
@ -31,6 +32,20 @@ int main(int argc, char* argv[])
//return 1; //return 1;
//加载资源
try
{
initCarDealerMap();
}
catch ( runtime_error & error )
{
QMessageBox::critical( nullptr,
"错误!",
error.what() );
return -1;
}
//登录界面 //登录界面
try try
{ {

View File

@ -55,7 +55,7 @@ void excelTest()
//LoadNewRepairMonitorReportFromXlsx(filePathNewRepairMonitor, 0, 1, repairMonitorVector); //LoadNewRepairMonitorReportFromXlsx(filePathNewRepairMonitor, 0, 1, repairMonitorVector);
//ImportNewRepairMonitorToOracle(userName, password, tnsName, repairMonitorVector); //ImportNewRepairMonitorToOracle(userName, password, tnsName, repairMonitorVector);
initCarDealerMap(); //initCarDealerMap();
return; return;
} }