protected bool BindObjectName() { try { bool result = false; string SourceIP = txtSourceIP.Value.Trim(); string UserName = txtUserName.Value.Trim(); string Pwd = txtPwd.Text.Trim(); string DBName = ddlDBName.SelectedValue; string ObjectType = ddlObjectType.SelectedValue; if (!string.IsNullOrEmpty(ObjectType) && !string.IsNullOrEmpty(DBName)) { ddlObjectName.Items.Clear(); ConnectionConfigComponent ccc = new ConnectionConfigComponent(SourceIP, UserName, Pwd, DBName); DataTable dt = ccc.GetDataListByDataType(ObjectType); ddlObjectName.DataSource = dt; ddlObjectName.DataTextField = "namedesc"; ddlObjectName.DataValueField = "name"; ddlObjectName.DataBind(); ddlObjectName.Items.Insert(0, new ListItem("请选择", "")); result = true; } return(result); } catch { return(false); } }
//测试是否连接通过 protected bool TestConn(out string alertstr, int ctype = 0) { alertstr = ""; string SourceIP = txtSourceIP.Value.Trim(); string UserName = txtUserName.Value.Trim(); string Pwd = txtPwd.Text.Trim(); string DbName = txtDBName.Text.Trim(); bool result = false; ConnectionConfigComponent ccc = new ConnectionConfigComponent(SourceIP, UserName, Pwd); if (ccc.CheckConnect())//如果连接成功 { DataTable dbtable = null; if (ctype == 1) { dbtable = ccc.GetAllDBOnDataSource(); //绑定数据源下所有数据库 ddlDBName.DataSource = dbtable; ddlDBName.DataTextField = "namedesc"; ddlDBName.DataValueField = "name"; ddlDBName.DataBind(); ddlDBName.Items.Insert(0, new ListItem("请选择", "")); } else//检查数据库与库中内容是否存在 { dbtable = ccc.GetAllDBOnDataSource(DbName); if (dbtable != null && dbtable.Rows.Count > 0) { string ObjectType = ddlObjectType.SelectedValue; string objname = ddlObjectName.SelectedValue; ConnectionConfigComponent ccctestobj = new ConnectionConfigComponent(SourceIP, UserName, Pwd, DbName); DataTable dt = ccctestobj.GetDataListByDataType(ObjectType, objname); if (dt != null && dt.Rows.Count > 0)//首先检查对象名是否存在 { string checkresult = ccctestobj.CheckCanExecute(ObjectType, objname).Trim(); if (string.IsNullOrEmpty(checkresult)) { result = true; } else { alertstr = ":" + checkresult.Replace("'", "").Replace("\"", ""); } } } } } return(result); }