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 ManageFoodName : Form
    {
        public ManageFoodName()
        {
            InitializeComponent();
        }
        Food objFood = new Food();
        int Radif_BreakFast = -1, Radif_Launch = -1, Radif_Dinner = -1;
        string Name_BreakFast = "*", Name_Launch = "*", Name_Dinner = "*";
        private void btn_Insert_Breakast_Click(object sender, EventArgs e)
        {
            //--------------------------------
            try
            {
                objFood.FoodType = Food.FoodTypes.صبحانه;
                objFood.FoodName = txt_Insert_Breakfast.TEXT;
                objFood.Create();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Insert_Breakfast.TEXT = "";
                txt_Insert_Breakfast.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Breakfast.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Breakfast.Focus();
            }
        }

        private void btn_Insert_Launch_Click(object sender, EventArgs e)
        {
            try
            {
                objFood.FoodType = Food.FoodTypes.نهار;
                objFood.FoodName = txt_Insert_Launch.TEXT;
                objFood.Create();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Insert_Launch.TEXT = "";
                txt_Insert_Launch.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Launch.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Launch.Focus();
            }
        }

        private void btn_Insert_Dinner_Click(object sender, EventArgs e)
        {
            try
            {
                objFood.FoodType = Food.FoodTypes.شام;
                objFood.FoodName = txt_Insert_Dinner.TEXT;
                objFood.Create();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Insert_Dinner.TEXT = "";
                txt_Insert_Dinner.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Dinner.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Insert_Launch.Focus();
            }
        }

        private void ManageFoodName_Load(object sender, EventArgs e)
        {
            objFood.ShowFoodNames(Food.FoodTypes.صبحانه, lst_Update_Breackfast);
            objFood.ShowFoodNames(Food.FoodTypes.نهار, lst_Update_Launch);
            objFood.ShowFoodNames(Food.FoodTypes.شام, lst_Update_Dinner);
        }

        private void lst_Update_Breackfast_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Radif_BreakFast = Convert.ToInt32(lst_Update_Breackfast.SelectedValue);
            }
            catch { return; }
            //-----------------------------------------------------
            Name_BreakFast = txt_Update_Breackfast.TEXT = lst_Update_Breackfast.Text.ToString();
        }

        private void lst_Update_Launch_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Radif_Launch = Convert.ToInt32(lst_Update_Launch.SelectedValue);
            }
            catch { return; }
            //-----------------------------------------------------
            Name_Launch = txt_Update_Launch.TEXT = lst_Update_Launch.Text.ToString();
        }

        private void lst_Update_dinner_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Radif_Dinner = Convert.ToInt32(lst_Update_Dinner.SelectedValue);
            }
            catch { return; }
            //-----------------------------------------------------
            Name_Dinner = txt_Update_Dinner.TEXT = lst_Update_Dinner.Text.ToString();
        }

        private void btn_Update_Breackfast_Click(object sender, EventArgs e)
        {
            if (txt_Update_Breackfast.TEXT == Name_BreakFast)
            {
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Breackfast.TEXT = "";
                lst_Update_Breackfast.Focus();
                return;
            }
            //-----------------------------
            if (Radif_BreakFast == -1)
            {
                MessageBox.Show("هیچ غذایی انتخاب نشده است", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Breackfast.Focus();
                return;
            }
            //-----------------------------
            try
            {
                objFood.FoodType = Food.FoodTypes.صبحانه;
                objFood.FoodName = txt_Update_Breackfast.TEXT;
                objFood.Radif = Radif_BreakFast;
                objFood.Update();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Breackfast.TEXT = "";
                lst_Update_Breackfast.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Breackfast.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Breackfast.Focus();
            }
        }

        private void btn_Update_Launch_Click(object sender, EventArgs e)
        {
            if (txt_Update_Launch.TEXT == Name_Launch)
            {
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Launch.TEXT = "";
                lst_Update_Launch.Focus();
                return;
            }
            //-----------------------------
            if (Radif_Launch == -1)
            {
                MessageBox.Show("هیچ غذایی انتخاب نشده است", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Launch.Focus();
                return;
            }
            //-----------------------------
            try
            {
                objFood.FoodType = Food.FoodTypes.صبحانه;
                objFood.FoodName = txt_Update_Launch.TEXT;
                objFood.Radif = Radif_Launch;
                objFood.Update();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Launch.TEXT = "";
                lst_Update_Launch.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Launch.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Launch.Focus();
            }
        }

        private void btn_Update_Dinner_Click(object sender, EventArgs e)
        {
            if (txt_Update_Dinner.TEXT == Name_Dinner)
            {
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Dinner.TEXT = "";
                lst_Update_Dinner.Focus();
                return;
            }
            //-----------------------------
            if (Radif_Dinner == -1)
            {
                MessageBox.Show("هیچ غذایی انتخاب نشده است", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Dinner.Focus();
                return;
            }
            //-----------------------------
            try
            {
                objFood.FoodType = Food.FoodTypes.صبحانه;
                objFood.FoodName = txt_Update_Dinner.TEXT;
                objFood.Radif = Radif_Dinner;
                objFood.Update();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_Update_Dinner.TEXT = "";
                lst_Update_Dinner.Focus();
                return;
            }
            catch (Food_Exceptions_FoodName ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Dinner.Focus();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ثبت غذا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Update_Dinner.Focus();
            }
        }
    }
}