<!-- #include file="Encoder.asp" -->	

<%
Server.ScriptTimeout=900
Session.Timeout=300

'*****************************************************
' CAUTION: 	THIS PAGE CONTAINS NO VARIABLE TO BE MODIFIED BY USER
' 			DO NOT MAKE ANY CHANGE IN CODE BELOW
'*****************************************************
Dim DBIP
DBIP = ""
DBIP= g_PARAM_HASH("DBIP")

Dim DBName
DBName = ""
DBName= g_PARAM_HASH("DBName")

Dim DBUID
DBUID= ""
DBUID= g_PARAM_HASH("DBUID")

Dim DBPWD
DBPWD= ""
DBPWD= g_PARAM_HASH("DBPWD")

Dim sDBDSNBit
sDBDSNBit = ""
sDBDSNBit = g_PARAM_HASH("DBDSNBit")

Dim sReqHeader
sReqHeader = ""
sReqHeader = g_PARAM_HASH("reqheader")

Dim sCmdType,sProCli,sGroupId,sUserId,sMktSegId,sFrmDt,sToDt,sValidityType,sCurrPg,sRecCount,sGTDOrderId,sCurrDt

sCmdType		= ""
sProCli			= ""
sGroupId		= ""
sUserId			= ""
sMktSegId		= ""
sFrmDt			= ""
sToDt			= ""
sValidityType	= ""
sCurrPg			= ""
sRecCount		= ""
sGTDOrderId		= ""
sCurrDt			= ""

sCmdType		= g_PARAM_HASH("cmd")
sProCli			= g_PARAM_HASH("procli")
sGroupId		= g_PARAM_HASH("gid")
sUserId			= g_PARAM_HASH("uid")
sMktSegId		= g_PARAM_HASH("mktseg")
sFrmDt			= g_PARAM_HASH("from")
sToDt			= g_PARAM_HASH("to")
sValidityType	= g_PARAM_HASH("validity")
sCurrPg			= g_PARAM_HASH("pg")
sRecCount		= g_PARAM_HASH("cnt")
sGTDOrderId		= g_PARAM_HASH("oid")
sCurrDt			= g_PARAM_HASH("dt")

Dim SqlString, sHeaderString
'*****************************************************
' DATABASE SETTINGS AND FUNCTIONALITY
'*****************************************************

Dim DataConn, DSN_STRINGNEW

If sDBDSNBit = "1" Then
DSN_STRINGNEW = "DRIVER={MySQL ODBC 5.3 ANSI Driver};Server="&DBIP&";Port=3306;Database="&DBName&";Uid="&DBUID&";Pwd="&DBPWD&";OPTION=3"
Else
DSN_STRINGNEW = "Driver={SQL Server};SERVER="&DBIP&";Database="&DBName&";Uid="&DBUID&";Pwd="&DBPWD&";Connect Timeout=900;"
End If

Set DataConn = Server.CreateObject("ADODB.Connection")

DataConn.ConnectionTimeout=900
DataConn.Open DSN_STRINGNEW
DataConn.CommandTimeout=900

If sCmdType = "1" Then
	SqlString = "Exec stp_GTDOrderBook "&sProCli&","&sGroupId&","&sUserId&","&sMktSegId&",'"&sFrmDt&"','"&sToDt&"',"&sValidityType&","&sCurrPg&","&sRecCount
	
	If sReqHeader = "1" Then
		sHeaderString = "Id~L~25#Date~L~140#Order Entry Time~L~120#GTD Order Id~L~150#Exchange~L~80#Symbol~L~80#Series~L~50#Buy/Sell~L~40#Total Quantity~L~100#Price~R~80#GTD Order Status~L~100#Status~L~100#Quantity Open~L~50#Quantity Executed~L~50#Prev Traded Quantity~L~50##"
	Else
		sHeaderString = "##"
	End If
	
ElseIf sCmdType = "2" Then
	SqlString = "Exec stp_GTDOrderSummery '"&sGTDOrderId&"',"&sCurrPg&","& sRecCount
	
	If sReqHeader = "1" Then
		sHeaderString = "Id~L~25#Date~L~140#Order Entry Time~L~120#GTD Order Id~L~150#Exchange Order Number~L~100#Cli Order Number~L~100#Exchange~L~80#Symbol~L~80#Series~L~50#Buy/Sell~L~40#Total Quantity~L~100#Price~R~80#GTD Order Status~L~100#Status~L~100#Quantity Open~L~50#Quantity Executed~L~50#Prev Traded Quantity~L~50##"
	Else
		sHeaderString = "##"
	End If
	
ElseIf sCmdType = "3" Then
	SqlString = "Exec stp_GTDOrderDetail '"&sGTDOrderId&"','"&sCurrDt&"',"&sCurrPg&","&sRecCount
	
	If sReqHeader = "1" Then
		sHeaderString = "Id~L~25#User Id~L~60#Group~L~50#Exchange~L~80#Member Id~L~80#Trader Id~L~80#Instrument Type~L~50#Instrument Name~L~80#Code~L~80#Symbol~L~80#Series~L~50#Strike Price~L~80#Option Type~L~80#Order Type~L~80#Buy/Sell~L~50#Total Quantity~L~50#Quantity Open~L~50#Quantity Executed~L~50#Price~L~100#PRO/CLI~L~50#Client~L~80#Exchange Order Number~L~100#Cli Order Number~L~100#Time~L~140#Settlor~L~80#User Remarks~L~160#Part Type~L~80#Validity~L~80#Good Till Date~L~140#Status~L~50#Reason~L~80##"
	Else
		sHeaderString = "##"
	End If
Else
	SqlString = ""
End If

'Response.Write(SqlString)

Dim sId,sDate,sOrderEntryTime,strGTDOrderId,sExchange,sSymbol,sSeries,sBuySell
Dim sTotalQuantity,sPrice,sGTDOrderStatus,sStatus,sQtyOpen,sQtyExecuted,sQtyExpCancelled,sTotalCount

Dim sExchangeOrderNumber,sCliOrderNumber

Dim sUId,sGroup,sMemberId,sTraderId,sInstType,sInstName,sCode,sStrikePrice
Dim sOptionType,sOrderType,strProCli,sClient
Dim sTime,sSettlor,sUserRemarks,sPartType,sValidity,sGoodTillDate,sReason
Dim sQtyTotal

If SqlString <> "" Then
	Response.Write(sHeaderString)
	set recset = DataConn.Execute(SqlString)

	do while not recset.eof
		' Input	************************************************************* Start
		If sCmdType = "1" Or sCmdType = "2" Then
			sId						=	recset.Fields("Id")
			sDate                   =	recset.Fields("Date")
			sOrderEntryTime         =	recset.Fields("Order Entry Time")
			strGTDOrderId           =	recset.Fields("GTD Order ID")
			sExchange               =	recset.Fields("Exchange")
			sSymbol                 =	recset.Fields("Symbol")
			sSeries                 =	recset.Fields("Series")
			sBuySell                =	recset.Fields("Buy/Sell")
			sTotalQuantity          =	recset.Fields("Total Quantity")
			sPrice                  =	recset.Fields("Price")
			sGTDOrderStatus         =	recset.Fields("GTD Order Status")
			sStatus                 =	recset.Fields("Status")
			sQtyOpen                =	recset.Fields("Quantity Open")
			sQtyExecuted            =	recset.Fields("Quantity Executed")
			sQtyExpCancelled        =	recset.Fields("Prev Traded Quantity")
			sTotalCount             =	recset.Fields("TotalCount")
		ElseIf sCmdType = "3" Then
			sId						=	recset.Fields("Id")
			sUId					=	recset.Fields("User Id")
			sGroup					=	recset.Fields("Group")
			sExchange				=	recset.Fields("Exchange")
			sMemberId				=	recset.Fields("Member Id")
			sTraderId				=	recset.Fields("Trader Id")
			sInstType				=	recset.Fields("Instrument Type")
			sInstName				=	recset.Fields("Instrument Name")
			sCode					=	recset.Fields("Code")
			sSymbol					=	recset.Fields("Symbol")
			sSeries					=	recset.Fields("Series")
			sStrikePrice			=	recset.Fields("Strike Price")
			sOptionType				=	recset.Fields("Option Type")
			sOrderType				=	recset.Fields("Order Type")
			sBuySell 				= 	recset.Fields("Buy/Sell")
			sQtyTotal				=	recset.Fields("Total Quantity")
			sQtyOpen				=	recset.Fields("Quantity Open")
			sQtyExecuted			=  	recset.Fields("Quantity Executed")
			sPrice					=	recset.Fields("Price")
			strProCli				=	recset.Fields("PRO/CLI")
			sClient					=	recset.Fields("Client")
			sExchangeOrderNumber	=	recset.Fields("Exchange Order Number")
			sCliOrderNumber			=	recset.Fields("Cli Order Number")
			sTime					=	recset.Fields("Time")
			sSettlor				=	recset.Fields("Settlor")
			sUserRemarks			=	recset.Fields("User Remarks")
			sPartType				=	recset.Fields("Part Type")
			sValidity				=	recset.Fields("Validity")
			sGoodTillDate			=	recset.Fields("Good Till Date")
			sStatus					=	recset.Fields("Status")
			sReason					=	recset.Fields("Reason")
			sTotalCount				=	recset.Fields("TotalCount")
		Else
			' Do Nothing
		End If
		' Input	************************************************************* End
		
		'Print to output page *********************************************** Start
		If sCmdType = "1" Then
		
			Response.Write( sTotalCount&"#"&sId&"#"&sDate&"#"&sOrderEntryTime&"#"&strGTDOrderId&"#"&sExchange&"#"&sSymbol&"#"&sSeries&"#"&sBuySell&"#"&sTotalQuantity&"#"&sPrice&"#"&sGTDOrderStatus&"#"&sStatus&"#"&sQtyOpen&"#"&sQtyExecuted&"#"&sQtyExpCancelled&"##")
			
		ElseIf sCmdType = "2" Then
		
			sExchangeOrderNumber        =	recset.Fields("Exchange Order Number")
			sCliOrderNumber             =	recset.Fields("Client Order Number")
			
			Response.Write( sTotalCount&"#"&sId&"#"&sDate&"#"&sOrderEntryTime&"#"&strGTDOrderId&"#"&sExchangeOrderNumber&"#"&sCliOrderNumber&"#"&sExchange&"#"&sSymbol&"#"&sSeries&"#"&sBuySell&"#"&sTotalQuantity&"#"&sPrice&"#"&sGTDOrderStatus&"#"&sStatus&"#"&sQtyOpen&"#"&sQtyExecuted&"#"&sQtyExpCancelled&"##")
			
		ElseIf sCmdType = "3" Then
		
			Response.Write( sTotalCount&"#"&sId&"#"&sUId&"#"&sGroup&"#"&sExchange&"#"&sMemberId&"#"&sTraderId&"#"&sInstType&"#"&sInstName&"#"&sCode&"#"&sSymbol&"#"&sSeries&"#"&sStrikePrice&"#"&sOptionType&"#"&sOrderType&"#"&sBuySell&"#"&sQtyTotal&"#"&sQtyOpen&"#"&sQtyExecuted&"#"&sPrice&"#"&strProCli&"#"&sClient&"#"&sExchangeOrderNumber&"#"&sCliOrderNumber&"#"&sTime&"#"&sSettlor&"#"&sUserRemarks&"#"&sPartType&"#"&sValidity&"#"&sGoodTillDate&"#"&sStatus&"#"&sReason&"##" )
			
		Else
			' Do Nothing
		End If
		'Print to output page *********************************************** End
		
		recset.movenext
	loop
	
Else

End If

DataConn.Close
%>