using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Aram_CRM_Project.BLL.Entity;


namespace Aram_CRM_Project.BLL
{
    class StuffGroupCRUD : Aram_CRM_Project.DAL.DA
    {
        public int InsertStuffGroup(StuffGroup StuffGroupVar)
        {
            try
            {
                base.SQL = "SP_InsertStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Name", StuffGroupVar.Name);
                base.AddParameter("@Comment", StuffGroupVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public int UpdateStuffGroup(StuffGroup StuffGroupVar)
        {
            try
            {
                base.SQL = "SP_UpdateStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Id", StuffGroupVar.Id);
                base.AddParameter("@Name", StuffGroupVar.Name);
                base.AddParameter("@Comment", StuffGroupVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public int DeleteStuffGroup(string Id)
        {
            try
            {
                base.SQL = "SP_DeleteStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Id", Id);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("COLUMN REFERENCE"))
                    return -1;
                else
                    return 0;
            }
        }

        public StuffGroup ReadStuffGroup(string Id)
        {
            try
            {
                StuffGroup StuffGroupVar = new StuffGroup();
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_ReadStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Id", Id);
                base.FillDataTable(dtTemp);
                StuffGroupVar.Id = dtTemp.Rows[0]["Id"].ToString();
                StuffGroupVar.Name = dtTemp.Rows[0]["Name"].ToString();
                StuffGroupVar.Comment = dtTemp.Rows[0]["Comment"].ToString();
                dtTemp.Dispose();
                return StuffGroupVar;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable SearchStuffGroup(string Name)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_SearchStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Name", Name);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable ReportStuffGroup(string Name)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_ReportStuffGroup";
                base.InitializeCommand();
                base.AddParameter("@Name", Name);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

    }
}
