using System;
using System.Data;
using Advantage.Data.Provider;
using System.Collections;
namespace AEPDemoCS
{
public class aep_procedures
{
// Declare a collection of objects that can be used to store state information
private static Hashtable colClientInfo = new Hashtable();
public aep_procedures()
{
}
// This is the AEP startup function. This is called the first time an Advantage
// connection calls a procedure in this AEP module. It is called once for each
// Advantage connection that calls a procedure in this module.
// Do any per-connection initialization here. Use the ulConnectionID as a
// unique identifier for each connection.
public Int32 Startup(Int32 ulConnectionID,
Int64 hConnection)
{
StateInfo oStateInfo = new StateInfo("ConnectionHandle=" + hConnection.ToString());
try
{
// Store the connection ID
oStateInfo.ConnID = ulConnectionID;
// Open the connection, which was passed the active ACE connection hConnection
oStateInfo.DataConn.Open();
// Place this client state info into our collection. Use a synclock, as there might be other
// threads accessing colClientInfo right now
lock (colClientInfo)
{
colClientInfo.Add(ulConnectionID, oStateInfo);
}
}
catch (Exception e)
{
IDbCommand oErrCommand = oStateInfo.DataConn.CreateCommand();
// Handle any exceptions here. Errors can be returned by placing a
// row into the __error table.
oErrCommand.CommandText = "INSERT INTO __error VALUES( 1, '" + e.Message + "' )";
oErrCommand.ExecuteNonQuery();
}
// Result is currently reserved and not used. Always return zero.
return 0;
} // Startup
// This is the AEP shutdown function. This is called once for each Advantage
// connection that has called a procedure in this module, and is called when
// the connection is terminating.
// The prototype must be exactly as it is in the example.
// Do your per-connection clean-up here. Use the ulConnectionID as a
// unique identifier for each connection.
public Int32 Shutdown(Int32 ulConnectionID,
Int64 hConnection)
{
StateInfo oStateInfo;
// Get this clients state information before doing anything
lock (colClientInfo)
{
oStateInfo = (StateInfo)(colClientInfo[ulConnectionID]);
oStateInfo.DataConn.Close();
// free the clients state information
colClientInfo.Remove(ulConnectionID);
}
return 0;
} // Shutdown
public Int32 Get10Percent(Int32 ulConnectionID,
Int32 hConnection,
ref Int32 ulNumRowsAffected)
{
StateInfo oStateInfo;
AdsCommand oCommand;
Int32 custID;
Int32 recCount;
lock( colClientInfo )
oStateInfo = (StateInfo)(colClientInfo[ulConnectionID]);
try
{
oCommand = oStateInfo.DataConn.CreateCommand();
oCommand.CommandText = "SELECT CustID FROM __input";
custID = Convert.ToInt32(oCommand.ExecuteScalar());
oCommand.CommandText = "SELECT Count(*) " +
"FROM INVOICE "+
"WHERE [Customer ID] = :cust;";
oCommand.Parameters.Add("cust", System.Data.DbType.Int32).Value = custID;
recCount = Convert.ToInt32(oCommand.ExecuteScalar());
if (recCount < 10)
{
oCommand.CommandText = "INSERT INTO __error "+
"VALUES ( 2501, 'There are less than 10 " +
"records for " + custID.ToString();
oCommand.ExecuteNonQuery();
return 0;
}
oCommand.CommandText = "INSERT INTO __output " +
"SELECT TOP 10 PERCENT [Invoice No] " +
"FROM INVOICE WHERE [Customer ID] = " + custID.ToString();
oCommand.ExecuteNonQuery();
}
catch( Exception e )
{
IDbCommand oErrCommand =
oStateInfo.DataConn.CreateCommand();
oErrCommand.CommandText = "INSERT INTO __error "+
"VALUES( 1, '" + e.Message + "' )";
oErrCommand.ExecuteNonQuery();
}
return 0;
} // Get10Percent
// Do not change or remove this function. It is used internally by the Advantage server
public Int32 GetInterfaceVersion()
{
return 3;
} // GetInterfaceVersion
} // aep_procedures
public class StateInfo
{
public Int32 ConnID;
public AdsConnection DataConn;
public StateInfo(String ConnString)
{
DataConn = new AdsConnection(ConnString);
}
}
} // AEPDemoCS
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Timm Sodtalbers and 43 guests