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 SettingCRUD : Aram_CRM_Project.DAL.DA
    {

        public int UpdateSetting(Setting SettingVar)
        {
            try
            {
                base.SQL = "SP_UpdateSetting";
                base.InitializeCommand();
                base.AddParameter("@ReserveComment", SettingVar.ReserveComment);
                base.AddParameter("@OrderComment", SettingVar.OrderComment);
                base.AddParameter("@ByteArray", SettingVar.ByteArray);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public Setting ReadSetting()
        {
            try
            {
                DataTable dtTemp = new DataTable();
                Setting SettingVar = new Setting();

                base.SQL = "SP_ReadSetting";
                base.InitializeCommand();
                base.FillDataTable(dtTemp);
                //=dtTemp.Rows[0][""].ToString();
                SettingVar.ReserveComment = dtTemp.Rows[0]["ReserveComment"].ToString();
                SettingVar.OrderComment = dtTemp.Rows[0]["OrderComment"].ToString();
                if (dtTemp.Rows[0]["PicBill"].ToString() != "")
                    SettingVar.ByteArray = (byte[])dtTemp.Rows[0]["PicBill"];
                dtTemp.Dispose();
                return SettingVar;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable ReadSettingForReport()
        {
            try
            {
                DataTable dtTemp = new DataTable();

                base.SQL = "SP_ReadSetting";
                base.InitializeCommand();
                base.FillDataTable(dtTemp);
                return dtTemp;
                
            }
            catch (Exception exp)
            {
                return null;
            }
        }
    }
}
