예제 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }
            bool flag = TestConn(sqlType);

            if (flag)
            {
                if (chkRem.Checked)
                {
                    DataSet ds = dal.GetList("IP='" + cboServer.Text.Trim() + "'");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        dal.DeleteByCond("IP='" + cboServer.Text.Trim() + "'");
                    }
                    DbConnect model = new DbConnect();
                    model.CreateDate = DateTime.Now.ToString();
                    model.IP         = cboServer.Text.Trim();
                    model.Pwd        = DESEncryptHelper.Encrypt(txtPassword.Text.Trim(), "test332211");
                    model.User       = cboUser.Text.Trim();
                    model.Remark     = sqlType.ToString().ToLower();
                    dal.Add(model);
                }
                strConn = DESEncryptHelper.Encrypt(BuildConn(sqlType), "test332211");
                DBName  = txtDB.Text.Trim();
                MessageBox.Show("连接成功");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("测试连接失败");
            }
        }
예제 #2
0
        /// <summary>连接
        /// 连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }
#if !DEBUG
            if (txtDB.Text.Trim() == string.Empty)
            {
                m_ServerDB = DataBaseManager.GetDataBase(dbType, BuildConn(this.dbType));
                if (m_ServerDB.Rows.Count > 5)
                {
                    dialog = MessageBox.Show(@"一共需要加载【" + m_ServerDB.Rows.Count + "】个数据库,需要时间较长,建议按需加载", "提示", MessageBoxButtons.YesNo);
                    if (dialog == DialogResult.Yes)
                    {
                        btnSelectDB_Click(null, null);
                        return;
                    }
                }
            }
#endif
#if  DEBUG
            LoadDatabase = new DataTable();
            LoadDatabase.Columns.Add("name", typeof(string));
            DataRow dr = LoadDatabase.NewRow();
            dr["name"] = GlobalHelp.DefauleDatabase;
            LoadDatabase.Rows.Add(dr);
#endif

            bool flag = TestConn(this.dbType);
            if (flag)
            {
                if (chkRem.Checked)
                {
                    DataSet ds = m_dalConn.GetList("IP='" + cboServer.Text.Trim() + "'");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        m_dalConn.DeleteByCond("IP='" + cboServer.Text.Trim() + "'");
                    }
                    DbConnect model = new DbConnect
                    {
                        IP         = cboServer.Text.Trim(),
                        Pwd        = DESEncryptHelper.Encrypt(txtPassword.Text.Trim(), "test332211"),
                        User       = cboUser.Text.Trim(),
                        Remark     = this.dbType.ToString(),
                        CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                    };
                    m_dalConn.Add(model);
                }
                DBConn = BuildConn(this.dbType);
                Server = cboServer.Text.Trim();
                UID    = cboUser.Text.Trim();
                PWD    = txtPassword.Text.Trim();
                if (this.dbType == SqlType.MySql)
                {
                    Port = cboLogin.Text.Trim();
                }
                List <string> lstLoadType = new List <string>();
                foreach (CCBoxItem item in chkAllowType.CheckedItems)
                {
                    lstLoadType.Add(item.Name);
                }
                LoadType = lstLoadType;

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(@"连接失败");
            }
        }