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

#include "stdafx.h"

//	Indicator variables for Frame1 
//
typedef struct TIndicatorTUFrame1
{	
	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_price_ind;

	SQLINTEGER		trade_history_dts_ind[TPCE::TradeUpdateMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_history_status_id_ind[TPCE::TradeUpdateMaxTradeHistoryRowsReturned];
} *PIndicatorTUFrame1;

//	Indicator variables for Frame2 
//
typedef struct TIndicatorTUFrame2
{		
	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::TradeUpdateMaxTradeHistoryRowsReturned];
	SQLINTEGER		trade_history_status_id_ind[TPCE::TradeUpdateMaxTradeHistoryRowsReturned];
} *PIndicatorTUFrame2;

//	Indicator variables for Frame3 
//
typedef struct TIndicatorTUFrame3
{		
	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			s_name_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			type_name_ind;

	SQLINTEGER			trade_history_dts_ind[TPCE::TradeUpdateMaxTradeHistoryRowsReturned];
	SQLINTEGER			trade_history_status_id_ind[TPCE::TradeUpdateMaxTradeHistoryRowsReturned];
} *PIndicatorTUFrame3;


class CTradeUpdateDB : public CTxnHarnessDBBase, public TPCE::CTradeUpdateDBInterface
{
	SQLHSTMT					m_hstmtFrame1;
	SQLHSTMT					m_hstmtFrame2;
	SQLHSTMT					m_hstmtFrame3;	

	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;

	TPCE::TTradeUpdateFrame1Input	Frame1Input;
	TPCE::TTradeUpdateFrame1Output	Frame1Output;
	TPCE::TTradeUpdateFrame2Input	Frame2Input;
	TPCE::TTradeUpdateFrame2Output	Frame2Output;
	TPCE::TTradeUpdateFrame3Input	Frame3Input;
	TPCE::TTradeUpdateFrame3Output	Frame3Output;
	
	//TIndicatorTUFrame1			Frame1Ind[TradeUpdateFrame1MaxRows];
	//TIndicatorTUFrame2			Frame2Ind[TradeUpdateFrame2MaxRows];
	//TIndicatorTUFrame3			Frame3Ind[TradeUpdateFrame3MaxRows];

	SQLUINTEGER					m_BindOffsetFrame1Col1;
	SQLUINTEGER					m_BindOffsetFrame1Col2;
	SQLUINTEGER					m_BindOffsetFrame2Col1;
	SQLUINTEGER					m_BindOffsetFrame2Col2;
	SQLUINTEGER					m_BindOffsetFrame3Col1;
	SQLUINTEGER					m_BindOffsetFrame3Col2;

	void InitFrame1();
	void InitFrame2();
	void InitFrame3();	

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

	void DoTradeUpdateFrame1(   const TPCE::TTradeUpdateFrame1Input*    pFrame1Input, 
                                TPCE::PTradeUpdateFrame1Output          pFrame1Output);

	void DoTradeUpdateFrame2(   const TPCE::TTradeUpdateFrame2Input*    pFrame2Input,
                                TPCE::PTradeUpdateFrame2Output          pFrame2Output);

	void DoTradeUpdateFrame3(   const TPCE::TTradeUpdateFrame3Input*    pFrame3Input,
                                TPCE::PTradeUpdateFrame3Output          pFrame3Output);

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