Ejemplo n.º 1
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbbServer.Text))
            {
                MessageBox.Show("服务器不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBox.Show("登陆名不能为空!");
                return;
            }
            WEF.DbDAL.MySql.DbObject dbObejct;

            var dataBase = cbbDatabase.Items[cbbDatabase.SelectedIndex].ToString();

            if (!string.IsNullOrEmpty(dataBase) && dataBase != "全部")
            {
                dbObejct = new WEF.DbDAL.MySql.DbObject(false, cbbServer.Text, txtUserName.Text, txtPassword.Text, txtport.Text, dataBase);
            }
            else
            {
                dbObejct = new WEF.DbDAL.MySql.DbObject(false, cbbServer.Text, txtUserName.Text, txtPassword.Text, txtport.Text);
            }

            string tempconnectionstring = dbObejct.DbConnectStr;

            try
            {
                dbObejct.OpenDB();
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                return;
            }

            Connection connectionModel = new Connection();

            connectionModel.Database         = cbbDatabase.SelectedIndex == 0 ? "all" : cbbDatabase.Text;
            connectionModel.ID               = Guid.NewGuid();
            connectionModel.Name             = cbbServer.Text + "(MySql)[" + connectionModel.Database + "]";
            connectionModel.ConnectionString = tempconnectionstring;
            connectionModel.DbType           = DatabaseType.MySql.ToString();



            UtilsHelper.AddConnection(connectionModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                LoadForm.ShowLoading(this);
                try
                {
                    var mongoTool = MongoDBTool.Connect(connectStr);

                    var dataBaseNames = mongoTool.GetDataBases();

                    var dataBaseName = "";

                    if (dataBaseNames != null && dataBaseNames.Any())
                    {
                        if (System.Linq.Enumerable.Count(dataBaseNames) == 1)
                        {
                            dataBaseName = dataBaseNames.First();
                        }
                        else
                        {
                            dataBaseName = "all";
                        }
                    }

                    this.Invoke(new Action(() =>
                    {
                        Connection connectionModel       = new Connection();
                        connectionModel.Database         = dataBaseName;
                        connectionModel.ID               = Guid.NewGuid();
                        connectionModel.Name             = mongoTool.ServerInfo + "(MongoDB)[" + connectionModel.Database + "]";
                        connectionModel.DbType           = DatabaseType.MongoDB.ToString();
                        connectionModel.ConnectionString = connectStr;

                        UtilsHelper.AddConnection(connectionModel);

                        this.DialogResult = DialogResult.OK;

                        this.Close();
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接失败!\n\r" + ex.Message);
                }
                LoadForm.HideLoading();
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            button1_Click(null, null);

            if (!isConnection)
            {
                return;
            }

            var serviceName = cbbService.Text;

            if (string.IsNullOrEmpty(serviceName))
            {
                var index1 = dbObject.DbConnectStr.IndexOf("SERVICE_NAME", StringComparison.OrdinalIgnoreCase);
                var str1   = dbObject.DbConnectStr.Substring(0, index1);
                var str2   = dbObject.DbConnectStr.Substring(index1);
                var index2 = str2.IndexOf("=");
                var str3   = str2.Substring(index2 + 1);
                var index3 = str3.IndexOf(")");
                var str4   = str3.Substring(0, index3);
                serviceName = str4;
            }


            ConnectionModel connectionModel = new ConnectionModel();

            connectionModel.Database         = serviceName;
            connectionModel.ID               = Guid.NewGuid();
            connectionModel.Name             = serviceName + "(Oracle)";
            connectionModel.ConnectionString = dbObject.DbConnectStr;
            connectionModel.DbType           = DatabaseType.Oracle.ToString();
            UtilsHelper.AddConnection(connectionModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (rbconnstring.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectionString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtfilepath.Text))
                {
                    MessageBox.Show("请选择Access文件!");
                    return;
                }
            }

            Model.Connection connModel = new WEF.ModelGenerator.Model.Connection();

            if (rbdatabaseselect.Checked)
            {
                StringBuilder cstring = new StringBuilder();

                string exstension = txtfilepath.Text.Substring(txtfilepath.Text.LastIndexOf('.') + 1);
                if (exstension.ToLower().Equals("mdb"))
                {
                    cstring.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
                }
                else if (exstension.ToLower().Equals("accdb"))
                {
                    cstring.Append("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=");
                }

                cstring.Append(txtfilepath.Text);
                cstring.Append(";");
                if (!string.IsNullOrEmpty(txtPassword.Text))
                {
                    cstring.Append("User Id=");
                    cstring.Append(txtUserName.Text);
                    cstring.Append(";Password="******";");
                }

                connModel.ConnectionString = cstring.ToString();
                connModel.Name             = txtfilepath.Text;
                connModel.Database         = connModel.Name.Substring(connModel.Name.LastIndexOf('\\') + 1);
            }
            else
            {
                connModel.ConnectionString = txtConnectionString.Text;


                string constring       = txtConnectionString.Text;
                string templeftstring  = string.Empty;
                string temprightstring = string.Empty;
                if (constring.IndexOf('/') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('/'));
                    temprightstring = constring.Substring(constring.LastIndexOf('/') + 1);
                }
                else if (constring.IndexOf('\\') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('\\'));
                    temprightstring = constring.Substring(constring.LastIndexOf('\\') + 1);
                }
                else
                {
                    MessageBox.Show("连接字符串格式不正确!");
                    return;
                }

                if (temprightstring.IndexOf(';') > 0)
                {
                    temprightstring = temprightstring.Substring(0, temprightstring.IndexOf(';'));
                }

                templeftstring = templeftstring.Substring(templeftstring.IndexOf('=') + 1);


                connModel.Name     = templeftstring + temprightstring;
                connModel.Database = temprightstring;
            }

            try
            {
                using (OleDbConnection oledbConn = new OleDbConnection(connModel.ConnectionString))
                {
                    oledbConn.Open();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                return;
            }

            connModel.DbType = DatabaseType.MsAccess.ToString();
            connModel.ID     = Guid.NewGuid();

            UtilsHelper.AddConnection(connModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (rbconnstring.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectionString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtfilepath.Text))
                {
                    MessageBox.Show("请选择Sqlite数据库文件!");
                    return;
                }
            }

            Model.Connection connModel = new WEF.ModelGenerator.Model.Connection();

            if (rbdatabaseselect.Checked)
            {
                StringBuilder cstring = new StringBuilder("Data Source=");
                cstring.Append(txtfilepath.Text);
                cstring.Append(";");
                if (!string.IsNullOrEmpty(txtPassword.Text))
                {
                    cstring.Append("Password="******";");
                }

                connModel.ConnectionString = cstring.ToString();
                connModel.Name             = txtfilepath.Text;
                connModel.Database         = connModel.Name.Substring(connModel.Name.LastIndexOf('\\') + 1);
            }
            else
            {
                connModel.ConnectionString = txtConnectionString.Text;


                string constring       = txtConnectionString.Text;
                string templeftstring  = string.Empty;
                string temprightstring = string.Empty;
                if (constring.IndexOf('/') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('/'));
                    temprightstring = constring.Substring(constring.LastIndexOf('/') + 1);
                }
                else if (constring.IndexOf('\\') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('\\'));
                    temprightstring = constring.Substring(constring.LastIndexOf('\\') + 1);
                }
                else
                {
                    MessageBox.Show("连接字符串格式不正确!");
                    return;
                }

                if (temprightstring.IndexOf(';') > 0)
                {
                    temprightstring = temprightstring.Substring(0, temprightstring.IndexOf(';'));
                }

                templeftstring = templeftstring.Substring(templeftstring.IndexOf('=') + 1);


                connModel.Name     = templeftstring + temprightstring;
                connModel.Database = temprightstring;
            }

            try
            {
                using (SQLiteConnection oledbConn = new SQLiteConnection(connModel.ConnectionString))
                {
                    oledbConn.Open();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                return;
            }

            connModel.DbType = DatabaseType.Sqlite3.ToString();
            connModel.ID     = Guid.NewGuid();

            UtilsHelper.AddConnection(connModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbbServer.Text))
            {
                MessageBox.Show("服务器不能为空!");
                return;
            }

            if (cbbShenFenRZ.SelectedIndex == 1 && string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBox.Show("登陆名不能为空!");
                return;
            }

            string tempconnectionstring = createConnectionString(cbbDatabase.SelectedIndex == 0 ? "master" : cbbDatabase.Text);

            Task.Factory.StartNew(() =>
            {
                LoadForm.ShowLoading(this);

                try
                {
                    using (SqlConnection conn = new SqlConnection(tempconnectionstring))
                    {
                        conn.Open();
                    }
                    LoadForm.HideLoading();

                    Dictionary <string, string> dic = new Dictionary <string, string>();

                    this.Invoke(new Action(() =>
                    {
                        if (checkBox1.Checked)
                        {
                            var cnnStr = textBox1.Text;

                            var arr1 = cnnStr.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                            foreach (var item in arr1)
                            {
                                var arr2 = item.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                                try
                                {
                                    dic.Add(arr2[0].ToLower(), arr2[1].ToLower());
                                }
                                catch { }
                            }


                            Connection connectionModel = new Connection();
                            connectionModel.Database   = dic["initial catalog"];
                            connectionModel.ID         = Guid.NewGuid();
                            connectionModel.Name       = dic["data source"] + "(" + DatabaseType.SqlServer9.ToString() + ")[" + connectionModel.Database + "]";

                            connectionModel.DbType           = DatabaseType.SqlServer9.ToString();
                            connectionModel.ConnectionString = tempconnectionstring;
                            UtilsHelper.AddConnection(connectionModel);
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            Connection connectionModel = new Connection();
                            connectionModel.Database   = cbbDatabase.SelectedIndex == 0 ? "all" : cbbDatabase.Text;
                            connectionModel.ID         = Guid.NewGuid();
                            connectionModel.Name       = cbbServer.Text + "(" + cbbServerType.Text + ")[" + connectionModel.Database + "]";
                            if (cbbServerType.SelectedIndex == 0)
                            {
                                connectionModel.DbType = DatabaseType.SqlServer.ToString();
                            }
                            else
                            {
                                connectionModel.DbType = DatabaseType.SqlServer9.ToString();
                            }
                            connectionModel.ConnectionString = tempconnectionstring;

                            UtilsHelper.AddConnection(connectionModel);

                            this.DialogResult = DialogResult.OK;

                            this.Close();
                        }
                    }));
                }
                catch (Exception ex)
                {
                    LoadForm.HideLoading();
                    MessageBox.Show("连接失败!\n\r" + ex.Message);
                }
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                if (string.IsNullOrEmpty(skinWaterTextBox1.Text))
                {
                    MessageBox.Show("连接字符串不能为空!");
                    return;
                }

                Dictionary <string, string> keyValuePairs = skinWaterTextBox1.Text.ToConnectParmaDic();

                if (string.IsNullOrEmpty(keyValuePairs["database"]))
                {
                    MessageBox.Show("连接字符串中不包含database!\n\r");
                    return;
                }

                WEF.DbDAL.PostgreSQL.DbObject dbObejct = new WEF.DbDAL.PostgreSQL.DbObject(skinWaterTextBox1.Text);

                try
                {
                    dbObejct.OpenDB();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接失败!\n\r" + ex.Message);
                    return;
                }



                ConnectionModel connectionModel = new ConnectionModel();
                connectionModel.Database         = keyValuePairs["database"];
                connectionModel.ID               = Guid.NewGuid();
                connectionModel.Name             = keyValuePairs["server"] + "(PostgreSql)[" + connectionModel.Database + "]";
                connectionModel.ConnectionString = dbObejct.DbConnectStr;
                connectionModel.DbType           = DatabaseType.PostgreSQL.ToString();

                UtilsHelper.AddConnection(connectionModel);

                this.DialogResult = DialogResult.OK;

                this.Close();
            }
            else
            {
                if (string.IsNullOrEmpty(cbbServer.Text))
                {
                    MessageBox.Show("服务器不能为空!");
                    return;
                }

                if (string.IsNullOrEmpty(txtUserName.Text))
                {
                    MessageBox.Show("登陆名不能为空!");
                    return;
                }
                WEF.DbDAL.PostgreSQL.DbObject dbObejct;

                var dataBase = cbbDatabase.Items[cbbDatabase.SelectedIndex].ToString();

                if (!string.IsNullOrEmpty(dataBase) && dataBase != "全部")
                {
                    dbObejct = new WEF.DbDAL.PostgreSQL.DbObject(cbbServer.Text, txtport.Text, txtUserName.Text, txtPassword.Text, dataBase);
                }
                else
                {
                    dbObejct = new WEF.DbDAL.PostgreSQL.DbObject(cbbServer.Text, txtport.Text, txtUserName.Text, txtPassword.Text);
                }

                string tempconnectionstring = dbObejct.DbConnectStr;

                try
                {
                    dbObejct.OpenDB();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接失败!\n\r" + ex.Message);
                    return;
                }

                ConnectionModel connectionModel = new ConnectionModel();
                connectionModel.Database         = cbbDatabase.SelectedIndex == 0 ? "all" : cbbDatabase.Text;
                connectionModel.ID               = Guid.NewGuid();
                connectionModel.Name             = cbbServer.Text + "(DBPostgre)[" + connectionModel.Database + "]";
                connectionModel.ConnectionString = tempconnectionstring;
                connectionModel.DbType           = DatabaseType.PostgreSQL.ToString();

                UtilsHelper.AddConnection(connectionModel);

                this.DialogResult = DialogResult.OK;

                this.Close();
            }
        }