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 FMSStore_DB
{
   public class ShoppingCart : System.IDisposable
   {
      bool _disposed = false;
      private const string m_modName = "FMSStore_DB.ShoppingCart";
      // Declare the DBHelper Object--see class initialization
      private FMStocks_DB.DBHelper m_dbh = null;
      public ShoppingCart() : base()
      {
         Class_Initialize();
      }
      private void Class_Initialize()
      {
         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 void Add(int AccountID,int SKU,int Quantity)
      {

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

            m_dbh.RunSP("ShoppingCart_Add",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU),FMStocks_DB.Helpers.mp("@Quantity",System.Data.SqlDbType.Int,2,Quantity)},String.Empty);

            return;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"Add(" + AccountID + ")",String.Empty,0,false);
         }
      }
      public gmRTL.DataLib.SqlClient.Recordset GetByKey(int AccountID,int SKU)
      {
         gmRTL.DataLib.SqlClient.Recordset GetByKey = default;

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

            GetByKey = m_dbh.RunSPReturnRS("ShoppingCart_GetByKey",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU)},String.Empty);

            return GetByKey;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"GetByKey(" + AccountID + "," + SKU + ")",String.Empty,0,false);
         }
         return GetByKey;
      }
      public gmRTL.DataLib.SqlClient.Recordset ListByAccount(int AccountID)
      {
         gmRTL.DataLib.SqlClient.Recordset ListByAccount = default;

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

            ListByAccount = m_dbh.RunSPReturnRS("ShoppingCart_ListByAccount",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty);

            return ListByAccount;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"ListByAccount(" + AccountID + ")",String.Empty,0,false);
         }
         return ListByAccount;
      }
      public void Modify(int AccountID,int SKU,int Quantity)
      {

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

            m_dbh.RunSP("ShoppingCart_Modify",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU),FMStocks_DB.Helpers.mp("@Quantity",System.Data.SqlDbType.Int,2,Quantity)},String.Empty);

            return;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"Modify(" + AccountID + "," + SKU + "," + Quantity + ")",String.Empty,0,false);
         }
      }
      public void Remove(int AccountID,int SKU)
      {
         try
         {
            gmRTL.Core.GlobalException.Clear();

            m_dbh.RunSP("ShoppingCart_Remove",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU)},String.Empty);

            return;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"Remove(" + AccountID + "," + SKU + ")",String.Empty,0,false);
         }
      }
      public void RemoveAll(int AccountID)
      {
         try
         {
            gmRTL.Core.GlobalException.Clear();

            m_dbh.RunSP("ShoppingCart_RemoveAll",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty);

            return;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"RemoveAll(" + AccountID + ")",String.Empty,0,false);
         }
      }
      public gmRTL.DataLib.SqlClient.Recordset TotalByAccount(int AccountID)
      {
         gmRTL.DataLib.SqlClient.Recordset TotalByAccount = default;

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

            TotalByAccount = m_dbh.RunSPReturnRS("ShoppingCart_TotalByAccount",new object[]{FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty);

            return TotalByAccount;

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

            FMStocks_DB.Helpers.RaiseError(m_modName,"TotalByAccount(" + AccountID + ")",String.Empty,0,false);
         }
         return TotalByAccount;
      }
   }
}
