This commit is contained in:
2020-11-23 11:43:54 +08:00
parent 82600f1beb
commit a4d1e51da8
11 changed files with 285 additions and 29 deletions

View File

@@ -1,9 +1,9 @@
// **********************************************************
// 文件名CarDealer.h
// 文件名CarDealer.cpp
// 创建日期2020-11-20 13:59
// 作者: 王炜
// 说明:车商对象定义
// **********************************************************
#pragma once
#include "CarDealer.h"

View File

@@ -0,0 +1,56 @@
// **********************************************************
// 文件名CarDealer.h
// 创建日期2020-11-20 13:59
// 作者: 王炜
// 说明:车商对象定义
// **********************************************************
#pragma once
#include <string>
#include <QString>
class CarDealer
{
public:
CarDealer(QString carDealerCode, QString carDealerName )
: carDealerCode( std::move( carDealerCode ) ),
carDealerName( std::move( carDealerName ) )
{
}
CarDealer( const CarDealer & other )
: carDealerCode( other.carDealerCode ),
carDealerName( other.carDealerName )
{
}
CarDealer( CarDealer && other )
: carDealerCode( std::move( other.carDealerCode ) ),
carDealerName( std::move( other.carDealerName ) )
{
}
CarDealer & operator=( const CarDealer & other )
{
if ( this == &other )
return *this;
carDealerCode = other.carDealerCode;
carDealerName = other.carDealerName;
return *this;
}
CarDealer & operator=( CarDealer && other )
{
if ( this == &other )
return *this;
carDealerCode = std::move( other.carDealerCode );
carDealerName = std::move( other.carDealerName );
return *this;
}
private:
QString carDealerCode;
QString carDealerName;
};

View File

@@ -0,0 +1,155 @@
// **********************************************************
// 文件名CarDealerMap.cpp
// 创建日期2020-11-23 13:59
// 作者: 王炜
// 说明:车商对象映射表
// **********************************************************
#include <QString>
#include <ocilib.hpp>
#include <stdexcept>
#include "CarDealer.h"
#include "CarDealerMap.h"
#include <xlocale>
#include "../../../db/ocilib/db_oper.h"
using namespace std;
using namespace ocilib;
unordered_map<string, CarDealer> * pCarDealerMap = nullptr;
void initCarDealerMap()
{
if ( pCarDealerMap != nullptr )
{
delete pCarDealerMap;
}
OCI_Connection * pConnection = nullptr;
OCI_Statement * pStatement = nullptr;
OCI_Resultset * pResult = nullptr;
int returnCode = 0;
ostring sql =
"SELECT auto_code, "
" auto_name "
"FROM idst0.auto_store_t ";
//以后要修改
string userName = "car_dealer";
string password = "cpic123456";
string tnsName = "xmcx1";
returnCode = OCI_Initialize( error_handler, nullptr, OCI_ENV_DEFAULT );
if ( static_cast<bool>(returnCode) == false )
{
//初始化失败
string errorMessage = "ocilib初始化失败";
}
try
{
pConnection = OCI_ConnectionCreate( tnsName.c_str(),
userName.c_str(),
password.c_str(),
OCI_SESSION_DEFAULT );
}
catch ( runtime_error & error )
{
//连接数据库失败
OCI_Cleanup();
}
OCI_Cleanup();
}
void initCarDealerMapCpp()
{
if ( pCarDealerMap != nullptr )
{
delete pCarDealerMap;
}
// OCI_Connection * pConnection = nullptr;
// OCI_Statement * pStatement = nullptr;
// OCI_Resultset * pResult = nullptr;
// int returnCode = 0;
ostring sql =
"SELECT auto_code, "
" auto_name "
"FROM idst0.auto_store_t ";
//以后要修改
string userName = "car_dealer";
string password = "cpic123456";
string tnsName = "xmcx1";
Connection * pConnection = nullptr;
Statement * pStatement = nullptr;
//Resultset * pResult = nullptr;
try
{
Environment::Initialized();
}
catch ( exception * error )
{
string errorMessage = "ocilib初始化失败";
errorMessage.append( error->what() );
throw runtime_error( errorMessage.c_str() );
}
try
{
pConnection = new Connection( tnsName.c_str(), userName.c_str(), password.c_str() );
}
catch ( exception & error )
{
string errorMessage = "连接oracle数据库失败";
errorMessage.append( error.what() );
Environment::Cleanup();
throw runtime_error( errorMessage.c_str() );
}
try
{
pStatement = new Statement( *pConnection );
pStatement->Execute( sql );
Resultset result = pStatement->GetResultset();
pCarDealerMap = new unordered_map<string, CarDealer>;
while ( result.Next() )
{
string carDealerCodeIndex = result.Get<ostring>( "auto_code" ).c_str();
QString carDealerCode = QString::fromLocal8Bit( result.Get<ostring>( "auto_code" ).c_str() );
QString carDealerName = QString::fromLocal8Bit( result.Get<ostring>( "auto_name" ).c_str() );
CarDealer dealer( carDealerCode, carDealerName );
pCarDealerMap->insert( pair<string, CarDealer>( carDealerCodeIndex, dealer ) );
}
}
catch ( exception & error )
{
Environment::Cleanup();
}
Environment::Cleanup();
}
std::unordered_map<string, CarDealer> * getCarDealerMap()
{
return pCarDealerMap;
}

View File

@@ -0,0 +1,25 @@
// **********************************************************
// 文件名CarDealerMap.h
// 创建日期2020-11-23 13:59
// 作者: 王炜
// 说明:车商对象映射表
// **********************************************************
#pragma once
#include <unordered_map>
#include <QString>
#include <string>
#include "CarDealer.h"
/************************************************
* \brief
************************************************/
void initCarDealerMap();
/************************************************
* \brief
* \return
************************************************/
std::unordered_map<std::string, CarDealer> * getCarDealerMap();

View File

@@ -5,6 +5,7 @@
#include "../data/DataManipulation/Excel/LoadFromExcel.h"
#include "../data/DataManipulation/oracle/ImportToOracle.h"
#include "../system/system_util.h"
#include "../Data/Datastructure/CarDealer/CarDealerMap.h"
using namespace std;
@@ -53,6 +54,8 @@ void excelTest()
//测试新送返修监控报表
//LoadNewRepairMonitorReportFromXlsx(filePathNewRepairMonitor, 0, 1, repairMonitorVector);
//ImportNewRepairMonitorToOracle(userName, password, tnsName, repairMonitorVector);
initCarDealerMap();
return;
}

View File

@@ -1 +0,0 @@
#include "CarDealer.h"

View File

@@ -1,14 +0,0 @@
// **********************************************************
// 文件名CarDealer.h
// 创建日期2020-11-20 14:00
// 作者:
// 说明:
// **********************************************************
#pragma once
class CarDealer
{
public:
};