示例#1
0
        private void Form_Database_Load(object sender, EventArgs e)
        {
            Form.CheckForIllegalCrossThreadCalls = false;

            var serverList = ServersConfigClass.Instance.GetList();

            foreach (var server in serverList)
            {
                Servers servers = new Servers();
                servers.DatabaseName = server.Database;
                servers.Id           = server.Id;
                servers.Name         = server.Server;
                servers.Pwd          = server.Pwd;
                servers.Port         = server.Port.ToInt();
                servers.Server       = server.Server;
                servers.Uid          = server.Uid;
                servers.Type         = (DatabaseType)Enum.Parse(typeof(DatabaseType), server.Type);

                ServersHelper.AddServers(servers);

                TreeNode rootNode = new TreeNode();
                rootNode.Name = server.Server;
                rootNode.Text = string.Format("{0}({1}{2})",
                                              server.Server,
                                              server.Type.ToString(),
                                              string.IsNullOrWhiteSpace(server.Uid) ? "" : string.Format("-{0}", server.Uid));

                rootNode.ImageIndex         = 0;
                rootNode.SelectedImageIndex = 0;
                rootNode.Tag = new Model.TreeNodeTag {
                    Type = TreeNodeType.ServerNode, Tag = servers
                };
                treeViewLeft.Nodes.Add(rootNode);
            }
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            this.btnTest.Enabled = false;

            var server = this.server.Text.Trim();
            var uid    = this.uid.Text.Trim();
            var pwd    = this.pwd.Text.Trim();

            var model = new Servers
            {
                Id     = CommonHelper.NewGuid,
                Name   = server,
                Type   = DatabaseType.SqlServer,
                Server = server,
                Uid    = uid,
                Pwd    = pwd
            };

            ServersHelper.AddServers(model);

            //var model = new ConfigServers
            //{
            //    Id = CommonHelper.NewGuid,
            //    Name = string.Format("{0}({1})", server, DatabaseType.SqlServer.ToString()),
            //    Type = DatabaseType.SqlServer.ToString(),
            //    Server = server,
            //    Uid = uid,
            //    Pwd = pwd,
            //};
            //ServersConfigClass.Instance.Add(model);

            string err;
            var    b = new BLL_Database(DatabaseType.SqlServer).TestDatabaseConnnection(model.Id, out err);

            if (!b)
            {
                MessageBox.Show(err, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("连接成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }

            this.btnTest.Enabled = true;
        }