Beispiel #1
0
        //改变连接
        void ChangeConnection(string csName)
        {
            ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[csName];
            currentSchema = DbSchemaFactory.Create(css.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;
                }
            }
        }
        private void cbConnectionStrings_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvDatabase.Nodes.Clear();

            ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[cbConnectionStrings.SelectedItem.ToString()];
            dbSchema = DbSchemaFactory.Create(css.Name);
            DbSchemaHelper.Instance.CurrentSchema = dbSchema;

            TreeNode root = new TreeNode(css.Name, 0, 0);
            root.ToolTipText = css.ConnectionString;
            tvDatabase.Nodes.Add(root);

            Main m = this.ParentForm as Main;
            m.ClearDbList();

            this.Cursor = Cursors.WaitCursor;
            IList<SODatabase> dbList = dbSchema.GetDatabaseList();
            this.Cursor = Cursors.Default;

            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();
        }