Ejemplo n.º 1
0
        static void Main()
        {
            #region Exception Process
            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
            {
                HandleException(e.ExceptionObject as Exception);
            };
            // 处理UI线程异常
            Application.ThreadException += (object sender, ThreadExceptionEventArgs e) =>
            {
                HandleException(e.Exception);
            };
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadExit += new EventHandler(Application_ThreadExit);

            #endregion  Exception Process

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            Application.DoEvents();
            //Application.Run(new Waiting());
            Waiting.Show("正在加载程序,请稍候...", 20);

            bool existRunningInstance = ExistRunInstance();
            if (existRunningInstance)
            {
                CCMsgBox.Show("对不起,你已经运行了该程序!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);
                return;
            }

            Waiting.Show("正在测试数据库连接,请稍候...", 40);
            if (!TestDbConnect())
            {
                CCMsgBox.Show("对不起!数据库连接失败,请联系相关管理人员!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);
                return;
            }

            Waiting.Show("正在检测INI配置文件,请稍候...", 50);
            string iniFilePath = Path.Combine(Application.StartupPath, "ODConfig.ini");
            if (File.Exists(iniFilePath))
            {
                IniManager.Open(iniFilePath);
            }
            else
            {
                CreateIniFile(iniFilePath);
                CCMsgBox.Show("对不起!INI配置文件,请联系相关管理人员!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);
            }

            Waiting.Show("正在检测客户端信息,请稍候...", 60);
            SalesPointBusiness salesPointManage = new SalesPointBusiness();
            string             localMacAddress  = NetHelper.GetLocalMACAddress();
            if (!salesPointManage.ExistsMacAddress(localMacAddress))
            {
                CCMsgBox.Show("对不起!客户端信息不对,请先注册客户端信息或联系相关管理人员!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);
                return;
            }
            else
            {
            }

            Waiting.Show("正在检测营业点信息,请稍候...", 60);
            IniEntry iniEntry       = new IniEntry(iniFilePath);
            string   salesPointName = iniEntry.Sections["ClientInfo"]["SalesPointName"].ToString();
            if (!salesPointManage.Exists(salesPointName))
            {
                CCMsgBox.Show("对不起!营业点信息不对,请先注册营业点信息或联系相关管理人员!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);

                return;
            }
            else
            {
                CurrentSystemInfo.SalesPoint = salesPointManage.GetInstanceObj(new SalesPoint {
                    Name = salesPointName
                });
            }

            Waiting.Show("正在检测餐牌信息,请稍候...", 80);
            RestaurantTypeBusiness typeManage = new RestaurantTypeBusiness();

            if (!typeManage.Exists(iniEntry.Sections["ClientInfo"]["DishType"]))
            {
                CCMsgBox.Show("对不起!餐牌信息不对,请先配制餐牌信息或联系相关管理人员!", Application.ProductName, CCMsgBox.CButtons.OK, CCMsgBox.CIcon.Error);
                return;
            }
            else
            {
                CurrentSystemInfo.RestaurantType = typeManage.GetInstanceObj(new RestaurantType {
                    Name = iniEntry.Sections["ClientInfo"]["DishType"]
                });
            }

            Waiting.Show("正在读取餐段信息,请稍候...", 90);

            //string mealTypeId = new MealTimeManage().GetMealTimeId();

            MealTimesBusiness workShiftManager = new MealTimesBusiness();

            if (workShiftManager.GetInstanceList().Count < 1)
            {
                MessageBox.Show("对不起,没有找着餐段信息,请先配制餐牌信息!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
            }

            //Waiting.Show("正在同步系统时间,请稍候....", 80);
            // 同步时间
            //GetDbDateTime dbcomm = new GetDbDateTime();
            //dbcomm.SynchoronizeServerTime();

            ////InitForm();

            Waiting.Show("准备登录界面,请稍候....", 90);
            frmLogin login = new frmLogin();

            Waiting.Show("程序加载完成", 100);
            Waiting.Hide();



            //new FormMain().ShowDialog();
            while (login.ShowDialog() == DialogResult.OK)
            {
                //    dbcomm.SynchoronizeServerTime();                        // 再次同步时间

                login.Close();
            }
        }