Exemplo n.º 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (GV_DBConfigs.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int         Id     = Convert.ToInt32(GV_DBConfigs.SelectedRows[0].Cells[0].Value);
            DBCHMConfig config = ConfigUtils.Get(Id);


            if ((DBType)Enum.Parse(typeof(DBType), config.DBType) == DBType.SqlServer &&
                !GV_DBConfigs.SelectedRows[0].Cells[6].Value.ToString().Equals("sa", StringComparison.OrdinalIgnoreCase))
            {
                var dia = MessageBox.Show("非超级管理员的账号,可能因权限不足,查询不出表结构信息,确定要继续吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dia == DialogResult.Cancel)
                {
                    return;
                }
            }

            FormUtils.ShowProcessing("正在查询表结构信息,请稍等......", this, arg =>
            {
                try
                {
                    DBUtils.Instance = DBMgr.UseDB((DBType)Enum.Parse(typeof(DBType), config.DBType), config.ConnString, 300);
                    ConfigUtils.UpLastModified(Id);
                }
                catch (Exception ex)
                {
                    LogUtils.LogError("连接数据库失败", Developer.SysDefault, ex, config);
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }, null);
        }
Exemplo n.º 2
0
        public DBForm(OPType opType, int?id = null)
        {
            InitializeComponent();

            this.OpType = opType;

            if ((this.OpType == OPType.编辑 || this.OpType == OPType.克隆) && !id.HasValue)
            {
                throw new ArgumentNullException(this.OpType + "操作必须传递要操作的Id!");
            }
            else
            {
                if (id.HasValue)
                {
                    foreach (var item in FormUtils.DictDBType)
                    {
                        cboDBType.Items.Add(item.Value.ToString());
                    }

                    this.Id = id.Value;
                    DBCHMConfig config = ConfigUtils.Get(id.Value);
                    TxtConnectName.Text = config.Name;
                    cboDBType.Text      = config.DBType;
                    TxtHost.Text        = config.Server;
                    TxtPort.Text        = config.Port?.ToString();
                    TxtUName.Text       = config.Uid;
                    TxtPwd.Text         = config.Pwd;
                    cboDBName.Text      = config.DBName;
                    txtConnTimeOut.Text = config.ConnTimeOut?.ToString();

                    if (this.OpType == OPType.克隆)
                    {
                        TxtConnectName.Text += "_Clone";
                    }

                    if (config.DBType == DBType.SQLite.ToString())
                    {
                        btnSelectFile.Visible = true;

                        TxtHost.Enabled  = false;
                        TxtPort.Enabled  = false;
                        TxtUName.Enabled = false;

                        //暂不支持 加密的 Sqlite数据库
                        TxtPwd.Enabled = false;
                    }

                    //编辑时,确定后刷新连接列表
                    BtnOk.DialogResult = DialogResult.OK;
                }
                else
                {
                    btnSelectFile.Visible = false;
                }

                if (string.IsNullOrWhiteSpace(txtConnTimeOut.Text))
                {
                    txtConnTimeOut.Text = "60";
                }
            }

            //为KeyDown能应用到所有控件上 注册 KeyDown 事件
            foreach (Control control in this.Controls)
            {
                control.KeyDown += control_KeyDown;
            }
            lblMsg.Text = string.Empty;
        }