using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlServerCe;
using SinosysHardware.DataAccess;
using System.IO;
namespace SinosysHardware.Business
{
    class InventoryDB
    {
        public  int InventoryId;
        public  string InventoryName;
        public  byte[] Picture;
        public  decimal Price;
        public  int InStock;
        public MemoryStream Ms;

     

       
        public MemoryStream PictureAsStream()
        {
           
                Ms = new MemoryStream(Picture);
                return Ms;
            
        }

        /// <summary>
        /// Retrieve Inventory objects
        /// </summary>
        /// <returns></returns>
        public  DataSet GetInventory()
        {
            string Sql = "SELECT InventoryId, Name, Picture, Price, InStock FROM Inventory";
            HelperDB hdb = new HelperDB();
            DataSet Ds = hdb.GetDataSet(Sql, "Inventory");
            return Ds;

        }

      

        public DataSet GetInventory(int inventoryid)
        {
            string Sql = "SELECT * FROM Inventory where InventoryId=@Inventoryid";
            SqlCeParameter paras = new SqlCeParameter("@Inventoryid", inventoryid);
            HelperDB hdb = new HelperDB();
            DataSet Ds = hdb.GetDataSet(Sql, "Inventory", paras);
            return Ds;
        }
        /// <summary>
        /// Update the amount of Inventory items in stock
        /// </summary>
        /// <param name="inventoryId"></param>
        /// <param name="inStock"></param>
        public void UpdateInStockAmount(int inventoryId, int inStock)
        {
            string Sql = "UPDATE Inventory SET InStock = @InStock WHERE InventoryId = @InventoryId";
            SqlCeParameter[] paras = new SqlCeParameter[2];
            paras[0] = new SqlCeParameter("@InStock", inStock);
            paras[1] = new SqlCeParameter("@InventoryId",inventoryId);
            HelperDB hdb = new HelperDB();
            hdb.ExcuteSql(Sql, paras);
        }


        /// <summary>
        /// Get the price of an Inventory item
        /// </summary>
        /// <param name="inventoryId"></param>
        /// <returns></returns>
        public  decimal GetPrice(int inventoryId)
        {
            string Sql = "SELECT Price from Inventory WHERE InventoryId = @InventoryId";
            SqlCeParameter p = new SqlCeParameter("@InventoryId", inventoryId);
            HelperDB hdb = new HelperDB();
            return (decimal)hdb.ExcuteScale(Sql, p);
        }

    }
}
