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

namespace Memo_Project
{
    public partial class frm_Main : Form
    {
        public frm_Main()
        {
            InitializeComponent();
        }
        private void frm_Main__Load(object sender, EventArgs e)
        {
            string fn = Application.StartupPath + "\\Data\\Images\\User_Pic\\about.jpg";
            try
            {
                Forms.frm_Login log = new Forms.frm_Login();
                log.ShowDialog();
                //*****************************************************************
                lbl_Version.Text = Application.ProductVersion.ToString();
                //*****************************************************************
                Cmb_Creator();
                Image_Loader();
                //*****************************************************************
                cmb_Musix();
                Music_Loader();
                //*****************************************************************
                Calender();
                //*****************************************************************
                lbl_User_Name.Text = Memo_Project.Properties.Settings.Default.User_Name;
                //*****************************************************************
                if (System.IO.File.Exists(fn))
                {
                    pictureBox1.Load(fn);
                }
                else
                {
                    MessageBox.Show("تصویر کاربر وجود ندارد", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            

        }


        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult yes;
                yes = MessageBox.Show("آیا مطمن هستید که می خواهید از برنامه خارج شوید؟",
                    "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (yes == DialogResult.Yes)
                {
                    Application.Exit();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void btn_Minimize_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        private void Cmb_Creator()
        {
            try
            {
                for (int i = 1; i <= 10; i++)
                {
                    this.cmb_Back_Image.Items.Add("تصویر" + i);
                }

            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void Image_Loader()
        {
            string fn;
            try
            {
                fn = Application.StartupPath + "\\Data\\Images\\Back_Ground_Picture\\"
                                + Memo_Project.Properties.Settings.Default.Select_Picture + ".jpg";
                this.BackgroundImage = Image.FromFile(fn);
                Int32 num = Int32.Parse(Memo_Project.Properties.Settings.Default.Select_Picture) - 1;
                this.cmb_Back_Image.SelectedIndex = num;
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
             
        }

        private void cmb_Back_Image_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Index = this.cmb_Back_Image.SelectedIndex + 1;
            try
            {
                Memo_Project.Properties.Settings.Default.Select_Picture = Index.ToString();
                Memo_Project.Properties.Settings.Default.Save();
                Image_Loader();
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void cmb_Musix()
        {
            try
            {
                for (int i = 1; i <= 7; i++)
                {
                    this.cmb_Music.Items.Add("موسیقی" + i);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void Music_Loader()
        {
            string mn = Memo_Project.Properties.Settings.Default.Select_Music;
            string fn = Application.StartupPath + "\\Data\\Music\\Back_Ground_Music\\" + mn + ".mp3";
            try
            {
                this.axWindowsMediaPlayer1.URL = fn;
                this.cmb_Music.SelectedIndex = int.Parse(mn) - 1;
            }
            catch (Exception)
            {

            }
            

        }

        private void Calender()
        {
            System.Globalization.PersianCalendar c = new System.Globalization.PersianCalendar();
            int month = c.GetMonth(DateTime.Now);
            string mm;
            string Week_Day = c.GetDayOfWeek(DateTime.Now).ToString();

            try
            {
                this.lbl_Years.Text = c.GetYear(DateTime.Now).ToString();

                switch (month)
                {
                    case 1:
                        mm = "فروردین";
                        break;
                    case 2:
                        mm = "اردیبهشت";
                        break;
                    case 3:
                        mm = "خرداد";
                        break;
                    case 4:
                        mm = "تیر";
                        break;
                    case 5:
                        mm = "مرداد";
                        break;
                    case 6:
                        mm = "شهریور";
                        break;
                    case 7:
                        mm = "مهر";
                        break;
                    case 8:
                        mm = "آبان";
                        break;
                    case 9:
                        mm = "آذر";
                        break;
                    case 10:
                        mm = "دی";
                        break;
                    case 11:
                        mm = "بهمن";
                        break;
                    case 12:
                        mm = "اسفند";
                        break;
                    default:
                        mm = "نامعلوم";
                        break;
                        
                }
                this.lbl_Month.Text = mm;

                this.lbl_Day.Text = c.GetDayOfMonth(DateTime.Now).ToString();
                switch (Week_Day)
                {
                    case "Monday":
                        this.lbl_Week.Text = "دوشنبه";
                        break;
                    case "Tuesday":
                        this.lbl_Week.Text = "سه شنبه";
                        break;
                    case "Wednesday":
                        this.lbl_Week.Text = "چهارشنبه";
                        break;
                    case "Thursday":
                        this.lbl_Week.Text = "پنجشنبه";
                        break;
                    case "Friday":
                        this.lbl_Day.ForeColor = Color.Red;
                        this.lbl_Week.ForeColor = Color.Red;
                        this.lbl_Week.Text = "جمعه";
                        break;
                    case "Saturday":
                        this.lbl_Week.Text = "شنبه";
                        break;
                    case "Sunday":
                        this.lbl_Week.Text = "یکشنبه";
                        break;

                    default:
                        break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }


        private void cmb_Music_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Index =cmb_Music.SelectedIndex +1;
            try
            {
            Memo_Project.Properties.Settings.Default.Select_Music = Index.ToString();
            Memo_Project.Properties.Settings.Default.Save();
            Music_Loader();
            }
            catch (Exception)
            {
                MessageBox.Show("کاربر عزیز: این کار امکان پذیر نیست", "هشدار",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void دربارهماToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frm_About About = new frm_About();
            About.MdiParent = this;
            About.Show();
        }

        private void تعیینکاربرToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Memo_Project.Forms.frm_User us = new Forms.frm_User();
            us.MdiParent = this;
            us.Show();
        }

        private void خروجموقتToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.frm_Login log = new Forms.frm_Login();
            log.ShowDialog();
        }

        private void بروزرسانیToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Refresh();
            string fn = Application.StartupPath + "\\Data\\Images\\User_Pic\\about.jpg";
            this.pictureBox1.Load(fn);
        }

        private void f2btn_Register_Click(object sender, EventArgs e)
        {
            Forms.frm_Register reg = new Forms.frm_Register();
            reg.MdiParent = this;
            reg.Show();
        }

        private void f3btn_Search_Click(object sender, EventArgs e)
        {
            Forms.frm_Search srch = new Forms.frm_Search();
            srch.MdiParent = this;
            srch.Show();
        }

        private void lbl_Week_Click(object sender, EventArgs e)
        {

        }

        private void frm_Main_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.F2)
            {
                f2btn_Register_Click(sender, e);
            }
            //----------------------------------------------
            if (e.KeyCode==Keys.F3)
            {
                f3btn_Search_Click(sender, e);
            }
            //----------------------------------------------
            if (e.KeyCode == Keys.F4)
            {
                btn_Setting.ShowDropDown();
            }
            //----------------------------------------------
            if (e.KeyCode == Keys.F5)
            {
                btn_Tools.ShowDropDown();
            }
            //----------------------------------------------
            if (e.KeyCode == Keys.F6)
            {
                btn_Help.ShowDropDown();
            }
        }

        private void f4btn_Setting_ButtonClick(object sender, EventArgs e)
        {

        }

        private void f5btn_Tools_Click(object sender, EventArgs e)
        {

        }

        private void f6btn_Help_ButtonClick(object sender, EventArgs e)
        {

        }
    }
}
