using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data;
using VBNET = Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Linq;
using System.Collections.Generic;

namespace FMStocks_DB
{
   public class Tx : System.IDisposable
   {
      bool _disposed = false;
      private const string m_modName = "FMStocks_DB.Tx";
      private DBHelper m_dbh = null;
      public Tx() : base()
      {
         Class_Initialize();
      }
      private void Class_Initialize()
      {
         // must call CreateObject or COM+ will
         // not call IObjectConstructor inferface that DBHelper needs
         m_dbh = new FMStocks_DB.DBHelper();
      }
      public void Dispose()
      {
         Dispose(true);
         GC.SuppressFinalize(this);
      }
      protected virtual void Dispose(bool disposing)
      {
         if (_disposed)
         {
            return;
         }
         if (disposing)
         {
            Class_Terminate();
         }
         _disposed = true;
      }
      private void Class_Terminate()
      {
         m_dbh = null;
      }
      public gmRTL.DataLib.SqlClient.Recordset GetByID(int TxID)
      {
         gmRTL.DataLib.SqlClient.Recordset GetByID = default;

         try
         {
            gmRTL.Core.GlobalException.Clear();

            GetByID = m_dbh.RunSPReturnRS("Tx_GetByID",new object[]{Helpers.mp("@TxID",System.Data.SqlDbType.Int,4,TxID)},String.Empty);

            return GetByID;

         }
         catch(System.Exception exc)
         {
            gmRTL.Core.GlobalException.Initialize(exc);

            Helpers.RaiseError(m_modName,"GetByID(" + TxID + ")","",0,false);
         }
         return GetByID;
      }
      public int AddSellOrder(int AccountID,string Ticker,int Shares)
      {
         int AddSellOrder = 0;



         try
         {
            gmRTL.Core.GlobalException.Clear();

            AddSellOrder = m_dbh.RunSPReturnInteger("Tx_AddSellOrder",new object[]{Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker),Helpers.mp("@Shares",System.Data.SqlDbType.Int,4,Shares)},String.Empty);


            return AddSellOrder;

         }
         catch(System.Exception exc)
         {
            gmRTL.Core.GlobalException.Initialize(exc);

            Helpers.RaiseError(m_modName,"AddSellOrder(" + AccountID + "," + Ticker + "," + Shares + ")","",0,false);
         }
         return AddSellOrder;
      }
      public int AddBuyOrder(int AccountID,string Ticker,int Shares)
      {
         int AddBuyOrder = 0;


         try
         {
            gmRTL.Core.GlobalException.Clear();

            AddBuyOrder = m_dbh.RunSPReturnInteger("Tx_AddBuyOrder",new object[]{Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker),Helpers.mp("@Shares",System.Data.SqlDbType.Int,4,Shares)},String.Empty);


            return AddBuyOrder;

         }
         catch(System.Exception exc)
         {
            gmRTL.Core.GlobalException.Initialize(exc);

            Helpers.RaiseError(m_modName,"AddBuyOrder(" + AccountID + "," + Ticker + "," + Shares + ")","",0,false);
         }
         return AddBuyOrder;
      }
   }
}
