/*!
 * \file DataManipulation.h
 * \date 2014/08/18 15:43
 *
 * \author Kane
 * Contact: user@company.com
 *
 * \brief 转介绍数据处理
 *
 * TODO: long description
 *
 * \note
*/

#ifndef DataManipulation_h__
#define DataManipulation_h__

#include <libxl.h>
#include <string>
#include <QtCore/QString>
#include <vector>
#include <unordered_map>
#include "SystemData.h"

using namespace std;
using namespace libxl;

//准备废弃
typedef struct
{
	string strPolicySerial;
	string strSignDate;
	string strSalerCode;
	string strSalerName;
	string strSalerDeptCode;
	string strSalerDeptName;
	string strSalerOfficeCode;
	string strSalerOfficeName;
	string strAutoTraderCode;
	string strAutoTraderName;
	string strCustomerName;
	string strPlateSerial;
	string strFrameSerial;
	string strEngineSerial;
	string strOperatorDate;
	string strOperatorCode;
	bool   bIsAutotraderCall;
}          SPolicyRecord;



//准备废弃
typedef struct
{
	string strPolicySerial;
	string strSalerCode;
	string strDeptName;
	string strOfficeName;
	string strCDLH;
	string strAutoTraderCode;
	string strAutoTraderName;
	double dGiftPriceSum;
	string strGifts;
	string strInputDate;
}          SPolicyQuery;



class TelSalePolicyGift
{
public:
	TelSalePolicyGift()
	{
	};

	TelSalePolicyGift( int id, const string & name, const string & defaultPrice ) : m_id( id ),
	                                                                                m_giftName( name ),
	                                                                                m_giftDefaultPrice( defaultPrice )
	{
	}

	inline int Id() const { return m_id; }
	void       Id( int val ) { m_id = val; }

	string GiftName() const { return m_giftName; }
	void   GiftName( string val ) { m_giftName = val; }

	string GiftDefaultPrice() const { return m_giftDefaultPrice; }
	void   GiftDefaultPrice( string val ) { m_giftDefaultPrice = val; }

private:
	int    m_id;
	string m_giftName;
	string m_giftDefaultPrice;
};


//************************************
// Method:    queryTelsalePolicyGifts
// FullName:  queryTelsalePolicyGifts
// Access:    public 
// Returns:   void
// Qualifier: 查询礼品信息
// Parameter: vector<TelSalePolicyGift> & giftList 礼品列表
//************************************
//void queryTelsalePolicyGifts(vector<TelSalePolicyGift> & giftList);

//************************************
// Method:    SaveTelSalePolicyInfo
// FullName:  SaveTelSalePolicyInfo
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: const SPolicyRecord & policy
// Parameter: const vector<TelSalePolicyGift> & giftList
//************************************
void SaveTelSalePolicyInfo( const SPolicyRecord & policy, const vector<TelSalePolicyGift> & giftList );

//************************************
// Method:    QueryTelSalePolicyInfo
// FullName:  QueryTelSalePolicyInfo
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: const string & strPolicyNo
// Parameter: const string & strOperatorCode
// Parameter: const string & strStartDate
// Parameter: const string & strEndDate
// Parameter: vector<SPolicyQuery> & vPolicyInfo
//************************************
void QueryTelSalePolicyInfo( const string &         strPolicyNo,
                             const string &         strOperatorCode,
                             const string &         strStartDate,
                             const string &         strEndDate,
                             vector<SPolicyQuery> & vPolicyInfo );

//************************************
// Method:    QueryPolicyGifts
// FullName:  QueryPolicyGifts
// Access:    public 
// Returns:   void
// Qualifier: 查询礼品列表，生成字符串
// Parameter: const string & strPolicyNo
// Parameter: string & strGifts
//************************************
// void QueryPolicyGifts(const string & strPolicyNo,
//                       string &       strGifts,
//                       double         dGiftPriceSum);

//void readTelsaleXlsFile( const string & strFilePath, vector<SPolicyRecord> & listPolicy, bool hasTitle, bool isXML );

void readTelsaleXlsxFile( const wstring & filePath, vector<SPolicyRecord> & listPolicy, bool hasTitle );

/************************************************
* \brief 读取xls文件的单元格内容，返回std::string
* \param pSheet xls文件的sheet对象指针
* \param iRowIndex 行索引
* \param iColIndex 列索引
* \return 返回读取的单元格内容，以std::string为载体
************************************************/
string readXlsCell( ISheetT<char> * pSheet, int iRowIndex, int iColIndex );

/************************************************
* \brief 读取xlsx文件的单元格内容，返回std::string
* \param pSheet xlsx文件的sheet对象指针
* \param iRowIndex 行索引
* \param iColIndex 列索引
* \return 返回读取的单元格内容，以std::string为载体
************************************************/
string readXlsxCell( ISheetT<wchar_t> * pSheet, int iRowIndex, int iColIndex );

#endif // DataManipulation_h__
