Пример #1
0
        static void Main()
        {
            #region DAL init
            DbConnDAL.Init();
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
        }
Пример #2
0
        private void cbConnectionStrings_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvDatabase.Nodes.Clear();
            var dal   = new DbConnDAL();
            var model = dal.FindOne(cbConnectionStrings.SelectedItem.ToString());

            var tmpDbSchema = DbSchemaFactory.Create(model.Name);

            Main m = this.ParentForm as Main;

            m.ClearDbList();

            IList <SODatabase> dbList = null;

            this.Cursor = Cursors.WaitCursor;
            try
            {
                dbList = tmpDbSchema.GetDatabaseList();
            }
            catch (Exception e1)
            {
                MsgBox.ShowErrorMessage("数据库连接异常:" + e1.Message);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            this.dbSchema = tmpDbSchema;
            DbSchemaHelper.Instance.CurrentSchema = dbSchema;

            TreeNode root = new TreeNode(model.Name, 0, 0);

            root.ToolTipText = model.ConnectionString;
            tvDatabase.Nodes.Add(root);

            foreach (SODatabase db in dbList)
            {
                TreeNode dbNode = new TreeNode(db.Name, 1, 1);
                dbNode.Tag              = db;
                dbNode.ToolTipText      = string.IsNullOrEmpty(db.Comment) ? db.Name : db.Comment;
                dbNode.ContextMenuStrip = cmsDatabase;
                root.Nodes.Add(dbNode);

                MainForm.AddDbListItem(db);
            }

            root.Expand();
        }
Пример #3
0
        public void RefreshDatabase()
        {
            cbConnectionStrings.Items.Clear();
            tvDatabase.Nodes.Clear();

            var dal = new DbConnDAL();
            //dal.InitData();

            var list = dal.FindAll().ToList();

            foreach (var item in list)
            {
                if (item.IsActive)
                {
                    cbConnectionStrings.Items.Add(item.Name);
                }
            }
        }
Пример #4
0
        //改变连接
        void ChangeConnection(string csName)
        {
            DbConnDAL dal = new DbConnDAL();

            var model = dal.FindOne(csName);

            currentSchema = DbSchemaFactory.Create(model.Name);

            List <SODatabase> dbList = currentSchema.GetDatabaseList();

            cbDatabase.Items.Clear();
            foreach (SODatabase db in dbList)
            {
                if (db.IsSystemDatabase)
                {
                    continue;
                }
                cbDatabase.Items.Add(db);
            }

            //if (cbDatabase.Items.Count > 0)
            //{
            //    DbName = cbDatabase.Items[0].ToString();
            //    cbDatabase.SelectedIndex = 0;
            //}
            //else
            //{
            //    DbName = string.Empty;
            //}

            foreach (object item in cbConnectionStrings.Items)
            {
                if (item.ToString() == CSName)
                {
                    cbConnectionStrings.SelectedItem = item;
                    break;
                }
            }
        }
Пример #5
0
        private void DbSchemaViewer_Load(object sender, EventArgs e)
        {
            var dal = new DbConnDAL();
            //dal.InitData();

            var list = dal.FindAll().ToList();

            foreach (var item in list)
            {
                if (item.IsActive)
                {
                    cbConnectionStrings.Items.Add(item.Name);
                }
            }

            cbSchemaName.DataSource = new string[] {
                "MetaDataCollections",
                "Databases",
                "Catalogs",
                "Users",
                "Tables",
                "Columns",
                "Views",
                "ViewColumns",
                "Procedures",
                "ProcedureParameters",
                "Indexes",
                "IndexColumns",
                "ForeignKeys",
                "UserDefinedTypes",
                "StructuredTypeMembers",
                "DataSourceInformation",
                "DataTypes",
                "Restrictions",
                "ReservedWords"
            };
        }
Пример #6
0
        private void DbDocBuilder_Load(object sender, EventArgs e)
        {
            var dal = new DbConnDAL();
            //dal.InitData();

            var list = dal.FindAll().ToList();

            foreach (var item in list)
            {
                if (item.IsActive)
                {
                    cbConnectionStrings.Items.Add(item.Name);
                }
            }

            if (string.IsNullOrEmpty(CSName) == false)
            {
                ChangeConnection(CSName);
            }
            if (CurrentDatabase != null)
            {
                ChangeDatabase(CurrentDatabase);
            }
        }
Пример #7
0
        /// <summary>
        /// 创建一个数据提供程序实例
        /// </summary>
        /// <param name="connectionStringName"></param>
        /// <returns></returns>
        public static Database Create(string connectionStringName)
        {
            CheckUtil.ArgumentNotNullOrEmpty(connectionStringName, "connectionStringName");
            DbConnDAL dal = new DbConnDAL();

            var model = dal.FindOne(connectionStringName);

            if (model == null)
            {
                throw new Exception(string.Format(Resources.Data.ConnectionStringNameNotFound, connectionStringName));
            }

            string            connectionString = model.ConnectionString;
            string            providerName     = model.ProviderName;
            Database          db = new SqlServerDatabase(connectionString);
            DbProviderFactory providerFactory = null;

            if (string.IsNullOrEmpty(providerName))
            {
                return(db);
            }

            //if (css.ProviderName == "System.Data.OleDb")
            //{
            //    providerFactory = OleDbFactory.Instance;
            //}
            //else
            //{
            //    providerFactory = DbProviderFactories.GetFactory(css.ProviderName);
            //}
            //if (providerFactory == null) throw new Exception(string.Format(Resources.Data.DataProviderNotFound, css.ProviderName));

            switch (providerName)
            {
            //case "System.Data.SqlClient":
            //    break;
            case "System.Data.Odbc":
                db = new OdbcDatabase(connectionString);
                break;

            case "System.Data.OleDb":
                db = new OleDbDatabase(connectionString);
                break;

            case "System.Data.OracleClient":
                db = new OracleDatabase(connectionString);
                break;

            case "Oracle.ManagedDataAccess.Client":
                db = new OracleDatabase(connectionString);
                break;

            case "Devart.Data.Oracle": //http://evget.com/zh-CN/product/954/feature.aspx  http://www.devart.com/
            case "DDTek.Oracle":       //http://www.datadirect.com/index.html 由于删除了版权DLL,导致该功能可能无法使用。可在QQ群:122161138中下载source_lib.zip
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new OracleDatabase(connectionString, providerFactory);
                break;

            case "System.Data.SQLite":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new SQLiteDatabase(connectionString, providerFactory);
                break;

            case "MySql.Data.MySqlClient":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new MySqlDatabase(connectionString, providerFactory);
                break;

            case "IBM.Data.DB2":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new DB2Database(connectionString, providerFactory);
                break;

            case "FirebirdSql.Data.FirebirdClient":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new FirebirdDatabase(connectionString, providerFactory);
                break;

            default:
                break;
            }

            return(db);
        }