/*
*	©Copyright 2002-2004, Microsoft Corporation
*	Microsoft Confidential.
*	Written by Sergey Vasilevskiy, 2002-2004.
*/
#pragma once

#include "stdafx.h"

//	Indicator variables for Frame1 
//	(because they are not in TTradeLookupFrame1Params).
//
typedef struct TIndicatorTLFrame1
{
	SQLINTEGER		trade_id_ind;	
	SQLINTEGER		bid_price_ind;
	SQLINTEGER		cash_transaction_amount_ind;
	SQLINTEGER		cash_transaction_dts_ind;
	SQLINTEGER		cash_transaction_name_ind;
	SQLINTEGER		exec_name_ind;	
	SQLINTEGER		is_cash_ind;
	SQLINTEGER		is_market_ind;
	SQLINTEGER		settlement_amount_ind;
	SQLINTEGER		settlement_cash_due_date_ind;
	SQLINTEGER		settlement_cash_type_ind;
	
	SQLINTEGER		trade_history_dts_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_history_status_id_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_price_ind;
} *PIndicatorTLFrame1;

//	Indicator variables for Frame2 
//	(because they are not in TTradeLookupFrame2Params).
//
typedef struct TIndicatorTLFrame2
{	
	SQLINTEGER		bid_price_ind;
	SQLINTEGER		cash_transaction_amount_ind;
	SQLINTEGER		cash_transaction_dts_ind;
	SQLINTEGER		cash_transaction_name_ind;
	SQLINTEGER		exec_name_ind;	
	SQLINTEGER		is_cash_ind;
	SQLINTEGER		settlement_amount_ind;
	SQLINTEGER		settlement_cash_due_date_ind;
	SQLINTEGER		settlement_cash_type_ind;	
	SQLINTEGER		trade_id_ind;	
	SQLINTEGER		trade_price_ind;
	SQLINTEGER		trade_history_dts_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_history_status_id_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
} *PIndicatorTLFrame2;

//	Indicator variables for Frame3 
//	(because they are not in TTradeLookupFrame3Params).
//
typedef struct TIndicatorTLFrame3
{	
	SQLINTEGER		holding_history_id_ind;
	SQLINTEGER		holding_history_trade_id_ind;
	SQLINTEGER		quantity_before_ind;
	SQLINTEGER		quantity_after_ind;	
} *PIndicatorTLFrame3;

//	Indicator variables for Frame4 
//	(because they are not in TTradeLookupFrame4Params).
//
typedef struct TIndicatorTLFrame4
{
	SQLINTEGER		acct_id_ind;
	SQLINTEGER		cash_transaction_amount_ind;
	SQLINTEGER		cash_transaction_dts_ind;
	SQLINTEGER		cash_transaction_name_ind;
	SQLINTEGER		exec_name_ind;
	SQLINTEGER		is_cash_ind;
	SQLINTEGER		price_ind;
	SQLINTEGER		quantity_ind;
	SQLINTEGER		settlement_amount_ind;
	SQLINTEGER		settlement_cash_due_date_ind;
	SQLINTEGER		settlement_cash_type_ind;
	SQLINTEGER		trade_dts_ind;
	SQLINTEGER		trade_id_ind;
	SQLINTEGER		trade_type_ind;
	SQLINTEGER		trade_history_dts_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_history_status_id_ind[TPCE::TradeLookupMaxTradeHistoryRowsReturned];
} *PIndicatorTLFrame4;

class CTradeLookupDB : public CTxnHarnessDBBase, public TPCE::CTradeLookupDBInterface
{		
	SQLHSTMT					m_hstmtFrame1;
	SQLHSTMT					m_hstmtFrame2;
	SQLHSTMT					m_hstmtFrame3;
	SQLHSTMT					m_hstmtFrame4;

	SQLHDESC					m_descFrame1Col1;
	SQLHDESC					m_descFrame1Col2;
	SQLHDESC					m_descFrame1Col3;
	SQLHDESC					m_descFrame2Col1;
	SQLHDESC					m_descFrame2Col2;
	SQLHDESC					m_descFrame2Col3;
	SQLHDESC					m_descFrame3Col1;
	SQLHDESC					m_descFrame3Col2;
	SQLHDESC					m_descFrame3Col3;
	SQLHDESC					m_descFrame4Col1;
	SQLHDESC					m_descFrame4Col2;
	SQLHDESC					m_descFrame4Col3;

	TPCE::TTradeLookupFrame1Input		Frame1Input;
	TPCE::TTradeLookupFrame1Output	    Frame1Output;
	TPCE::TTradeLookupFrame2Input		Frame2Input;
	TPCE::TTradeLookupFrame2Output	    Frame2Output;
	TPCE::TTradeLookupFrame3Input		Frame3Input;
	TPCE::TTradeLookupFrame3Output	    Frame3Output;
	TPCE::TTradeLookupFrame4Input		Frame4Input;
	TPCE::TTradeLookupFrame4Output	    Frame4Output;

	//TIndicatorTLFrame1			Frame1Ind[TradeLookupFrame1MaxRows];
	//TIndicatorTLFrame2			Frame2Ind[TradeLookupFrame2MaxRows];
	//TIndicatorTLFrame3			Frame3Ind[TradeLookupFrame3MaxRows];
	//TIndicatorTLFrame4			Frame4Ind[TradeLookupFrame4MaxRows];

	SQLUINTEGER					m_BindOffsetFrame1Col1;
	SQLUINTEGER					m_BindOffsetFrame1Col2;
	SQLUINTEGER					m_BindOffsetFrame2Col1;
	SQLUINTEGER					m_BindOffsetFrame2Col2;
	SQLUINTEGER					m_BindOffsetFrame3Col1;
	SQLUINTEGER					m_BindOffsetFrame3Col2;
	SQLUINTEGER					m_BindOffsetFrame4Col1;
	SQLUINTEGER					m_BindOffsetFrame4Col2;
	
	void InitFrame1();
	void InitFrame2();
	void InitFrame3();
	void InitFrame4();

public:
	CTradeLookupDB(CDBConnection *pDBConn);
	~CTradeLookupDB();

	void DoTradeLookupFrame1(   const TPCE::TTradeLookupFrame1Input*    pFrame1Input, 
                                TPCE::PTradeLookupFrame1Output          pFrame1Output);

	void DoTradeLookupFrame2(   const TPCE::TTradeLookupFrame2Input*    pFrame2Input, 
                                TPCE::PTradeLookupFrame2Output          pFrame2Output);

	void DoTradeLookupFrame3(   const TPCE::TTradeLookupFrame3Input*    pFrame3Input,
                                TPCE::PTradeLookupFrame3Output          pFrame3Output);

	void DoTradeLookupFrame4(   const TPCE::TTradeLookupFrame4Input*    pFrame4Input, 
                                TPCE::PTradeLookupFrame4Output          pFrame4Output);

	// Function to pass any exception thrown inside
	// database class frame implementation
	// back into the database class
	void Cleanup(void* pException);
};
