using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; 
namespace Stone
{
    public partial class MainFrom : Form
    {


        string XmlDataFileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\Products.xml";
        string XmlSchemaFileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\Products.xsd";

        Class.Waiting wt = new Class.Waiting();

        private int CounterImage = 0;
        private int childFormNumber = 0;
     
        public MainFrom()
        {
            InitializeComponent();
        }


        public void DoWorkInForm(object sender, Jacksonsoft.WaitWindowEventArgs e)
        {
            if (!File.Exists(XmlDataFileName) || !File.Exists(XmlSchemaFileName))
            {
                Make_DTProducts();
                Program.MP.DS.Tables[0].ReadXmlSchema(XmlSchemaFileName);
                Program.MP.DS.Tables[0].ReadXml(XmlDataFileName);
            }

            else
            {
                Program.MP.DS.Tables[0].ReadXmlSchema(XmlSchemaFileName);
                Program.MP.DS.Tables[0].ReadXml(XmlDataFileName);

            }

        }

        private void Make_DTProducts()
        {

            if (!File.Exists(XmlDataFileName))
            {
                Program.MP.DS.Tables[0].WriteXml(XmlDataFileName);
            }
            if (!File.Exists(XmlSchemaFileName))
            {
                Program.MP.DS.Tables[0].WriteXml(XmlSchemaFileName);
            }

            Program.MP.DS.Tables[0].WriteXmlSchema(XmlSchemaFileName);

        }


        private void ShowNewForm(object sender, EventArgs e)
        {
            pictureBox2_Click(sender, e);
        }

        private void OpenFile(object sender, EventArgs e)
        {
            PicManagmentFactor_Click(sender, e);
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
           
                Application.Exit();
        }



        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

     


        private void Main_Load(object sender, EventArgs e)
        {

           

          
            Stone.Class.PersianTagvim  DatePer =  new  Stone.Class.PersianTagvim(DateTime.Now);
            LblDate.Text = DatePer.CompletePrsDate() + DatePer.taghvim();

            LoadSettingImage();
            LoadSettingCalendar();
            LoadSettingTime();
            LoadSettingPlayer();
        }



        private void button5_Click(object sender, EventArgs e)
        {
            OFD.Filter = "Audio Files(*.mp3) |*.mp3|"
          + "wma files (*.wma) |*.wma";
            OFD.FilterIndex = 1;
            OFD.Title = "زمرد";
            OFD.FileName = "";
            if (OFD.ShowDialog() == DialogResult.OK)
            {
                WMP.URL = OFD.FileName;
            }

          
        }


        private void خــــروجToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
          
            Application.Exit();
        }

        private void helpMenu_Click(object sender, EventArgs e)
        {
            AboutUs AU = new AboutUs();
            AU.ShowDialog();
        }


        private void BtnManagmentProducts_Click(object sender, EventArgs e)
        {
            Program.MP = new ManagmentProducts();

            if (Properties.Settings.Default.FrmPosition == 0)
                Program.MP.StartPosition = FormStartPosition.CenterScreen;
            if (Properties.Settings.Default.FrmPosition == 1)
                Program.MP.StartPosition = FormStartPosition.CenterParent;
            if (Properties.Settings.Default.FrmStatus == 0)
                Program.MP.WindowState = FormWindowState.Normal;
            if (Properties.Settings.Default.FrmStatus == 1)
                Program.MP.WindowState = FormWindowState.Maximized;
            if (Properties.Settings.Default.FrmStatus == 2)
                Program.MP.WindowState = FormWindowState.Minimized;

            if (Properties.Settings.Default.FrmMin == false)
                Program.MP.MinimizeBox = false;
            if (Properties.Settings.Default.FrmMax == false)
                Program.MP.MaximizeBox = false;

            Program.MP.Show();
        }




    


        private void PicFactor_MouseEnter(object sender, EventArgs e)
        {
            PicFactor.BackColor = SystemColors.GradientInactiveCaption;
            PicFactor.BorderStyle = BorderStyle.FixedSingle;

        }



        private void PicManagmentFactor_MouseEnter(object sender, EventArgs e)
        {
            PicManagmentFactor.BackColor = SystemColors.GradientInactiveCaption;
            PicManagmentFactor.BorderStyle = BorderStyle.FixedSingle;
        }

  

        private void panel5_MouseMove(object sender, MouseEventArgs e)
        {
            PicFactor.BackColor = SystemColors.Control;
            PicFactor.BorderStyle = BorderStyle.None;
            PicManagmentFactor.BackColor = SystemColors.Control;
            PicManagmentFactor.BorderStyle = BorderStyle.None;
            SaleListMNU.BackColor = SystemColors.Control;
            SaleListMNU.BorderStyle = BorderStyle.None;
            MPro.BackColor = SystemColors.Control;
            MPro.BorderStyle = BorderStyle.None;
        }

        private void pictureBox3_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void pictureBox3_MouseEnter(object sender, EventArgs e)
        {
           SaleListMNU.BackColor = SystemColors.GradientInactiveCaption;
           SaleListMNU.BorderStyle = BorderStyle.FixedSingle;
        }

        private void SaleList_Click(object sender, EventArgs e)
        {
            SaleList SL = new SaleList();
            if (Properties.Settings.Default.FrmPosition == 0)
                SL.StartPosition = FormStartPosition.CenterScreen;
            if (Properties.Settings.Default.FrmPosition == 1)
                SL.StartPosition = FormStartPosition.CenterParent;
            if (Properties.Settings.Default.FrmStatus == 0)
                SL.WindowState = FormWindowState.Normal;
            if (Properties.Settings.Default.FrmStatus == 2)
                SL.WindowState = FormWindowState.Minimized;
            if (Properties.Settings.Default.FrmMin == false)
                SL.MinimizeBox = false; 
            SL.ShowDialog();
        }

        private void PicManagmentFactor_Click(object sender, EventArgs e)
        {

            if (Program.MGF != null && !Program.MGF.IsDisposed)
            {
                Program.MGF.Activate();
                return;
                
            }

            Program.MGF = new ManagmentFactors();
            if (Properties.Settings.Default.FrmPosition == 0)
                Program.MGF.StartPosition = FormStartPosition.CenterScreen;
            if (Properties.Settings.Default.FrmPosition == 1)
                Program.MGF.StartPosition = FormStartPosition.CenterParent;
            if (Properties.Settings.Default.FrmStatus == 0)
                Program.MGF.WindowState = FormWindowState.Normal;
            if (Properties.Settings.Default.FrmStatus == 1)
                Program.MGF.WindowState = FormWindowState.Maximized;
            if (Properties.Settings.Default.FrmStatus == 2)
                Program.MGF.WindowState = FormWindowState.Minimized;

            if (Properties.Settings.Default.FrmMin == false)
                Program.MGF.MinimizeBox = false;
            if (Properties.Settings.Default.FrmMax == false)
                Program.MGF.MaximizeBox = false;
            Program.MGF.Show();
        }

        private void PicFactor_Click(object sender, EventArgs e)
        {


            if (Program.F != null && !Program.F.IsDisposed)
            {
                Program.F.Activate();
                return;

            }

            Program.F = new Factor();
            if (Properties.Settings.Default.FrmPosition == 0)
                Program.F.StartPosition = FormStartPosition.CenterScreen;
            if (Properties.Settings.Default.FrmPosition == 1)
                Program.F.StartPosition = FormStartPosition.CenterParent;
            if (Properties.Settings.Default.FrmStatus == 0)
                Program.F.WindowState = FormWindowState.Normal;
            if (Properties.Settings.Default.FrmStatus == 1)
                Program.F.WindowState = FormWindowState.Maximized;
            if (Properties.Settings.Default.FrmStatus == 2)
                Program.F.WindowState = FormWindowState.Minimized;

            if (Properties.Settings.Default.FrmMin == false)
                Program.F.MinimizeBox = false;
            if (Properties.Settings.Default.FrmMax == false)
                Program.F.MaximizeBox = false;
            Program.F.Show();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

            if (Program.MP != null && !Program.MP.IsDisposed)
            {
                Program.MP.Activate();
                return;

            }

           
            Program.MP = new ManagmentProducts();
            if (Properties.Settings.Default.FrmPosition == 0)
                Program.MP.StartPosition = FormStartPosition.CenterScreen;
            if (Properties.Settings.Default.FrmPosition == 1)
                Program.MP.StartPosition = FormStartPosition.CenterParent;
            if (Properties.Settings.Default.FrmStatus == 0)
                Program.MP.WindowState = FormWindowState.Normal;
            if (Properties.Settings.Default.FrmStatus == 1)
                Program.MP.WindowState = FormWindowState.Maximized;
            if (Properties.Settings.Default.FrmStatus == 2)
                Program.MP.WindowState = FormWindowState.Minimized;

            if (Properties.Settings.Default.FrmMin == false)
                Program.MP.MinimizeBox = false;
            if (Properties.Settings.Default.FrmMax == false)
                Program.MP.MaximizeBox = false;

            object result = Jacksonsoft.WaitWindow.Show(DoWorkInForm);
            Program.MP.Show();
         
        }


       
        

        private void pictureBox2_MouseEnter(object sender, EventArgs e)
        {
            MPro.BackColor = SystemColors.GradientInactiveCaption;
            MPro.BorderStyle = BorderStyle.FixedSingle;
        }

        private void لیستفــروشToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaleList_Click(sender, e);
        }

        private void صدورفــاکتورToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PicFactor_Click(sender, e);
        }

        private void toolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelLeft.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void تنـظیماتفروشـگاهToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting();
            Setting.ShowDialog();

        }

        private void vistaClock1_Click(object sender, EventArgs e)
        {

        }


        private void LoadSettingImage()
        {
            if (Properties.Settings.Default.ImagePath != "" && Properties.Settings.Default.EnableBG == true)
            {
                pictureBoxBG.ImageLocation = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\ImagesBG\\" + Properties.Settings.Default.ImagePath;
                RightClick.Items[14].Enabled = false;
              
                if (Properties.Settings.Default.ImageMod == 0)
                    Program.MF.pictureBoxBG.SizeMode = PictureBoxSizeMode.Normal;

                if (Properties.Settings.Default.ImageMod == 1)
                    Program.MF.pictureBoxBG.SizeMode = PictureBoxSizeMode.StretchImage;

                if (Properties.Settings.Default.ImageMod == 2)
                    Program.MF.pictureBoxBG.SizeMode = PictureBoxSizeMode.AutoSize;

                if (Properties.Settings.Default.ImageMod == 3)
                    Program.MF.pictureBoxBG.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }

        private void LoadSettingCalendar()
        {
            if (Properties.Settings.Default.EnableCalendar == true)
            {
                PerCalendar.DaysBackColor = Properties.Settings.Default.DaysBGColor;
                PerCalendar.DaysForeColor = Properties.Settings.Default.DaysColor;
                PerCalendar.HolidayForeColor = Properties.Settings.Default.HolidayDaysColor;
                PerCalendar.TodayBackColor = Properties.Settings.Default.TodayDateBGColor;
                PerCalendar.TitleBackColor = Properties.Settings.Default.YearMonBGColor;
                PerCalendar.TodayForeColor = Properties.Settings.Default.TodayDateColor;
                PerCalendar.WeekDaysForeColor = Properties.Settings.Default.WeekColor;
                PerCalendar.WeekDaysBackColor = Properties.Settings.Default.WeekBGColor;
                PerCalendar.TrailingForeColor = Properties.Settings.Default.BeforeAfterMonDayColor;
                PerCalendar.BorderColor = Properties.Settings.Default.BorderColor;

                PerCalendar.DaysFont = Properties.Settings.Default.DaysFont;
                PerCalendar.TodayFont = Properties.Settings.Default.TodayDateFont;
                PerCalendar.ShowToday = Properties.Settings.Default.ShowTodayDate;

                PerCalendar.ShowTrailing = Properties.Settings.Default.ShowBeforeAfterMonDay;
            }
            else
            {
                PerCalendar.Visible = false;
            }
        }

        private void LoadSettingTime()
        {
            if (Properties.Settings.Default.EnableClock == true)
            {
                vistaClockMain.ShowSecond = Properties.Settings.Default.EnableSecond;
               vistaClockMain.SecondSpring = Properties.Settings.Default.EnableSecondEffect;

               if (Properties.Settings.Default.ClockTheme == 0)
                vistaClockMain.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Black;
               if (Properties.Settings.Default.ClockTheme == 1)
                   vistaClockMain.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Silver;
               if (Properties.Settings.Default.ClockTheme == 2)
                   vistaClockMain.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Red;
               if (Properties.Settings.Default.ClockTheme == 3)
                   vistaClockMain.Style = VistaClockPersian.Controls.VistaClock.VistaClockStyle.Flower;
            }
            else
            {
                vistaClockMain.Visible = false;
            }
        }

        private void LoadSettingPlayer()
        {
  
            if(Properties.Settings.Default.EnablePlayer == true)
            {
                WMP.enableContextMenu = Properties.Settings.Default.EnableMenuPlayer;
                WMP.Ctlenabled = Properties.Settings.Default.CtlEnable;
            }
            else
            {
                WMP.Visible = false;
            }

        }

        private void MainFrom_Activated(object sender, EventArgs e)
        {

            if (Properties.Settings.Default.KeyboardLan == 0)
            {
                System.Globalization.CultureInfo language = new System.Globalization.CultureInfo("fa-ir");
                InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(language);
            }

            if (Properties.Settings.Default.KeyboardLan == 1)
            {
                System.Globalization.CultureInfo language = new System.Globalization.CultureInfo("en-us");
                InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(language);
            }
         
        }

        private void printSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void optionsCalculator_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc.exe");
        }

        private void optionNotepad_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("notepad.exe");
        }

        private void تاریخوساعتToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("timedate.cpl");
        }

        private void تقویمشمسیToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("Calendar");
            
            Setting.ShowDialog();
    
        }

        private void اطلاعاتسیستمToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("InfoSys");

            Setting.ShowDialog();
        }

        private void پخشصداوتصویرToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("Player");

            Setting.ShowDialog();
        }

        private void مرورگراینترنتToolStripMenuItem_Click(object sender, EventArgs e)
        {

            System.Diagnostics.Process.Start("iexplore.exe");
        }

        private void تنظیماتصفحهکلیدToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("intl.cpl");
        }

        private void کنترلپنلToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("control.exe");
        }

        private void تهیهنسخهپشتیبانToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting();

            Setting.ShowDialog();
        }

        private void مــدیریتمحــصولاتToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pictureBox2_Click(sender, e);
        }

        private void مــدیریتفاکــتورهاToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PicManagmentFactor_Click(sender, e);
        }

        private void صــدورفاکتـورToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PicFactor_Click(sender, e);
        }

        private void لیسـتفـروشToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaleList_Click(sender, e);
        }

        private void TSNA_Click(object sender, EventArgs e)
        {
            panelLeft.Visible = TSNA.Checked;
        }

        private void TSNV_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = TSNV.Checked;
        }

        private void تنظیماتساعتToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("timedate.cpl");
        }

        private void تنظیماتتقویمشمسیToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("Calendar");

            Setting.ShowDialog();
        }

        private void تنظیماتپخـشصداوتصـویرToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("Player");

            Setting.ShowDialog();
        }

        private void تنظیماتصفحـهکلیـدToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("intl.cpl");
        }

        private void انتخـابپـسزمـینهToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSetting Setting = new FrmSetting("SoftWare");
            Setting.ShowDialog();
        }

        private void پــسزمـینهبعــدیToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CounterImage++;
            if (CounterImage == 0)
            {
                pictureBoxBG.Image = Properties.Resources.b2;
                return;
            }

            if (CounterImage == 1)
            {
                pictureBoxBG.Image = Properties.Resources.b3;
                return;
            }

            if (CounterImage == 2)
            {
                pictureBoxBG.Image = Properties.Resources.b4;
                return;
            }

            if (CounterImage == 3)
            {
                pictureBoxBG.Image = Properties.Resources.b5;
                return;
            }

            if (CounterImage == 4)
            {
                pictureBoxBG.Image = Properties.Resources.b6;
                return;
            }

            if (CounterImage == 5)
            {
                pictureBoxBG.Image = Properties.Resources.b7;
               
                return;
            }

            if (CounterImage == 6)
            {
                pictureBoxBG.Image = Properties.Resources.b8;
                return;
            }

            if (CounterImage == 7)
            {
                pictureBoxBG.Image = Properties.Resources.b9;
                return;
            }

            if (CounterImage == 8)
            {
                pictureBoxBG.Image = Properties.Resources.b10;
                return;
            }

            if (CounterImage == 9)
            {
                pictureBoxBG.Image = Properties.Resources.b11;
                return;
            }

            if (CounterImage == 10)
            {
                pictureBoxBG.Image = Properties.Resources.b12;
                CounterImage = -1;
            }
            return;
        }

        private void بـــروزرسانیToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(" برای بروز رسانی برنامه ، احتیاج است برنامه بسته شود آیا مایلید؟", "زمرد", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath + "\\" + "StoneUpdater.exe");
                Application.Exit();
            }
        }
        
     
    }
}
