using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Self_Project
{
    public partial class VacationsWeek : Form
    {
        public VacationsWeek()
        {
            InitializeComponent();
        }
        Week objWeek = new Week();
        Vacation objVacation = new Vacation();
        
        private void VacationsWeek_Load(object sender, EventArgs e)
        {
            objWeek.LoadWeek();
            for (int i = objWeek.WeekNum; i <= 52; i++)
            {
                if (i < 10)
                    lst_Weeks.Items.Add("0" + i.ToString());
                else
                    lst_Weeks.Items.Add(i);
            }
            lst_Weeks.SelectedIndex = 0;
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                if (R_Vacation.Checked)
                    objVacation.WeekState = Vacation.VacationState.تعطیل;
                else
                    objVacation.WeekState = Vacation.VacationState.عادی;
                objVacation.WeekNum = Convert.ToInt16(lst_Weeks.Text);
                objVacation.SetWeekVacation();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "هفته های تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Vacation_Exceptions_WeekNum ex)
            {
                MessageBox.Show(ex.Message, "هفته تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lst_Weeks.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "هفته های تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lst_Weeks_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                objVacation.WeekNum = Convert.ToInt16(lst_Weeks.Text);
                objVacation.LoadWeekVacation();
                if (objVacation.WeekState == Vacation.VacationState.تعطیل)
                    R_Vacation.Checked = true;
                else
                    R_Normal.Checked = true;
            }
            catch (Vacation_Exceptions_WeekNum ex)
            {
                MessageBox.Show(ex.Message, "روزهای تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lst_Weeks.Focus();
            }
            catch{}
        }
    }
}