//测试是否连接通过 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); }
protected bool BindDbName(int contype = 0) { string SourceIP = txtSourceIP.Value.Trim(); string UserName = txtUserName.Value.Trim(); string Pwd = txtPwd.Text.Trim(); bool result = false; ConnectionConfigComponent ccc = new ConnectionConfigComponent(SourceIP, UserName, Pwd); if (ccc.CheckConnect())//如果连接成功 { //绑定数据源下所有数据库 DataTable dbtable = ccc.GetAllDBOnDataSource(); ddlDBName.DataSource = dbtable; ddlDBName.DataTextField = "namedesc"; ddlDBName.DataValueField = "name"; ddlDBName.DataBind(); ddlDBName.Items.Insert(0, new ListItem("请选择", "")); txtDBName.Text = ""; txtSourceName.Value = ""; //ddlObjectType.SelectedValue = ""; //txtObjectType.Text = ""; ddlObjectName.Items.Clear(); ddlObjectName.Items.Insert(0, new ListItem("请选择", "")); txtObjectName.Text = ""; ddlCATEGORY.SelectedValue = ""; txtCATEGORY.Text = ""; ddlsmallcategory.Items.Clear(); ddlsmallcategory.Items.Insert(0, new ListItem("请选择", "")); txtsmallcategory.Text = ""; txtSourceDesc.Value = ""; result = true; } return(result); }