Exemplo n.º 1
0
        /// <summary>
        /// 临时处理
        /// TODO 初始化连接串
        /// </summary>
        private string InitConnectionStr(DBType type)
        {
            CreateExtraParam();
            string connString = "";

            if (type == DBType.MySql)
            {
                connString = DBMgr.GetConnectionString(type, TxtHost.Text,
                                                       (string.IsNullOrWhiteSpace(TxtPort.Text) ? null : new Nullable <int>(Convert.ToInt32(TxtPort.Text))),
                                                       cboDBName.Text, TxtUName.Text, TxtPwd.Text,
                                                       (string.IsNullOrWhiteSpace(txtConnTimeOut.Text) ? 60 : Convert.ToInt32(txtConnTimeOut.Text)),
                                                       this.extraParam);
            }
            else
            {
                connString = DBMgr.GetConnectionString(type, TxtHost.Text,
                                                       (string.IsNullOrWhiteSpace(TxtPort.Text) ? null : new Nullable <int>(Convert.ToInt32(TxtPort.Text))),
                                                       cboDBName.Text, TxtUName.Text, TxtPwd.Text,
                                                       (string.IsNullOrWhiteSpace(txtConnTimeOut.Text) ? 60 : Convert.ToInt32(txtConnTimeOut.Text))
                                                       );
            }
            return(connString);
        }
Exemplo n.º 2
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(TxtConnectName.Text))
                {
                    MessageBox.Show("请输入连接名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (string.IsNullOrWhiteSpace(cboDBName.Text))
                {
                    MessageBox.Show("请输入数据库名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DBType type       = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text);
                string connString = DBMgr.GetConnectionString(type, TxtHost.Text,
                                                              (string.IsNullOrWhiteSpace(TxtPort.Text) ? null : new Nullable <int>(Convert.ToInt32(TxtPort.Text))),
                                                              cboDBName.Text, TxtUName.Text, TxtPwd.Text,
                                                              (string.IsNullOrWhiteSpace(txtConnTimeOut.Text) ? 60 : Convert.ToInt32(txtConnTimeOut.Text))
                                                              );
                NameValueCollection nvc = new NameValueCollection();
                if (OpType == OPType.新建 || OpType == OPType.克隆)
                {
                    nvc.Add("Name", TxtConnectName.Text.Trim());
                    nvc.Add("DBType", cboDBType.Text.Trim());

                    nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
                    nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
                    nvc.Add("DBName", cboDBName.Text.Trim());
                    nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
                    nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
                    nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "60");
                    nvc.Add("ConnString", connString);
                    nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                    ConfigUtils.Save(nvc);
                }
                else if (OpType == OPType.编辑)
                {
                    nvc.Add("Id", Id.ToString());
                    nvc.Add("Name", TxtConnectName.Text.Trim());
                    nvc.Add("DBType", cboDBType.Text.Trim());

                    nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
                    nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
                    nvc.Add("DBName", cboDBName.Text.Trim());
                    nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
                    nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
                    nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "60");
                    nvc.Add("ConnString", connString);
                    nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    ConfigUtils.Save(nvc);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }