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 VacationsDay : Form
    {
        public VacationsDay()
        {
            InitializeComponent();
        }
        Vacation objVacation = new Vacation();

        private void VacationsDay_Load(object sender, EventArgs e)
        {
            try
            {
                lst_Month.SelectedIndex = 0;
            }
            catch { }
            lst_Day.SelectedIndex = 0;
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                if (lst_Month.SelectedIndex < 9)
                    objVacation.Tarikh = "0" + (lst_Month.SelectedIndex + 1).ToString() + "/" + lst_Day.Text;
                else
                    objVacation.Tarikh = (lst_Month.SelectedIndex + 1).ToString() + "/" + lst_Day.Text;
                if (R_Vacation.Checked)
                    objVacation.DayState = Vacation.VacationState.تعطیل;
                else
                    objVacation.DayState = Vacation.VacationState.عادی;

                objVacation.SetDayVacation();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "روزهای تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Vacation_Exceptions_Tarikh ex)
            {
                MessageBox.Show(ex.Message, "روزهای تعطیل", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lst_Day.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_Day_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lst_Month.SelectedIndex < 9)
                objVacation.Tarikh = "0" + (lst_Month.SelectedIndex + 1).ToString() + "/" + lst_Day.Text;
            else
                objVacation.Tarikh = (lst_Month.SelectedIndex + 1).ToString() + "/" + lst_Day.Text;
            objVacation.LoadDayVacation();
            if (objVacation.DayState == Vacation.VacationState.تعطیل)
                R_Vacation.Checked = true;
            else
                R_Normal.Checked = true;
        }

        private void lst_Month_SelectedIndexChanged(object sender, EventArgs e)
        {
            lst_Day_SelectedIndexChanged(null, null);
        }
    }
}