using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Self_Project
{
    public class Week : IControlable
    {
        //=================================================================
        private Int16 _weekNum;
        public Int16 WeekNum
        {
            get { return _weekNum; }
            set 
            {
                if (value <= 0 || value > 52)
                    throw new Week_Exceptions_WeekNum();
                else
                    _weekNum = value;
            }
        }
        //=================================================================
        public void ControlInfo()
        {
            if (_weekNum <= 0 || _weekNum > 52)
                throw new Week_Exceptions_WeekNum();
        }
        //=================================================================
        public void LoadWeek()
        {
            _weekNum = Convert.ToInt16(DataBase_SQL.Action(DBOperation.Select, null, "NumberOfWeek", "Num").Rows[0][0]);
        }
        //=================================================================
        public void SetWeek()
        {
            ControlInfo();
            DataBase_SQL.Action(DBOperation.Update, null, "NumberOfWeek", "Num", _weekNum);
        }
        //=================================================================
        public String FindHafteID()
        {
            string Tarikh1, Tarikh2;
            DataTable DT = new DataTable();
            int Rooz = 0, i;
            Tarikh1 = Functions.FarsiDate("/");
            DT = DataBase_SQL.Action(DBOperation.Select, null, "HafteDetail", "Num,HafteEsm");
            for (i = 0; i < DT.Rows.Count; i++)
            {
                Tarikh2 = Tarikh1.Substring(0, 5) + DT.Rows[i][1].ToString();
                Rooz = Convert.ToInt16(Functions.Sub2Date(Tarikh1, Tarikh2));
                if (Rooz >= 0 && Rooz <= 6)
                {
                    _weekNum = Convert.ToInt16(DT.Rows[i][0]);
                    SetWeek();
                    if (Rooz == 0) return "شنبه";
                    if (Rooz == 1) return "یکشنبه";
                    if (Rooz == 2) return "دوشنبه";
                    if (Rooz == 3) return "سه شنبه";
                    if (Rooz == 4) return "چهارشنبه";
                    if (Rooz == 5) return "پنج شنبه";
                    if (Rooz == 6) return "جمعه";
                }
            }
            return "";
        }
        //=================================================================
    }
}
