private void btnRefreshData_Click(object sender, EventArgs e)
 {
     GlobalValue.groupList      = NoiseDataBaseHelper.GetGroups();
     GlobalValue.recorderList   = NoiseDataBaseHelper.GetRecorders();
     GlobalValue.controllerList = NoiseDataBaseHelper.GetController();
     this.ClearView();
     this.BindGroup();
 }
        private void FrmSystem_Load(object sender, EventArgs e)
        {
            this.Text = "IGC DataLog系列产品应用软件" + "(" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")";
            // 读取数据库 初始化界面
            try
            {
                GlobalValue.MainForm = this;
                SkinHelper.InitSkinGallery(this.ribbonGalleryBarItem1);

                SplashScreenManager.ShowForm(typeof(WelcomSplash));
                if (SplashScreenManager.Default.IsSplashFormVisible)
                {
                    SplashScreenManager.Default.SendCommand(null, "正在加载皮肤...");
                }
                //Set Skin
                string skin = Settings.Instance.GetString(SettingKeys.Skin);
                if (string.IsNullOrEmpty(skin))
                {
                    skin = "SevenClassic";
                }
                UserLookAndFeel.Default.SkinName = skin;
                //HideNavigateBar
                foreach (DevExpress.XtraNavBar.NavBarGroup group in this.navBarControl1.Groups)
                {
                    foreach (DevExpress.XtraNavBar.NavBarItemLink itemlink in group.ItemLinks)
                    {
                        itemlink.Item.Visible = false;
                    }
                    group.Visible = false;
                }

                if (SplashScreenManager.Default.IsSplashFormVisible)
                {
                    SplashScreenManager.Default.SendCommand(null, "正在加载控件...");
                }
                #region 加载控件
                var files = Directory.GetFiles(Application.StartupPath, "I*");
                for (int i = 0; i < files.Length; i++)
                {
                    if (System.Text.RegularExpressions.Regex.IsMatch(files[i], @".dll$"))
                    {
                        LoadAddin(files[i]);
                    }
                }

                if (lstType != null && lstType.Count > 0)
                {
                    InitNavigate();
                }
                else
                {
                }
                #endregion

                BLL.NoiseDataHandler.TestPath = GlobalValue.TestPath;

                #region 数据库操作
                //SQLiteDbManager dbMgr = new SQLiteDbManager();
                //#region 创建数据库
                ////如果数据库文件不存在创建
                //if (!(dbMgr.Exists))
                //{
                //    if (SplashScreenManager.Default.IsSplashFormVisible)
                //    {
                //        SplashScreenManager.Default.SendCommand(null, "正在创建数据库...");
                //    }
                //    if (!dbMgr.ResetDatabase())
                //    {
                //        //error.ErrorCode = -1;
                //        logger.Error("ResetDatabase","创建数据库失败,请联系系统管理员");
                //    }
                //}
                //#endregion

                //#region 升级数据库
                //DBVersion versionBLL = new DBVersion();
                //string dbVersion = versionBLL.GetVersion(VersionType.DataBase.ToString());
                //if (dbVersion != dbMgr.LastestDBVersion)
                //{
                //    if (SplashScreenManager.Default.IsSplashFormVisible)
                //    {
                //        SplashScreenManager.Default.SendCommand(null, "正在更新数据库...");
                //    }
                //    if (!dbMgr.UpgradeDB())
                //    {
                //        //error.ErrorCode = 0;
                //        //error.ErrorMessage = "      自动升级数据库失败,请联系系统管理员";
                //    }
                //    else
                //    {
                //        if (SplashScreenManager.Default.IsSplashFormVisible)
                //        {
                //            SplashScreenManager.Default.SendCommand(null, "正在更新数据库版本...");
                //        }
                //        if (!versionBLL.UpdateVersion(VersionType.DataBase.ToString(), dbMgr.LastestDBVersion))
                //        {
                //            //error.ErrorCode = 0;
                //            //error.ErrorMessage = "      自动升级数据库失败,请联系系统管理员";
                //        }
                //    }
                //}
                //#endregion
                #endregion

                bool DatabaseConnected = false;
                SQLHelper.ConnectionString = Settings.Instance.GetString(SettingKeys.DBString);
                if (!string.IsNullOrEmpty(SQLHelper.ConnectionString))
                {
                    bool sqlconnect = SQLHelper.TryConn(SQLHelper.ConnectionString);
                    if (!sqlconnect)
                    {
                        if (DialogResult.No == XtraMessageBox.Show("连接SQL数据库失败,部分页面不会显示,请设置数据库连接!", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Error))
                        {
                            //logger.Info("TryConn func:SQL数据库连接失败,主动退出");
                            //Application.Exit();
                        }
                        else
                        {
                            barBtnSetDBConnect_ItemClick(null, null);
                        }
                    }
                    else
                    {
                        DatabaseConnected = true;
                    }
                }
                else
                {
                    barBtnSetDBConnect_ItemClick(null, null);
                }

                if (DatabaseConnected)
                {
                    if (SplashScreenManager.Default.IsSplashFormVisible)
                    {
                        SplashScreenManager.Default.SendCommand(null, "正在加载数据...");
                    }
                    GlobalValue.groupList      = NoiseDataBaseHelper.GetGroups();
                    GlobalValue.recorderList   = NoiseDataBaseHelper.GetRecorders();
                    GlobalValue.controllerList = NoiseDataBaseHelper.GetController();
                }

                if (SplashScreenManager.Default.IsSplashFormVisible)
                {
                    SplashScreenManager.Default.SendCommand(null, "正在初始化参数...");
                }

                GlobalValue.SerialPortMgr.SerialPortEvent += new SerialPortHandle(SerialPortMgr_SerialPortEvent);
                GlobalValue.SerialPortMgr.Start();

                //if (string.IsNullOrEmpty(Settings.Instance.GetString(SettingKeys.GPRS_IP))|| string.IsNullOrEmpty(Settings.Instance.GetString(SettingKeys.GPRS_PORT)))
                //{
                //    XtraMessageBox.Show("未设置Socket地址,远传终端监控和招测将不能使用!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
                //else
                //{
                try
                {
                    GlobalValue.SocketMgr.Start();
                }
                catch (InvalidOperationException ex)
                {
                    XtraMessageBox.Show(ex.Message + ",远传终端监控和招测将不能使用!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //}

                SplashScreenManager.CloseForm();

                ClearLogAndDb();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("初始化异常", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                logger.ErrorException("FrmSystem_Load", ex);
                logger.Info(ex.StackTrace);
                Application.Exit();
            }
        }