public static DataSourceSchema BuildTableSchema(string connName, string tableName) { string defCon = ConnectionAdmin.getDefaultConnName(); if (!string.IsNullOrEmpty(connName) && connName.Equals(defCon, StringComparison.OrdinalIgnoreCase)) { connName = null; } DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); DataSourceSchema ret = new DataSourceSchema(); ret.ConnectionName = connName; ret.TableName = tableName; ret.SelectCommand = new CommandSchema(); ret.SelectCommand.CommandText = tableName; ret.SelectCommand.CommandType = CommandType.TableDirect; BuildFields(ret); ret.PrimaryKeys = dba.GetPrimaryKeys(tableName); BuildSchemaCommand(ret); //string dsId = tableName; //if (!string.IsNullOrEmpty(connName)) // dsId = connName + "." + dsId; // DataSourceSchemaContainer.Instance().AddItem(dsId, ret); return(ret); }
public static Database GetDb() { string connName = _settings.ConnectionName; if (string.IsNullOrEmpty(connName)) { connName = ConnectionAdmin.getDefaultConnName(); } Database db = DatabaseFactory.CreateDatabase(connName); return(db); }
public static Dictionary <string, string> getConnections() { List <string> conns = ConnectionAdmin.getConnNameList(); Dictionary <string, string> ret = new Dictionary <string, string>(); ret.Add("", "默认"); for (int i = 0; i < conns.Count(); i++) { string conn = conns[i]; ret.Add(conn, conn); } return(ret); }
public static DataSourceSchema BuildTableSchema(string connName, string tableName) { string defCon = ConnectionAdmin.getDefaultConnName(); if (connName.Equals(defCon, StringComparison.OrdinalIgnoreCase)) { connName = null; } string sql = "Select top " + DEF_PAGE_SIZE.ToString() + " * From [" + tableName + "]"; DataSourceSchema ret = CreateTableSchema(tableName, connName, sql); string dsId = tableName; if (!string.IsNullOrEmpty(connName)) { dsId = connName + "." + dsId; } DataSourceSchemaContainer.Instance().AddItem(dsId, ret); return(ret); }
/// <summary> /// 删除连接 /// </summary> /// <param name="connName">连接名</param> public static void deleteConn(string connName) { ConnectionAdmin.deleteConnection(connName); }
public static List <TreeNode> getTree() { List <TreeNode> nodes = new List <TreeNode>(); DataTable tb = ConnectionAdmin.getAllConnInfoTable(); foreach (DataRow row in tb.Rows) { string conn = row["Name"].ToString(); TreeNode connNode = new TreeNode() { nodeType = (int)DataNodeType.DB, label = conn, name = conn, text = conn, attr = new Dictionary <string, string>() { { "conn", conn } }, id = conn }; nodes.Add(connNode); connNode.children = new List <TreeNode>(); List <TreeNode> subNodes = connNode.children; DatabaseAdmin db = null; try { db = DatabaseAdmin.getInstance(conn); } catch (Exception e) { TreeNode errNode = new TreeNode(); errNode.name = "连接错误:" + e.Message; errNode.label = errNode.name; subNodes.Add(errNode); } if (db != null) { //string connName; List <TreeNode> tbNodes = new List <TreeNode>(); List <TreeNode> viewNodes = new List <TreeNode>(); List <TreeNode> spNodes = new List <TreeNode>(); TreeNode tbNode = new TreeNode(); tbNode.nodeType = (int)DataNodeType.TABLE_FOLDER; tbNode.label = DataNodeLabel.TABLE_LABEL; tbNode.name = DataNodeLabel.TABLE_LABEL; tbNode.attr = new Dictionary <string, string>() { { "conn", conn } }; tbNode.id = "Table"; tbNode.text = DataNodeLabel.TABLE_LABEL; tbNode.children = tbNodes; //Table节点 subNodes.Add(tbNode); //获取Table List <string> tbList = null; try { tbList = db.getTableNames(); } catch (Exception e) { tbNode.label = e.Message; continue; } if (tbList == null) { continue; } foreach (string t in tbList) { List <TreeNode> tbChildNode = new List <TreeNode>(); List <TreeNode> trigNode = new List <TreeNode>(); List <TreeNode> contriantNode = new List <TreeNode>(); //表 tbNodes.Add(new TreeNode() { nodeType = (int)DataNodeType.TABLE, label = t, name = t, text = t, attr = new Dictionary <string, string>() { { "conn", conn } }, id = t, children = tbChildNode }); } //存储过程 subNodes.Add(new TreeNode() { attr = new Dictionary <string, string>() { { "conn", conn } }, nodeType = (int)DataNodeType.SP_FOLDER, label = DataNodeLabel.SP_LABEL, name = DataNodeLabel.SP_LABEL, text = DataNodeLabel.SP_LABEL, id = "StoreProcess", children = spNodes }); //存储过程 List <string> spList = db.getProcNames(); if (spList != null) { foreach (string sp in spList) { spNodes.Add(new TreeNode() { attr = new Dictionary <string, string>() { { "conn", conn } }, nodeType = (int)DataNodeType.SP, id = sp, name = sp, text = sp, label = sp }); } } //视图 subNodes.Add(new TreeNode() { attr = new Dictionary <string, string>() { { "conn", conn } }, nodeType = (int)DataNodeType.VIEW_FOLDER, label = DataNodeLabel.VIEW_LABEL, name = DataNodeLabel.VIEW_LABEL, id = "View", text = DataNodeLabel.VIEW_LABEL, children = viewNodes }); //视图 List <string> viewList = db.getViewNames(); if (viewList != null) { foreach (string view in viewList) { viewNodes.Add(new TreeNode() { attr = new Dictionary <string, string>() { { "conn", conn } }, label = view, name = view, id = view, text = view, nodeType = (int)DataNodeType.VIEW }); } } } } return(nodes); }
public static void saveConnDef(ConnDef connDef) { ConnectionAdmin.modifyConnection(connDef.Name, connDef.ConnStr, connDef.Provider); }
public static ConnDef getConnDef(string connName) { return(ConnectionAdmin.getConnDef(connName)); }