Ejemplo n.º 1
0
        /// <summary>
        /// 测试数据库连接
        /// </summary>
        /// <param name="isShowTip">是否弹出提示</param>
        /// <returns></returns>
        public bool TestDB(bool isShowTip)
        {
            if (!CheckData(isShowTip))
            {
                return(false);
            }

            Func <bool> error = () =>
            {
                if (isShowTip)
                {
                    MsgBox.Error("测试连接失败,请检查后重试!");
                }
                return(false);
            };

            return(LogExt.Exec(() =>
            {
                if (!DBExt.TestSqlServerDB(DB))
                {
                    return error();
                }
                return true;
            }, error));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 刷新数据库列表
        /// </summary>
        public async void RefreshDB(string defaultDB = null)
        {
            if (!CheckData())
            {
                cmbDatabase.DataSource = null;
                return;
            }

            // 记录默认值
            string defaultValue = defaultDB ?? Database;

            DataTable dtDBName = new DataTable();

            // 查询所有数据库
            await Task.Run(() =>
            {
                LogExt.Exec(() =>
                {
                    DBInfo dbMaster = new DBInfo(Server, "master", UserName, Password);

                    var adapter = new SqlDataAdapter(@"
                        SELECT '' AS name, 0 AS OrderID 
                        UNION 
                        SELECT name, 1
                        FROM master..sysdatabases 
				        WHERE dbid <= 4
				        UNION
				        SELECT name, 2
                        FROM master..sysdatabases 
				        WHERE dbid > 4
                        ORDER BY OrderID, name", dbMaster.Conn);

                    lock (adapter)
                    {
                        adapter.Fill(dtDBName);
                    }
                });
            });

            // 绑定数据源
            if (dtDBName.Rows.Count > 1)
            {
                cmbDatabase.DisplayMember = "name";
                cmbDatabase.ValueMember   = "name";
                cmbDatabase.DataSource    = dtDBName;

                cmbDatabase.SelectedValue = defaultValue;
            }
            else
            {
                cmbDatabase.DataSource = null;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存填写的数据库信息
        /// </summary>
        public void SaveConfig()
        {
            RefreshHistoryDic();

            // 新增当前信息
            _dicHistory.SafeAdd($"{DB.Server}@{DB.Database}", (DataBase)DB);

            // 序列化保存
            List <DataBase> dbList = _dicHistory.Select(e => e.Value).ToList();

            LogExt.Exec(() =>
            {
                SerializeExt.ToXml(dbList, ConfigFilePath);
            });
        }
Ejemplo n.º 4
0
        private void RefreshHistoryDic()
        {
            // 反序列化
            var dbList = LogExt.Exec
                         (
                () => SerializeExt.XmlTo <List <DataBase> >(GetConfigXml().InnerXml),
                () => new List <DataBase>()
                         );

            // 绑定
            _dicHistory.Clear();
            if (dbList.Count > 0)
            {
                dbList.OrderByDescending(db => db.UpdateTime)
                .Take(10)
                .ForEach(db => _dicHistory.Add($"{db.Server}@{db.Database}", db));
            }
        }