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 RelationshipWayCRUD : Aram_CRM_Project.DAL.DA
    {
        public int InsertRelationshipWay(RelationshipWay RelationshipWayVar)
        {
            try
            {
                base.SQL = "SP_InsertRelationshipWay";
                base.InitializeCommand();
                base.AddParameter("@Name", RelationshipWayVar.Name);
                base.AddParameter("@StartDate", RelationshipWayVar.StartDate);
                base.AddParameter("@EndDate", RelationshipWayVar.EndDate);
                base.AddParameter("@Address", RelationshipWayVar.Address);
                base.AddParameter("@Comment", RelationshipWayVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public int UpdateRelationshipWay(RelationshipWay RelationshipWayVar)
        {
            try
            {
                base.SQL = "SP_UpdateRelationshipWay";
                base.InitializeCommand();
                base.AddParameter("@Id", RelationshipWayVar.Id);
                base.AddParameter("@Name", RelationshipWayVar.Name);
                base.AddParameter("@StartDate", RelationshipWayVar.StartDate);
                base.AddParameter("@EndDate", RelationshipWayVar.EndDate);
                base.AddParameter("@Address", RelationshipWayVar.Address);
                base.AddParameter("@Comment", RelationshipWayVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

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

        public RelationshipWay ReadRelationshipWay(string Id)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                RelationshipWay RelationshipWayVar = new RelationshipWay();
                base.SQL = "SP_ReadRelationshipWay";
                base.InitializeCommand();
                base.AddParameter("@Id", Id);
                base.FillDataTable(dtTemp);
                RelationshipWayVar.Id = dtTemp.Rows[0]["Id"].ToString();
                RelationshipWayVar.Name = dtTemp.Rows[0]["Name"].ToString();
                RelationshipWayVar.StartDate = dtTemp.Rows[0]["StartDate"].ToString();
                RelationshipWayVar.EndDate = dtTemp.Rows[0]["EndDate"].ToString();
                RelationshipWayVar.Address = dtTemp.Rows[0]["Address"].ToString();
                RelationshipWayVar.Comment = dtTemp.Rows[0]["Comment"].ToString();
                dtTemp.Dispose();
                return RelationshipWayVar;
            }
            catch(Exception exp)
            {
                return null;
            }
        }

        public DataTable SearchRelationshipWay(RelationshipWay RelationshipWayVar)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_SearchRelationshipWay";
                base.InitializeCommand();
                base.AddParameter("@Name", RelationshipWayVar.Name);
                base.AddParameter("@StartDate", RelationshipWayVar.StartDate);
                base.AddParameter("@EndDate", RelationshipWayVar.EndDate);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable ReportRelationshipWay(RelationshipWay RelationshipWayVar)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_ReportRelationshipWay";
                base.InitializeCommand();
                base.AddParameter("@Name", RelationshipWayVar.Name);
                base.AddParameter("@StartDate", RelationshipWayVar.StartDate);
                base.AddParameter("@EndDate", RelationshipWayVar.EndDate);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
    }
}
