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

namespace Self_Project
{
    public class Vacation : IControlable
    {
        //=================================================================
        public enum VacationState
        {
            تعطیل, عادی
        }
        //=================================================================
        public VacationState WeekState = VacationState.عادی;
        public VacationState DayState = VacationState.عادی;
        //=================================================================
        private Int16 _weekNum;
        public Int16 WeekNum
        {
            get { return _weekNum; }
            set
            {
                if (value <= 0 || value > 52)
                    throw new Vacation_Exceptions_WeekNum();
                else
                    _weekNum = value;
            }
        }
        //=================================================================
        private string _tarikh = "";
        public string Tarikh
        {
            get { return _tarikh; }
            set 
            {
                if (value.Length != 5)
                    throw new Vacation_Exceptions_Tarikh();
                else
                    _tarikh = value;
            }
        }
        //=================================================================
        public void ControlInfo()
        {
            if (_weekNum <= 0 || _weekNum > 52)
                throw new Vacation_Exceptions_WeekNum();
            if (_tarikh.Length != 5)
                throw new Vacation_Exceptions_Tarikh();
        }
        //=================================================================
        public void SetWeekVacation()
        {
            Condition Cond = new Condition(1);
            Cond.AddCondition("WeekNum", Operatotrs.مساوی, _weekNum, Concat_Type.None);
            if (WeekState == VacationState.عادی)
                DataBase_SQL.Action(DBOperation.Delete, Cond, "VacationWeek", "");
            else
                if (DataBase_SQL.Action(DBOperation.Select, Cond, "VacationWeek", "WeekNum").Rows.Count == 0)
                    DataBase_SQL.Action(DBOperation.Insert, null, "VacationWeek", "WeekNum", _weekNum);
        }
        //=================================================================
        public void LoadWeekVacation()
        {
            Condition Cond = new Condition(1);
            Cond.AddCondition("WeekNum", Operatotrs.مساوی, _weekNum, Concat_Type.None);
            if (DataBase_SQL.Action(DBOperation.Select, Cond, "VacationWeek", "WeekNum").Rows.Count == 0)
                WeekState = VacationState.عادی;
            else
                WeekState = VacationState.تعطیل;
        }
        //=================================================================
        public void SetDayVacation()
        {
            Condition Cond = new Condition(1);
            Cond.AddCondition("Tarikh", Operatotrs.مساوی, _tarikh, Concat_Type.None);
            if (DayState == VacationState.عادی)
                DataBase_SQL.Action(DBOperation.Delete, Cond, "VacationDay", "");
            else
                if (DataBase_SQL.Action(DBOperation.Select, Cond, "VacationDay", "Tarikh").Rows.Count == 0)
                    DataBase_SQL.Action(DBOperation.Insert, null, "VacationDay", "Tarikh", _tarikh);
        }
        //=================================================================
        public void LoadDayVacation()
        {
            Condition Cond = new Condition(1);
            Cond.AddCondition("Tarikh", Operatotrs.مساوی, _tarikh, Concat_Type.None);
            if (DataBase_SQL.Action(DBOperation.Select, Cond, "VacationDay", "Tarikh").Rows.Count == 0)
                DayState = VacationState.عادی;
            else
                DayState = VacationState.تعطیل;
        }
        //=================================================================
        //=================================================================
        //=================================================================
    }
}
