using Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JC_MeasuringSystem
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool createNew;
            using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                FrmLogin frm = new FrmLogin();
                frm.ShowDialog();

                if (!string.IsNullOrEmpty(frm.UserInfo.userid))
                {
                    CoreAppUser user = frm.UserInfo;
                    frm.Dispose();
                    Application.Run(new ST_MainForm(user));
                }


                /*
                if (createNew)
                {
                    bool ExistsProcess = false;
                    do
                    {
                        ExistsProcess = false;
                        Process currentProcess = Process.GetCurrentProcess();
                        foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
                        {
                            Thread.Sleep(500);
                            if ((process.Id != currentProcess.Id) &&
                                (Assembly.GetExecutingAssembly().Location == currentProcess.MainModule.FileName))
                            {
                                ExistsProcess = true;
                            }
                        }
                    } while (ExistsProcess);

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    FrmLogin frm = new FrmLogin();
                    frm.ShowDialog();

                    if (!string.IsNullOrEmpty(frm.UserInfo.userid))
                    {
                        CoreAppUser user = frm.UserInfo;
                        frm.Dispose();
                        Application.Run(new ST_MainForm(user));
                    }
                }
                else
                {
                    MessageBox.Show("已启动该程序，不允许重复启动!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }
                */
            }
        }
    }
}
