using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data;
using Stone.Class;
using System.IO;
using System.Threading;

using System.Diagnostics;
namespace Stone
{

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// 
       
        static public ManagmentProducts MP = null;
        static public FactorClass FC = null;
        static public Factor F = null;
        static public MainFrom MF = null;
        static public ManagmentFactors MGF = null;
        static public FrmSearchFactors SF = null;
        static public bool SettingCheck = false;
        static public AccountUser ACU = null;
      
        [STAThread]
        static void Main()
        {

           
            bool ok;
            Mutex m = new Mutex(true, "Stone", out ok);
            if (!ok)
            {
                MessageBox.Show("یک نمونه از برنامه در حال اجرا است","زمرد", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
         
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException +=new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            do
            {
               
                SettingCheck = false;
                object result = Jacksonsoft.WaitWindow.Show(loadfc);
                MF = new MainFrom();
                Application.Run(MF);
                GC.KeepAlive(m);
            }
            while (SettingCheck);
        }

        static public void loadfc(object sender, Jacksonsoft.WaitWindowEventArgs e)
        {

            string XmlDataFileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\Information.xml";
            try
            {

                if (!Directory.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB"))
                {
                    Properties.Settings.Default.Reset();
                    Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB");
                    Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\ImagesBG");
                    File.Copy(Application.StartupPath + "\\ImagesBG\\King.jpg", System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\ParsZSDB" + "\\ImagesBG\\King.jpg");
                    FC = new FactorClass();
                    InforManagment IM = new InforManagment();
                    ACU = new AccountUser();
                    Program.FC.DSFactor.Tables.Add(IM.Information);
                    DataRow Rows = Program.FC.DSFactor.Tables["Information"].NewRow();
                    Rows["Name"] = "";
                    Rows["Mobile"] = "";
                    Rows["Tel"] = "";
                    Rows["Address"] = "";
                    Program.FC.DSFactor.Tables["Information"].Rows.Add(Rows);
                    Program.FC.DSFactor.Tables["Information"].WriteXml(XmlDataFileName);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            FC = new FactorClass();
            ACU = new AccountUser();
            InforManagment IM1 = new InforManagment();
            Program.FC.DSFactor.Tables.Add(IM1.Information);
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            MessageBox.Show("کاربر گرامی ، خطای در حین اجرای دستورات بوجود آمده است", "زمرد", MessageBoxButtons.OK, MessageBoxIcon.Information);
        
        }
      
    }
}
